From 7eb5c68f25d2a1cbe6ce409ed4c055d99adc3097 Mon Sep 17 00:00:00 2001 From: jxnshi Date: Sun, 29 Dec 2024 14:40:13 +0100 Subject: [PATCH] Remove cattoland tab --- public/cattoland/catto.png | Bin 362 -> 0 bytes public/cattoland/cattoland.js | 245 ------------------------------- public/cattoland/index.html | 4 - public/cattoland/server-down.png | Bin 422 -> 0 bytes public/cattoland/shadow.png | Bin 103 -> 0 bytes public/layout.html | 1 - 6 files changed, 250 deletions(-) delete mode 100644 public/cattoland/catto.png delete mode 100644 public/cattoland/cattoland.js delete mode 100644 public/cattoland/index.html delete mode 100644 public/cattoland/server-down.png delete mode 100644 public/cattoland/shadow.png diff --git a/public/cattoland/catto.png b/public/cattoland/catto.png deleted file mode 100644 index 7c81b4c920b8eedf1115ab4712238fb73b163ee7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 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 diff --git a/public/cattoland/cattoland.js b/public/cattoland/cattoland.js deleted file mode 100644 index ecbd351..0000000 --- a/public/cattoland/cattoland.js +++ /dev/null @@ -1,245 +0,0 @@ -const canvas_width = 600; -const canvas_height = 400; - -let context; - -let events = new Map(); - -let camera = { x: 0, y: 0 }; -let images = new Map(); -let entities = []; -let state; - -let socket; -let socket_state; - -let player_id; -let player; - -let requests_funcs = new Map(); - -const image_load = (path) => { - let image = new Image(); - image.src = path; - - images.set(path, image); -}; - -const entity_play_anim = (entity, anim) => { - entity.anim = anim; - entity.anim_frame = 0; - entity.anim_counter = 0; -}; - -const scene_clear = () => { - entities = []; -}; - -const request = (type, content, func) => { - if (socket_state !== "connected") { - return; - } - - let id = Math.floor(Math.random() * 1000000000); - - while (requests_funcs.has(id)) { - id = Math.floor(Math.random() * 1000000000); - } - - requests_funcs.set(id, func); - - socket.send(`${id} |${type}| ${content}`); -}; - -const handle_message = (event) => { - let data = event.data; - - let id_raw = data.split(' ')[0]; - let id = parseInt(id_raw, 10); - - let content = data.substring(id_raw.length + 1); - - let func = requests_funcs.get(id); - - if (func !== null) { - func(content); - } - - requests_funcs.delete(id); -}; - -const init_game = () => { - scene_clear(); - state = "game"; -}; - -const init_error = () => { - scene_clear(); - - state = "error"; - - let server_down = { - x: 0, - y: 0, - width: 26 * 3, - height: 49 * 3, - anchor: "center", - sheet_rect: { x: 0, y: 0, width: 26, height: 49 }, - image: "server-down.png", - shadow: false, - }; - - entities.push(server_down); -}; - -const socket_connect = () => { - socket = new WebSocket("wss://jxnshi.xyz/cattoland-ws/"); - socket_state = "connecting"; - - socket.onerror = (event) => { - socket_state = "error"; - init_error(); - }; - - socket.onopen = (event) => { - socket_state = "connected"; - - request("Gimme catto pleaz", "", (content) => { - player_id = parseInt(content, 10); - }); - - init_game(); - }; - - socket.onmessage = handle_message; -}; - -const loop = (delta) => { - let events_obj = Object.fromEntries(events); - - request("Take me events", JSON.stringify(events_obj), null); - - { // Update. - if (state === "error") { - if (socket_state === "error") { - socket_connect(); - } - } else if (state === "game") { - request("Update plz", "", (content) => { - entities = JSON.parse(content); - }) - } - } - - { // Render. - let shadow_image = images.get("shadow.png"); - - context.fillStyle = "#FFFFFF"; - context.fillRect(0, 0, 600, 400); - - for (let entity of entities) { - if (entity.image === undefined) { - continue; - } - - // Draw shadow. - if (entity.shadow) { - let width = 16 * 3; - let height = 3 * 3; - - let anchor_x = width / 2; - let anchor_y = height - 3; - - let x = entity.x + canvas_width / 2 + camera.x - anchor_x; - let y = entity.y + canvas_height / 2 + camera.y - anchor_y; - - context.drawImage( - shadow_image, - 0, 0, 16, 3, - x, y, width, height, - ); - } - - { // Draw entity. - let anchor_x; - let anchor_y; - - if (entity.anchor === "bottom") { - anchor_x = entity.width / 2; - anchor_y = entity.height; - } else if (entity.anchor === "center") { - anchor_x = entity.width / 2; - anchor_y = entity.height / 2; - } - - let x = entity.x + canvas_width / 2 + camera.x - anchor_x; - let y = entity.y + canvas_height / 2 + camera.y - anchor_y; - - let image = images.get(entity.image); - - context.drawImage( - image, - entity.sheet_rect.x, entity.sheet_rect.y, entity.sheet_rect.width, entity.sheet_rect.height, - x, y, entity.width, entity.height, - ); - } - } - } - - // Update events. - for (let [event, state] of events) { - if (state === "pressed") { - events.set(event, "down"); - } - - if (state === "released") { - events.set(event, undefined); - } - } - - setTimeout(() => { - window.requestAnimationFrame(loop); - }, 1000 / 60); -}; - -const main = () => { - image_load("catto.png"); - image_load("server-down.png"); - image_load("shadow.png"); - - socket_connect(); - - 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); -}; - -document.onkeydown = (event) => { - let old_event = events.get(event.code); - - if (old_event === "pressed" || old_event === "down") { - return; - } - - events.set(event.code, "pressed"); -}; - -document.onkeyup = (event) => { - events.set(event.code, "released"); -}; - -window.onload = main; diff --git a/public/cattoland/index.html b/public/cattoland/index.html deleted file mode 100644 index 491064c..0000000 --- a/public/cattoland/index.html +++ /dev/null @@ -1,4 +0,0 @@ - - diff --git a/public/cattoland/server-down.png b/public/cattoland/server-down.png deleted file mode 100644 index a03a17f6a96137c0fd839f04f0452ba3585512d1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 422 zcmV;X0a^ZuP)Px$U`a$lR9J=WSIZKEAPmep{{Jthhl-?;JP>T_j5(o(Y!;FQK}1Ynu$732c^nIX z83(`{s61H4%;EPIpd7C)=O|d#PmY_6WJpjSBPxE|9Gj5}$ojiya<1AlNCI9ci%$e! z<}C#^+@sA$`e$pEnU8zqP6p}{ID59ctMMWBj1JamY(>=woygcU6)$YqGtA@?eKapw zjA{mXl(Q1l%}6wBi5W8**&_i~01s7{VbLsA!>`!V)qu=3(}W~R`P%m=Tq+@~tj6Bl zy#mYljLx+JTJ!4(Yh{(xGyrYCEp{#MMpk%7$e%|lVHwjtj}(*iy+WR_;Hq)$ diff --git a/public/cattoland/shadow.png b/public/cattoland/shadow.png deleted file mode 100644 index 3a5f387626bffeb3a58d50f878bd40983965cdc4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 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{ diff --git a/public/layout.html b/public/layout.html index 5654d39..9560178 100644 --- a/public/layout.html +++ b/public/layout.html @@ -13,7 +13,6 @@

Projects

-- 2.49.0