Add game end condition and restart/quit menu

This commit is contained in:
Kienan Stewart 2022-04-02 23:13:46 -04:00
parent 5c7839d84c
commit 911bceb750
5 changed files with 116 additions and 12 deletions

14
TODO.md
View File

@ -2,23 +2,21 @@
* every now and again, the opponents has new units that spawn
* indicator to show respawn is nearing
* is it all the missing units, or a chance for each?
2. game end
* when a side is out of pieces
3. Power ups
2. Power ups
* a chance of having power ups spawn on an random unoccupied square when a unit dies
* +health, +attack, +speed, +jump, (pawn only) remove "attack_only", spawn a new (random?) piece, change movement type
* then the enemy respawns units, their new untis are stronger
* then the enemy respawns units, their new units are stronger
* support for pieces with multiple hit points
* unit info panel
4. Visual polish
3. Visual polish
* clean up tile borders
* multiple square tiles to add variation
* make the help text indicate (flash, etc.)
5. Sound effects
4. Sound effects
* on hit
* on piece lost
* on piece kill
* on opponent victory
* if possible, a small bit of background music
6. Further visual polish
7. New units
5. Further visual polish
6. New units

View File

@ -43,6 +43,13 @@ window/size/height=1024
window/stretch/mode="2d"
window/stretch/aspect="keep"
[input]
cancel={
"deadzone": 0.5,
"events": [ ]
}
[rendering]
environment/default_environment="res://default_env.tres"

53
src/EndMenu.tscn Normal file
View File

@ -0,0 +1,53 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://assets/source/Bitstream Vera Sans Mono Bold Nerd Font Complete.ttf" type="DynamicFontData" id=1]
[sub_resource type="DynamicFont" id=1]
size = 32
font_data = ExtResource( 1 )
[sub_resource type="DynamicFont" id=2]
size = 24
font_data = ExtResource( 1 )
[node name="Control" type="WindowDialog"]
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 256.0
margin_top = 256.0
margin_right = -256.0
margin_bottom = -512.0
popup_exclusive = true
[node name="VBoxContainer" type="VBoxContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 40.0
margin_top = 40.0
margin_right = -40.0
margin_bottom = -40.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Label" type="Label" parent="VBoxContainer"]
margin_right = 688.0
margin_bottom = 38.0
custom_fonts/font = SubResource( 1 )
text = "Game over!"
align = 1
valign = 1
[node name="New" type="Button" parent="VBoxContainer"]
margin_top = 42.0
margin_right = 688.0
margin_bottom = 77.0
custom_fonts/font = SubResource( 2 )
text = "New Game"
[node name="Quit" type="Button" parent="VBoxContainer"]
margin_top = 81.0
margin_right = 688.0
margin_bottom = 116.0
custom_fonts/font = SubResource( 2 )
text = "Quit"

View File

@ -238,8 +238,31 @@ func _ready():
self.pf_scale = scale
self.rng = RandomNumberGenerator.new()
self.rng.randomize()
get_node("/root/Game/EndMenu/VBoxContainer/New").connect("pressed", self, "_on_new_game_pressed")
get_node("/root/Game/EndMenu/VBoxContainer/Quit").connect("pressed", self, "_on_quit_game_pressed")
reset_game_state()
func _input(ev):
if Input.is_action_just_pressed("ui_cancel"):
print(ev)
self._on_escape()
func _on_escape(force_visible = false):
var n = get_node("/root/Game/EndMenu")
if n.is_visible() and not force_visible:
n.set_visible(false)
else:
n.popup_centered()
func _on_new_game_pressed():
get_node("/root/Game/EndMenu").set_visible(false)
self.reset_game_state()
func _on_quit_game_pressed():
get_node("/root/Game/EndMenu").set_visible(false)
get_tree().quit()
func reset_game_state():
self.is_player_turn = true
self.turn = 0
@ -318,6 +341,19 @@ func _process(delta):
else:
self._reset_help()
self.flash_help = null
if get_tree().get_nodes_in_group("opponent").empty() or get_tree().get_nodes_in_group("player").empty():
# The game is over
self.current_state = 99
var player_victory = false
if get_tree().get_nodes_in_group("opponent").empty():
player_victory = true
get_node("/root/Game/TopBar/Bottom/Instruction").set_text("Game over")
if not player_victory:
get_node("/root/Game/BottomBar/Help").set_text("Unsurprisingly, the result was known before-hand.")
else:
get_node("/root/Game/BottomBar/Help").set_text("Well, I'll be damned. I didn't think this would happen!")
# Show a popup for new one, or quit
self._on_escape(true)
if self.current_state == 1:
if self.ai_target != null:
var target_square = self.board_squares[self.ai_target]
@ -358,13 +394,19 @@ func _process(delta):
var i = self.rng.randi() % (priority_moves.size())
self.ai_target = priority_moves[i]['pos']
self.ai_piece = priority_moves[i]['source']
else:
print("Opponent moving ", self.ai_piece, " to ", self.ai_target, " from ", square_of_piece(self.ai_piece))
elif not moves.empty():
# @TODO Sort our moves to try and get the furthest forward
# possible
var i = self.rng.randi() % (moves.size())
self.ai_target = moves[i]['pos']
self.ai_piece = moves[i]['source']
print("Opponent moving ", self.ai_piece, " to ", self.ai_target, " from ", square_of_piece(self.ai_piece))
else:
# @TODO Would be a good time to spawn a new piece for the opponent
self._on_phase_end()
print("No possible moves")
func _physics_process(delta):
if self.landing_piece != null:

View File

@ -1,9 +1,10 @@
[gd_scene load_steps=6 format=2]
[gd_scene load_steps=7 format=2]
[ext_resource path="res://src/Game.gd" type="Script" id=1]
[ext_resource path="res://src/Playfield.tscn" type="PackedScene" id=2]
[ext_resource path="res://src/large font.tres" type="DynamicFont" id=3]
[ext_resource path="res://assets/source/Bitstream Vera Sans Mono Bold Nerd Font Complete.ttf" type="DynamicFontData" id=4]
[ext_resource path="res://src/EndMenu.tscn" type="PackedScene" id=5]
[sub_resource type="DynamicFont" id=1]
size = 24
@ -94,3 +95,6 @@ rect_min_size = Vector2( 0, 64 )
custom_fonts/font = SubResource( 1 )
text = "Do a thing"
valign = 1
[node name="EndMenu" parent="." instance=ExtResource( 5 )]
visible = true