Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions game.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
game = class('game')

-- CONSTANTS
ORIGINAL_STEP_SIZE = 8 -- this is excessively fast on a modern computer
-- anything above is dangerously fast, as it makes the cursor fly across screen
FPS_DANGER = 60

function game:initialize()

self.screen = {}
Expand Down Expand Up @@ -118,25 +123,41 @@ function game:update(dt)
end

if love.keyboard.isDown('up') and self.cursor.y > 0 then
self.cursor.y = self.cursor.y - 8
local fps = love.timer.getFPS()
if fps > FPS_DANGER then
local step_size = ORIGINAL_STEP_SIZE / love.timer.getFPS() * 60
self.cursor.y = self.cursor.y - step_size
end
elseif self.cursor.y < 0 then
self.cursor.y = 0
end

if love.keyboard.isDown('right') and self.cursor.x < self.screen.width then
self.cursor.x = self.cursor.x + 8
local fps = love.timer.getFPS()
if fps > FPS_DANGER then
local step_size = ORIGINAL_STEP_SIZE / love.timer.getFPS() * 60
self.cursor.x = self.cursor.x + step_size
end
elseif self.cursor.x > self.screen.width then
self.cursor.x = self.screen.width
end

if love.keyboard.isDown('down') and self.cursor.y < (self.bombtower.y - self.cursor.height) then
self.cursor.y = self.cursor.y + self.cursor.height
local fps = love.timer.getFPS()
if fps > FPS_DANGER then
local step_size = ORIGINAL_STEP_SIZE / love.timer.getFPS() * 60
self.cursor.y = self.cursor.y + step_size
end
elseif self.cursor.y > self.bombtower.y then
self.cursor.y = self.bombtower.y
end

if love.keyboard.isDown('left') and self.cursor.x > 0 then
self.cursor.x = self.cursor.x - 8
local fps = love.timer.getFPS()
if fps > FPS_DANGER then
local step_size = ORIGINAL_STEP_SIZE / love.timer.getFPS() * 60
self.cursor.x = self.cursor.x - step_size
end
elseif self.cursor.x < 0 then
self.cursor.x = 0
end
Expand Down Expand Up @@ -302,4 +323,4 @@ function launchMissiles()
game:launchMissile()
end

end
end