Add blocking

This commit is contained in:
Jaidyn Ann 2020-09-21 18:42:37 -05:00
parent cabf913f2f
commit efb8a53f4c

View File

@ -64,6 +64,7 @@ function love.draw ()
end end
love.graphics.draw(bg, 0, 0) love.graphics.draw(bg, 0, 0)
love.graphics.draw(bg, 512, 0) love.graphics.draw(bg, 512, 0)
love.graphics.draw(bg, 1024, 0)
love.graphics.draw(waveText, 200, 340, 0, 2, 2) love.graphics.draw(waveText, 200, 340, 0, 2, 2)
love.graphics.draw(lifeText, 125, 355, 0, 1.3, 1.3) love.graphics.draw(lifeText, 125, 355, 0, 1.3, 1.3)
@ -393,6 +394,8 @@ function game_keypressed ( key )
player.flying = 2 player.flying = 2
elseif ( key == "a" or key == "z" ) then elseif ( key == "a" or key == "z" ) then
player:dash() player:dash()
elseif ( key == "s" or key == "x" ) then
player.blocking = true
elseif ( key == "escape" ) then elseif ( key == "escape" ) then
pause_load() pause_load()
end end
@ -417,6 +420,8 @@ function game_keyreleased (key)
player.pointing = unsetUp( player.pointing ) player.pointing = unsetUp( player.pointing )
elseif ( key == "down" ) then elseif ( key == "down" ) then
player.pointing = unsetDown( player.pointing ) player.pointing = unsetDown( player.pointing )
elseif ( key == "s" or key == "x" ) then
player.blocking = false
end end
end end
@ -437,6 +442,7 @@ function Flier:initialize ( x, y, actor )
self.x_vel = 0 self.x_vel = 0
self.pointing = right self.pointing = right
self.moving = false self.moving = false
self.blocking = false
self.flying = 0 self.flying = 0
self.dashTime = 0 self.dashTime = 0
self.actor = actor self.actor = actor
@ -455,11 +461,16 @@ end
function Flier:draw ( ) function Flier:draw ( )
if ( self.living == false ) then if ( self.living == false ) then
self.actor:switch('die') self.actor:switch('die')
elseif ( self.blocking == true ) then
self.actor:switch('block')
elseif ( self.blocking == false and self.actor:getName() == "block" ) then
self.actor:switch('idle')
elseif ( self.flying > 0 ) then 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
end end
if ( self.direction == right ) then if ( self.direction == right ) then
self.actor:flipX(true) self.actor:flipX(true)
elseif (self.direction == left) then elseif (self.direction == left) then
@ -528,7 +539,7 @@ end
-- physics on the y-axis -- physics on the y-axis
function Flier:physics_y ( dt ) function Flier:physics_y ( dt )
-- wing-flap -- wing-flap
if ( self.flying > 0 ) then if ( self.flying > 0 and self.blocking == false ) then
self.y_vel = -200 self.y_vel = -200
self.flying = self.flying - 1 self.flying = self.flying - 1
if ( self.species ) then if ( self.species ) then
@ -595,7 +606,7 @@ function Flier:physics_dead ( dt )
end end
function Flier:dash () function Flier:dash ()
if ( self.dashTime > 0 ) then if ( self.dashTime > 0 or self.blocking == true ) then
return return
end end
self.dashTime = 1 self.dashTime = 1
@ -662,7 +673,8 @@ function Bat:initialize ()
} }
batActor = animx.newActor { batActor = animx.newActor {
['idle'] = batIdleAnim, ['flap'] = batFlapAnim, ['die'] = batDieAnim ['idle'] = batIdleAnim, ['flap'] = batFlapAnim, ['die'] = batDieAnim,
['block'] = batBlockAnim
}:switch('idle') }:switch('idle')
Flier.initialize( self, 50, 100, batActor ) Flier.initialize( self, 50, 100, batActor )
@ -798,7 +810,7 @@ function Bird:destiny_x ()
end end
if ( self.species > 1 ) then if ( self.species > 1 ) then
if ( inRange( self.x, player.x - 30, player.x + 30 ) if ( inRange( self.x, player.x - 40, player.x + 40 )
and math.random(0,300) == 25 ) then and math.random(0,300) == 25 ) then
if ( self.y < player.y ) then if ( self.y < player.y ) then
self.pointing = down self.pointing = down
@ -818,7 +830,7 @@ function Bird:destiny_y ()
end end
if ( self.species > 1 ) then if ( self.species > 1 ) then
if ( inRange( self.y, player.y - 30, player.y + 30 ) if ( inRange( self.y, player.y - 40, player.y + 40 )
and math.random(0,300) == 25 ) then and math.random(0,300) == 25 ) then
if ( self.x < player.x ) then if ( self.x < player.x ) then
self.pointing = right self.pointing = right
@ -917,7 +929,7 @@ function nextWave ( )
love.audio.play(waveSfx) love.audio.play(waveSfx)
bird_n = wave * 3 bird_n = wave * 2
for i = 1,bird_n do for i = 1,bird_n do
if ( i % 2 == 0 ) then if ( i % 2 == 0 ) then
@ -932,13 +944,23 @@ end
-- 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 - 9 and ( b.living ) and ( a.living or a.class() == "Bat" ) ) then if ( a.y < b.y - 9 and ( b.living ) and ( a.living or a.class() == "Bat" ) ) then
if ( (maxSpeed( a.x_vel ) or a.dashTime > 0) and b.blocking == true ) then
a.x_vel = a.x_vel * -1
b.x_vel = b.x_vel * -1
else
b:kill( a ) b:kill( a )
end
elseif ( a.y > b.y + 9 and ( a.living ) and ( b.living or a.class() == "Bat" ) ) then elseif ( a.y > b.y + 9 and ( a.living ) and ( b.living or a.class() == "Bat" ) ) then
if ( (maxSpeed( b.x_vel ) or b.dashTime > 0) and a.blocking == true ) then
a.x_vel = a.x_vel * -1
b.x_vel = b.x_vel * -1
else
a:kill( b ) a:kill( b )
end
elseif ( a.living and b.living ) then elseif ( a.living and b.living ) then
if ( a.x_vel > 300 or a.x_vel < -300 ) then if ( maxSpeed(b.x_vel) and a.blocking == false ) then
a.kill( b ) a.kill( b )
elseif ( b.x_vel > 300 or b.x_vel < -300 ) then elseif ( maxSpeed(a.x_vel) and b.blocking == false ) then
b.kill( a ) b.kill( a )
else else
a.x_vel = a.x_vel * -1 a.x_vel = a.x_vel * -1
@ -949,6 +971,14 @@ function judgeCollision ( a, b )
end end
end end
function maxSpeed ( speed )
if ( inRange( speed, -301, 301 ) ) then
return false
else
return true
end
end
function pauseGame () function pauseGame ()
pause_load() pause_load()
end end