2025-05-11 20:35:08 +10:00
|
|
|
extends CharacterBody2D
|
|
|
|
|
|
2025-05-15 14:35:32 +10:00
|
|
|
signal remote_get
|
2025-05-11 20:35:08 +10:00
|
|
|
|
2025-05-14 13:30:27 +10:00
|
|
|
@export var SPEED = 200.0
|
|
|
|
|
@export var JUMP_VELOCITY = -450.0
|
2025-05-15 15:28:16 +10:00
|
|
|
@export var remote_sprite : Texture
|
2025-05-17 14:41:41 +10:00
|
|
|
@export var player_sprite : AnimatedSprite2D
|
2025-05-15 14:35:32 +10:00
|
|
|
var controls_enabled : bool = true
|
2025-05-11 20:35:08 +10:00
|
|
|
|
2025-05-15 15:28:16 +10:00
|
|
|
func _ready() -> void:
|
|
|
|
|
GameManager.allow_movement.connect(change_player_movement)
|
2025-05-11 20:35:08 +10:00
|
|
|
|
2025-05-14 19:53:34 +10:00
|
|
|
func _process(delta: float) -> void:
|
2025-05-15 14:35:32 +10:00
|
|
|
|
2025-05-11 20:35:08 +10:00
|
|
|
# Add the gravity.
|
|
|
|
|
if not is_on_floor():
|
|
|
|
|
velocity += get_gravity() * delta
|
2025-05-17 14:41:41 +10:00
|
|
|
player_sprite.play("jump")
|
2025-05-11 20:35:08 +10:00
|
|
|
|
2025-05-15 15:28:16 +10:00
|
|
|
|
2025-05-15 14:35:32 +10:00
|
|
|
if(controls_enabled):
|
|
|
|
|
# Handle jump.
|
|
|
|
|
if Input.is_action_just_pressed("platformer_jump") and is_on_floor():
|
|
|
|
|
velocity.y = JUMP_VELOCITY
|
2025-05-11 20:35:08 +10:00
|
|
|
|
2025-05-15 14:35:32 +10:00
|
|
|
# Get the input direction and handle the movement/deceleration.
|
|
|
|
|
# As good practice, you should replace UI actions with custom gameplay actions.
|
|
|
|
|
var direction := Input.get_axis("platformer_left", "platformer_right")
|
|
|
|
|
if direction:
|
|
|
|
|
velocity.x = direction * SPEED
|
|
|
|
|
else:
|
|
|
|
|
velocity.x = move_toward(velocity.x, 0, SPEED)
|
2025-05-17 14:41:41 +10:00
|
|
|
|
|
|
|
|
if(direction < 0):
|
|
|
|
|
player_sprite.flip_h = true
|
|
|
|
|
elif(direction>0):
|
|
|
|
|
player_sprite.flip_h = false
|
|
|
|
|
|
|
|
|
|
if(direction != 0 and is_on_floor()):
|
|
|
|
|
player_sprite.play("run")
|
|
|
|
|
elif(is_on_floor()):
|
|
|
|
|
player_sprite.play("idle")
|
2025-05-15 15:28:16 +10:00
|
|
|
else:
|
|
|
|
|
velocity.x = move_toward(velocity.x, 0, SPEED)
|
2025-05-11 20:35:08 +10:00
|
|
|
|
|
|
|
|
move_and_slide()
|
2025-05-17 14:41:41 +10:00
|
|
|
|
|
|
|
|
|
2025-05-14 19:53:34 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
func _on_hitbox_area_entered(area: Area2D) -> void:
|
2025-05-15 14:35:32 +10:00
|
|
|
#print(area.name)
|
|
|
|
|
if(area.name == "Box"):
|
2025-05-15 15:28:16 +10:00
|
|
|
#GameManager.play_zoom_out()
|
2025-05-16 01:29:12 +10:00
|
|
|
area.queue_free()
|
2025-05-15 15:28:16 +10:00
|
|
|
GameManager.show_item("TV Remote", remote_sprite)
|
|
|
|
|
GameManager.show_chat("Wonder what i can do with this")
|
|
|
|
|
if(is_instance_of(area,Event)):
|
|
|
|
|
#GameManager.play_zoom_out()
|
2025-05-16 01:29:12 +10:00
|
|
|
area.queue_free()
|
2025-05-15 15:28:16 +10:00
|
|
|
if(area.type == Event.Type.Chat):
|
|
|
|
|
GameManager.show_chat(area.text)
|
|
|
|
|
elif(area.type == Event.Type.Item):
|
|
|
|
|
GameManager.show_item(area.text, area.texture)
|
|
|
|
|
|
|
|
|
|
if(area.name == "Zoomer"):
|
2025-05-16 01:29:12 +10:00
|
|
|
area.queue_free()
|
2025-05-15 14:35:32 +10:00
|
|
|
GameManager.play_zoom_out()
|
2025-05-15 15:28:16 +10:00
|
|
|
GameManager.show_chat("I guess it did something..?")
|
2025-05-16 01:29:12 +10:00
|
|
|
if(area.name == "TheBitWhereYouTrip"):
|
|
|
|
|
area.queue_free()
|
|
|
|
|
GameManager.show_chat("Ouch, I tripped")
|
|
|
|
|
if(area.name == "BrokenRemote"):
|
|
|
|
|
area.queue_free()
|
|
|
|
|
GameManager.prepare_for_gaming()
|
2025-05-15 15:28:16 +10:00
|
|
|
#GameManager.play_zoom_out()
|
|
|
|
|
|
2025-05-14 19:53:34 +10:00
|
|
|
#box event
|
|
|
|
|
#laser event
|
|
|
|
|
#sticky tape event
|
|
|
|
|
pass # Replace with function body.
|
2025-05-15 15:28:16 +10:00
|
|
|
|
|
|
|
|
func change_player_movement(state : bool):
|
|
|
|
|
#print(state) #im an idiot :3
|
|
|
|
|
controls_enabled = state
|