From 8278445e881e64510257ebff0ed89097526d5e86 Mon Sep 17 00:00:00 2001 From: biglyderv Date: Mon, 25 Nov 2024 14:14:20 -0500 Subject: [PATCH] add map --- common/game_basic.js | 2 + common/player.js | 5 +- static/assets/map.svg | 130 ++++++++++++++++++++++++++++++++++++++++++ static/js/index.js | 5 +- 4 files changed, 140 insertions(+), 2 deletions(-) create mode 100644 static/assets/map.svg diff --git a/common/game_basic.js b/common/game_basic.js index 9bdc673..93b59d2 100644 --- a/common/game_basic.js +++ b/common/game_basic.js @@ -11,6 +11,8 @@ class GameBasic { this.player = player; this.entities = entities; + + this.width = this.height = 2500; } main() { let { entities } = this; diff --git a/common/player.js b/common/player.js index 2ed49d1..9a106ab 100644 --- a/common/player.js +++ b/common/player.js @@ -50,7 +50,7 @@ Player.prototype.bump = function () { } Player.prototype.handleTick = function (game) { - let { entities } = game; + let { entities, width, height } = game; let ent = this; @@ -59,6 +59,9 @@ Player.prototype.handleTick = function (game) { ent.pos.x += ent.vel.x; ent.pos.y += ent.vel.y; + ent.pos.x = Math.max(Math.min(ent.pos.x, width / 2), - width / 2); + ent.pos.y = Math.max(Math.min(ent.pos.y, height / 2), - height / 2); + ent.vel.x *= 0.9; ent.vel.y *= 0.9; diff --git a/static/assets/map.svg b/static/assets/map.svg new file mode 100644 index 0000000..e6d3e60 --- /dev/null +++ b/static/assets/map.svg @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/static/js/index.js b/static/js/index.js index 3de6f66..a5ba318 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -5,6 +5,7 @@ const cs = 1024; const assets = [ 'assets/player.svg', 'assets/head.svg', + 'assets/map.svg' ]; class Game extends GameBasic { @@ -27,7 +28,7 @@ class Game extends GameBasic { this.assetsIn = assetsIn; } render() { - let { ctx, assetsIn, entities, player } = this; + let { ctx, assetsIn, entities, player, width, height } = this; ctx.clearRect(0, 0, cs, cs); @@ -35,6 +36,8 @@ class Game extends GameBasic { ctx.translate(player.camera.x + cs / 2, player.camera.y + cs / 2); + ctx.drawImage(assetsIn[2],-width/2,-height/2,width,height); + for (let ent of entities) { if (ent.health <= 0) continue;