Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add 1..9 speeds and add stamina to Player so movement gets slower wit…

…h less stamina
  • Loading branch information...
commit 0b30f6b2ccdea48852d6a12dd8c6b0fccd5b482d 1 parent 8cd47cb
@TomK32 authored
Showing with 61 additions and 10 deletions.
  1. +2 −1  game_controller.lua
  2. +6 −7 main.lua
  3. +53 −2 player_controller.lua
View
3  game_controller.lua
@@ -28,7 +28,8 @@ GameController:include({
self.control_map.keyboard.on_press[' '] = 'toggleGameStatePaused'
end,
- update = function(self)
+ update = function(self, dt)
+ self.game_state.player:update(dt)
end,
designate = function(self)
View
13 main.lua
@@ -25,11 +25,7 @@ function love.update(dt)
if game_state.focus == 'inspector' or game_state.focus == 'main' then
if love.keyboard.isDown('up', 'down','left', 'right', 'kp1', 'kp2', 'kp3', 'kp4', 'kp6', 'kp7', 'kp8', 'kp9') then
if dt_since_last_move + dt > 0.1 then
- if love.keyboard.isDown('rshift', 'lshift') then
- moves = 5
- else
- moves = 1
- end
+ moves = 1
movements = {
up = { x = 0, y = - moves },
kp8 = { x = 0, y = - moves },
@@ -48,7 +44,7 @@ function love.update(dt)
if love.keyboard.isDown(key) then
dt_since_last_move = 0
moved = true
- game_state.player:move(m)
+ game_state.player:move(m, love.keyboard.isDown('rshift', 'lshift'))
end
end
else
@@ -61,11 +57,14 @@ function love.update(dt)
if game_state.paused then
return
end
- game_controller:update()
+ game_controller:update(dt)
end
function love.keypressed(key, unicode)
dt_since_last_move = 1 -- to allow rapid key hitting
+ if unicode >= 49 and unicode < 59 then
+ game_state.player:setSpeed(unicode - 48)
+ end
if game_controller.active_controller then
game_controller.active_controller:keypressed(key, unicode)
end
View
55 player_controller.lua
@@ -2,12 +2,55 @@
PlayerController = class("PlayerController")
function PlayerController:initialize(game_state)
+ self.speed = 5 -- 5 gets you to the next field, 4 won't yet, 10 is two fields but exhausting
+ self.stamina = 100
self.position = {x = 0, y = 0}
+ self.tile_position = 0 -- depending on the speed the player might not yet reach the next field
self.game_state = game_state
+ self.offset = {}
+ self.sprint = false
end
-function PlayerController:move(offset)
- gui_main.map_view:moveCursor(offset)
+
+function PlayerController:move(offset, sprint)
+ self.offset = offset
+ self.sprint = sprint
+end
+
+function PlayerController:update(dt)
+ self.stamina = self.stamina + 1
+
+ local s = self.speed
+ -- FIXME sprint doesn't work yet
+ if self.sprint then
+ s = 10
+ self.stamina = self.stamina - 3
+ end
+ self.sprint = false
+
+ -- exhausted, go only 1/10th
+ if self.stamina <= 10 then
+ self.tile_position = self.tile_position + 1
+ return
+ elseif self.stamina > 100 then
+ self.stamina = 100
+ end
+ if not self.offset then
+ return
+ end
+ self.stamina = self.stamina - s
+ self.tile_position = self.tile_position + s * dt
+ if self.tile_position >= 10 and self.stamina > 10 then
+ gui_main.map_view:moveCursor({x = self.offset.x * 2, y = self.offset.y * 2})
+ self.tile_position = self.tile_position % 10
+ elseif self.tile_position > 5 then
+ self.tile_position = self.tile_position - 5
+ gui_main.map_view:moveCursor(self.offset)
+ else
+ return
+ end
+ self.offset = nil
+
if self.next_waypoint and
self.position.x == self.next_waypoint.position.x and
self.position.y == self.next_waypoint.position.y then
@@ -20,6 +63,14 @@ function PlayerController:move(offset)
end
end
end
+
+function PlayerController:setSpeed(speed)
+ if speed < 1 or speed > 10 then
+ return false
+ end
+ self.speed = speed
+end
+
function PlayerController.finishScreen()
love.graphics.print('AWESOME, you reached your target', love.graphics.getWidth() / 2 - 120, love.graphics.getHeight() / 2 - 5)
love.graphics.print('Press [q] to quit', love.graphics.getWidth() / 2 - 40, love.graphics.getHeight() / 2 + 25)
Please sign in to comment.
Something went wrong with that request. Please try again.