extends Node2D # ActionState should probably be expandable to enum ActionState {None, Deploying, Firing, Charging} enum MoveState {Still, Moving, Dashing, Loading} @export var speed = 100 # How fast the player will move (pixels/sec). @export var dash_speed = 200 @export var dash_end = 0.8 @export var dash_cooldown = 0.5 const drawpile = []; const hand = []; const discard_pile = []; 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_timer = 0; var dash_cooldown_timer = 0; var dash_on_cooldown = false; var dash_ease_factor_minimum = speed / float(dash_speed) var move_direction = Vector2.ZERO; var velocity = Vector2.ZERO # The player's movement vector. func update_move_direction(): if Input.is_action_pressed("move_right"): move_direction.x += 1 if move_direction.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 func charge(): # Charge attack if not charged and action_state == ActionState.Charging: charge_level += charge_rate; if charge_level >= 100: charged = false; charge_level = 0; elif charge_level > 0: # Gradual charge dropoff charge_level = max(charge_level - charge_rate * 2, 0); func dash(delta): dash_timer += delta; const easeFactor = 1; velocity = move_direction.normalize() * dash_speed * easeFactor; if (dash_timer >= dash_end): dash_on_cooldown = true; dash_timer = 0; func _ready(): screen_size = get_viewport_rect().size func _process(delta): 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.Loading: pass # Idk dude, thought it might be a fun effect when you take damage elif Input.is_action_pressed("dash") or action_state == MoveState.Dashing: move_state = MoveState.Dashing; dash(delta); else: velocity = move_direction.normalize() * speed; if velocity.x || velocity.y: move_state = MoveState.Moving; else: move_state = MoveState.Still; # Handle action_state if Input.is_action_pressed("deploy"): action_state = ActionState.Deploying; # Deploy elif Input.is_action_pressed("fire"): action_state = ActionState.Firing; # Fire elif Input.is_action_pressed("charge"): action_state = ActionState.Charging; charge();