mirror of
https://github.com/libretro/lutro-platformer.git
synced 2024-11-23 16:19:46 +00:00
Sword collision
This commit is contained in:
parent
0e7693c98f
commit
b8cd546b18
7
anim.lua
7
anim.lua
@ -11,6 +11,7 @@ function newAnimation(image, width, height, period, speed)
|
||||
a.speed = speed
|
||||
a.period = period
|
||||
a.steps = a.image:getWidth() / a.width
|
||||
a.id = 1
|
||||
return setmetatable(a, animation)
|
||||
end
|
||||
|
||||
@ -25,15 +26,15 @@ function animation:update(dt)
|
||||
end
|
||||
|
||||
function animation:draw(x, y)
|
||||
local id = math.floor(self.timer / self.period + 1)
|
||||
self.id = math.floor(self.timer / self.period + 1)
|
||||
local tw = self.width
|
||||
local th = self.height
|
||||
local sw = self.image:getWidth()
|
||||
local sh = self.image:getHeight()
|
||||
|
||||
local q = lutro.graphics.newQuad(
|
||||
((id-1)%(sw/tw))*tw,
|
||||
math.floor((id-1)/(sw/tw))*tw,
|
||||
((self.id-1)%(sw/tw))*tw,
|
||||
math.floor((self.id-1)/(sw/tw))*tw,
|
||||
tw, th,
|
||||
sw, sh)
|
||||
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 2.3 KiB |
@ -145,7 +145,7 @@ function ninja:update(dt)
|
||||
end
|
||||
|
||||
-- jumping
|
||||
if JOY_A and self.hit == 0 then
|
||||
if JOY_B and self.hit == 0 then
|
||||
self.DO_JUMP = self.DO_JUMP + 1
|
||||
else
|
||||
self.DO_JUMP = 0
|
||||
@ -171,7 +171,7 @@ function ninja:update(dt)
|
||||
end
|
||||
|
||||
-- throwing
|
||||
if JOY_B and self.hit == 0 then
|
||||
if JOY_A and self.hit == 0 then
|
||||
self.DO_THROW = self.DO_THROW + 1
|
||||
else
|
||||
self.DO_THROW = 0
|
||||
@ -198,13 +198,13 @@ function ninja:update(dt)
|
||||
end
|
||||
|
||||
-- moving
|
||||
if JOY_LEFT and self.hit == 0 then
|
||||
if JOY_LEFT and self.hit == 0 and self.sword == 0 then
|
||||
self.xspeed = self.xspeed - self.xaccel * dt;
|
||||
self.xspeed = math.max(self.xspeed, -self.max_xspeed)
|
||||
self.direction = "left";
|
||||
end
|
||||
|
||||
if JOY_RIGHT and self.hit == 0 then
|
||||
if JOY_RIGHT and self.hit == 0 and self.sword == 0 then
|
||||
self.xspeed = self.xspeed + self.xaccel * dt;
|
||||
self.xspeed = math.min(self.xspeed, self.max_xspeed)
|
||||
self.direction = "right";
|
||||
|
19
obake.lua
19
obake.lua
@ -111,5 +111,24 @@ function obake:on_collide(e1, e2, dx, dy)
|
||||
lutro.audio.play(sfx_enemydie)
|
||||
self.die = 30
|
||||
end
|
||||
|
||||
elseif e2.type == "sword" and e2.anim.id >= 3 and e2.anim.id <= 6 and self.hit == 0 and self.die == 0 then
|
||||
self.hit = 30
|
||||
if e2.direction == "right" then
|
||||
self.xspeed = 100
|
||||
self.xaccel = -100
|
||||
else
|
||||
self.xspeed = -100
|
||||
self.xaccel = 100
|
||||
end
|
||||
|
||||
lutro.audio.play(sfx_enemyhit)
|
||||
self.hp = self.hp - 1
|
||||
|
||||
if self.hp <= 0 then
|
||||
lutro.audio.play(sfx_enemydie)
|
||||
self.die = 30
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
17
porc.lua
17
porc.lua
@ -148,7 +148,7 @@ function porc:update(dt)
|
||||
end
|
||||
|
||||
function porc:draw()
|
||||
self.anim:draw(self.x + 5, self.y - 6)
|
||||
self.anim:draw(self.x - 5, self.y - 6)
|
||||
end
|
||||
|
||||
function porc:on_collide(e1, e2, dx, dy)
|
||||
@ -186,5 +186,20 @@ function porc:on_collide(e1, e2, dx, dy)
|
||||
self.xspeed = -2
|
||||
end
|
||||
end
|
||||
elseif e2.type == "sword" and e2.anim.id >= 3 and e2.anim.id <= 6 and self.hit == 0 and self.die == 0 then
|
||||
self.hp = self.hp - 1
|
||||
if self.hp <= 0 then
|
||||
lutro.audio.play(sfx_porcdie)
|
||||
self.die = 60
|
||||
self.xspeed = 0
|
||||
else
|
||||
lutro.audio.play(sfx_porchit)
|
||||
self.hit = 60
|
||||
if dx > 0 then
|
||||
self.xspeed = 2
|
||||
else
|
||||
self.xspeed = -2
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
26
sword.lua
26
sword.lua
@ -6,15 +6,16 @@ sword.__index = sword
|
||||
function newSword(parent)
|
||||
local n = {}
|
||||
n.type = "sword"
|
||||
n.y = parent.y - 16
|
||||
n.direction = parent.direction
|
||||
n.y = parent.y - 16 + 14
|
||||
n.parent = parent
|
||||
n.direction = n.parent.direction
|
||||
if n.direction == "left" then
|
||||
n.x = parent.x - 16 - 6
|
||||
n.x = n.parent.x - 16 - 6
|
||||
else
|
||||
n.x = parent.x - 16 + 6
|
||||
n.x = n.parent.x - 16 + 6
|
||||
end
|
||||
n.width = 48
|
||||
n.height = 48
|
||||
n.height = 27
|
||||
n.die = 0
|
||||
|
||||
n.animations = {
|
||||
@ -30,13 +31,18 @@ function newSword(parent)
|
||||
end
|
||||
|
||||
function sword:update(dt)
|
||||
|
||||
self.y = self.parent.y - 16 + 14
|
||||
self.direction = self.parent.direction
|
||||
if self.direction == "left" then
|
||||
self.x = self.parent.x - 16 - 6
|
||||
else
|
||||
self.x = self.parent.x - 16 + 6
|
||||
end
|
||||
|
||||
self.anim:update(dt)
|
||||
end
|
||||
|
||||
function sword:draw()
|
||||
self.anim:draw(self.x, self.y)
|
||||
end
|
||||
|
||||
function sword:on_collide(e1, e2, dx, dy)
|
||||
|
||||
self.anim:draw(self.x, self.y - 14)
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user