diff options
author | ubq323 <ubq323@ubq323.website> | 2022-03-30 22:17:29 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2022-03-30 22:17:29 +0100 |
commit | 9120ff684d62691c04564cc8a038c80a85b91bce (patch) | |
tree | b59331677793ba1ea306360a9d7c151449c0dd19 /src/player.lua | |
parent | 2ebd13947d71d78892690c45690fa49157ac4612 (diff) |
more thing
Diffstat (limited to 'src/player.lua')
-rw-r--r-- | src/player.lua | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/player.lua b/src/player.lua new file mode 100644 index 0000000..16a54dd --- /dev/null +++ b/src/player.lua @@ -0,0 +1,38 @@ +local player = { + x = 250, + y = 250, +} + +local SPEED = 170 +local SPRINT_SPEED = 280 + +function player:move(dt,world) + local speed = + (love.keyboard.isScancodeDown("lshift","rshift") and SPRINT_SPEED or SPEED) + local vx = 0 + local vy = 0 + + if love.keyboard.isScancodeDown('w','up') then vy = vy - 1 end + if love.keyboard.isScancodeDown('s','down') then vy = vy + 1 end + if love.keyboard.isScancodeDown('a','left') then vx = vx - 1 end + if love.keyboard.isScancodeDown('d','right') then vx = vx + 1 end + + local sf = math.sqrt(vx*vx+vy*vy) + if sf == 0 then return end + vx = vx / sf + vy = vy / sf + + local tx = self.x + vx * dt * speed + local ty = self.y + vy * dt * speed + + local ax, ay = world:move("player",tx,ty) + self.x = ax + self.y = ay +end + +function player:draw() + love.graphics.setColor(0.91,0.62,0) + love.graphics.rectangle("fill", self.x,self.y, 10,10) +end + +return player |