MADE COLLISION AND GRAVITY FOR THE JETPACK TO WORK!!!!!
Added a y velocity and gravity for the player and jetpack.
y_vel = 0
grav = 0.2
made a if statement for the jetpack to work
if not pause:
if booster:
y_vel -= grav
#makes player go up when pressing button
else: y_vel += grav
if (colliding[0] and y_vel > 0) or (colliding[1] and y_vel < 0):
y_vel = 0
#makes player go down when not pressing button
player_y += y_vel
if the player presses the key down, the y vel will become negative, causing the player to go up (- gravity). if the player lets go of the key, the y vel will become positive, causing the player to go down (+ gravity).
colliding is a function to check_colliding. colliding[0] is the top of the game’s screen, and colliding[1] is the bottom. when the player goes up. check_colliding will check if the player has reached the top, and will add collision. Same thing will happen to the bottom of the screen.
check_colliding function
def check_colliding():
coll = [False, False]
if player.colliderect(bottom_plat):
coll[0] = True
elif player.colliderect(top_plat):
coll[1] = True
return coll
RESULT.