tank
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
Ground = {}
|
||||
class("Ground").extends(Graphics.sprite)
|
||||
|
||||
local groundImage = playdate.graphics.image.new("assets/sprites/groundFin")
|
||||
local groundImage = Graphics.image.new("assets/sprites/groundFin")
|
||||
|
||||
function Ground:init(x, y, player)
|
||||
Ground.super.init(self, groundImage)
|
||||
@@ -24,6 +24,12 @@ function Ground:setMoveSpeed(speed)
|
||||
end
|
||||
|
||||
function Ground:update()
|
||||
|
||||
-- Stop ground
|
||||
if Ground.moveSpeed == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
-- Speedup when player is moving right
|
||||
if Ground.player.isMovingRight() == false then
|
||||
Ground.moveSpeed = 0.2
|
||||
|
@@ -99,6 +99,24 @@ function Player:changeToRunState(direction)
|
||||
end
|
||||
end
|
||||
|
||||
function Player:boom(collisionObject)
|
||||
Player.dead = true
|
||||
self:changeState("boom")
|
||||
|
||||
local particleB = ParticlePoly(self.x, self.y)
|
||||
particleB:setThickness(2)
|
||||
particleB:setAngular(-15, 15)
|
||||
particleB:setSize(1, 2)
|
||||
particleB:setSpeed(1, 3)
|
||||
particleB:setMode(Particles.modes.STAY)
|
||||
particleB:setBounds(0, 0, 400, 240)
|
||||
particleB:setColour(Graphics.kColorXOR)
|
||||
particleB:add(20)
|
||||
if collisionObject then
|
||||
collisionObject:remove()
|
||||
end
|
||||
end
|
||||
|
||||
function Player:handleMovementAndCollisions()
|
||||
if Player.dead then
|
||||
return
|
||||
@@ -134,23 +152,24 @@ function Player:handleMovementAndCollisions()
|
||||
end
|
||||
|
||||
if collisionTag == 3 then -- Ground
|
||||
Player.dead = true
|
||||
self:changeState("boom")
|
||||
self:boom()
|
||||
return
|
||||
elseif collisionTag == 154 then -- Baleba
|
||||
Player.dead = true
|
||||
self:changeState("boom")
|
||||
-- self:boom(collisionObject)
|
||||
return
|
||||
elseif collisionTag == 2 then -- Tank
|
||||
self:boom()
|
||||
|
||||
local particleB = ParticlePoly(self.x, self.y)
|
||||
particleB:setThickness(2)
|
||||
particleB:setAngular(-15, 15)
|
||||
particleB:setSize(1, 2)
|
||||
particleB:setSpeed(1, 3)
|
||||
particleB:setMode(Particles.modes.STAY)
|
||||
particleB:setBounds(0, 0, 400, 240)
|
||||
particleB:setColour(Graphics.kColorXOR)
|
||||
particleB:add(20)
|
||||
collisionObject:remove()
|
||||
local particleC = ParticlePoly(collisionObject.x, collisionObject.y)
|
||||
particleC:setThickness(5)
|
||||
particleC:setAngular(-15, 15)
|
||||
particleC:setSize(1, 5)
|
||||
particleC:setSpeed(1, 3)
|
||||
particleC:setMode(Particles.modes.STAY)
|
||||
particleC:setBounds(0, 0, 400, 240)
|
||||
particleC:setColour(Graphics.kColorXOR)
|
||||
particleC:add(50)
|
||||
collisionObject:fadeout()
|
||||
return
|
||||
end
|
||||
end
|
||||
|
55
source/scripts/tankSprite.lua
Normal file
55
source/scripts/tankSprite.lua
Normal file
@@ -0,0 +1,55 @@
|
||||
Tank = {}
|
||||
|
||||
class("Tank").extends(Graphics.sprite)
|
||||
|
||||
function Tank:init(x, y, player, ground)
|
||||
self.tankImage = Graphics.image.new("assets/sprites/tank")
|
||||
self.tankImageD = Graphics.image.new("assets/sprites/tankD")
|
||||
Tank.super.init(self)
|
||||
|
||||
local width, height = self.tankImage:getSize()
|
||||
|
||||
self.faded_image = Graphics.image.new(width, height, Graphics.kColorClear)
|
||||
|
||||
Graphics.pushContext(self.faded_image)
|
||||
self.tankImageD:drawBlurred(0, 0, 2, 2, Graphics.image.kDitherTypeFloydSteinberg)
|
||||
Graphics.popContext()
|
||||
|
||||
-- Collision properties
|
||||
self:setZIndex(99)
|
||||
self:setTag(2)
|
||||
self:setCollideRect(4, 56, 147, 65)
|
||||
|
||||
-- Main properties
|
||||
Tank.moveSpeed = 2
|
||||
Tank.player = player
|
||||
Tank.ground = ground
|
||||
|
||||
self:fadein()
|
||||
|
||||
self:moveTo(x, y)
|
||||
end
|
||||
|
||||
function Tank:fadein()
|
||||
self:setImage(self.tankImage)
|
||||
end
|
||||
|
||||
function Tank:fadeout()
|
||||
self:setImage(self.faded_image)
|
||||
end
|
||||
|
||||
function Tank:update()
|
||||
if self.x <= 330 then
|
||||
Tank.ground:setMoveSpeed(0)
|
||||
return
|
||||
end
|
||||
|
||||
-- Speedup when player is moving right
|
||||
if Tank.player.isMovingRight() == false then
|
||||
Tank.moveSpeed = 0.2
|
||||
else
|
||||
Tank.moveSpeed = 1
|
||||
end
|
||||
|
||||
self:moveTo(self.x-Tank.moveSpeed, self.y)
|
||||
end
|
Reference in New Issue
Block a user