player deck + card logic
This commit is contained in:
103
growth/player.gd
103
growth/player.gd
@@ -1,17 +1,23 @@
|
||||
extends Node2D
|
||||
|
||||
# ActionState should probably be expandable to
|
||||
enum ActionState {None, Deploying, Firing, Charging}
|
||||
enum MoveState {Still, Moving, Dashing, Loading}
|
||||
enum ActionState {None, Cycling, Firing, Charging}
|
||||
enum MoveState {Still, Moving, Dashing, Knockback}
|
||||
|
||||
@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
|
||||
@export var dash_cooldown = 0.3
|
||||
@export var hand_size = 3
|
||||
|
||||
var shield_active = true;
|
||||
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 = [];
|
||||
const hand = [];
|
||||
const discard_pile = [];
|
||||
var active_card_index = -1;
|
||||
|
||||
var screen_size # Size of the game window.
|
||||
var action_state = ActionState.None
|
||||
@@ -21,13 +27,8 @@ 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"):
|
||||
@@ -38,6 +39,10 @@ func update_move_direction():
|
||||
move_direction.y += 1
|
||||
if Input.is_action_pressed("move_up"):
|
||||
move_direction.y -= 1
|
||||
move_direction = move_direction.normalize()
|
||||
|
||||
func update_target_coords():
|
||||
target = get_viewport().get_mouse_position()
|
||||
|
||||
func charge():
|
||||
# Charge attack
|
||||
@@ -50,49 +55,87 @@ func charge():
|
||||
# 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;
|
||||
func dash():
|
||||
var card = hand[active_card_index];
|
||||
if not card or dash_on_cooldown:
|
||||
return;
|
||||
|
||||
card.discard(self); # Must set move_state at start and end of dash
|
||||
dash_on_cooldown = true;
|
||||
|
||||
if (dash_timer >= dash_end):
|
||||
dash_on_cooldown = true;
|
||||
dash_timer = 0;
|
||||
func play_card():
|
||||
if active_card_index >= 0 and active_card_index < hand.size():
|
||||
var card = hand[active_card_index];
|
||||
card.play(self, target);
|
||||
|
||||
func cycle_card(index_shift):
|
||||
if hand.size() > 0:
|
||||
active_card_index = (active_card_index + index_shift) % hand.size();
|
||||
else:
|
||||
draw_card();
|
||||
|
||||
func discard_active_card():
|
||||
if active_card_index >= 0 and active_card_index < hand.size():
|
||||
var card = hand[active_card_index];
|
||||
discard_pile.append(card);
|
||||
hand.remove_at(active_card_index);
|
||||
active_card_index = min(active_card_index, hand.size() - 1);
|
||||
draw_card();
|
||||
|
||||
func draw_card():
|
||||
if drawpile.size() == 0:
|
||||
shuffle_deck();
|
||||
if drawpile.size() > 0 and hand.size() < hand_size:
|
||||
var card = drawpile.pop_back();
|
||||
hand.append(card);
|
||||
if active_card_index == -1:
|
||||
active_card_index = 0;
|
||||
|
||||
# TODO: Reboot mechanics
|
||||
func shuffle_deck():
|
||||
for card in discard_pile:
|
||||
drawpile.append(card);
|
||||
discard_pile.clear();
|
||||
drawpile.shuffle();
|
||||
active_card_index = 0;
|
||||
|
||||
func _ready():
|
||||
screen_size = get_viewport_rect().size
|
||||
while (hand.size() < hand_size and drawpile.size() > 0):
|
||||
draw_card();
|
||||
|
||||
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.Loading:
|
||||
if move_state == MoveState.Knockback:
|
||||
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);
|
||||
elif Input.is_action_just_pressed("dash"):
|
||||
dash();
|
||||
else:
|
||||
velocity = move_direction.normalize() * speed;
|
||||
velocity = move_direction * 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
|
||||
if Input.is_action_pressed("play_card"):
|
||||
play_card();
|
||||
|
||||
if Input.is_action_just_pressed("cycle_card_left"):
|
||||
action_state = ActionState.Cycling;
|
||||
cycle_card(-1);
|
||||
elif Input.is_action_just_pressed("cycle_card_right"):
|
||||
action_state = ActionState.Cycling;
|
||||
cycle_card(1);
|
||||
elif Input.is_action_pressed("charge"):
|
||||
action_state = ActionState.Charging;
|
||||
charge();
|
||||
|
||||
Reference in New Issue
Block a user