Collision tweaks; new animations
This commit is contained in:
parent
1fa1b3ce39
commit
d214d7dc3f
Binary file not shown.
Before Width: | Height: | Size: 898 B After Width: | Height: | Size: 7.3 KiB |
Binary file not shown.
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 17 KiB |
80
main.lua
80
main.lua
|
@ -24,7 +24,7 @@ function love.load ()
|
||||||
dieParticle = nil
|
dieParticle = nil
|
||||||
love.graphics.setDefaultFilter("nearest", "nearest", 0)
|
love.graphics.setDefaultFilter("nearest", "nearest", 0)
|
||||||
bg = love.graphics.newImage("art/bg/sky.png")
|
bg = love.graphics.newImage("art/bg/sky.png")
|
||||||
a_ttf = love.graphics.newFont("art/font/alagard.ttf")
|
a_ttf = love.graphics.newFont("art/font/alagard.ttf", nil, "none")
|
||||||
|
|
||||||
lifeText = love.graphics.newText(a_ttf, "Press Enter")
|
lifeText = love.graphics.newText(a_ttf, "Press Enter")
|
||||||
waveText = love.graphics.newText(a_ttf, "")
|
waveText = love.graphics.newText(a_ttf, "")
|
||||||
|
@ -297,7 +297,9 @@ end
|
||||||
|
|
||||||
-- drawing the flier (ofc)
|
-- drawing the flier (ofc)
|
||||||
function Flier:draw ( )
|
function Flier:draw ( )
|
||||||
if ( self.flying > 0 ) then
|
if ( self.living == false ) then
|
||||||
|
self.actor:switch('die')
|
||||||
|
elseif ( self.flying > 0 ) then
|
||||||
self.actor:switch('flap')
|
self.actor:switch('flap')
|
||||||
self.actor:getAnimation():restart()
|
self.actor:getAnimation():restart()
|
||||||
self.flying = self.flying - 1
|
self.flying = self.flying - 1
|
||||||
|
@ -387,8 +389,23 @@ end
|
||||||
function Flier:physics_dead ( dt )
|
function Flier:physics_dead ( dt )
|
||||||
-- ignore all input, fall through bottom
|
-- ignore all input, fall through bottom
|
||||||
gravity = 2
|
gravity = 2
|
||||||
|
max_vel = 300
|
||||||
self.y_vel = self.y_vel + gravity
|
self.y_vel = self.y_vel + gravity
|
||||||
self.y = self.y + self.y_vel * dt
|
self.y = self.y + self.y_vel * dt
|
||||||
|
|
||||||
|
if ( self.x_vel > 0 ) then
|
||||||
|
self.x_vel = self.x_vel - (max_vel / (turn * 3))
|
||||||
|
elseif ( self.x_vel < 0 ) then
|
||||||
|
self.x_vel = self.x_vel + (max_vel / (turn * 3))
|
||||||
|
end
|
||||||
|
|
||||||
|
if ( self.x < -10 ) then
|
||||||
|
self.x = 800
|
||||||
|
elseif ( self.x > 810 ) then
|
||||||
|
self.x = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
self.x = self.x + self.x_vel * dt
|
||||||
if ( self.y > 700 ) then
|
if ( self.y > 700 ) then
|
||||||
self:killFinalize()
|
self:killFinalize()
|
||||||
return false
|
return false
|
||||||
|
@ -398,10 +415,12 @@ function Flier:physics_dead ( dt )
|
||||||
end
|
end
|
||||||
|
|
||||||
-- kill the Flier, show cool particles
|
-- kill the Flier, show cool particles
|
||||||
function Flier:kill ()
|
function Flier:kill ( murderer )
|
||||||
self.living = false
|
self.living = false
|
||||||
dieParticle:moveTo(self.x, self.y)
|
self.x_vel = murderer.x_vel
|
||||||
dieParticle:emit(30)
|
|
||||||
|
dieParticle:moveTo( self.x, self.y )
|
||||||
|
dieParticle:emit( 30 )
|
||||||
end
|
end
|
||||||
|
|
||||||
-- run after Flier falls through screen
|
-- run after Flier falls through screen
|
||||||
|
@ -418,21 +437,24 @@ Bat = class('Bat', Flier)
|
||||||
function Bat:initialize ()
|
function Bat:initialize ()
|
||||||
-- animations
|
-- animations
|
||||||
batSheet = love.graphics.newImage("art/sprites/bat.png")
|
batSheet = love.graphics.newImage("art/sprites/bat.png")
|
||||||
flapFrames = {2,3,4,5}
|
|
||||||
idleFrames = {1}
|
|
||||||
|
|
||||||
batFlapAnim = animx.newAnimation{
|
batFlapAnim = animx.newAnimation{
|
||||||
img = batSheet, tileWidth = 32, frames = flapFrames
|
img = batSheet, tileWidth = 32, frames = {2,3,4,5}
|
||||||
}:onAnimOver( function()
|
}:onAnimOver( function()
|
||||||
self.actor:switch('idle')
|
self.actor:switch('idle')
|
||||||
end )
|
end )
|
||||||
|
|
||||||
batIdleAnim = animx.newAnimation {
|
batIdleAnim = animx.newAnimation {
|
||||||
img = batSheet, tileWidth = 32, frames = idleFrames
|
img = batSheet, tileWidth = 32, frames = {1}
|
||||||
|
}
|
||||||
|
batDieAnim = animx.newAnimation {
|
||||||
|
img = batSheet, tileWidth = 32, frames = {6}
|
||||||
|
}
|
||||||
|
batBlockAnim = animx.newAnimation {
|
||||||
|
img = batSheet, tileWidth = 32, frames = {7}
|
||||||
}
|
}
|
||||||
|
|
||||||
batActor = animx.newActor {
|
batActor = animx.newActor {
|
||||||
['idle'] = batIdleAnim, ['flap'] = batFlapAnim
|
['idle'] = batIdleAnim, ['flap'] = batFlapAnim, ['die'] = batDieAnim
|
||||||
}:switch('idle')
|
}:switch('idle')
|
||||||
|
|
||||||
Flier.initialize( self, 50, 100, batActor )
|
Flier.initialize( self, 50, 100, batActor )
|
||||||
|
@ -491,8 +513,10 @@ function Bird:initialize ( x, y )
|
||||||
|
|
||||||
-- animations
|
-- animations
|
||||||
birdSheet = love.graphics.newImage("art/sprites/bird.png")
|
birdSheet = love.graphics.newImage("art/sprites/bird.png")
|
||||||
flapFrames = { {2,3,4,5}, {7,8,9,10}, {12,13,14,15} }
|
flapFrames = { {2,3,4,5}, {9,10,11,12}, {16,17,18,19} }
|
||||||
idleFrames = { {1}, {6}, {11} }
|
idleFrames = { {1}, {8}, {15} }
|
||||||
|
dieFrames = { {6}, {13}, {20} }
|
||||||
|
blockFrames = { {7}, {14}, {21} }
|
||||||
|
|
||||||
birdFlapAnim = animx.newAnimation{
|
birdFlapAnim = animx.newAnimation{
|
||||||
img = birdSheet, tileWidth = 32, tileHeight = 32, frames = flapFrames[self.species]
|
img = birdSheet, tileWidth = 32, tileHeight = 32, frames = flapFrames[self.species]
|
||||||
|
@ -504,8 +528,17 @@ function Bird:initialize ( x, y )
|
||||||
img = birdSheet, tileWidth = 32, tileHeight = 32, frames = idleFrames[self.species]
|
img = birdSheet, tileWidth = 32, tileHeight = 32, frames = idleFrames[self.species]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
birdDieAnim = animx.newAnimation {
|
||||||
|
img = birdSheet, tileWidth = 32, tileHeight = 32, frames = dieFrames[self.species]
|
||||||
|
}
|
||||||
|
|
||||||
|
birdBlockAnim = animx.newAnimation {
|
||||||
|
img = birdSheet, tileWidth = 32, tileHeight = 32, frames = blockFrames[self.species]
|
||||||
|
}
|
||||||
|
|
||||||
birdActor = animx.newActor {
|
birdActor = animx.newActor {
|
||||||
['idle'] = birdIdleAnim, ['flap'] = birdFlapAnim
|
['idle'] = birdIdleAnim, ['flap'] = birdFlapAnim, ['die'] = birdDieAnim,
|
||||||
|
['block'] = birdBlockAnim
|
||||||
}:switch('idle')
|
}:switch('idle')
|
||||||
|
|
||||||
self.actor = birdActor
|
self.actor = birdActor
|
||||||
|
@ -594,11 +627,11 @@ end
|
||||||
-- assuming a and b are colliding, act accordingly
|
-- assuming a and b are colliding, act accordingly
|
||||||
-- aka, bounce-back or kill one
|
-- aka, bounce-back or kill one
|
||||||
function judgeCollision ( a, b )
|
function judgeCollision ( a, b )
|
||||||
if ( a.y < b.y - 5 and a.living ) then
|
if ( a.y < b.y - 9 and ( a.living or a.class() == "Bat" ) ) then
|
||||||
b:kill()
|
b:kill( a )
|
||||||
elseif ( a.y > b.y + 5 and b.living ) then
|
elseif ( a.y > b.y + 9 and ( b.living or a.class() == "Bat" ) ) then
|
||||||
a:kill()
|
a:kill( b )
|
||||||
else
|
elseif ( a.living and b.living ) then
|
||||||
a.x_vel = a.x_vel * -1
|
a.x_vel = a.x_vel * -1
|
||||||
b.x_vel = b.x_vel * -1
|
b.x_vel = b.x_vel * -1
|
||||||
end
|
end
|
||||||
|
@ -611,7 +644,14 @@ end
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- return whether or not two objects are colliding/overlapping
|
-- return whether or not two objects are colliding/overlapping
|
||||||
function colliding ( a, b )
|
function colliding ( a, b )
|
||||||
if ( inRange(a.x, b.x - 16, b.x + 16) and inRange(a.y, b.y - 16, b.y + 16) ) then
|
-- min_b_y = -16; max_b_y = 16
|
||||||
|
-- min_b_x = -16; max_b_x = 16
|
||||||
|
-- if ( b.direction == right ) then
|
||||||
|
-- min_b_x = min_b_x + 16
|
||||||
|
-- max_b_x = max_b_x + 16
|
||||||
|
-- end
|
||||||
|
|
||||||
|
if ( inRange(a.x, b.x - 16, b.x + 16) and inRange(a.y, b.y + -16, b.y + 16) ) then
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
return false
|
return false
|
||||||
|
|
Ŝarĝante…
Reference in New Issue