Refactor targeting code into a utility function, add reverse images until we add code to do that programmatically.

This commit is contained in:
Anna Rose 2023-10-05 16:53:23 -04:00
parent 0c3b0dbd64
commit d9d8ce17fd
10 changed files with 16 additions and 10 deletions

View File

@ -19,7 +19,7 @@ function Ika:init(target)
end
function Ika:onReady()
self.weaponTimer = playdate.timer.new(7000,
self.weaponTimer = playdate.timer.new(5000,
function()
local b = Bullet(10, 20, self:calculateVector(self.target))
b:moveTo(self.x - (self.width/2) - 1, self.y)
@ -30,7 +30,9 @@ function Ika:onReady()
end
function Ika:calculateVector(target)
return util.unitPointer(self:getPosition(), target:getPosition()) * 5
local x1,y1 = self:getPosition()
local x2,y2 = target:getPosition()
return util.unitPointer(x1,y1,x2,y2) * 5
end
function Ika:remove()

Binary file not shown.

After

Width:  |  Height:  |  Size: 285 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 314 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 322 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 365 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 442 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 499 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 525 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 562 B

View File

@ -6,14 +6,18 @@ local geom <const> = playdate.geometry
util = {}
-- creates a unit vector that "points" from point A to point B
function util.unitPointer(a, b)
return (b - a):normalized()
end
-- create a unit vector that points from x1, y1 to x2, y2
-- alternately you can pass 2 playdate.geometry.point() objects instead
function util.unitPointer(x1, y1, x2, y2)
local a = geom.point.new(x1, y1)
local b = geom.point.new(x2, y2)
return unitPointer(a,b)
local a = nil
local b = nil
if type(x1) == "number" then
a = geom.point.new(x1, y1)
b = geom.point.new(x2, y2)
else
a = x1
b = y1
end
return (b-a):normalized()
end