add retrieving of bolts
This commit is contained in:
parent
6ae7e3b1a4
commit
96d4d1f7d3
@ -80,4 +80,13 @@ function Player:pressed_shoot()
|
||||
end
|
||||
end
|
||||
|
||||
function Player:pressed_retrieve_bolt()
|
||||
if self.controls == "keyboard" then
|
||||
return love.keyboard.isDown("r")
|
||||
elseif self.controls == "joystick" and self.joystick then
|
||||
return false
|
||||
-- return self.joystick:isGamepadDown("leftshoulder")
|
||||
end
|
||||
end
|
||||
|
||||
return Player
|
||||
|
@ -98,6 +98,14 @@ function MainState:start_match()
|
||||
self:create_player("joystick", Vec(600, 300))
|
||||
end
|
||||
|
||||
function MainState:find_bolt_by_player(player)
|
||||
for _, bolt in ipairs(self.bolts) do
|
||||
if bolt.shot_by == player then
|
||||
return bolt
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function MainState:update(dt)
|
||||
local now = love.timer.getTime()
|
||||
for _, bolt in ipairs(self.bolts) do
|
||||
@ -129,6 +137,15 @@ function MainState:update(dt)
|
||||
end
|
||||
end
|
||||
|
||||
if not player.has_bolt and player:pressed_retrieve_bolt() then
|
||||
local bolt = self:find_bolt_by_player(player)
|
||||
if bolt and bolt.dead then
|
||||
player.pickup_bolt_attributes = nil
|
||||
player.has_bolt = true
|
||||
self:destroy_bolt(bolt)
|
||||
end
|
||||
end
|
||||
|
||||
local move_dir = player:get_move_dir()
|
||||
local acc = move_dir * 1700
|
||||
player.vel = player.vel + acc * dt
|
||||
|
Loading…
Reference in New Issue
Block a user