yay dependency injections
This commit is contained in:
@@ -3,12 +3,15 @@
|
||||
[sub_resource type="GDScript" id="GDScript_cmuwy"]
|
||||
script/source = "extends Node
|
||||
|
||||
var dash_speed = 200
|
||||
|
||||
func activate(world, activator):
|
||||
if $Timer.time_left != 0:
|
||||
return
|
||||
$Timer.start()
|
||||
const easeFactor = 1;
|
||||
activator.velocity = activator.move_direction.normalize() * activator.dash_speed * easeFactor
|
||||
activator.velocity = activator.move_direction.normalized() * dash_speed * easeFactor
|
||||
activator.move_state = 2
|
||||
|
||||
func discard(world, activator):
|
||||
pass
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://dg8euc6mh055m"]
|
||||
[gd_scene load_steps=2 format=3 uid="uid://b0g5wd4n3py3x"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://c4x7n1r3ce1bc" path="res://Card/card.gd" id="1_yeifr"]
|
||||
|
||||
@@ -6,12 +6,4 @@
|
||||
offset_right = 1.0
|
||||
script = ExtResource("1_yeifr")
|
||||
|
||||
[node name="RichTextLabel" type="RichTextLabel" parent="."]
|
||||
layout_mode = 2
|
||||
text = "Isnt that nice?"
|
||||
|
||||
[node name="Label" type="Label" parent="RichTextLabel"]
|
||||
layout_mode = 0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 23.0
|
||||
text = "Test label"
|
||||
[node name="Behaviors" type="Node" parent="."]
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
extends Control
|
||||
|
||||
class_name BaseCard
|
||||
|
||||
@export var behaviors = []
|
||||
|
||||
@export var title = ""
|
||||
|
||||
func _ready() -> void:
|
||||
$CenterContainer/RichTextLabel.text = title
|
||||
for behavior in behaviors:
|
||||
$Behaviors.add_child(behavior.instantiate())
|
||||
|
||||
func activate(world, activator):
|
||||
for behavior in behaviors:
|
||||
for behavior in $Behaviors.get_children():
|
||||
behavior.activate(world, activator)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://lqw1rkwsv8xt"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://dg8euc6mh055m" path="res://Card/base_bard.tscn" id="1_7jxl2"]
|
||||
[ext_resource type="PackedScene" uid="uid://dg8euc6mh055m" path="res://Card/BaseCard.tscn" id="1_7jxl2"]
|
||||
[ext_resource type="Script" uid="uid://b1exu0m00vjaw" path="res://Card/card_inner.gd" id="2_2q6qc"]
|
||||
|
||||
[sub_resource type="GDScript" id="GDScript_7jxl2"]
|
||||
|
||||
7
growth/Cards/dash_card.tscn
Normal file
7
growth/Cards/dash_card.tscn
Normal file
@@ -0,0 +1,7 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://ee0t3qv6gyam"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://b0g5wd4n3py3x" path="res://Card/base_bard.tscn" id="1_wwyou"]
|
||||
[ext_resource type="PackedScene" uid="uid://b3piw7awjaxgj" path="res://Card/DashCardInject.tscn" id="2_2qs8v"]
|
||||
|
||||
[node name="Card" instance=ExtResource("1_wwyou")]
|
||||
behaviors = [ExtResource("2_2qs8v")]
|
||||
30
growth/hand.gd
Normal file
30
growth/hand.gd
Normal file
@@ -0,0 +1,30 @@
|
||||
extends Panel
|
||||
|
||||
@export var player: NodePath
|
||||
@export var world: NodePath
|
||||
|
||||
var dash_card_scene = preload("res://Cards/dash_card.tscn")
|
||||
var active_card_index = 0
|
||||
|
||||
func _ready() -> void:
|
||||
var actual_dash_card = dash_card_scene.instantiate()
|
||||
$MarginContainer/HBoxContainer.add_child(actual_dash_card)
|
||||
|
||||
func _process(delta):
|
||||
if Input.is_action_pressed("play_card"):
|
||||
play_card()
|
||||
if Input.is_action_just_pressed("cycle_card_left"):
|
||||
#player.action_state = ActionState.Cycling;
|
||||
active_card_index += -1
|
||||
elif Input.is_action_just_pressed("cycle_card_right"):
|
||||
#player.action_state = ActionState.Cycling;
|
||||
#player.cycle_card(1);
|
||||
active_card_index += 1
|
||||
|
||||
|
||||
func play_card():
|
||||
var cards = $MarginContainer/HBoxContainer.get_children();
|
||||
if active_card_index >= 0 and active_card_index < cards.size():
|
||||
var card = cards[active_card_index]
|
||||
card.activate(get_node(world), get_node(player));
|
||||
print(active_card_index)
|
||||
1
growth/hand.gd.uid
Normal file
1
growth/hand.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bykc0ufv25ij5
|
||||
@@ -1,7 +1,8 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://cyr5hbucxlmm5"]
|
||||
[gd_scene load_steps=4 format=3 uid="uid://cyr5hbucxlmm5"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://dhhnr3xkxbxlu" path="res://player.tscn" id="1_vonw3"]
|
||||
[ext_resource type="PackedScene" uid="uid://bsv3h2lpv7h77" path="res://virus.tscn" id="2_oi3di"]
|
||||
[ext_resource type="Script" uid="uid://bykc0ufv25ij5" path="res://hand.gd" id="3_oi3di"]
|
||||
|
||||
[node name="Level" type="Node2D"]
|
||||
|
||||
@@ -14,14 +15,17 @@ position = Vector2(969, 289)
|
||||
|
||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||
|
||||
[node name="Panel" type="Panel" parent="CanvasLayer"]
|
||||
[node name="Hand" type="Panel" parent="CanvasLayer"]
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
script = ExtResource("3_oi3di")
|
||||
player = NodePath("../../Player")
|
||||
world = NodePath("../..")
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="CanvasLayer/Panel"]
|
||||
[node name="MarginContainer" type="MarginContainer" parent="CanvasLayer/Hand"]
|
||||
layout_mode = 0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="CanvasLayer/Panel/MarginContainer"]
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="CanvasLayer/Hand/MarginContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
extends CharacterBody2D
|
||||
extends Node2D
|
||||
|
||||
# ActionState should probably be expandable to
|
||||
enum ActionState {None, Cycling, Firing, Charging}
|
||||
@@ -8,11 +8,9 @@ enum MoveState {Still, Moving, Dashing, Knockback}
|
||||
@export var dash_cooldown = 0.3
|
||||
@export var hand_size = 3
|
||||
|
||||
@onready var camera: Camera2D = %PlayerCamera
|
||||
@onready var sprite: AnimatedSprite2D = $PlayerSprite
|
||||
|
||||
var shield_active = true;
|
||||
var move_direction = Vector2.ZERO;
|
||||
@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 = [];
|
||||
@@ -45,77 +43,13 @@ func update_move_direction():
|
||||
|
||||
func update_target_coords():
|
||||
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():
|
||||
screen_size = get_viewport_rect().size
|
||||
while (hand.size() < hand_size and drawpile.size() > 0):
|
||||
draw_card();
|
||||
|
||||
func _process(delta):
|
||||
update_target_coords();
|
||||
update_camera_position();
|
||||
if (move_state != MoveState.Dashing):
|
||||
update_move_direction();
|
||||
|
||||
@@ -128,24 +62,12 @@ func _process(delta):
|
||||
# handle move_state
|
||||
if move_state == MoveState.Knockback:
|
||||
pass
|
||||
elif Input.is_action_just_pressed("dash"):
|
||||
dash();
|
||||
elif (move_state != MoveState.Dashing):
|
||||
velocity = move_direction * speed;
|
||||
if velocity.x || velocity.y:
|
||||
move_state = MoveState.Moving;
|
||||
else:
|
||||
move_state = MoveState.Still;
|
||||
|
||||
move_and_slide();
|
||||
|
||||
# Handle action_state
|
||||
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);
|
||||
position += velocity * delta
|
||||
position = position.clamp(Vector2.ZERO, screen_size)
|
||||
|
||||
Reference in New Issue
Block a user