Joust-like player movement

This commit is contained in:
Jaidyn Ann 2020-09-19 01:15:36 -05:00
parent 25b84c0e7a
commit 8fa50c2916

View File

@ -7,18 +7,35 @@ function love.load ()
left = 0; right = 1; up = 2; down = 3 left = 0; right = 1; up = 2; down = 3
upleft = 4; downleft = 5; upright = 6; downright = 7 upleft = 4; downleft = 5; upright = 6; downright = 7
aBatFly = animx.newAnimation{ batSheet = love.graphics.newImage("art/sprites/bat.png")
img = "art/sprites/bat.png",
sprites_per_row = 5, batFlapAnim = animx.newAnimation{
noOfFrames = 5 img = batSheet,
}:loop() tileWidth = 32,
frames = { 2, 3, 4, 5 }
}:onAnimOver( function()
bat.actor:switch('idle')
end )
batIdleAnim = animx.newAnimation {
img = batSheet,
tileWidth = 32,
frames = { 1 }
}
batActor = animx.newActor {
['idle'] = batIdleAnim,
['flap'] = batFlapAnim
}:switch('idle')
-- batActor:switch('idle')
bat = { x = 50, y = 200, bat = { x = 50, y = 200,
y_vel = 0, x_vel = 0, y_vel = 0, x_vel = 0,
moving = false, moving = false,
flying = false, flying = false,
direction = left, direction = left,
animation = aBatFly actor = batActor
} }
-- for compliance with Statute 43.5 (2019); all birds must report births to local Officials -- for compliance with Statute 43.5 (2019); all birds must report births to local Officials
@ -51,13 +68,13 @@ function love.keypressed ( key )
if ( key == "right" ) then if ( key == "right" ) then
bat.moving = true bat.moving = true
bat.direction = right bat.direction = right
aBatFly:flipX(true)
elseif ( key == "left" ) then elseif ( key == "left" ) then
bat.moving = true bat.moving = true
bat.direction = left bat.direction = left
aBatFly:flipX(false)
elseif ( key == "space" ) then elseif ( key == "space" ) then
bat.flying = true bat.flying = true
bat.actor:switch('flap')
bat.actor:getAnimation():restart()
end end
end end
@ -87,7 +104,12 @@ function flier_update ( flier, dt )
end end
function flier_draw ( flier ) function flier_draw ( flier )
flier.animation:draw( flier.x, flier.y ) if ( flier.direction == right ) then
flier.actor:flipX(true)
elseif (flier.direction == left) then
flier.actor:flipX(false)
end
flier.actor:draw( flier.x, flier.y )
end end
---------------------------------------- ----------------------------------------
@ -104,18 +126,20 @@ end
function flier_physics_x ( flier, dt ) function flier_physics_x ( flier, dt )
max_vel = 300 max_vel = 300
min_vel = -300 min_vel = -300
floor = 500
turn = 300
if ( flier.moving ) then if ( flier.moving ) then
if ( flier.x_vel < max_vel and flier.direction == right ) then if ( flier.x_vel < max_vel and flier.direction == right ) then
flier.x_vel = flier.x_vel + (max_vel / 300) flier.x_vel = flier.x_vel + (max_vel / turn)
elseif ( flier.x_vel > min_vel and flier.direction == left ) then elseif ( flier.x_vel > min_vel and flier.direction == left ) then
flier.x_vel = flier.x_vel - (max_vel / 300) flier.x_vel = flier.x_vel - (max_vel / turn)
end end
else else
if ( flier.x_vel > 0 ) then if ( flier.x_vel > 0 ) then
flier.x_vel = flier.x_vel - (max_vel / 600) flier.x_vel = flier.x_vel - (max_vel / (turn * 3))
elseif ( flier.x_vel < 0 ) then elseif ( flier.x_vel < 0 ) then
flier.x_vel = flier.x_vel + (max_vel / 600) flier.x_vel = flier.x_vel + (max_vel / (turn * 3))
end end
end end