Added in horizontal gravity manipulation.

This commit is contained in:
Tanner van Teeffelen 2026-01-13 13:30:49 -05:00
parent a3a880f8e4
commit 5da58e4c98
6 changed files with 40 additions and 10 deletions

File diff suppressed because one or more lines are too long

View file

@ -1,3 +1,5 @@
extends Node
var gravity : float = 500
var x_gravity : float = 0
var y_gravity : float = gravity

View file

@ -32,11 +32,14 @@ func _physics_process(delta: float) -> void:
velocity.x = lerp(velocity.x, 0.0, braking * delta)
#Vertical movement.
velocity.y += al_globals.gravity * delta
velocity.y += al_globals.y_gravity * delta
#Horizonal gravity, if applied.
velocity.x += al_globals.x_gravity * delta
#Gravity flip.
if Input.is_action_just_pressed("flip") and (is_on_floor() or is_on_ceiling()):
al_globals.gravity *= -1
al_globals.y_gravity *= -1
#If the player is moving downwards fast, turn on particles. Otherwise, disable them.
if velocity.y > 500 and not (is_on_floor() or is_on_ceiling()):
@ -68,6 +71,18 @@ func tilemap_detection() -> void:
if exit_data == true:
next_level(current_level.next_level) #Pulls next level data from parent Node2D.
var left_grav_data = tile_data.get_custom_data("left_grav")
if left_grav_data:
al_globals.x_gravity = al_globals.gravity * -5
var right_grav_data = tile_data.get_custom_data("right_grav")
if right_grav_data:
al_globals.x_gravity = al_globals.gravity * 5
var canc_grav_data = tile_data.get_custom_data("canc_grav")
if canc_grav_data:
al_globals.x_gravity = 0
#Facilitates the death of the player.
func death(fallen: bool) -> void:
@ -82,10 +97,6 @@ func death(fallen: bool) -> void:
scale.x = lerp(scale.x, 0.0, 0.1)
scale.y = lerp(scale.y, 0.0, 0.1)
#Sets the gravity back to default (downwards)
if al_globals.gravity < 0:
al_globals.gravity *= -1
#Pauses for a second for effect, then triggers the respawn function.
await get_tree().create_timer(1.0).timeout
respawn()
@ -97,6 +108,14 @@ func respawn() -> void:
scale.x = lerp(scale.x, 1.0, 0.1)
scale.y = lerp(scale.y, 1.0, 0.1)
#Sets the X gravity back to default (nothing)
if al_globals.x_gravity != 0:
al_globals.x_gravity = 0
#Sets the Y gravity back to default (downwards)
if al_globals.y_gravity < 0:
al_globals.gravity *= -1
#Change their position to the start position of the current level.
position.x = current_level.startPosX
position.y = current_level.startPosY

View file

@ -12,8 +12,11 @@ texture = ExtResource("1_tl1wk")
1:1/0 = 0
1:1/0/custom_data_0 = true
0:2/0 = 0
0:2/0/custom_data_3 = true
1:2/0 = 0
1:2/0/custom_data_5 = true
2:2/0 = 0
2:2/0/custom_data_4 = true
2:1/0 = 0
2:1/0/custom_data_2 = true
2:0/0 = 0
@ -27,4 +30,10 @@ custom_data_layer_1/name = "exit"
custom_data_layer_1/type = 1
custom_data_layer_2/name = "event"
custom_data_layer_2/type = 1
custom_data_layer_3/name = "right_grav"
custom_data_layer_3/type = 1
custom_data_layer_4/name = "left_grav"
custom_data_layer_4/type = 1
custom_data_layer_5/name = "canc_grav"
custom_data_layer_5/type = 1
sources/0 = SubResource("TileSetAtlasSource_bo1nx")

Binary file not shown.

BIN
Sprites/png/spritesheet.png (Stored with Git LFS)

Binary file not shown.