diff --git a/arenas/anchor.gd b/arenas/anchor.gd index 8370d9c..76cdda2 100644 --- a/arenas/anchor.gd +++ b/arenas/anchor.gd @@ -5,7 +5,8 @@ class_name Anchor export var selectable = false export var selected = false export(String, "normal", "attack_start", "defend_start") var anchor_type = "normal" -export(NodePath) var content + +var content func _process(delta): if selected: @@ -18,6 +19,9 @@ func _process(delta): func _ready(): add_to_group("anchors") + if not content and self.get_child_count() == 1: + set_content(self.get_child(0)) + func is_connected_to(other: Anchor) -> bool: for route in get_tree().get_nodes_in_group("routes"): if route is Route and route.is_connecting(self, other): @@ -31,16 +35,14 @@ func set_content(val): if old_parent.has_method("set_content"): old_parent.set_content(null) old_parent.remove_child(val) - self.add_child(val) - content = val.get_path() + if not get_children().has(val): + add_child(val) + content = val else: content = null func get_content(): - if content: - return get_node_or_null(content) - else: - return null + return content if content else null func is_empty() -> bool: - return not get_content() + return not content diff --git a/cards/base_card.gd b/cards/base_card.gd index 9b6a1c4..e4df8bf 100644 --- a/cards/base_card.gd +++ b/cards/base_card.gd @@ -9,6 +9,7 @@ const BattleHelper = preload("res://helpers/battle.gd") export var title = "Card" setget set_title export(Texture) var portrait setget set_portrait export(PackedScene) var spawned_unit setget set_spawned_unit +export var damage_dealt = 0 setget set_damage_dealt var dragged = false var base_position @@ -19,6 +20,7 @@ func _ready(): set_portrait(portrait) set_title(title) set_spawned_unit(spawned_unit) + set_damage_dealt(damage_dealt) base_position = position func get_size() -> Vector2: @@ -47,6 +49,15 @@ func set_spawned_unit(val): else: $points.visible = false +func set_damage_dealt(val): + damage_dealt = val + if has_node("damage"): + if damage_dealt: + $damage/value.text = String(damage_dealt) + $damage.visible = true + else: + $damage.visible = false + func set_hero(val: Node): hero = val @@ -73,6 +84,11 @@ func play(anchor): if spawned_unit: unit = BattleHelper.spawn_unit(spawned_unit, anchor, hero.attacker if hero else false) + if damage_dealt: + var target = anchor.get_content() + if target and target.has_method("do_damage"): + target.do_damage(damage_dealt) + emit_signal("played", self, anchor, unit) func return_to_base(): diff --git a/cards/base_card.tscn b/cards/base_card.tscn index 39a784d..0a99f0e 100644 --- a/cards/base_card.tscn +++ b/cards/base_card.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=8 format=2] +[gd_scene load_steps=9 format=2] [ext_resource path="res://cards/base_card.png" type="Texture" id=1] [ext_resource path="res://cards/base_card.gd" type="Script" id=2] @@ -6,6 +6,7 @@ [ext_resource path="res://theme/fonts/daggersquare.regular.otf" type="DynamicFontData" id=4] [ext_resource path="res://helpers/drag.gd" type="Script" id=5] [ext_resource path="res://units/points.tscn" type="PackedScene" id=6] +[ext_resource path="res://cards/damage.png" type="Texture" id=7] [sub_resource type="DynamicFont" id=1] size = 32 @@ -43,6 +44,29 @@ position = Vector2( 130, 171 ) visible = false position = Vector2( 130, 299 ) scale = Vector2( 0.75, 0.75 ) +move = 0 +hull = 0 +shield = 0 +damage = 0 +enemy = false + +[node name="damage" type="Sprite" parent="."] +visible = false +position = Vector2( 130, 299 ) +scale = Vector2( 0.75, 0.75 ) +texture = ExtResource( 7 ) + +[node name="value" type="Label" parent="damage"] +margin_left = 1.26668 +margin_top = -24.0666 +margin_right = 41.2667 +margin_bottom = 24.9334 +theme = ExtResource( 3 ) +text = "1" +align = 1 +__meta__ = { +"_edit_use_anchors_": false +} [node name="drag" type="Control" parent="."] margin_right = 260.0 diff --git a/cards/damage.png b/cards/damage.png new file mode 100644 index 0000000..6f529ed Binary files /dev/null and b/cards/damage.png differ diff --git a/cards/damage.png.import b/cards/damage.png.import new file mode 100644 index 0000000..6cd1691 --- /dev/null +++ b/cards/damage.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/damage.png-3352fd8ab631efa2b7ccbb8d4b72932a.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://cards/damage.png" +dest_files=[ "res://.import/damage.png-3352fd8ab631efa2b7ccbb8d4b72932a.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/cards/damage.svg b/cards/damage.svg new file mode 100644 index 0000000..af529a8 --- /dev/null +++ b/cards/damage.svg @@ -0,0 +1,217 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/cards/damage.svg.import b/cards/damage.svg.import new file mode 100644 index 0000000..4bd80ab --- /dev/null +++ b/cards/damage.svg.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/damage.svg-5bef143185717e9acb3627b0c36c69a2.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://cards/damage.svg" +dest_files=[ "res://.import/damage.svg-5bef143185717e9acb3627b0c36c69a2.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/cards/weapons/gatling.png b/cards/weapons/gatling.png new file mode 100644 index 0000000..f30599c Binary files /dev/null and b/cards/weapons/gatling.png differ diff --git a/cards/weapons/gatling.png.import b/cards/weapons/gatling.png.import new file mode 100644 index 0000000..9f78bbb --- /dev/null +++ b/cards/weapons/gatling.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/gatling.png-f06085be1d8034bbf73061f63324e83c.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://cards/weapons/gatling.png" +dest_files=[ "res://.import/gatling.png-f06085be1d8034bbf73061f63324e83c.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/cards/weapons/gatling.svg b/cards/weapons/gatling.svg new file mode 100644 index 0000000..4900029 --- /dev/null +++ b/cards/weapons/gatling.svg @@ -0,0 +1,928 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cards/weapons/gatling.svg.import b/cards/weapons/gatling.svg.import new file mode 100644 index 0000000..b485341 --- /dev/null +++ b/cards/weapons/gatling.svg.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/gatling.svg-9eb48f3b5b8778c8c99b3fcf328890a7.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://cards/weapons/gatling.svg" +dest_files=[ "res://.import/gatling.svg-9eb48f3b5b8778c8c99b3fcf328890a7.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/cards/weapons/gatling.tscn b/cards/weapons/gatling.tscn new file mode 100644 index 0000000..d28aca6 --- /dev/null +++ b/cards/weapons/gatling.tscn @@ -0,0 +1,21 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://cards/base_card.tscn" type="PackedScene" id=1] +[ext_resource path="res://cards/weapons/gatling.png" type="Texture" id=2] + +[node name="card" instance=ExtResource( 1 )] +title = "Gatling Gun" +portrait = ExtResource( 2 ) +damage_dealt = 3 + +[node name="title" parent="." index="1"] +text = "Gatling Gun" + +[node name="portrait" parent="." index="2"] +texture = ExtResource( 2 ) + +[node name="damage" parent="." index="4"] +visible = true + +[node name="value" parent="damage" index="0"] +text = "3" diff --git a/decks/all.tscn b/decks/all.tscn index a6692f1..1e7311b 100644 --- a/decks/all.tscn +++ b/decks/all.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=10 format=2] +[gd_scene load_steps=11 format=2] [ext_resource path="res://cards/spawns/spawn_trapper.tscn" type="PackedScene" id=1] [ext_resource path="res://cards/spawns/spawn_xander.tscn" type="PackedScene" id=2] @@ -9,31 +9,35 @@ [ext_resource path="res://cards/spawns/spawn_avenger.tscn" type="PackedScene" id=7] [ext_resource path="res://cards/spawns/spawn_commodore.tscn" type="PackedScene" id=8] [ext_resource path="res://cards/spawns/spawn_creeper.tscn" type="PackedScene" id=9] +[ext_resource path="res://cards/weapons/gatling.tscn" type="PackedScene" id=10] [node name="deck" type="Node2D"] [node name="spawn_avenger" parent="." instance=ExtResource( 7 )] [node name="spawn_breeze" parent="." instance=ExtResource( 3 )] -position = Vector2( 270, 0 ) +position = Vector2( 272, 0 ) [node name="spawn_commorode" parent="." instance=ExtResource( 8 )] -position = Vector2( 540, 0 ) +position = Vector2( 544, 0 ) [node name="spawn_creeper" parent="." instance=ExtResource( 9 )] -position = Vector2( 810, 0 ) +position = Vector2( 816, 0 ) [node name="spawn_falcon" parent="." instance=ExtResource( 6 )] -position = Vector2( 0, 330 ) +position = Vector2( 0, 336 ) [node name="spawn_flea" parent="." instance=ExtResource( 5 )] -position = Vector2( 270, 330 ) +position = Vector2( 272, 336 ) [node name="spawn_jumper" parent="." instance=ExtResource( 4 )] -position = Vector2( 540, 330 ) +position = Vector2( 544, 336 ) [node name="spawn_trapper" parent="." instance=ExtResource( 1 )] -position = Vector2( 810, 330 ) +position = Vector2( 816, 336 ) [node name="spawn_xander" parent="." instance=ExtResource( 2 )] -position = Vector2( 0, 660 ) +position = Vector2( 0, 672 ) + +[node name="card" parent="." instance=ExtResource( 10 )] +position = Vector2( 272, 672 ) diff --git a/helpers/nodes.gd b/helpers/nodes.gd index e1cc157..6f71ab2 100644 --- a/helpers/nodes.gd +++ b/helpers/nodes.gd @@ -4,5 +4,5 @@ static func set_parent(node: Node, parent: Node): var old_parent = node.get_parent() if old_parent and old_parent != parent: old_parent.remove_child(node) - + parent.add_child(node) diff --git a/screens/battle/battle.tscn b/screens/battle/battle.tscn index 1b5affb..98c99b1 100644 --- a/screens/battle/battle.tscn +++ b/screens/battle/battle.tscn @@ -12,7 +12,7 @@ [ext_resource path="res://units/heroes/tomahawk.tscn" type="PackedScene" id=10] [ext_resource path="res://units/heroes/rhino.tscn" type="PackedScene" id=11] -[sub_resource type="GDScript" id=2] +[sub_resource type="GDScript" id=1] script/source = "extends Polygon2D func start(text): @@ -20,8 +20,7 @@ func start(text): $anim.play(\"show\") " -[sub_resource type="Animation" id=1] -resource_name = "show" +[sub_resource type="Animation" id=2] length = 1.5 tracks/0/type = "value" tracks/0/path = NodePath(".:position") @@ -124,16 +123,26 @@ __meta__ = { [node name="attacker_points" parent="combat_info" instance=ExtResource( 7 )] position = Vector2( 260, -167.5 ) +move = 0 +hull = 0 +shield = 0 +damage = 0 +enemy = false [node name="defender_points" parent="combat_info" instance=ExtResource( 7 )] position = Vector2( 840, -167.5 ) +move = 0 +hull = 0 +shield = 0 +damage = 0 +enemy = false [node name="turn_indicator" type="Polygon2D" parent="."] position = Vector2( 170, 80 ) z_index = 50 color = Color( 0.227451, 0.392157, 0.47451, 1 ) polygon = PoolVector2Array( -570, 980, -470, 780, 1420, 780, 1320, 980 ) -script = SubResource( 2 ) +script = SubResource( 1 ) __meta__ = { "_edit_group_": true } @@ -155,7 +164,7 @@ __meta__ = { } [node name="anim" type="AnimationPlayer" parent="turn_indicator"] -anims/show = SubResource( 1 ) +anims/show = SubResource( 2 ) [connection signal="unit_created" from="hand_attack" to="." method="_on_unit_created"] [connection signal="pressed" from="hand_attack/skip" to="hand_attack" method="emit_turn_end"] [connection signal="unit_created" from="hand_defend" to="." method="_on_unit_created"] diff --git a/tests/hand_play_card.tscn b/tests/hand_play_card.tscn index c1e5190..b5ee9a7 100644 --- a/tests/hand_play_card.tscn +++ b/tests/hand_play_card.tscn @@ -1,23 +1,103 @@ -[gd_scene load_steps=6 format=2] +[gd_scene load_steps=10 format=2] [ext_resource path="res://screens/battle/hand.gd" type="Script" id=1] [ext_resource path="res://arenas/anchor.tscn" type="PackedScene" id=2] [ext_resource path="res://cards/spawns/spawn_breeze.tscn" type="PackedScene" id=3] [ext_resource path="res://theme/ui.tres" type="Theme" id=4] +[ext_resource path="res://arenas/route.tscn" type="PackedScene" id=5] +[ext_resource path="res://units/heroes/tomahawk.tscn" type="PackedScene" id=6] +[ext_resource path="res://cards/weapons/gatling.tscn" type="PackedScene" id=7] +[ext_resource path="res://units/basic/avenger.tscn" type="PackedScene" id=8] [sub_resource type="GDScript" id=1] script/source = "extends Node2D func _ready(): - $hand.add_card($card) + $card_unit.set_hero($arena1/anchor3/hero) + $hand.add_card($card_unit) + $card_weapon.set_hero($arena2/anchor1/hero) + $hand.add_card($card_weapon) $hand.rearrange() " [node name="Node2D" type="Node2D"] script = SubResource( 1 ) -[node name="anchor" parent="." instance=ExtResource( 2 )] -position = Vector2( 570, 900 ) +[node name="arena1" type="Node2D" parent="."] + +[node name="help" type="Label" parent="arena1"] +margin_left = 8.0 +margin_top = 360.0 +margin_right = 1080.0 +margin_bottom = 409.0 +theme = ExtResource( 4 ) +text = "Units can be deployed next to the hero unit" +align = 1 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="route1" parent="arena1" instance=ExtResource( 5 )] +points = PoolVector2Array( 192, 192, 552, 192 ) +start = NodePath("../anchor1") +end = NodePath("../anchor2") + +[node name="route2" parent="arena1" instance=ExtResource( 5 )] +points = PoolVector2Array( 552, 192, 896, 192 ) +start = NodePath("../anchor2") +end = NodePath("../anchor3") + +[node name="anchor1" parent="arena1" instance=ExtResource( 2 )] +position = Vector2( 192, 192 ) + +[node name="anchor2" parent="arena1" instance=ExtResource( 2 )] +position = Vector2( 552, 192 ) + +[node name="anchor3" parent="arena1" instance=ExtResource( 2 )] +position = Vector2( 896, 192 ) + +[node name="hero" parent="arena1/anchor3" instance=ExtResource( 6 )] +attacker = true + +[node name="arena2" type="Node2D" parent="."] + +[node name="help2" type="Label" parent="arena2"] +margin_left = 8.0 +margin_top = 872.0 +margin_right = 1080.0 +margin_bottom = 921.0 +theme = ExtResource( 4 ) +text = "Weapons can fire from the hero unit" +align = 1 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="route1" parent="arena2" instance=ExtResource( 5 )] +points = PoolVector2Array( 192, 640, 512, 640 ) +start = NodePath("../anchor1") +end = NodePath("../anchor2") + +[node name="route2" parent="arena2" instance=ExtResource( 5 )] +points = PoolVector2Array( 512, 640, 832, 640 ) +start = NodePath("../anchor2") +end = NodePath("../anchor3") + +[node name="anchor1" parent="arena2" instance=ExtResource( 2 )] +position = Vector2( 192, 640 ) + +[node name="hero" parent="arena2/anchor1" instance=ExtResource( 6 )] +attacker = true + +[node name="anchor2" parent="arena2" instance=ExtResource( 2 )] +position = Vector2( 512, 640 ) + +[node name="avenger" parent="arena2/anchor2" instance=ExtResource( 8 )] + +[node name="anchor3" parent="arena2" instance=ExtResource( 2 )] +position = Vector2( 832, 640 ) + +[node name="avenger" parent="arena2/anchor3" instance=ExtResource( 8 )] [node name="hand" type="Control" parent="."] margin_left = 160.0 @@ -28,16 +108,10 @@ script = ExtResource( 1 ) __meta__ = { "_edit_use_anchors_": false } +attack = true -[node name="card" parent="." instance=ExtResource( 3 )] +[node name="card_unit" parent="." instance=ExtResource( 3 )] +position = Vector2( -320, 0 ) -[node name="help" type="Label" parent="."] -margin_left = 170.0 -margin_top = 470.0 -margin_right = 953.0 -margin_bottom = 519.0 -theme = ExtResource( 4 ) -text = "Drag the card to the anchor, to deploy it" -__meta__ = { -"_edit_use_anchors_": false -} +[node name="card_weapon" parent="." instance=ExtResource( 7 )] +position = Vector2( -320, 520 ) diff --git a/tests/unit_combat.tscn b/tests/unit_combat.tscn index 8794f0d..c8a2b4c 100644 --- a/tests/unit_combat.tscn +++ b/tests/unit_combat.tscn @@ -6,7 +6,6 @@ [ext_resource path="res://units/basic/flea.tscn" type="PackedScene" id=4] [ext_resource path="res://units/basic/avenger.tscn" type="PackedScene" id=5] - [node name="Node2D" type="Node2D"] [node name="route" parent="." instance=ExtResource( 1 )] @@ -21,9 +20,9 @@ end = NodePath("../anchor3") [node name="anchor" parent="." instance=ExtResource( 2 )] position = Vector2( 400, 800 ) -content = NodePath("flea") [node name="flea" parent="anchor" instance=ExtResource( 4 )] +modulate = Color( 1, 1, 1, 1 ) base_move_points = 1 base_hull_points = 2 base_damage_points = 2 @@ -32,10 +31,8 @@ playable = true [node name="anchor2" parent="." instance=ExtResource( 2 )] position = Vector2( 700, 800 ) -content = NodePath("trapper") [node name="trapper" parent="anchor2" instance=ExtResource( 3 )] -modulate = Color( 0.5, 0.5, 0.5, 1 ) base_move_points = 0 base_hull_points = 1 base_shield_points = 0 @@ -43,8 +40,6 @@ base_damage_points = 2 [node name="anchor3" parent="." instance=ExtResource( 2 )] position = Vector2( 550, 1100 ) -content = NodePath("avenger") [node name="avenger" parent="anchor3" instance=ExtResource( 5 )] -modulate = Color( 0.5, 0.5, 0.5, 1 ) base_shield_points = 3 diff --git a/tests/unit_move.tscn b/tests/unit_move.tscn index 5904239..9ed3817 100644 --- a/tests/unit_move.tscn +++ b/tests/unit_move.tscn @@ -23,7 +23,6 @@ end = NodePath("../anchor") [node name="anchor" parent="." instance=ExtResource( 1 )] position = Vector2( 300, 900 ) -content = NodePath("creeper") [node name="creeper" parent="anchor" instance=ExtResource( 3 )] modulate = Color( 1, 1, 1, 1 ) diff --git a/units/base_unit.gd b/units/base_unit.gd index c7df612..4ffe7f5 100644 --- a/units/base_unit.gd +++ b/units/base_unit.gd @@ -133,6 +133,14 @@ func attack(other): if otherpoints.hull <= 0: other.destroy() +func do_damage(val): + var selfpoints = get_points() + var fakepoints = load("res://units/points.tscn").instance() + fakepoints.damage = val + BattleHelper.apply_combat(fakepoints, get_points()) + if selfpoints.hull <= 0: + destroy() + func reset_state(): dragged = null $move_hint.visible = false