Add Ika weaponry, lots of cleanup, new art assets.

This commit is contained in:
Anna Rose 2023-10-01 01:48:06 -04:00
parent 5019be454c
commit e2a30253dd
6 changed files with 65 additions and 39 deletions

View File

@ -4,18 +4,18 @@ import "CoreLibs/graphics"
import "CoreLibs/sprites" import "CoreLibs/sprites"
local gfx <const> = playdate.graphics local gfx <const> = playdate.graphics
local geom <const> = playdate.geometry
class("Bullet").extends(gfx.sprite) class("Bullet").extends(gfx.sprite)
-- Bullet's defaults assume a (slow, weak) enemy bullet
-- Bullet's defaults assume a friendly bullet
function Bullet:init(size, damage, vector, collisionMask) function Bullet:init(size, damage, vector, collisionMask)
Bullet.super.init(self) Bullet.super.init(self)
self.power = power self.power = power
self.damage = damage or 1 self.damage = damage or 1
self.vector = vector or {x=5, y=0} self.vector = vector or geom.vector2D.new(-1, 0)
local mask = collisionMask or 0x4 local mask = collisionMask or 0x2
local img = gfx.image.new(size, size) local img = gfx.image.new(size, size)
gfx.pushContext(img) gfx.pushContext(img)
@ -31,7 +31,7 @@ function Bullet:init(size, damage, vector, collisionMask)
end end
function Bullet:update() 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 for i=1, #collisions, 1 do
-- anything the bullet can collide with should be damaged by it -- anything the bullet can collide with should be damaged by it
local obj = collisions[i].other local obj = collisions[i].other

View File

@ -5,12 +5,12 @@ import "CoreLibs/sprites"
import "entity" import "entity"
local gfx <const> = playdate.graphics local gfx <const> = playdate.graphics
local geom <const> = playdate.geometry
class("Ebi").extends(Entity) class("Ebi").extends(Entity)
function Ebi:init() function Ebi:init()
local img = gfx.image.new(10, 10, gfx.kColorBlack) Ebi.super.init(self, gfx.image.new("images/ebi.png"), 5)
Ebi.super.init(self, img, 5)
self:setCollidesWithGroupsMask(0x3) self:setCollidesWithGroupsMask(0x3)
local dir = 1 local dir = 1
@ -18,11 +18,11 @@ function Ebi:init()
dir = -1 dir = -1
end end
self.vector = {x=0, y=dir} self.vector = geom.vector2D.new(0, dir)
self.weaponTimer = playdate.timer.new(2500, self.weaponTimer = playdate.timer.new(2500,
function() 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:moveTo(self.x - (self.width/2) - 1, self.y)
b:add() b:add()
end end
@ -34,7 +34,7 @@ function Ebi:update()
local collisions = Ebi.super.update(self) local collisions = Ebi.super.update(self)
for i=1, #collisions, 1 do for i=1, #collisions, 1 do
if collisions[i].other:getGroupMask() == 0x1 then if collisions[i].other:getGroupMask() == 0x1 then
self.vector.y *= -1 self.vector.dy *= -1
end end
end end
end end

View File

@ -2,13 +2,33 @@
import "CoreLibs/object" import "CoreLibs/object"
import "CoreLibs/graphics" import "CoreLibs/graphics"
import "CoreLibs/sprites" import "CoreLibs/sprites"
import "CoreLibs/timer"
import "entity" import "entity"
local gfx <const> = playdate.graphics local gfx <const> = playdate.graphics
local geom <const> = playdate.geometry
class("Ika").extends(Entity) class("Ika").extends(Entity)
function Ika:init() function Ika:init(target)
local img = gfx.image.new(50, 50, gfx.kColorBlack) Ika.super.init(self, gfx.image.new("images/ika.png"), 25, 1)
Ika.super.init(self, img, 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 end

View File

@ -4,6 +4,7 @@ import "CoreLibs/graphics"
import "CoreLibs/sprites" import "CoreLibs/sprites"
local gfx <const> = playdate.graphics local gfx <const> = playdate.graphics
local geom <const> = playdate.geometry
class("Entity").extends(gfx.sprite) 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 -- movement direction, every update() the entity will move along this vector and return
-- collision data to the subclass -- collision data to the subclass
self.vector = {x=0,y=0} self.vector = geom.vector2D.new(0, 0)
self:setCollideRect(0, 0, self:getSize()) self:setCollideRect(0, 0, self:getSize())
@ -35,7 +36,7 @@ function Entity:damage(amount)
end end
function Entity:update() 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 return collisions
end end

View File

@ -8,6 +8,7 @@ import "bullet"
import "ui" import "ui"
local gfx <const> = playdate.graphics local gfx <const> = playdate.graphics
local geom <const> = playdate.geometry
local BASE_CHARGE_FACTOR <const> = 15 local BASE_CHARGE_FACTOR <const> = 15
local BASE_WEAPON_CHARGE_SPEED <const> = 1000 local BASE_WEAPON_CHARGE_SPEED <const> = 1000
@ -39,8 +40,7 @@ local POWER_DAMAGE_LOOKUP <const> = {
class("Kani").extends(Entity) class("Kani").extends(Entity)
function Kani:init(ui) function Kani:init(ui)
local img = gfx.image.new("images/kani.png") Kani.super.init(self, gfx.image.new("images/kani.png"), 100)
Kani.super.init(self, img, 100)
self:setGroupMask(0x2) self:setGroupMask(0x2)
self:setCollidesWithGroupsMask(0xd) self:setCollidesWithGroupsMask(0xd)
@ -60,14 +60,14 @@ function Kani:init(ui)
self.ui = ui self.ui = ui
self.inputHandlers = { self.inputHandlers = {
upButtonDown = function() self.vector.y = -3 end, upButtonDown = function() self.vector.dy = -3 end,
downButtonDown = function() self.vector.y = 3 end, downButtonDown = function() self.vector.dy = 3 end,
leftButtonDown = function() self.vector.x = -3 end, leftButtonDown = function() self.vector.dx = -3 end,
rightButtonDown = function() self.vector.x = 3 end, rightButtonDown = function() self.vector.dx = 3 end,
upButtonUp = function() self.vector.y = 0 end, upButtonUp = function() self.vector.dy = 0 end,
downButtonUp = function() self.vector.y = 0 end, downButtonUp = function() self.vector.dy = 0 end,
leftButtonUp = function() self.vector.x = 0 end, leftButtonUp = function() self.vector.dx = 0 end,
rightButtonUp = function() self.vector.x = 0 end, rightButtonUp = function() self.vector.dx = 0 end,
cranked = function(change, accelChange) self:chargeReserve(change) end, cranked = function(change, accelChange) self:chargeReserve(change) end,
AButtonDown = function() AButtonDown = function()
self.firingTimer = playdate.timer.keyRepeatTimerWithDelay(self.weaponChargeSpeed / 2, self.firingTimer = playdate.timer.keyRepeatTimerWithDelay(self.weaponChargeSpeed / 2,
@ -111,7 +111,12 @@ function Kani:fire()
return return
end 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:moveTo(self.x+16, self.y)
bullet:add() bullet:add()
self.weaponPower = 0 self.weaponPower = 0

View File

@ -25,25 +25,25 @@ function setup()
player:add() player:add()
ui:add() ui:add()
local enemy = Ika() local enemy = Ika(player)
enemy:moveTo(350, 120) enemy:moveTo(350, 120)
enemy:add() enemy:add()
enemy = Ebi() -- enemy = Ebi()
enemy:moveTo(270, 50) -- enemy:moveTo(270, 50)
enemy:add() -- enemy:add()
enemy = Ebi() -- enemy = Ebi()
enemy:moveTo(280, 100) -- enemy:moveTo(280, 100)
enemy:add() -- enemy:add()
enemy = Ebi() -- enemy = Ebi()
enemy:moveTo(290, 150) -- enemy:moveTo(290, 150)
enemy:add() -- enemy:add()
enemy = Ebi() -- enemy = Ebi()
enemy:moveTo(300, 200) -- enemy:moveTo(300, 200)
enemy:add() -- enemy:add()
makeWalls() makeWalls()
drawBackground() drawBackground()