Spawn random unit powerup
This commit is contained in:
parent
6a62c84595
commit
f279ac3f54
2
TODO.md
2
TODO.md
|
@ -1,5 +1,3 @@
|
||||||
1. Power ups
|
|
||||||
* spawn a new random piece powerup
|
|
||||||
2. Visual polish
|
2. Visual polish
|
||||||
* a visual / title in the left sidebar
|
* a visual / title in the left sidebar
|
||||||
* multiple square tiles to add variation
|
* multiple square tiles to add variation
|
||||||
|
|
57
src/Game.gd
57
src/Game.gd
|
@ -261,7 +261,7 @@ func _ready():
|
||||||
get_node("/root/Game/EndMenu/VBoxContainer/Fail Game").connect("pressed", self, "_on_fail_game")
|
get_node("/root/Game/EndMenu/VBoxContainer/Fail Game").connect("pressed", self, "_on_fail_game")
|
||||||
get_node("/root/Game/EndMenu/VBoxContainer/Win Game").connect("pressed", self, "_on_win_game")
|
get_node("/root/Game/EndMenu/VBoxContainer/Win Game").connect("pressed", self, "_on_win_game")
|
||||||
get_node("/root/Game/PanelRight/VBox/PieceInfo").connect("stat_change_requested", self, "_on_piece_stat_change_requested")
|
get_node("/root/Game/PanelRight/VBox/PieceInfo").connect("stat_change_requested", self, "_on_piece_stat_change_requested")
|
||||||
get_node("/root/Game/PanelRight/VBox/PieceInfo/Vbox/Powerup").connect("pressed", self, "try_spawn_powerup")
|
get_node("/root/Game/PanelRight/VBox/PieceInfo/Vbox/Powerup").connect("pressed", self, "try_spawn_powerup", [true])
|
||||||
reset_game_state()
|
reset_game_state()
|
||||||
|
|
||||||
func _on_piece_stat_change_requested(piece, attribute, value):
|
func _on_piece_stat_change_requested(piece, attribute, value):
|
||||||
|
@ -271,7 +271,7 @@ func _on_piece_stat_change_requested(piece, attribute, value):
|
||||||
|
|
||||||
func _input(ev):
|
func _input(ev):
|
||||||
if Input.is_action_just_pressed("ui_cancel"):
|
if Input.is_action_just_pressed("ui_cancel"):
|
||||||
print(ev)
|
#print(ev)
|
||||||
self._on_escape(false, "Paused")
|
self._on_escape(false, "Paused")
|
||||||
|
|
||||||
func _on_escape(force_visible = false, message = null):
|
func _on_escape(force_visible = false, message = null):
|
||||||
|
@ -297,7 +297,8 @@ func reset_game_state():
|
||||||
self.turn = 0
|
self.turn = 0
|
||||||
for p in get_tree().get_nodes_in_group("pieces"):
|
for p in get_tree().get_nodes_in_group("pieces"):
|
||||||
p.queue_free()
|
p.queue_free()
|
||||||
|
for p in get_tree().get_nodes_in_group("powerup"):
|
||||||
|
p.queue_free()
|
||||||
self.board_squares = {}
|
self.board_squares = {}
|
||||||
var x = 0;
|
var x = 0;
|
||||||
var y = 0;
|
var y = 0;
|
||||||
|
@ -452,7 +453,7 @@ func _on_new_turn():
|
||||||
if self.reinforcements == null and not just_spawned:
|
if self.reinforcements == null and not just_spawned:
|
||||||
var chance = lerp(0, 50, 1 - float(opponent_pieces.size())/16.0)
|
var chance = lerp(0, 50, 1 - float(opponent_pieces.size())/16.0)
|
||||||
var i = self.rng.randi() % 100
|
var i = self.rng.randi() % 100
|
||||||
print("Roll for reinforcements ", i, " < ", chance)
|
#print("Roll for reinforcements ", i, " < ", chance)
|
||||||
if i < chance:
|
if i < chance:
|
||||||
self.reinforcements = 2
|
self.reinforcements = 2
|
||||||
self.reinforcements_size = 1
|
self.reinforcements_size = 1
|
||||||
|
@ -555,6 +556,9 @@ func _process(delta):
|
||||||
for m in moves:
|
for m in moves:
|
||||||
if m.has("target"):
|
if m.has("target"):
|
||||||
priority_moves.append(m)
|
priority_moves.append(m)
|
||||||
|
continue
|
||||||
|
if self.board_squares[m['pos']]['powerup'] != null:
|
||||||
|
priority_moves.append(m)
|
||||||
if not priority_moves.empty():
|
if not priority_moves.empty():
|
||||||
# @TODO Check for the most "valuable" piece to take
|
# @TODO Check for the most "valuable" piece to take
|
||||||
var i = self.rng.randi() % (priority_moves.size())
|
var i = self.rng.randi() % (priority_moves.size())
|
||||||
|
@ -585,7 +589,7 @@ func _physics_process(delta):
|
||||||
var s = null
|
var s = null
|
||||||
for m in matches:
|
for m in matches:
|
||||||
if m["collider"].get_parent() is Square:
|
if m["collider"].get_parent() is Square:
|
||||||
print(m["collider"].get_parent())
|
#print(m["collider"].get_parent())
|
||||||
s = m["collider"].get_parent()
|
s = m["collider"].get_parent()
|
||||||
if s == null:
|
if s == null:
|
||||||
# No valid position, we'll return the piece to where it should be
|
# No valid position, we'll return the piece to where it should be
|
||||||
|
@ -599,7 +603,7 @@ func _physics_process(delta):
|
||||||
if pf.squares[k].get_ref() == s:
|
if pf.squares[k].get_ref() == s:
|
||||||
dest = k
|
dest = k
|
||||||
if dest != null:
|
if dest != null:
|
||||||
print(dest)
|
#print(dest)
|
||||||
var dest_valid = false;
|
var dest_valid = false;
|
||||||
for m in moves:
|
for m in moves:
|
||||||
if m['pos'] == dest:
|
if m['pos'] == dest:
|
||||||
|
@ -708,8 +712,7 @@ var available_powerups = {
|
||||||
# @TODO remove attack_only from pawn
|
# @TODO remove attack_only from pawn
|
||||||
# @TODO choose a new movement pattern
|
# @TODO choose a new movement pattern
|
||||||
}
|
}
|
||||||
func try_spawn_powerup():
|
func try_spawn_powerup(var force = false):
|
||||||
print('blah')
|
|
||||||
var try = 0
|
var try = 0
|
||||||
var i = null
|
var i = null
|
||||||
var sq = null
|
var sq = null
|
||||||
|
@ -724,7 +727,8 @@ func try_spawn_powerup():
|
||||||
return
|
return
|
||||||
i = null
|
i = null
|
||||||
var c = self.rng.randi() % 100
|
var c = self.rng.randi() % 100
|
||||||
print("Chance: ", c)
|
if force:
|
||||||
|
c = self.rng.randi() % 46 + 55
|
||||||
for k in self.available_powerups.keys():
|
for k in self.available_powerups.keys():
|
||||||
if c >= k:
|
if c >= k:
|
||||||
i = k
|
i = k
|
||||||
|
@ -751,13 +755,36 @@ func try_spawn_powerup():
|
||||||
func apply_powerup_to_piece(square):
|
func apply_powerup_to_piece(square):
|
||||||
print("Applying powerup ", square['powerup'], " to piece ", square['piece'])
|
print("Applying powerup ", square['powerup'], " to piece ", square['piece'])
|
||||||
# @TODO Play a sound
|
# @TODO Play a sound
|
||||||
if square['powerup'].target_attribute == "special":
|
var powerup = square['powerup']
|
||||||
print("Special powerups not implemented yet")
|
if powerup.target_attribute == "special":
|
||||||
|
if powerup.target_value == "spawn_unit":
|
||||||
|
var for_opponent = true
|
||||||
|
var group = "opponent"
|
||||||
|
if square['piece'].is_in_group("player"):
|
||||||
|
for_opponent = false
|
||||||
|
group = "player"
|
||||||
|
var coords = choose_reinforcements(1, for_opponent, false)
|
||||||
|
for c in coords:
|
||||||
|
square = self.board_squares[c]
|
||||||
|
new_piece(square['reinforcement'], group, c)
|
||||||
|
square = self.board_squares[c]
|
||||||
|
if self.reinforcement_buff != null:
|
||||||
|
square['piece'].damage += self.reinforcement_buff
|
||||||
|
square['piece'].movement += self.reinforcement_buff
|
||||||
|
square['piece'].health += self.reinforcement_buff
|
||||||
|
if self.reinforcement_buff > 5:
|
||||||
|
square['piece'].jump = true
|
||||||
else:
|
else:
|
||||||
if square['powerup'].target_value == "increase":
|
print("Unknown special powerup: ", powerup.target_value)
|
||||||
var value = square['piece'].get(square['powerup'].target_attribute) + 1
|
else:
|
||||||
square['piece'].set(square['powerup'].target_attribute, value)
|
if powerup.target_value == "increase":
|
||||||
|
var value = square['piece'].get(powerup.target_attribute) + 1
|
||||||
|
square['piece'].set(powerup.target_attribute, value)
|
||||||
|
elif powerup.target_value == "set_true":
|
||||||
|
square['piece'].set(powerup.target_attribute, true)
|
||||||
|
else:
|
||||||
|
print("Unknown value type: ", powerup.target_value)
|
||||||
if square['piece'] == self.selected_piece:
|
if square['piece'] == self.selected_piece:
|
||||||
get_node("/root/Game/PanelRight/VBox/PieceInfo").set_piece_info(square['piece'])
|
get_node("/root/Game/PanelRight/VBox/PieceInfo").set_piece_info(square['piece'])
|
||||||
square['powerup'].queue_free()
|
powerup.queue_free()
|
||||||
square['powerup'] = null
|
square['powerup'] = null
|
||||||
|
|
Loading…
Reference in New Issue