Browse Source

Fixed explosion detection

tags/v0.0.6_dev
Madiwka 2 years ago
parent
commit
4dbfa5cb5a
2 changed files with 27 additions and 15 deletions
  1. +6
    -1
      src/class/FX.lua
  2. +21
    -14
      src/class/Player.lua

+ 6
- 1
src/class/FX.lua View File

@@ -1,13 +1,14 @@
-- Effect object -- Effect object
FX = Class {} FX = Class {}


function FX:init(type, x, y)
function FX:init(type, x, y, target)
self.type = type self.type = type
self.id = #effects self.id = #effects
self.frame = 0 self.frame = 0
self.x = x self.x = x
self.y = y self.y = y
self.finished = false -- So that main can kill it later. For some reason it does not want to kill itself. self.finished = false -- So that main can kill it later. For some reason it does not want to kill itself.
self.target = target
end end




@@ -16,6 +17,10 @@ function FX:flash()
love.graphics.circle("fill", self.x, self.y, self.frame) love.graphics.circle("fill", self.x, self.y, self.frame)
self.frame = self.frame + 100/love.timer.getFPS() self.frame = self.frame + 100/love.timer.getFPS()
--debug("Frame is " .. self.frame) --debug("Frame is " .. self.frame)
if self.frame > 500 then
self.target.exploding = false
self.target:reset()
end
if self.frame > 1000 then if self.frame > 1000 then
self.finished = true self.finished = true
end end


+ 21
- 14
src/class/Player.lua View File

@@ -26,6 +26,9 @@ function Player:init(tempX, tempY)


-- Rotation: -- Rotation:
self.angle = calc.pi/2 self.angle = calc.pi/2

-- Status:
self.exploding = false
end end




@@ -153,11 +156,11 @@ end


function Player:hasCrashed() --Testing function, see if a player is inside a planet function Player:hasCrashed() --Testing function, see if a player is inside a planet
--debug(self.landingspeed) --debug(self.landingspeed)
if self.landingspeed > self.impacttolerance then
if self.landingspeed > self.impacttolerance and not self.exploding then
-- Add explosion effect? -- Add explosion effect?
table.insert(effects, FX("flash", self.x, self.y))
self:reset()
self.landingspeed = 0
table.insert(effects, FX("flash", self.x, self.y, self))
self.exploding = true
return
end end
end end


@@ -196,15 +199,17 @@ end


function Player:update(dt) function Player:update(dt)
--debug(self.warpspeed) --debug(self.warpspeed)
if self.angle > calc.pi*2 then if self.angle > calc.pi*2 then
self.angle = 0 self.angle = 0
elseif self.angle < 0 then elseif self.angle < 0 then
self.angle = calc.pi*2 self.angle = calc.pi*2
end end
self:gravity()
self:flightControls()
self:updatePosition()
if not self.exploding then
self:gravity()
self:flightControls()
self:updatePosition()
end
end end


function Player:draw() function Player:draw()
@@ -221,12 +226,14 @@ function Player:draw()
-- Right Bottom -- Right Bottom
x+dist, y+dist x+dist, y+dist
} }
love.graphics.setColor(0.5, 0.5, 0.7)
love.graphics.polygon("fill", vertices)
if not self.exploding then
love.graphics.setColor(0.5, 0.5, 0.7)
love.graphics.polygon("fill", vertices)


love.graphics.setColor(1, 0, 0)
love.graphics.circle("fill", x, y, 5, 20)
love.graphics.setColor(1, 0, 0)
love.graphics.circle("fill", x, y, 5, 20)


-- Directional Circle (temporary until actual rotatable ship texture is made)
love.graphics.circle("fill", x+dist*(1/zoomlevel*2)*math.cos(self.angle), y-dist*(1/zoomlevel*2)*math.sin(self.angle), 1/zoomlevel*2)
-- Directional Circle (temporary until actual rotatable ship texture is made)
love.graphics.circle("fill", x+dist*(1/zoomlevel*2)*math.cos(self.angle), y-dist*(1/zoomlevel*2)*math.sin(self.angle), 1/zoomlevel*2)
end
end end

Loading…
Cancel
Save