diff options
author | Indrajith K L | 2021-08-03 23:06:26 +0530 |
---|---|---|
committer | Indrajith K L | 2021-08-03 23:06:26 +0530 |
commit | c3c5832587bfd36d12790537c5acb36c02574ddb (patch) | |
tree | 8890b34a79d411180284ddb8960814482de2997b /entities/player_entity.wren | |
parent | 705886d371cf2cfa619b321c0d87caca0773a789 (diff) | |
download | rebirth-wren-c3c5832587bfd36d12790537c5acb36c02574ddb.tar.gz rebirth-wren-c3c5832587bfd36d12790537c5acb36c02574ddb.tar.bz2 rebirth-wren-c3c5832587bfd36d12790537c5acb36c02574ddb.zip |
Failed attempt to build collision detection
Diffstat (limited to 'entities/player_entity.wren')
-rw-r--r-- | entities/player_entity.wren | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/entities/player_entity.wren b/entities/player_entity.wren index 194bb5f..c547e4e 100644 --- a/entities/player_entity.wren +++ b/entities/player_entity.wren @@ -2,26 +2,48 @@ import "graphics" for ImageData, Canvas import "./controls" for Controls import "./config" for Config class Player { - construct new(x,y) { + construct new(x,y, gameState) { + __gameState = gameState _x = x _y = y _playerSprite = ImageData.loadFromFile("assets/sprites/player.png") } + x { _x } + y { _y } + w { 16 } + h { 16 } + update() { - if(Controls.isKeyDown(Config.KeyboardConstants["UP"])) { + + var collided = __gameState.checkCollision(this) + + if(Controls.isKeyDown(Config.KeyboardConstants["UP"]) && !collided) { _y = _y - 1 + } else if(Controls.isKeyDown(Config.KeyboardConstants["UP"]) && collided){ + _y = _y + 1 } - if(Controls.isKeyDown(Config.KeyboardConstants["DOWN"])) { + + if(Controls.isKeyDown(Config.KeyboardConstants["DOWN"]) && !collided) { _y = _y + 1 + } else if(Controls.isKeyDown(Config.KeyboardConstants["DOWN"]) && collided){ + _y = _y - 1 } - if(Controls.isKeyDown(Config.KeyboardConstants["LEFT"])) { + + if(Controls.isKeyDown(Config.KeyboardConstants["LEFT"]) && !collided) { _x = _x - 1 + } else if(Controls.isKeyDown(Config.KeyboardConstants["LEFT"]) && collided){ + _x = _x + 1 } - if(Controls.isKeyDown(Config.KeyboardConstants["RIGHT"])) { + + if(Controls.isKeyDown(Config.KeyboardConstants["RIGHT"]) && !collided) { _x = _x + 1 + } else if(Controls.isKeyDown(Config.KeyboardConstants["RIGHT"]) && collided){ + _x = _x - 1 } + + } draw(dt) { |