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