added the game

This commit is contained in:
JHDev2006
2025-09-13 16:30:32 +01:00
parent 5ef689109b
commit 3773bdaf64
3616 changed files with 263702 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
extends PlayerState
var climb_direction := 0
var vine: Vine = null
const CLIMB_SPEED := 50
var cutscene := false
var auto_climb := false
func enter(msg := {}) -> void:
vine = msg.get("Vine")
cutscene = msg.has("Cutscene")
func physics_update(_delta: float) -> void:
player.velocity.x = 0
if player.input_direction != 0 and climb_direction == 0 and not cutscene:
player.direction = -player.input_direction
player.sprite.scale.x = player.direction
player.global_position.x = vine.global_position.x - (8 * player.direction)
if not cutscene and not auto_climb:
climb_direction = sign(Input.get_axis("move_up" + "_" + str(player.player_id),"move_down" + "_" + str(player.player_id)))
if vine.can_tele and player.global_position.y - 64 < vine.top_point and climb_direction == -1:
climb_direction = -1
auto_climb = true
player.velocity.y = CLIMB_SPEED * climb_direction
player.sprite.play("Climb")
player.sprite.speed_scale = abs(climb_direction * 1.5)
player.move_and_slide()
if Global.player_action_just_pressed("jump", player.player_id) and not cutscene:
state_machine.transition_to("Normal")
player.jump()

View File

@@ -0,0 +1 @@
uid://c7kmriol0gj16

View File

@@ -0,0 +1,29 @@
extends PlayerState
var can_fall := false
func enter(msg := {}) -> void:
player.z_index = 20
can_fall = false
player.velocity = Vector2.ZERO
player.stop_all_timers()
await get_tree().create_timer(0.5).timeout
can_fall =true
for i in 16:
player.set_collision_mask_value(i + 1, false)
player.gravity = player.JUMP_GRAVITY
if msg["Pit"] == false:
player.velocity.y = -300
func physics_update(delta: float) -> void:
if can_fall:
player.play_animation("Die")
else:
player.play_animation("DieFreeze")
player.sprite.speed_scale = 1
if can_fall:
player.velocity.y += (player.JUMP_GRAVITY / delta) * delta
player.velocity.y = clamp(player.velocity.y, -INF, player.MAX_FALL_SPEED)
player.move_and_slide()
if Input.is_action_just_pressed("jump_0"):
player.death_load()

View File

@@ -0,0 +1 @@
uid://cvbj4qlyfat7e

View File

@@ -0,0 +1,26 @@
extends PlayerState
var can_land := true
@export var castle: Node = null
func enter(_msg := {}) -> void:
player.direction = 1
player.stop_all_timers()
await Global.level_complete_begin
state_machine.transition_to("LevelExit")
func physics_update(_delta: float) -> void:
player.velocity.y = 125
player.velocity.x = 0
player.sprite.scale.x = player.direction
if player.is_on_floor():
if can_land:
can_land = false
player.global_position.x += 10
player.direction = -1
player.sprite.speed_scale = 0
else:
player.sprite.speed_scale = 2
player.play_animation("FlagSlide")
player.move_and_slide()

View File

@@ -0,0 +1 @@
uid://ri1g4nllpkfj

View File

@@ -0,0 +1,12 @@
extends PlayerState
func enter(_msg := {}) -> void:
player.has_jumped = false
player.crouching = false
player.get_node("CameraCenterJoint/RightWall").set_collision_layer_value(1, false)
func physics_update(delta: float) -> void:
player.input_direction = 1
player.can_run = false
player.normal_state.handle_movement(delta)
player.normal_state.handle_animations()

View File

@@ -0,0 +1 @@
uid://bx2kc62lpphxv

View File

@@ -0,0 +1,23 @@
extends PlayerState
const SLOW_SPEED := 300.0
const FAST_SPEED := 800.0
var old_layers := []
func enter(_msg := {}) -> void:
player.can_hurt = false
player.set_collision_mask_value(1, false)
player.set_collision_mask_value(2, false)
func physics_update(_delta: float) -> void:
player.velocity = Input.get_vector("move_left_0", "move_right_0", "move_up_0", "move_down_0") * (FAST_SPEED if Input.is_action_pressed("run_0") else SLOW_SPEED)
player.move_and_slide()
if Input.is_action_just_pressed("jump_0"):
state_machine.transition_to("Normal")
func exit() -> void:
player.can_hurt = false
player.set_collision_mask_value(1, true)
player.set_collision_mask_value(2, true)
player.velocity = Vector2.ZERO

View File

@@ -0,0 +1 @@
uid://ugfx3sb3h6rj

View File

@@ -0,0 +1,239 @@
extends PlayerState
var swim_up_meter := 0.0
var jump_queued := false
var jump_buffer := 0
var walk_frame := 0
var bubble_meter := 0.0
var wall_pushing := false
var can_wall_push := false
func enter(_msg := {}) -> void:
jump_queued = false
func physics_update(delta: float) -> void:
if player.is_actually_on_floor():
grounded(delta)
else:
in_air()
handle_movement(delta)
handle_animations()
if player.global_position.y > 64 and not Level.in_vine_level and player.auto_death_pit:
player.die(true)
elif player.global_position.y < Global.current_level.vertical_height - 32 and player.gravity_vector == Vector2.UP:
player.die(true)
func handle_movement(delta: float) -> void:
jump_buffer -= 1
if jump_buffer <= 0:
jump_queued = false
player.apply_gravity(delta)
if player.is_actually_on_floor():
var player_transform = player.global_transform
player_transform.origin += Vector2.UP * 1
if player.is_actually_on_floor():
handle_ground_movement(delta)
elif player.in_water or player.flight_meter > 0:
handle_swimming(delta)
else:
handle_air_movement(delta)
player.move_and_slide()
player.moved.emit()
func grounded(delta: float) -> void:
player.jump_cancelled = false
if player.velocity.y >= 0:
player.has_jumped = false
if Global.player_action_just_pressed("jump", player.player_id):
if player.in_water or player.flight_meter > 0:
swim_up()
return
else:
player.jump()
if jump_queued and not (player.in_water or player.flight_meter > 0):
if player.spring_bouncing == false:
player.jump()
jump_queued = false
if not player.crouching:
if Global.player_action_pressed("move_down", player.player_id):
player.crouching = true
else:
can_wall_push = player.test_move(player.global_transform, Vector2.UP * 8 * player.gravity_vector.y) and player.power_state.hitbox_size != "Small"
if Global.player_action_pressed("move_down", player.player_id) == false:
if can_wall_push:
wall_pushing = true
else:
wall_pushing = false
player.crouching = false
else:
player.crouching = true
wall_pushing = false
if wall_pushing:
player.global_position.x += (-50 * player.direction * delta)
func handle_ground_movement(delta: float) -> void:
if player.skidding:
ground_skid(delta)
elif (player.input_direction != player.velocity_direction) and player.input_direction != 0 and abs(player.velocity.x) > 100 and not player.crouching:
print([player.input_direction, player.velocity_direction])
player.skidding = true
elif player.input_direction != 0 and not player.crouching:
ground_acceleration(delta)
else:
deceleration(delta)
func ground_acceleration(delta: float) -> void:
var target_move_speed := player.WALK_SPEED
if player.in_water or player.flight_meter > 0:
target_move_speed = 45
var target_accel := player.GROUND_WALK_ACCEL
if (Global.player_action_pressed("run", player.player_id) and abs(player.velocity.x) >= player.WALK_SPEED) and (not player.in_water and player.flight_meter <= 0) and player.can_run:
target_move_speed = player.RUN_SPEED
target_accel = player.GROUND_RUN_ACCEL
if player.input_direction != player.velocity_direction:
if Global.player_action_pressed("run", player.player_id) and player.can_run:
target_accel = player.RUN_SKID
else:
target_accel = player.WALK_SKID
player.velocity.x = move_toward(player.velocity.x, target_move_speed * player.input_direction, (target_accel / delta) * delta)
func deceleration(delta: float) -> void:
player.velocity.x = move_toward(player.velocity.x, 0, (player.DECEL / delta) * delta)
func ground_skid(delta: float) -> void:
var target_skid := player.RUN_SKID
player.velocity.x = move_toward(player.velocity.x, 1 * player.input_direction, (target_skid / delta) * delta)
if abs(player.velocity.x) < 10 or player.input_direction == player.velocity_direction or player.input_direction == 0:
player.skidding = false
func in_air() -> void:
if Global.player_action_just_pressed("jump", player.player_id):
if player.in_water or player.flight_meter > 0:
swim_up()
else:
jump_queued = true
jump_buffer = 4
func handle_air_movement(delta: float) -> void:
if player.input_direction != 0 and player.velocity_direction != player.input_direction:
air_skid(delta)
if player.input_direction != 0:
air_acceleration(delta)
if Global.player_action_pressed("jump", player.player_id) == false and player.has_jumped and not player.jump_cancelled:
player.jump_cancelled = true
if player.gravity_vector.y > 0:
if player.velocity.y < 0:
player.velocity.y /= 1.5
player.gravity = player.FALL_GRAVITY
elif player.gravity_vector.y < 0:
if player.velocity.y > 0:
player.velocity.y /= 1.5
player.gravity = player.FALL_GRAVITY
func air_acceleration(delta: float) -> void:
var target_speed = player.WALK_SPEED
if abs(player.velocity.x) >= player.WALK_SPEED and Global.player_action_pressed("run", player.player_id) and player.can_run:
target_speed = player.RUN_SPEED
player.velocity.x = move_toward(player.velocity.x, target_speed * player.input_direction, (player.AIR_ACCEL / delta) * delta)
func air_skid(delta: float) -> void:
player.velocity.x = move_toward(player.velocity.x, 1 * player.input_direction, (player.AIR_SKID / delta) * delta)
func handle_swimming(delta: float) -> void:
bubble_meter += delta
if bubble_meter >= 1 and player.flight_meter <= 0:
player.summon_bubble()
bubble_meter = 0
swim_up_meter -= delta
player.skidding = (player.input_direction != player.velocity_direction) and player.input_direction != 0 and abs(player.velocity.x) > 100 and not player.crouching
if player.skidding:
ground_skid(delta)
elif player.input_direction != 0 and not player.crouching:
swim_acceleration(delta)
else:
deceleration(delta)
func swim_acceleration(delta: float) -> void:
player.velocity.x = move_toward(player.velocity.x, player.SWIM_SPEED * player.input_direction, (player.GROUND_WALK_ACCEL / delta) * delta)
func swim_up() -> void:
if player.swim_stroke:
player.play_animation("SwimIdle")
player.velocity.y = -100 * player.gravity_vector.y
AudioManager.play_sfx("swim", player.global_position)
swim_up_meter = 0.5
player.crouching = false
func handle_animations() -> void:
if (player.is_actually_on_floor() or player.in_water or player.flight_meter > 0 or player.can_air_turn) and player.input_direction != 0 and not player.crouching:
player.direction = player.input_direction
var animation = get_animation_name()
player.sprite.speed_scale = 1
if ["Walk", "Move", "Run"].has(animation):
player.sprite.speed_scale = abs(player.velocity.x) / 40
player.play_animation(animation)
if player.sprite.animation == "Move":
walk_frame = player.sprite.frame
player.sprite.scale.x = player.direction * player.gravity_vector.y
func get_animation_name() -> String:
if player.attacking:
if player.crouching:
return "CrouchAttack"
if player.is_actually_on_floor():
return "Attack"
elif player.in_water or player.flight_meter > 0:
return "SwimAttack"
else:
return "AirAttack"
if player.crouching and not wall_pushing:
if player.velocity.y > 0 and player.is_on_floor() == false:
return "CrouchFall"
return "Crouch"
if player.is_actually_on_floor():
if player.skidding:
return "Skid"
elif abs(player.velocity.x) >= 5 and not player.is_actually_on_wall():
if player.in_water or player.flight_meter > 0:
return "WaterMove"
elif abs(player.velocity.x) < player.RUN_SPEED - 10:
return "Walk"
else:
return "Run"
else:
if player.in_water or player.flight_meter > 0:
return "WaterIdle"
if Global.player_action_pressed("move_up", player.player_id):
return "LookUp"
return "Idle"
else:
if player.in_water or player.flight_meter > 0:
if swim_up_meter > 0:
return "SwimUp"
else:
return "SwimIdle"
if player.has_jumped:
if player.velocity.y < 0:
if player.is_invincible:
return "StarJump"
return "Jump"
else:
if player.is_invincible:
return "StarFall"
return "JumpFall"
else:
player.sprite.speed_scale = 0
player.sprite.frame = walk_frame
return "Fall"
func exit() -> void:
player.on_hammer_timeout()
player.skidding = false

View File

@@ -0,0 +1 @@
uid://blxvov3jyx8gg

View File

@@ -0,0 +1,24 @@
extends PlayerState
const ENTER_SPEED := 50
func enter(_msg := {}) -> void:
player.can_hurt = false
player.velocity = Vector2.ZERO
player.z_index = -5
physics_update(0)
func physics_update(delta: float) -> void:
player.global_position += (ENTER_SPEED * (player.pipe_enter_direction * player.pipe_move_direction)) * delta
if player.pipe_enter_direction.x != 0:
player.sprite.speed_scale = 1
player.play_animation("PipeWalk")
player.direction = int(player.pipe_enter_direction.x)
player.sprite.scale.x = player.direction
else:
player.play_animation("Pipe")
func exit() -> void:
player.can_hurt = true
player.z_index = 1
player.show()

View File

@@ -0,0 +1 @@
uid://dvbib1gtmmvui

View File

@@ -0,0 +1,4 @@
class_name PlayerState
extends State
@onready var player: Player = owner

View File

@@ -0,0 +1 @@
uid://cnjpqn05bfm57

View File

@@ -0,0 +1,30 @@
extends PlayerState
var direction := 0
var fall_off := 0.0
func enter(_msg := {}) -> void:
fall_off = 0
direction = player.direction
player.direction *= -1
func physics_update(delta: float) -> void:
if player.input_direction == player.direction or player.input_direction == 0:
fall_off += 4 * delta
player.apply_gravity(delta)
player.velocity.y = clamp(player.velocity.y, -INF, 50)
player.sprite.play("Skid")
player.velocity.x = 50 * direction
if Global.player_action_just_pressed("jump", player.player_id):
jump_off()
if player.is_on_floor() or player.is_on_wall() == false or fall_off >= 1:
player.velocity.x = 50 * player.input_direction
state_machine.transition_to("Normal")
player.move_and_slide()
func jump_off() -> void:
AudioManager.play_sfx("bump", player.global_position)
player.state_machine.transition_to("Normal")
player.jump()
player.velocity.x = 120 * player.direction

View File

@@ -0,0 +1 @@
uid://b10ui1x45l6ly

19
Scripts/Classes/States/State.gd Executable file
View File

@@ -0,0 +1,19 @@
class_name State
extends Node
signal state_entered
signal state_exited
@onready var state_machine: StateMachine = get_parent()
func enter(_msg := {}) -> void:
pass
func exit() -> void:
pass
func physics_update(_delta: float) -> void:
pass
func update(_delta: float) -> void:
pass

View File

@@ -0,0 +1 @@
uid://dn07g2yvk1unf

View File

@@ -0,0 +1,17 @@
class_name StateMachine
extends Node
@export var state: State = null
func transition_to(state_name := "", state_msg := {}) -> void:
state.exit()
state.state_exited.emit()
state = get_node(state_name)
state.enter(state_msg)
state.state_entered.emit()
func _physics_process(delta: float) -> void:
state.physics_update(delta)
func _process(delta: float) -> void:
state.update(delta)

View File

@@ -0,0 +1 @@
uid://uribh0f1jttq