fix merge
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -1,4 +1,4 @@
|
|||||||
extends Node2D
|
extends CharacterBody2D
|
||||||
|
|
||||||
# ActionState should probably be expandable to
|
# ActionState should probably be expandable to
|
||||||
enum ActionState {None, Cycling, Firing, Charging}
|
enum ActionState {None, Cycling, Firing, Charging}
|
||||||
@@ -8,9 +8,11 @@ enum MoveState {Still, Moving, Dashing, Knockback}
|
|||||||
@export var dash_cooldown = 0.3
|
@export var dash_cooldown = 0.3
|
||||||
@export var hand_size = 3
|
@export var hand_size = 3
|
||||||
|
|
||||||
|
@onready var camera: Camera2D = %PlayerCamera
|
||||||
|
@onready var sprite: AnimatedSprite2D = $PlayerSprite
|
||||||
|
|
||||||
var shield_active = true;
|
var shield_active = true;
|
||||||
@export var move_direction = Vector2.ZERO;
|
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.
|
var target = Vector2.ZERO # The position of the player's cursor.
|
||||||
|
|
||||||
const drawpile = [];
|
const drawpile = [];
|
||||||
@@ -43,13 +45,77 @@ func update_move_direction():
|
|||||||
|
|
||||||
func update_target_coords():
|
func update_target_coords():
|
||||||
target = get_viewport().get_mouse_position()
|
target = get_viewport().get_mouse_position()
|
||||||
|
sprite.look_at(get_global_mouse_position())
|
||||||
|
|
||||||
|
func update_camera_position():
|
||||||
|
if not camera:
|
||||||
|
return;
|
||||||
|
var camera_target = (target - screen_size / 2) / 4
|
||||||
|
camera.position = camera.position.lerp(camera_target, 0.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():
|
||||||
|
var card = hand.get(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;
|
||||||
|
|
||||||
|
func play_card():
|
||||||
|
if active_card_index >= 0 and active_card_index < hand.size():
|
||||||
|
var card = hand[active_card_index];
|
||||||
|
card.play(self);
|
||||||
|
|
||||||
|
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():
|
func _ready():
|
||||||
screen_size = get_viewport_rect().size
|
screen_size = get_viewport_rect().size
|
||||||
|
while (hand.size() < hand_size and drawpile.size() > 0):
|
||||||
|
draw_card();
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
update_target_coords();
|
update_target_coords();
|
||||||
|
update_camera_position();
|
||||||
if (move_state != MoveState.Dashing):
|
if (move_state != MoveState.Dashing):
|
||||||
update_move_direction();
|
update_move_direction();
|
||||||
|
|
||||||
@@ -62,12 +128,24 @@ func _process(delta):
|
|||||||
# handle move_state
|
# handle move_state
|
||||||
if move_state == MoveState.Knockback:
|
if move_state == MoveState.Knockback:
|
||||||
pass
|
pass
|
||||||
|
elif Input.is_action_just_pressed("dash"):
|
||||||
|
dash();
|
||||||
elif (move_state != MoveState.Dashing):
|
elif (move_state != MoveState.Dashing):
|
||||||
velocity = move_direction * speed;
|
velocity = move_direction * speed;
|
||||||
if velocity.x || velocity.y:
|
if velocity.x || velocity.y:
|
||||||
move_state = MoveState.Moving;
|
move_state = MoveState.Moving;
|
||||||
else:
|
else:
|
||||||
move_state = MoveState.Still;
|
move_state = MoveState.Still;
|
||||||
|
|
||||||
|
move_and_slide();
|
||||||
|
|
||||||
position += velocity * delta
|
# Handle action_state
|
||||||
position = position.clamp(Vector2.ZERO, screen_size)
|
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user