From f4604624e7cb62a4c1f9cd4efd1447a9ca4b416d Mon Sep 17 00:00:00 2001 From: jxnshi Date: Sat, 7 Dec 2024 20:36:43 +0100 Subject: [PATCH] Working on cattoland --- public/catto.png | Bin 358 -> 0 bytes public/cattoland/catto.png | Bin 0 -> 362 bytes public/cattoland/cattoland.js | 114 +++++++++++++++++++++++++++++ public/cattoland/shadow.png | Bin 0 -> 103 bytes src/app/views/cattoland.zig | 8 ++ src/app/views/cattoland/index.zmpl | 4 + src/app/views/layouts/main.zmpl | 1 + 7 files changed, 127 insertions(+) delete mode 100644 public/catto.png create mode 100644 public/cattoland/catto.png create mode 100644 public/cattoland/cattoland.js create mode 100644 public/cattoland/shadow.png create mode 100644 src/app/views/cattoland.zig create mode 100644 src/app/views/cattoland/index.zmpl diff --git a/public/catto.png b/public/catto.png deleted file mode 100644 index 071a356e56bf0e857b37b0929a3c94982d1b5745..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 358 zcmeAS@N?(olHy`uVBq!ia0vp^3qY8I4M=vMPuB%fjKx9jP7LeL$-D%z6+B%WLn`LH zz3$D|q9DL}Anjd!dYUrZNA|~SmS`Dnb9()Z)rp1SL(tD9Z9huRR0=JaQ><58$}3nX zf8Zj+(`Q=poy)|Wl$4ZA&+kr{@?psov#){qvRh8im-}wK(2B*M>B`;ekGyIj+a4@r zu)XOv{eh#)7g;B>I^KYn(y^MA+ut$R@lJS9xWu}_oY6~JdvWfJNAKGw6h-AZhwWdT z<(V>dy2#q^zpNx~f1TUYe=b?6Ji4Ikcc@nA>d0LYH>;i-ZoG4+`Z&-}v;hsBwTzX^ V`Ys%}=b;0#!PC{xWt~$(6979=ZbAS6 diff --git a/public/cattoland/catto.png b/public/cattoland/catto.png new file mode 100644 index 0000000000000000000000000000000000000000..7c81b4c920b8eedf1115ab4712238fb73b163ee7 GIT binary patch literal 362 zcmV-w0hRuVP)Px$BuPX;R9J=WRWS~OFbq7SPGv81`Tw7~_W@nqg%roJi4)P5fs;_IBzI?<1b`DK zPJ9{c#E0-3_7>D!W==dAAI7iNfL1|PPZEKOJ&m4*X>Q@^RuUD6*u{Z1B;u|wo-Osq`?dgQ%oQQYzH}ngCnWxgo?;+H` z(^xBb&U$p;U;JxVfOMD4P4Y+?on5z)6(7o<)fipd3qSXN1BNUNIm?wWWB>pF07*qo IM6N<$f~QiNcmMzZ literal 0 HcmV?d00001 diff --git a/public/cattoland/cattoland.js b/public/cattoland/cattoland.js new file mode 100644 index 0000000..c8cb6a6 --- /dev/null +++ b/public/cattoland/cattoland.js @@ -0,0 +1,114 @@ +const canvas_width = 600; +const canvas_height = 400; + +const tile_size = 48; + +const camera_init = () => { + return { + x: 0, + y: 0, + }; +}; + +let context; + +let camera = camera_init(); +let images = new Map(); +let entities = []; + +const image_load = (images, path) => { + let image = new Image(); + image.src = path; + + images.set(path, image); +}; + +const entity_init = () => { + return { + x: 0, + y: 0, + sheet_x: 0, + sheet_y: 0, + image: undefined, + }; +}; + +const entity_draw = () => { + +}; + +const catto_init = () => { + let entity = entity_init(); + entity = images.get("cattoland/catto.png"); + + return entity; +}; + +const main = () => { + image_load(images, "cattoland/catto.png"); + + entities.push(catto_init()); + + let canvas = document.createElement("canvas") + + { // Add canvas to DOM. + canvas.width = canvas_width; + canvas.height = canvas_height; + + let script = document.getElementsByTagName("script")[0]; + script.insertAdjacentElement("afterend", canvas); + } + + context = canvas.getContext("2d"); + + context.webkitImageSmoothingEnabled = false; + context.mozImageSmoothingEnabled = false; + context.imageSmoothingEnabled = false; + + window.requestAnimationFrame(loop); +}; + +const loop = (delta) => { + context.fillStyle = "#FFFFFF"; + context.fillRect(0, 0, 600, 400); + + for (let entity of entities) { + { // Draw shadow. + let anchor_x = tile_size / 2; + let anchor_y = tile_size - 3; + + let x = entity.x + canvas_width / 2 + camera.x - anchor_x; + let y = entity.y + canvas_height / 2 + camera.y - anchor_y; + + let sheet_x = 0 * sheet_tile_size; + let sheet_y = 0 * sheet_tile_size; + + context.drawImage( + catto_image, + sheet_x, sheet_y, sheet_tile_size, sheet_tile_size, + x, y, tile_size, tile_size, + ); + } + + { // Draw catto. + let anchor_x = tile_size / 2; + let anchor_y = tile_size; + + let x = catto.x + canvas_width / 2 + camera.x - anchor_x; + let y = catto.y + canvas_height / 2 + camera.y - anchor_y; + + let sheet_x = catto.sheet_x * sheet_tile_size; + let sheet_y = catto.sheet_y * sheet_tile_size; + + context.drawImage( + catto_image, + sheet_x, sheet_y, sheet_tile_size, sheet_tile_size, + x, y, tile_size, tile_size, + ); + } + } + + window.requestAnimationFrame(loop); +}; + +window.onload = main; diff --git a/public/cattoland/shadow.png b/public/cattoland/shadow.png new file mode 100644 index 0000000000000000000000000000000000000000..3a5f387626bffeb3a58d50f878bd40983965cdc4 GIT binary patch literal 103 zcmeAS@N?(olHy`uVBq!ia0vp^0zk~n!3HE}ZR`&LQjEnx?oJHr&dIz4auhvX978x} zCZ{+sy?gi0Te5?}y8K;F+eXRGt1a9HL9dt?CirmH?JZ;r1S)3mboFyt=akR{0M@n~ AQ2+n{ literal 0 HcmV?d00001 diff --git a/src/app/views/cattoland.zig b/src/app/views/cattoland.zig new file mode 100644 index 0000000..84c5f44 --- /dev/null +++ b/src/app/views/cattoland.zig @@ -0,0 +1,8 @@ +const std = @import("std"); +const jetzig = @import("jetzig"); + +pub const layout = "main"; + +pub fn index(request: *jetzig.Request, _: *jetzig.Data) !jetzig.View { + return request.render(.ok); +} diff --git a/src/app/views/cattoland/index.zmpl b/src/app/views/cattoland/index.zmpl new file mode 100644 index 0000000..491064c --- /dev/null +++ b/src/app/views/cattoland/index.zmpl @@ -0,0 +1,4 @@ + + diff --git a/src/app/views/layouts/main.zmpl b/src/app/views/layouts/main.zmpl index bd28d39..dac9e15 100644 --- a/src/app/views/layouts/main.zmpl +++ b/src/app/views/layouts/main.zmpl @@ -14,6 +14,7 @@

Projets

-- 2.49.0