Files
hsgj25-growth/growth/player.gd

74 lines
1.9 KiB
GDScript

extends Node2D
# ActionState should probably be expandable to
enum ActionState {None, Cycling, Firing, Charging}
enum MoveState {Still, Moving, Dashing, Knockback}
@export var speed = 200 # How fast the player will move (pixels/sec).
@export var dash_cooldown = 0.3
@export var hand_size = 3
var shield_active = true;
@export var move_direction = Vector2.ZERO;
var velocity = Vector2.ZERO # The player's movement vector.
var target = Vector2.ZERO # The position of the player's cursor.
const drawpile = [];
@export var hand = [];
const discard_pile = [];
var active_card_index = -1;
var screen_size # Size of the game window.
var action_state = ActionState.None
var move_state = MoveState.Still
var charge_level = 0;
var charge_rate = 1;
var charged = false;
var dash_cooldown_timer = 0;
var dash_on_cooldown = false;
func update_move_direction():
move_direction = Vector2.ZERO
if Input.is_action_pressed("move_right"):
move_direction.x += 1
if Input.is_action_pressed("move_left"):
move_direction.x -= 1
if Input.is_action_pressed("move_down"):
move_direction.y += 1
if Input.is_action_pressed("move_up"):
move_direction.y -= 1
move_direction = move_direction.normalized()
func update_target_coords():
target = get_viewport().get_mouse_position()
func _ready():
screen_size = get_viewport_rect().size
func _process(delta):
update_target_coords();
if (move_state != MoveState.Dashing):
update_move_direction();
if (dash_on_cooldown):
dash_cooldown_timer += delta;
if (dash_cooldown_timer >= dash_cooldown):
dash_on_cooldown = false;
dash_cooldown_timer = 0;
# handle move_state
if move_state == MoveState.Knockback:
pass
elif (move_state != MoveState.Dashing):
velocity = move_direction * speed;
if velocity.x || velocity.y:
move_state = MoveState.Moving;
else:
move_state = MoveState.Still;
position += velocity * delta
position = position.clamp(Vector2.ZERO, screen_size)