浏览代码

Fixed explosion detection

tags/v0.0.6_dev
Madiwka 3 年前
父节点
当前提交
4dbfa5cb5a
共有 2 个文件被更改,包括 27 次插入15 次删除
  1. +6
    -1
      src/class/FX.lua
  2. +21
    -14
      src/class/Player.lua

+ 6
- 1
src/class/FX.lua 查看文件

@@ -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 查看文件

@@ -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)) table.insert(effects, FX("flash", self.x, self.y, self))
self:reset() self.exploding = true
self.landingspeed = 0 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() if not self.exploding then
self:flightControls() self:gravity()
self:updatePosition() 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) if not self.exploding then
love.graphics.polygon("fill", vertices) love.graphics.setColor(0.5, 0.5, 0.7)
love.graphics.polygon("fill", vertices)


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


-- Directional Circle (temporary until actual rotatable ship texture is made) -- 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) 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

||||||
x
 
000:0
正在加载...
取消
保存