49 lines
1.2 KiB
GDScript3
49 lines
1.2 KiB
GDScript3
|
|
#@tool
|
||
|
|
#@icon(icon_path: String)
|
||
|
|
#class_name MyNode
|
||
|
|
extends CharacterBody2D
|
||
|
|
## Documentation comments
|
||
|
|
|
||
|
|
#signal
|
||
|
|
enum FaceDirection {LEFT, RIGHT}
|
||
|
|
#const
|
||
|
|
@export_range(0, 360, 1.0, "radians_as_degrees") var rotation_speed: float = 0.0 ## degrees per second
|
||
|
|
|
||
|
|
var current_direction: FaceDirection = FaceDirection.LEFT: set = set_direction
|
||
|
|
var input_vector: Vector2
|
||
|
|
|
||
|
|
@onready var shark_sprite: AnimatedSprite2D = $SharkSprite
|
||
|
|
@onready var shark_collider: CollisionPolygon2D = $SharkCollider
|
||
|
|
@onready var shark_cam: Camera2D = $SharkCam
|
||
|
|
|
||
|
|
## OVERRIDES
|
||
|
|
|
||
|
|
func _ready() -> void:
|
||
|
|
pass
|
||
|
|
|
||
|
|
func _process(_delta: float) -> void:
|
||
|
|
pass
|
||
|
|
|
||
|
|
func _physics_process(delta: float) -> void:
|
||
|
|
input_vector = Input.get_vector("left", "right", "up", "down")
|
||
|
|
if input_vector.x > 0:
|
||
|
|
current_direction = FaceDirection.RIGHT
|
||
|
|
elif input_vector.x < 0:
|
||
|
|
current_direction = FaceDirection.LEFT
|
||
|
|
|
||
|
|
rotate(deg_to_rad(input_vector.y * rotation_speed * delta))
|
||
|
|
|
||
|
|
## CORE
|
||
|
|
|
||
|
|
## PRIVATE/HELPER
|
||
|
|
|
||
|
|
## RECEIVERS
|
||
|
|
|
||
|
|
## SETTERS/GETTERS
|
||
|
|
func set_direction(new_direction: FaceDirection) -> void:
|
||
|
|
if new_direction == FaceDirection.LEFT:
|
||
|
|
shark_sprite.flip_h = false
|
||
|
|
else:
|
||
|
|
shark_sprite.flip_h = true
|
||
|
|
current_direction = new_direction
|