diff --git a/growth/cpu_core.gd b/growth/cpu_core.gd new file mode 100644 index 0000000..ef0900a --- /dev/null +++ b/growth/cpu_core.gd @@ -0,0 +1,13 @@ +extends Node2D + +@onready var sprite: Sprite2D = $Sprite2D + +@export var core_id = 0 + + +func _ready(): + sprite.texture = load("res://assets/icons/Core_" + str(core_id) + ".png") + +func _process(delta): + rotation += delta * 0.5 + sprite.rotation = -rotation diff --git a/growth/cpu_core.gd.uid b/growth/cpu_core.gd.uid new file mode 100644 index 0000000..b3c81fc --- /dev/null +++ b/growth/cpu_core.gd.uid @@ -0,0 +1 @@ +uid://bmqel2posgesr diff --git a/growth/cpu_core.tscn b/growth/cpu_core.tscn new file mode 100644 index 0000000..7d206f8 --- /dev/null +++ b/growth/cpu_core.tscn @@ -0,0 +1,17 @@ +[gd_scene load_steps=3 format=3 uid="uid://bfvhqstsklntn"] + +[ext_resource type="Script" uid="uid://bmqel2posgesr" path="res://assets/animations/Firewalls/cpu_core.gd" id="1_wn7j6"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_8hjvn"] + +[node name="CpuCore" type="Node2D"] +script = ExtResource("1_wn7j6") + +[node name="Area2D" type="Area2D" parent="."] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] +scale = Vector2(20, 20) +shape = SubResource("RectangleShape2D_8hjvn") + +[node name="Sprite2D" type="Sprite2D" parent="."] +scale = Vector2(0.5, 0.5) diff --git a/growth/hand.gd b/growth/hand.gd index 246734c..2829ce9 100644 --- a/growth/hand.gd +++ b/growth/hand.gd @@ -2,29 +2,84 @@ extends Panel @export var player: NodePath @export var world: NodePath +@export const drawpile: Array[PackedScene] = [ + preload("res://Cards/FirewallCard.tscn"), + preload("res://Cards/FirewallCard.tscn"), + preload("res://Cards/CursorGunCard.tscn"), + preload("res://Cards/CursorGunCard.tscn"), + preload("res://Cards/DashCard.tscn"), + preload("res://Cards/DashCard.tscn"), + preload("res://Cards/ShieldCard.tscn"), + preload("res://Cards/ShieldCard.tscn"), + preload("res://Cards/OverclockCard.tscn"), + preload("res://Cards/OverclockCard.tscn"), +] -var dash_card_scene = preload("res://Cards/FirewallCard.tscn") var active_card_index = 0 +const discard_pile = []; + func _ready() -> void: - var actual_dash_card = dash_card_scene.instantiate() - $MarginContainer/HBoxContainer.add_child(actual_dash_card) + for card in drawpile: + card.instantiate() + drawpile.shuffle(); + for i in range(get_node(player).hand_size): + draw_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 + cycle_card(-1); elif Input.is_action_just_pressed("cycle_card_right"): - #player.action_state = ActionState.Cycling; - #player.cycle_card(1); - active_card_index += 1 - + cycle_card(1); func play_card(): - var cards = $MarginContainer/HBoxContainer.get_children(); + var cards = get_cards(); 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) + +func discard(self): + var cards = get_cards(); + if active_card_index >= 0 and active_card_index < cards.size(): + var card = cards[active_card_index] + card.discard(get_node(world), get_node(player)) + + discard_pile.append(card) + get_card_container().remove_child(card) + + active_card_index = min(active_card_index, hand.size() - 1); + draw_card(); + +func cycle_card(index_shift): + if hand.size() > 0: + active_card_index = (active_card_index + index_shift) % hand.size(); + else: + draw_card(); + +func draw_card(): + if drawpile.size() == 0: + shuffle_deck(); + if drawpile.size() > 0 and get_cards().size() < get_node(player).hand_size: + var card = drawpile.pop_back(); + if active_card_index == -1: + active_card_index = 0; + get_card_container().add_child(card) + +# TODO: Reboot mechanics +func shuffle_deck(): + drawpile.append_array(discard_pile) + discard_pile.clear(); + drawpile.shuffle(); + active_card_index = 0; + +func get_cards() -> Array: + return get_card_container().get_children() + +func get_card_container() -> Array: + return $MarginContainer/HBoxContainer + +func get_active_card() -> Card: + return get_cards().get(active_card_index) \ No newline at end of file diff --git a/growth/player.gd b/growth/player.gd index a5e6512..bd7b885 100644 --- a/growth/player.gd +++ b/growth/player.gd @@ -15,10 +15,7 @@ var shield_active = true; var move_direction = Vector2.ZERO; var target = Vector2.ZERO # The position of the player's cursor. -const drawpile = []; -@export var hand = []; -const discard_pile = []; -var active_card_index = -1; +@export var hand; var screen_size # Size of the game window. var action_state = ActionState.None @@ -68,32 +65,13 @@ func charge(): charge_level = max(charge_level - charge_rate * 2, 0); func dash(): - var card = hand.get(active_card_index); + var card = hand.get_active_card(); if not card or dash_on_cooldown: return; - card.discard(self); # Must set move_state at start and end of dash + hand.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(); @@ -103,14 +81,6 @@ func draw_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): @@ -141,14 +111,3 @@ func _process(delta): 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);