This commit is contained in:
1 parent
c40cbc4574
commit
231629d91e
28 files changed
+434
-91
No files matched your search
+273
@@ -0,0 +1,273 @@
|
||||
class_name PlayerClassextends
|
||||
extends CharacterBody2D
|
||||
|
||||
var controller_ui = false
|
||||
|
||||
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
|
||||
const BACKGROUND_COLOR = Color(Color.ORANGE.r + 0.80,Color.ORANGE.g + 0.20,Color.ORANGE.b - 0.10)
|
||||
|
||||
var is_on_moving_platform = false
|
||||
var platform_speed = 0.0
|
||||
|
||||
var death_cooldown = 0.0
|
||||
var fall_timer = 0.0
|
||||
var teleport_cooldown = 0
|
||||
var jumps = 0
|
||||
var dashes = 1
|
||||
var dashing = false
|
||||
var death_threshold = 2000
|
||||
var coins = 0
|
||||
|
||||
var spawn_point
|
||||
var last_ground_point
|
||||
|
||||
var data_disks = []
|
||||
var objectives = {}
|
||||
|
||||
func _ready() -> void:
|
||||
spawn_point = position
|
||||
DisplayServer.window_set_title("JUMPS EQUALS JUMPS")
|
||||
give_objective("sarc", 0, "Open the Sarcophagus")
|
||||
|
||||
for hidden_object in get_tree().get_nodes_in_group("Hidden in editor"):
|
||||
hidden_object.show()
|
||||
|
||||
for hidden_object in get_tree().get_nodes_in_group("Hidden"):
|
||||
hidden_object.hide()
|
||||
|
||||
if not OS.is_debug_build():
|
||||
for object in get_tree().get_nodes_in_group("Debug Mode Only"):
|
||||
object.queue_free()
|
||||
#%Dialogue.show_text("Hello world!").dismiss_after(2)
|
||||
|
||||
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, priority: int, description: String) -> void:
|
||||
objectives[id] = {
|
||||
"priority": priority,
|
||||
"description": description,
|
||||
"completed": false
|
||||
}
|
||||
|
||||
func has_objective(id: String) -> bool:
|
||||
return objectives.has(id) and not objectives[id].completed
|
||||
|
||||
func get_current_objectives() -> Array[String]:
|
||||
var current_objectives = objectives.values()
|
||||
current_objectives.sort_custom(func(a, b): return a.priority < b.priority)
|
||||
return current_objectives.filter(func(objective): return not objective.completed).map(func(objective): return objective.description)
|
||||
|
||||
func complete_objective(id: String) -> bool:
|
||||
if not has_objective(id):
|
||||
return false
|
||||
objectives[id].completed = true
|
||||
return true
|
||||
|
||||
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 spawn_ghost(ghost_position):
|
||||
var ghost = preload("res://ghost.tscn")
|
||||
ghost = ghost.instantiate()
|
||||
get_parent().add_child(ghost)
|
||||
ghost.position = ghost_position
|
||||
|
||||
func on_death(instant = false, player_position = position):
|
||||
death_cooldown += 1
|
||||
if !instant:
|
||||
await get_tree().create_timer(0.1).timeout
|
||||
get_tree().paused = true
|
||||
$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
|
||||
|
||||
spawn_ghost(player_position)
|
||||
get_tree().paused = false
|
||||
|
||||
#position = %LevelStart.position
|
||||
velocity = Vector2(0,0)
|
||||
var fall_offset = Vector2(0,-100)
|
||||
position = spawn_point# + fall_offset
|
||||
await get_tree().create_timer(0.1).timeout
|
||||
death_cooldown = 0
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
|
||||
if is_on_moving_platform:
|
||||
position.x = position.x + platform_speed
|
||||
|
||||
if Input.is_key_pressed(Key.KEY_W) or Input.is_key_pressed(Key.KEY_A) or Input.is_key_pressed(Key.KEY_S) or Input.is_key_pressed(Key.KEY_D):
|
||||
controller_ui = false
|
||||
elif Input.get_action_strength("move_horizontal") > 0:
|
||||
controller_ui = true
|
||||
|
||||
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 is_on_floor():
|
||||
last_ground_point = global_position
|
||||
#spawn_point = last_ground_point
|
||||
|
||||
if %OldComputer.visible:
|
||||
if Input.is_action_just_released("interact") or Input.is_action_just_released("jump"):
|
||||
%OldComputer.close()
|
||||
return
|
||||
|
||||
if Input.is_action_just_released("interact"):
|
||||
for interactable in get_tree().get_nodes_in_group("nearby_interactables"):
|
||||
interactable.interact()
|
||||
|
||||
if Input.is_action_just_pressed("jump"):
|
||||
%OldComputer.close()
|
||||
|
||||
# Single jump from floor.
|
||||
if is_on_floor():
|
||||
velocity.y = JUMP_VELOCITY
|
||||
# Air jump, if we have any left.
|
||||
elif !is_on_floor() and jumps >= 1:
|
||||
jumps -= 1
|
||||
velocity.y = JUMP_VELOCITY
|
||||
$Jetpack/DoubleJumpSound.play()
|
||||
if jumps == 0:
|
||||
$Jetpack/JumpIndicator.hide()
|
||||
|
||||
# Pull the player down more quickly when they let go of the jump key.
|
||||
# This improves responsiveness.
|
||||
if Input.is_action_just_released("jump"):
|
||||
velocity.y = -(0.001 * JUMP_VELOCITY)
|
||||
|
||||
# Eventual wall grabs
|
||||
if Input.is_action_pressed("jump") and is_on_wall_only():
|
||||
print("Spider Rhombini, Spider Rhombini...")
|
||||
|
||||
# Eventual ceiling grabs
|
||||
if Input.is_action_pressed("jump") and is_on_ceiling_only():
|
||||
print("Does whatever, a Spider Rhombini does...")
|
||||
|
||||
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_pressed("dash_down") and is_on_floor():
|
||||
$Sprite2D.play("crouch")
|
||||
$Parallax2D/Sprite2D.modulate = Color.CYAN
|
||||
|
||||
$MeditateMusic.volume_db = 0
|
||||
$BackgroundMusic.volume_db = -100
|
||||
|
||||
for hidden_object in get_tree().get_nodes_in_group("Hidden"):
|
||||
hidden_object.show()
|
||||
|
||||
elif 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()
|
||||
|
||||
# Slow the player down if they're on keyboard.
|
||||
elif direction and !dashing:
|
||||
if controller_ui:
|
||||
velocity.x = direction * SPEED
|
||||
else:
|
||||
velocity.x = direction * SPEED * 0.75
|
||||
$Sprite2D.play("running")
|
||||
#$Sprite2D/HatSprite.play("running")
|
||||
|
||||
elif !dashing and !is_on_moving_platform:
|
||||
velocity.x = move_toward(velocity.x, 0, FRICTION)
|
||||
$Sprite2D.play("idle")
|
||||
#$Sprite2D/HatSprite.play("idle")
|
||||
$Parallax2D/Sprite2D.modulate = BACKGROUND_COLOR
|
||||
|
||||
$MeditateMusic.volume_db = -100
|
||||
$BackgroundMusic.volume_db = 0
|
||||
|
||||
if get_tree():
|
||||
for hidden_object in get_tree().get_nodes_in_group("Hidden"):
|
||||
hidden_object.hide()
|
||||
|
||||
#Falling to death.
|
||||
if position.y >= death_threshold:
|
||||
print("SLASH KILL")
|
||||
on_death(true)
|
||||
|
||||
#func get_floor_tags():
|
||||
|
||||
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()
|
||||
Reference in new issue
Block a user