Track each individual disk and ensure they are loaded in order. Player can collect multiple disks in one run but must present them to the pharaoh in order.
173 lines
4.0 KiB
GDScript
173 lines
4.0 KiB
GDScript
extends CharacterBody2D
|
|
|
|
const SPEED = 380.0
|
|
const DASH_SPEED = 600
|
|
const HORIZONTAL_DASH_MULT = 1.8
|
|
const FRICTION = 100
|
|
const GRAVITY_MULT = 0.8
|
|
|
|
const JUMP_VELOCITY = -410.0
|
|
|
|
const DASH_LENGTH = 0.2
|
|
|
|
var fall_timer = 0.0
|
|
var teleport_cooldown = 0
|
|
var jumps = 0
|
|
var dashes = 1
|
|
var dashing = false
|
|
var death_threshold = 1000
|
|
var coins = 0
|
|
|
|
var data_disks = []
|
|
var objectives = {}
|
|
|
|
func _ready() -> void:
|
|
DisplayServer.window_set_title("JUMPS EQUALS JUMPS")
|
|
|
|
func refresh_dash(new_dashes):
|
|
if new_dashes:
|
|
dashes = new_dashes
|
|
else:
|
|
dashes = 1
|
|
if dashes > 0:
|
|
$Jetpack/DashIndicator.show()
|
|
|
|
|
|
func refresh_jump(new_jumps):
|
|
if new_jumps:
|
|
jumps = new_jumps
|
|
else:
|
|
jumps = 1
|
|
if jumps > 0:
|
|
$Jetpack/JumpIndicator.show()
|
|
|
|
func give_disk(disk_num: int) -> void:
|
|
data_disks.push_back(disk_num)
|
|
|
|
func take_disk(disk_num) -> bool:
|
|
if not has_disk(disk_num):
|
|
return false
|
|
|
|
data_disks.remove_at(data_disks.find(disk_num))
|
|
return true
|
|
|
|
func has_disk(disk_num: int) -> bool:
|
|
return disk_num in data_disks
|
|
|
|
func give_objective(id: String, description: String) -> void:
|
|
objectives[id] = description
|
|
|
|
func has_objective(id: String) -> bool:
|
|
return objectives.has(id)
|
|
|
|
func complete_objective(id: String) -> bool:
|
|
return objectives.erase(id)
|
|
|
|
func on_teleport():
|
|
refresh_jump(1)
|
|
teleport_cooldown = 1
|
|
$Camera2D.position_smoothing_enabled = true
|
|
await get_tree().create_timer(1).timeout
|
|
teleport_cooldown = 0
|
|
|
|
func on_death(instant = false):
|
|
#$BackgroundMusic
|
|
if !instant:
|
|
get_tree().paused = true
|
|
$Jetpack/DeathSound.play()
|
|
$Sprite2D.hide()
|
|
await get_tree().create_timer(0.2).timeout
|
|
$Sprite2D.show()
|
|
await get_tree().create_timer(0.2).timeout
|
|
$Sprite2D.hide()
|
|
await get_tree().create_timer(0.2).timeout
|
|
$Sprite2D.show()
|
|
await get_tree().create_timer(0.2).timeout
|
|
|
|
get_tree().paused = false
|
|
position = %LevelStart.position
|
|
|
|
func _process(delta: float) -> void:
|
|
if Input.is_action_just_released("restart") or (Input.is_action_pressed("controller_restart_left") and Input.is_action_pressed("controller_restart_right")):
|
|
get_tree().reload_current_scene()
|
|
|
|
if Input.is_action_just_pressed("jump"):
|
|
if is_on_floor():
|
|
velocity.y = JUMP_VELOCITY
|
|
elif !is_on_floor() and jumps >= 1:
|
|
#Air/double jump
|
|
jumps -= 1
|
|
velocity.y = JUMP_VELOCITY
|
|
$Jetpack/DoubleJumpSound.play()
|
|
if jumps == 0:
|
|
$Jetpack/JumpIndicator.hide()
|
|
|
|
if Input.is_action_pressed("jump") and is_on_wall_only():
|
|
print("WALL HANGING")
|
|
#velocity.y = 0
|
|
#velocity.x = 0
|
|
|
|
var direction = Input.get_axis("move_left","move_right")
|
|
|
|
if direction < 0:
|
|
$Sprite2D.flip_h = true
|
|
$Sprite2D/HatSprite.flip_h = true
|
|
elif direction > 0:
|
|
$Sprite2D.flip_h = false
|
|
$Sprite2D/HatSprite.flip_h = false
|
|
|
|
if Input.is_action_just_pressed("dash") and dashes > 0:
|
|
dashing = true
|
|
dashes -= 1
|
|
velocity = Vector2(
|
|
Input.get_axis("dash_left","dash_right") * HORIZONTAL_DASH_MULT,
|
|
Input.get_axis("dash_up","dash_down")
|
|
) * DASH_SPEED
|
|
await get_tree().create_timer(DASH_LENGTH).timeout
|
|
dashing = false
|
|
if dashes == 0:
|
|
$Jetpack/DashIndicator.hide()
|
|
|
|
elif direction and !dashing:
|
|
velocity.x = direction * SPEED
|
|
$Sprite2D.play("running")
|
|
$Sprite2D/HatSprite.play("running")
|
|
|
|
elif !dashing:
|
|
velocity.x = move_toward(velocity.x, 0, FRICTION)
|
|
$Sprite2D.play("idle")
|
|
$Sprite2D/HatSprite.play("idle")
|
|
|
|
#print("PLAYER X POSITION: " + str(position.y))
|
|
#Falling to death.
|
|
if position.y >= death_threshold:
|
|
print("SLASH KILL")
|
|
on_death(true)
|
|
|
|
fall_timer += 1*delta
|
|
if is_on_floor():
|
|
fall_timer = 0
|
|
refresh_jump(1)
|
|
refresh_dash(1)
|
|
#%Player2D.get_node("Camera2D").position_smoothing_speed = %Player2D.CAMERA_SMOOTHING_SPEED
|
|
|
|
if is_on_wall():
|
|
refresh_jump(1)
|
|
refresh_dash(1)
|
|
#%Player2D.get_node("Camera2D").position_smoothing_speed = %Player2D.CAMERA_SMOOTHING_SPEED
|
|
|
|
if is_on_ceiling():
|
|
refresh_jump(1)
|
|
refresh_dash(1)
|
|
|
|
if fall_timer > 3:
|
|
pass
|
|
#get_tree().reload_current_scene()
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
|
|
if not is_on_floor():
|
|
velocity += (get_gravity() * GRAVITY_MULT) * delta
|
|
|
|
move_and_slide()
|