From 7101277cb8fc8bae7abdf78818ac3af7a4076edb Mon Sep 17 00:00:00 2001 From: Sky Johnson Date: Fri, 11 Oct 2024 18:27:28 -0500 Subject: [PATCH] Add collision detection, initial player render --- database/auth.db | Bin 45056 -> 45056 bytes database/live.db | Bin 188416 -> 188416 bytes public/assets/css/dragon.css | 2 ++ src/helpers.php | 2 +- templates/components/left_nav.php | 2 +- templates/pages/world/base.php | 13 +++++++++++++ 6 files changed, 17 insertions(+), 2 deletions(-) diff --git a/database/auth.db b/database/auth.db index b9667c8a2676e9884a334461e3afa31e6dafeb22..26b28c44c1188afa6f619aa16bafaf6be5b1c067 100644 GIT binary patch delta 16 YcmZp8z|`=7X~QL1MxM==WpyV306pmj(*OVf delta 16 YcmZp8z|`=7X~QL1M&`|zWpyV306nt?$^ZZW diff --git a/database/live.db b/database/live.db index ef11fe4b7e66dbe70523aa0ca43573c654935bce..db1b7c49cfdd5082b3807372d89450bf0f6319a7 100644 GIT binary patch delta 87 zcmZoTz})~uEsR^3_U~t6XPtguQRZKWq~GKxX)w&0CPALzW@LL delta 87 zcmZoTz})~uEsR^3_U~unuQRZKWq~GKxX)w&0CnmV%>V!Z diff --git a/public/assets/css/dragon.css b/public/assets/css/dragon.css index 6a2a0c9..43e0c3e 100644 --- a/public/assets/css/dragon.css +++ b/public/assets/css/dragon.css @@ -35,6 +35,7 @@ body { text-align: center; border-radius: 3px; user-select: none; + -webkit-user-select: none; text-decoration: none; transition: opacity 0.1s ease, background-color 0.1s ease, color 0.1s ease, background 0.1s ease; -webkit-tap-highlight-color: transparent; @@ -529,6 +530,7 @@ body::-webkit-scrollbar-thumb { height: 440px; image-rendering: pixelated; image-rendering: crisp-edges; + image-rendering: -webkit-optimize-contrast; background-color: rgba(0, 0, 0, 0.5); } } diff --git a/src/helpers.php b/src/helpers.php index a17b027..93c6d90 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -275,7 +275,7 @@ function ajax_only() */ function json_response($data) { - header('Content-Type: application/json'); + header('Content-Type: application/json; charset=utf-8'); echo json_encode($data); exit; } diff --git a/templates/components/left_nav.php b/templates/components/left_nav.php index a7dbb11..5e0c119 100644 --- a/templates/components/left_nav.php +++ b/templates/components/left_nav.php @@ -11,7 +11,7 @@ foreach (links as $link): ?> - + diff --git a/templates/pages/world/base.php b/templates/pages/world/base.php index d7e7095..af5964a 100644 --- a/templates/pages/world/base.php +++ b/templates/pages/world/base.php @@ -76,6 +76,18 @@ }[e.key]; if (direction !== undefined) { + // If player would move outside map bounds, return early + if (direction === 0 && player.y === 0) return; + if (direction === 1 && player.y === map.length - 1) return; + if (direction === 2 && player.x === 0) return; + if (direction === 3 && player.x === map[0].length - 1) return; + + // Return early if the player is trying to move into a wall + if (direction === 0 && map[player.y - 1][player.x] === 2) return; + if (direction === 1 && map[player.y + 1][player.x] === 2) return; + if (direction === 2 && map[player.y][player.x - 1] === 2) return; + if (direction === 3 && map[player.y][player.x + 1] === 2) return; + // Execute a POST request to /move. If successful, the server will return a new x,y position fetch('/move', { method: 'POST', @@ -156,6 +168,7 @@ } window.addEventListener('load', () => { + map[player.y][player.x] = 1 updateCanvasSize() setupEventListeners() render()