Add Ika weaponry, lots of cleanup, new art assets.
This commit is contained in:
parent
5019be454c
commit
e2a30253dd
|
@ -4,18 +4,18 @@ import "CoreLibs/graphics"
|
|||
import "CoreLibs/sprites"
|
||||
|
||||
local gfx <const> = playdate.graphics
|
||||
local geom <const> = playdate.geometry
|
||||
|
||||
class("Bullet").extends(gfx.sprite)
|
||||
|
||||
|
||||
-- Bullet's defaults assume a friendly bullet
|
||||
-- Bullet's defaults assume a (slow, weak) enemy bullet
|
||||
function Bullet:init(size, damage, vector, collisionMask)
|
||||
Bullet.super.init(self)
|
||||
|
||||
self.power = power
|
||||
self.damage = damage or 1
|
||||
self.vector = vector or {x=5, y=0}
|
||||
local mask = collisionMask or 0x4
|
||||
self.vector = vector or geom.vector2D.new(-1, 0)
|
||||
local mask = collisionMask or 0x2
|
||||
|
||||
local img = gfx.image.new(size, size)
|
||||
gfx.pushContext(img)
|
||||
|
@ -31,7 +31,7 @@ function Bullet:init(size, damage, vector, collisionMask)
|
|||
end
|
||||
|
||||
function Bullet:update()
|
||||
local collisions = select(3, self:moveWithCollisions(self.x+self.vector.x, self.y+self.vector.y))
|
||||
local collisions = select(3, self:moveWithCollisions(self.x+self.vector.dx, self.y+self.vector.dy))
|
||||
for i=1, #collisions, 1 do
|
||||
-- anything the bullet can collide with should be damaged by it
|
||||
local obj = collisions[i].other
|
||||
|
|
|
@ -5,12 +5,12 @@ import "CoreLibs/sprites"
|
|||
import "entity"
|
||||
|
||||
local gfx <const> = playdate.graphics
|
||||
local geom <const> = playdate.geometry
|
||||
|
||||
class("Ebi").extends(Entity)
|
||||
|
||||
function Ebi:init()
|
||||
local img = gfx.image.new(10, 10, gfx.kColorBlack)
|
||||
Ebi.super.init(self, img, 5)
|
||||
Ebi.super.init(self, gfx.image.new("images/ebi.png"), 5)
|
||||
|
||||
self:setCollidesWithGroupsMask(0x3)
|
||||
local dir = 1
|
||||
|
@ -18,11 +18,11 @@ function Ebi:init()
|
|||
dir = -1
|
||||
end
|
||||
|
||||
self.vector = {x=0, y=dir}
|
||||
self.vector = geom.vector2D.new(0, dir)
|
||||
|
||||
self.weaponTimer = playdate.timer.new(2500,
|
||||
function()
|
||||
local b = Bullet(2, 1, {x=-1, y=0}, 0x2)
|
||||
local b = Bullet(2, 1)
|
||||
b:moveTo(self.x - (self.width/2) - 1, self.y)
|
||||
b:add()
|
||||
end
|
||||
|
@ -34,7 +34,7 @@ function Ebi:update()
|
|||
local collisions = Ebi.super.update(self)
|
||||
for i=1, #collisions, 1 do
|
||||
if collisions[i].other:getGroupMask() == 0x1 then
|
||||
self.vector.y *= -1
|
||||
self.vector.dy *= -1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,13 +2,33 @@
|
|||
import "CoreLibs/object"
|
||||
import "CoreLibs/graphics"
|
||||
import "CoreLibs/sprites"
|
||||
import "CoreLibs/timer"
|
||||
import "entity"
|
||||
|
||||
local gfx <const> = playdate.graphics
|
||||
local geom <const> = playdate.geometry
|
||||
|
||||
class("Ika").extends(Entity)
|
||||
|
||||
function Ika:init()
|
||||
local img = gfx.image.new(50, 50, gfx.kColorBlack)
|
||||
Ika.super.init(self, img, 25, 1)
|
||||
function Ika:init(target)
|
||||
Ika.super.init(self, gfx.image.new("images/ika.png"), 25, 1)
|
||||
|
||||
self:setCollidesWithGroupsMask(0x2)
|
||||
|
||||
self.weaponTimer = playdate.timer.new(7000,
|
||||
function()
|
||||
local b = Bullet(9, 20, self:calculateVector(target))
|
||||
b:moveTo(self.x - (self.width/2) - 1, self.y)
|
||||
b:add()
|
||||
end
|
||||
)
|
||||
self.weaponTimer.repeats = true
|
||||
end
|
||||
|
||||
function Ika:calculateVector(target)
|
||||
local vec = geom.vector2D.new(0,0)
|
||||
vec.dx = target.x - self.x
|
||||
vec.dy = target.y - self.y
|
||||
|
||||
return vec:normalized() * 3
|
||||
end
|
||||
|
|
|
@ -4,6 +4,7 @@ import "CoreLibs/graphics"
|
|||
import "CoreLibs/sprites"
|
||||
|
||||
local gfx <const> = playdate.graphics
|
||||
local geom <const> = playdate.geometry
|
||||
|
||||
class("Entity").extends(gfx.sprite)
|
||||
|
||||
|
@ -14,7 +15,7 @@ function Entity:init(img, health, armor)
|
|||
|
||||
-- movement direction, every update() the entity will move along this vector and return
|
||||
-- collision data to the subclass
|
||||
self.vector = {x=0,y=0}
|
||||
self.vector = geom.vector2D.new(0, 0)
|
||||
|
||||
self:setCollideRect(0, 0, self:getSize())
|
||||
|
||||
|
@ -35,7 +36,7 @@ function Entity:damage(amount)
|
|||
end
|
||||
|
||||
function Entity:update()
|
||||
local collisions = select(3, self:moveWithCollisions(self.x + self.vector.x, self.y + self.vector.y))
|
||||
local collisions = select(3, self:moveWithCollisions(self.x + self.vector.dx, self.y + self.vector.dy))
|
||||
return collisions
|
||||
end
|
||||
|
||||
|
|
27
src/kani.lua
27
src/kani.lua
|
@ -8,6 +8,7 @@ import "bullet"
|
|||
import "ui"
|
||||
|
||||
local gfx <const> = playdate.graphics
|
||||
local geom <const> = playdate.geometry
|
||||
|
||||
local BASE_CHARGE_FACTOR <const> = 15
|
||||
local BASE_WEAPON_CHARGE_SPEED <const> = 1000
|
||||
|
@ -39,8 +40,7 @@ local POWER_DAMAGE_LOOKUP <const> = {
|
|||
class("Kani").extends(Entity)
|
||||
|
||||
function Kani:init(ui)
|
||||
local img = gfx.image.new("images/kani.png")
|
||||
Kani.super.init(self, img, 100)
|
||||
Kani.super.init(self, gfx.image.new("images/kani.png"), 100)
|
||||
|
||||
self:setGroupMask(0x2)
|
||||
self:setCollidesWithGroupsMask(0xd)
|
||||
|
@ -60,14 +60,14 @@ function Kani:init(ui)
|
|||
self.ui = ui
|
||||
|
||||
self.inputHandlers = {
|
||||
upButtonDown = function() self.vector.y = -3 end,
|
||||
downButtonDown = function() self.vector.y = 3 end,
|
||||
leftButtonDown = function() self.vector.x = -3 end,
|
||||
rightButtonDown = function() self.vector.x = 3 end,
|
||||
upButtonUp = function() self.vector.y = 0 end,
|
||||
downButtonUp = function() self.vector.y = 0 end,
|
||||
leftButtonUp = function() self.vector.x = 0 end,
|
||||
rightButtonUp = function() self.vector.x = 0 end,
|
||||
upButtonDown = function() self.vector.dy = -3 end,
|
||||
downButtonDown = function() self.vector.dy = 3 end,
|
||||
leftButtonDown = function() self.vector.dx = -3 end,
|
||||
rightButtonDown = function() self.vector.dx = 3 end,
|
||||
upButtonUp = function() self.vector.dy = 0 end,
|
||||
downButtonUp = function() self.vector.dy = 0 end,
|
||||
leftButtonUp = function() self.vector.dx = 0 end,
|
||||
rightButtonUp = function() self.vector.dx = 0 end,
|
||||
cranked = function(change, accelChange) self:chargeReserve(change) end,
|
||||
AButtonDown = function()
|
||||
self.firingTimer = playdate.timer.keyRepeatTimerWithDelay(self.weaponChargeSpeed / 2,
|
||||
|
@ -111,7 +111,12 @@ function Kani:fire()
|
|||
return
|
||||
end
|
||||
|
||||
local bullet = Bullet(POWER_SIZE_LOOKUP[self.weaponPower], POWER_DAMAGE_LOOKUP[self.weaponPower])
|
||||
local bullet = Bullet(
|
||||
POWER_SIZE_LOOKUP[self.weaponPower],
|
||||
POWER_DAMAGE_LOOKUP[self.weaponPower],
|
||||
geom.vector2D.new(5,0),
|
||||
0x4
|
||||
)
|
||||
bullet:moveTo(self.x+16, self.y)
|
||||
bullet:add()
|
||||
self.weaponPower = 0
|
||||
|
|
26
src/main.lua
26
src/main.lua
|
@ -25,25 +25,25 @@ function setup()
|
|||
player:add()
|
||||
ui:add()
|
||||
|
||||
local enemy = Ika()
|
||||
local enemy = Ika(player)
|
||||
enemy:moveTo(350, 120)
|
||||
enemy:add()
|
||||
|
||||
enemy = Ebi()
|
||||
enemy:moveTo(270, 50)
|
||||
enemy:add()
|
||||
-- enemy = Ebi()
|
||||
-- enemy:moveTo(270, 50)
|
||||
-- enemy:add()
|
||||
|
||||
enemy = Ebi()
|
||||
enemy:moveTo(280, 100)
|
||||
enemy:add()
|
||||
-- enemy = Ebi()
|
||||
-- enemy:moveTo(280, 100)
|
||||
-- enemy:add()
|
||||
|
||||
enemy = Ebi()
|
||||
enemy:moveTo(290, 150)
|
||||
enemy:add()
|
||||
-- enemy = Ebi()
|
||||
-- enemy:moveTo(290, 150)
|
||||
-- enemy:add()
|
||||
|
||||
enemy = Ebi()
|
||||
enemy:moveTo(300, 200)
|
||||
enemy:add()
|
||||
-- enemy = Ebi()
|
||||
-- enemy:moveTo(300, 200)
|
||||
-- enemy:add()
|
||||
|
||||
makeWalls()
|
||||
drawBackground()
|
||||
|
|
Loading…
Reference in New Issue
Block a user