Added combat simulation display
This commit is contained in:
parent
db3ec0aa67
commit
c31a4740ae
2
ai/dumb.gd
Normal file
2
ai/dumb.gd
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
static func play(arena, hero, hand):
|
||||||
|
hand.emit_turn_end()
|
|
@ -1,7 +1,7 @@
|
||||||
tool
|
tool
|
||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
signal played(card, anchor)
|
signal played(card, anchor, unit)
|
||||||
|
|
||||||
const AnimHelper = preload("res://helpers/anims.gd")
|
const AnimHelper = preload("res://helpers/anims.gd")
|
||||||
const BattleHelper = preload("res://helpers/battle.gd")
|
const BattleHelper = preload("res://helpers/battle.gd")
|
||||||
|
@ -65,11 +65,14 @@ func update_anchors():
|
||||||
selected_anchor = BattleHelper.update_anchors(get_tree(), position, funcref(self, "can_be_used_on_anchor"))
|
selected_anchor = BattleHelper.update_anchors(get_tree(), position, funcref(self, "can_be_used_on_anchor"))
|
||||||
|
|
||||||
func play(anchor):
|
func play(anchor):
|
||||||
|
var unit
|
||||||
|
|
||||||
if spawned_unit:
|
if spawned_unit:
|
||||||
var unit = spawned_unit.instance()
|
unit = spawned_unit.instance()
|
||||||
unit.attacker = hero.attacker if hero else false
|
unit.attacker = hero.attacker if hero else false
|
||||||
anchor.set_content(unit)
|
anchor.set_content(unit)
|
||||||
emit_signal("played", self, anchor)
|
|
||||||
|
emit_signal("played", self, anchor, unit)
|
||||||
|
|
||||||
func return_to_base():
|
func return_to_base():
|
||||||
AnimHelper.linear_goto(self, base_position, 0.3)
|
AnimHelper.linear_goto(self, base_position, 0.3)
|
||||||
|
|
|
@ -40,6 +40,25 @@ static func list_units(tree: SceneTree):
|
||||||
|
|
||||||
return units
|
return units
|
||||||
|
|
||||||
|
static func apply_combat(attacker: UnitPoints, defender: UnitPoints):
|
||||||
|
""" Apply a unit combat to points
|
||||||
|
"""
|
||||||
|
while attacker.damage:
|
||||||
|
attacker.damage -= 1
|
||||||
|
|
||||||
|
if defender.shield:
|
||||||
|
defender.shield -= 1
|
||||||
|
elif defender.hull:
|
||||||
|
defender.hull -= 1
|
||||||
|
|
||||||
|
while defender.damage:
|
||||||
|
defender.damage -= 1
|
||||||
|
|
||||||
|
if attacker.shield:
|
||||||
|
attacker.shield -= 1
|
||||||
|
elif attacker.hull:
|
||||||
|
attacker.hull -= 1
|
||||||
|
|
||||||
static func get_state(tree: SceneTree):
|
static func get_state(tree: SceneTree):
|
||||||
""" Build the simple state associated with current battle scene
|
""" Build the simple state associated with current battle scene
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -4,6 +4,7 @@ const BattleHelper = preload("res://helpers/battle.gd")
|
||||||
|
|
||||||
export(PackedScene) var deck_attack
|
export(PackedScene) var deck_attack
|
||||||
export(PackedScene) var deck_defend
|
export(PackedScene) var deck_defend
|
||||||
|
export(Script) var defend_ai
|
||||||
|
|
||||||
onready var deck_attack_cards = deck_attack.instance()
|
onready var deck_attack_cards = deck_attack.instance()
|
||||||
onready var deck_defend_cards = deck_defend.instance()
|
onready var deck_defend_cards = deck_defend.instance()
|
||||||
|
@ -15,12 +16,12 @@ func _ready():
|
||||||
hero_attack = create_hero_unit("tomahawk", "attack_start", true)
|
hero_attack = create_hero_unit("tomahawk", "attack_start", true)
|
||||||
hero_defend = create_hero_unit("rhino", "defend_start", false)
|
hero_defend = create_hero_unit("rhino", "defend_start", false)
|
||||||
|
|
||||||
fill_hand($hand_attack, deck_attack_cards, hero_attack)
|
|
||||||
fill_hand($hand_defend, deck_defend_cards, hero_defend)
|
|
||||||
|
|
||||||
$hand_attack.connect("turn_end", self, "end_turn")
|
$hand_attack.connect("turn_end", self, "end_turn")
|
||||||
$hand_defend.connect("turn_end", self, "end_turn")
|
$hand_defend.connect("turn_end", self, "end_turn")
|
||||||
|
|
||||||
|
$combat_info.visible = false
|
||||||
|
|
||||||
|
fill_hands()
|
||||||
adjust_playable()
|
adjust_playable()
|
||||||
|
|
||||||
#print(BattleHelper.get_state(get_tree()))
|
#print(BattleHelper.get_state(get_tree()))
|
||||||
|
@ -34,7 +35,9 @@ func find_free_anchor(anchor_type: String):
|
||||||
func create_hero_unit(name: String, anchor_type: String, attacker: bool):
|
func create_hero_unit(name: String, anchor_type: String, attacker: bool):
|
||||||
var anchor = find_free_anchor(anchor_type)
|
var anchor = find_free_anchor(anchor_type)
|
||||||
if anchor:
|
if anchor:
|
||||||
return BattleHelper.spawn_unit("heroes/" + name, anchor, attacker)
|
var unit = BattleHelper.spawn_unit("heroes/" + name, anchor, attacker)
|
||||||
|
unit.connect("combat_simulation", self, "_on_combat_simulation")
|
||||||
|
return unit
|
||||||
else:
|
else:
|
||||||
return null
|
return null
|
||||||
|
|
||||||
|
@ -48,12 +51,36 @@ func fill_hand(hand: Node, deck: Node, hero: Node, limit=4):
|
||||||
|
|
||||||
hand.rearrange()
|
hand.rearrange()
|
||||||
|
|
||||||
|
func fill_hands():
|
||||||
|
fill_hand($hand_attack, deck_attack_cards, hero_attack)
|
||||||
|
fill_hand($hand_defend, deck_defend_cards, hero_defend)
|
||||||
|
|
||||||
func end_turn():
|
func end_turn():
|
||||||
turn_attack = not turn_attack
|
turn_attack = not turn_attack
|
||||||
|
fill_hands()
|
||||||
adjust_playable()
|
adjust_playable()
|
||||||
|
for unit in BattleHelper.list_units(get_tree()):
|
||||||
|
unit.turn_ended()
|
||||||
|
|
||||||
|
func _process(delta):
|
||||||
|
if not turn_attack and defend_ai:
|
||||||
|
defend_ai.play($arena, hero_defend, $hand_defend)
|
||||||
|
|
||||||
func adjust_playable():
|
func adjust_playable():
|
||||||
$hand_attack.visible = turn_attack
|
$hand_attack.visible = turn_attack
|
||||||
|
|
||||||
for unit in BattleHelper.list_units(get_tree()):
|
for unit in BattleHelper.list_units(get_tree()):
|
||||||
unit.playable = unit.attacker == turn_attack
|
unit.playable = unit.attacker == turn_attack
|
||||||
|
|
||||||
|
func _on_unit_created(unit):
|
||||||
|
unit.connect("combat_simulation", self, "_on_combat_simulation")
|
||||||
|
|
||||||
|
func _on_combat_simulation(attacker, defender):
|
||||||
|
if attacker and defender:
|
||||||
|
$combat_info/attacker_points.set_from(attacker.get_points())
|
||||||
|
$combat_info/defender_points.set_from(defender.get_points())
|
||||||
|
BattleHelper.apply_combat($combat_info/attacker_points, $combat_info/defender_points)
|
||||||
|
$combat_info.visible = true
|
||||||
|
$hand_attack.visible = false
|
||||||
|
else:
|
||||||
|
$combat_info.visible = false
|
||||||
|
$hand_attack.visible = turn_attack
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
[gd_scene load_steps=8 format=2]
|
[gd_scene load_steps=10 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://screens/battle/mechanolith.ogg" type="AudioStream" id=1]
|
[ext_resource path="res://screens/battle/mechanolith.ogg" type="AudioStream" id=1]
|
||||||
[ext_resource path="res://theme/ui.tres" type="Theme" id=2]
|
[ext_resource path="res://theme/ui.tres" type="Theme" id=2]
|
||||||
|
@ -6,6 +6,8 @@
|
||||||
[ext_resource path="res://screens/battle/background.jpg" type="Texture" id=4]
|
[ext_resource path="res://screens/battle/background.jpg" type="Texture" id=4]
|
||||||
[ext_resource path="res://screens/battle/battle.gd" type="Script" id=5]
|
[ext_resource path="res://screens/battle/battle.gd" type="Script" id=5]
|
||||||
[ext_resource path="res://screens/battle/hand.gd" type="Script" id=6]
|
[ext_resource path="res://screens/battle/hand.gd" type="Script" id=6]
|
||||||
|
[ext_resource path="res://units/points.tscn" type="PackedScene" id=7]
|
||||||
|
[ext_resource path="res://ai/dumb.gd" type="Script" id=8]
|
||||||
[ext_resource path="res://decks/all.tscn" type="PackedScene" id=9]
|
[ext_resource path="res://decks/all.tscn" type="PackedScene" id=9]
|
||||||
|
|
||||||
[node name="view" type="Panel"]
|
[node name="view" type="Panel"]
|
||||||
|
@ -14,10 +16,12 @@ anchor_bottom = 1.0
|
||||||
theme = ExtResource( 2 )
|
theme = ExtResource( 2 )
|
||||||
script = ExtResource( 5 )
|
script = ExtResource( 5 )
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
|
"_edit_lock_": true,
|
||||||
"_edit_use_anchors_": false
|
"_edit_use_anchors_": false
|
||||||
}
|
}
|
||||||
deck_attack = ExtResource( 9 )
|
deck_attack = ExtResource( 9 )
|
||||||
deck_defend = ExtResource( 9 )
|
deck_defend = ExtResource( 9 )
|
||||||
|
defend_ai = ExtResource( 8 )
|
||||||
|
|
||||||
[node name="background" type="Sprite" parent="."]
|
[node name="background" type="Sprite" parent="."]
|
||||||
position = Vector2( 540, 970 )
|
position = Vector2( 540, 970 )
|
||||||
|
@ -27,7 +31,7 @@ __meta__ = {
|
||||||
"_edit_lock_": true
|
"_edit_lock_": true
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="arena_normal1" parent="." instance=ExtResource( 3 )]
|
[node name="arena" parent="." instance=ExtResource( 3 )]
|
||||||
|
|
||||||
[node name="bgm" type="AudioStreamPlayer" parent="."]
|
[node name="bgm" type="AudioStreamPlayer" parent="."]
|
||||||
stream = ExtResource( 1 )
|
stream = ExtResource( 1 )
|
||||||
|
@ -69,3 +73,20 @@ script = ExtResource( 6 )
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
"_edit_use_anchors_": false
|
"_edit_use_anchors_": false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[node name="combat_info" type="Control" parent="."]
|
||||||
|
anchor_top = 1.0
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="attacker_points" parent="combat_info" instance=ExtResource( 7 )]
|
||||||
|
position = Vector2( 260, -167.5 )
|
||||||
|
|
||||||
|
[node name="defender_points" parent="combat_info" instance=ExtResource( 7 )]
|
||||||
|
position = Vector2( 840, -167.5 )
|
||||||
|
[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"]
|
||||||
|
|
|
@ -2,15 +2,12 @@ extends Control
|
||||||
|
|
||||||
const NodesHelpers = preload("res://helpers/nodes.gd")
|
const NodesHelpers = preload("res://helpers/nodes.gd")
|
||||||
|
|
||||||
|
signal unit_created(unit)
|
||||||
signal turn_end
|
signal turn_end
|
||||||
|
|
||||||
export var attack = false
|
export var attack = false
|
||||||
var cards = []
|
var cards = []
|
||||||
|
|
||||||
func _ready():
|
|
||||||
if has_node("skip"):
|
|
||||||
$skip.connect("pressed", self, "emit_turn_end")
|
|
||||||
|
|
||||||
func add_card(card):
|
func add_card(card):
|
||||||
""" Add a card to the hand
|
""" Add a card to the hand
|
||||||
"""
|
"""
|
||||||
|
@ -31,12 +28,14 @@ func rearrange():
|
||||||
card.set_hand_location(Vector2(i * 210, 0))
|
card.set_hand_location(Vector2(i * 210, 0))
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
func on_card_played(card, anchor):
|
func on_card_played(card, anchor, unit):
|
||||||
""" Called when a card is played
|
""" Called when a card is played
|
||||||
"""
|
"""
|
||||||
card.queue_free()
|
card.queue_free()
|
||||||
cards.erase(card)
|
cards.erase(card)
|
||||||
rearrange()
|
rearrange()
|
||||||
|
if unit:
|
||||||
|
emit_signal("unit_created", unit)
|
||||||
emit_turn_end()
|
emit_turn_end()
|
||||||
|
|
||||||
func emit_turn_end():
|
func emit_turn_end():
|
||||||
|
|
|
@ -3,6 +3,8 @@ extends Node2D
|
||||||
|
|
||||||
class_name BaseUnit
|
class_name BaseUnit
|
||||||
|
|
||||||
|
signal combat_simulation(attacker, defender)
|
||||||
|
|
||||||
const AnimHelper = preload("res://helpers/anims.gd")
|
const AnimHelper = preload("res://helpers/anims.gd")
|
||||||
const BattleHelper = preload("res://helpers/battle.gd")
|
const BattleHelper = preload("res://helpers/battle.gd")
|
||||||
|
|
||||||
|
@ -38,10 +40,7 @@ func destroy():
|
||||||
func set_attacker(val):
|
func set_attacker(val):
|
||||||
attacker = val
|
attacker = val
|
||||||
if has_node("points"):
|
if has_node("points"):
|
||||||
if attacker:
|
$points.enemy = not attacker
|
||||||
$points.modulate = Color(1.0, 1.0, 1.0)
|
|
||||||
else:
|
|
||||||
$points.modulate = Color(1.0, 0.3, 0.3)
|
|
||||||
|
|
||||||
func set_playable(val):
|
func set_playable(val):
|
||||||
playable = val
|
playable = val
|
||||||
|
@ -88,14 +87,25 @@ func update_anchors():
|
||||||
selected_anchor = BattleHelper.update_anchors(get_tree(), dragged, funcref(self, "can_be_used_on_anchor"))
|
selected_anchor = BattleHelper.update_anchors(get_tree(), dragged, funcref(self, "can_be_used_on_anchor"))
|
||||||
|
|
||||||
func play(anchor):
|
func play(anchor):
|
||||||
if playable:
|
if playable and anchor:
|
||||||
if anchor.is_empty():
|
if anchor.is_empty():
|
||||||
move_to(anchor)
|
move_to(anchor)
|
||||||
else:
|
else:
|
||||||
var other = anchor.get_content()
|
var other = anchor.get_content()
|
||||||
if other.has_method("get_points"):
|
if other.has_method("get_points"):
|
||||||
attack(other)
|
attack(other)
|
||||||
return_to_base()
|
|
||||||
|
reset_state()
|
||||||
|
|
||||||
|
func simulate(anchor):
|
||||||
|
if playable and anchor and not anchor.is_empty():
|
||||||
|
var other = anchor.get_content()
|
||||||
|
if other.has_method("get_points"):
|
||||||
|
emit_signal("combat_simulation", self, other)
|
||||||
|
else:
|
||||||
|
emit_signal("combat_simulation", null, null)
|
||||||
|
else:
|
||||||
|
emit_signal("combat_simulation", null, null)
|
||||||
|
|
||||||
func move_to(anchor):
|
func move_to(anchor):
|
||||||
if $points.move:
|
if $points.move:
|
||||||
|
@ -112,47 +122,36 @@ func get_points() -> UnitPoints:
|
||||||
else:
|
else:
|
||||||
return null
|
return null
|
||||||
|
|
||||||
func attack(other) -> bool:
|
func attack(other):
|
||||||
var selfpoints = get_points()
|
var selfpoints = get_points()
|
||||||
var otherpoints = other.get_points()
|
var otherpoints = other.get_points()
|
||||||
|
|
||||||
while selfpoints.damage:
|
BattleHelper.apply_combat(selfpoints, otherpoints)
|
||||||
selfpoints.damage -= 1
|
|
||||||
|
|
||||||
if otherpoints.shield:
|
|
||||||
otherpoints.shield -= 1
|
|
||||||
elif otherpoints.hull:
|
|
||||||
otherpoints.hull -= 1
|
|
||||||
|
|
||||||
while otherpoints.damage:
|
|
||||||
otherpoints.damage -= 1
|
|
||||||
|
|
||||||
if selfpoints.shield:
|
|
||||||
selfpoints.shield -= 1
|
|
||||||
elif selfpoints.hull:
|
|
||||||
selfpoints.hull -= 1
|
|
||||||
|
|
||||||
if selfpoints.hull <= 0:
|
if selfpoints.hull <= 0:
|
||||||
destroy()
|
destroy()
|
||||||
if otherpoints.hull <= 0:
|
if otherpoints.hull <= 0:
|
||||||
other.destroy()
|
other.destroy()
|
||||||
|
|
||||||
return selfpoints.hull > 0 && otherpoints.hull == 0
|
func reset_state():
|
||||||
|
|
||||||
func return_to_base():
|
|
||||||
dragged = null
|
dragged = null
|
||||||
$move_hint.visible = false
|
$move_hint.visible = false
|
||||||
$move_hint.set_point_position(1, Vector2(0, 0))
|
$move_hint.set_point_position(1, Vector2(0, 0))
|
||||||
|
|
||||||
|
func turn_ended():
|
||||||
|
$points.move = base_move_points
|
||||||
|
$points.damage = base_damage_points
|
||||||
|
$points.shield = base_shield_points
|
||||||
|
|
||||||
func on_dragged(active, relative, absolute):
|
func on_dragged(active, relative, absolute):
|
||||||
if not playable:
|
if not playable:
|
||||||
return
|
return
|
||||||
|
|
||||||
if dragged and not active:
|
if active:
|
||||||
if selected_anchor:
|
simulate(selected_anchor)
|
||||||
|
elif dragged:
|
||||||
|
simulate(null)
|
||||||
play(selected_anchor)
|
play(selected_anchor)
|
||||||
else:
|
|
||||||
return_to_base()
|
|
||||||
|
|
||||||
$move_hint.visible = active
|
$move_hint.visible = active
|
||||||
|
|
||||||
|
|
|
@ -7,12 +7,14 @@ export var move = 0 setget set_move
|
||||||
export var hull = 0 setget set_hull
|
export var hull = 0 setget set_hull
|
||||||
export var shield = 0 setget set_shield
|
export var shield = 0 setget set_shield
|
||||||
export var damage = 0 setget set_damage
|
export var damage = 0 setget set_damage
|
||||||
|
export var enemy = false setget set_enemy
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
set_move(move)
|
set_move(move)
|
||||||
set_hull(hull)
|
set_hull(hull)
|
||||||
set_shield(shield)
|
set_shield(shield)
|
||||||
set_damage(damage)
|
set_damage(damage)
|
||||||
|
set_enemy(enemy)
|
||||||
|
|
||||||
func set_move(val):
|
func set_move(val):
|
||||||
move = val
|
move = val
|
||||||
|
@ -34,3 +36,16 @@ func set_damage(val):
|
||||||
if has_node("hud/damage"):
|
if has_node("hud/damage"):
|
||||||
$hud/damage.text = String(val)
|
$hud/damage.text = String(val)
|
||||||
|
|
||||||
|
func set_enemy(val):
|
||||||
|
enemy = val
|
||||||
|
if enemy:
|
||||||
|
modulate = Color(1.0, 0.3, 0.3)
|
||||||
|
else:
|
||||||
|
modulate = Color(1.0, 1.0, 1.0)
|
||||||
|
|
||||||
|
func set_from(other):
|
||||||
|
set_move(other.move)
|
||||||
|
set_hull(other.hull)
|
||||||
|
set_shield(other.shield)
|
||||||
|
set_damage(other.damage)
|
||||||
|
set_enemy(other.enemy)
|
||||||
|
|
Loading…
Reference in a new issue