From 96d4d1f7d3ac4d9ed87e47e8c59f7063402ed1e6 Mon Sep 17 00:00:00 2001 From: Rokas Puzonas Date: Tue, 27 Dec 2022 19:20:22 +0200 Subject: [PATCH] add retrieving of bolts --- src/player.lua | 9 +++++++++ src/states/main.lua | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/player.lua b/src/player.lua index c9aefd8..a21983f 100644 --- a/src/player.lua +++ b/src/player.lua @@ -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 diff --git a/src/states/main.lua b/src/states/main.lua index 5028aac..c080ab5 100644 --- a/src/states/main.lua +++ b/src/states/main.lua @@ -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