Skip to content

Commit

Permalink
Made the sprite symbols larger.
Browse files Browse the repository at this point in the history
Game now runs in full screen mode. Added the tween node for smooth linear motion. Made some progress on AI. Fixed bug where removing a reinforcement was permanent.
  • Loading branch information
ra314 committed Aug 26, 2021
1 parent 4b36308 commit 9741d8d
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .import/Blue_Square.png-ae535163e31b183d7b98f1e9b7ee13d3.md5
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source_md5="201c8d64f549e4cd5bfafead420971c8"
dest_md5="2f77245de30b1cc29db0463f8328eb31"
source_md5="17a6d967f3b7416282a1320659ff3bde"
dest_md5="f99cd8dd7825f1ee2d3e36f96720f05d"

Binary file modified .import/Blue_Square.png-ae535163e31b183d7b98f1e9b7ee13d3.stex
Binary file not shown.
3 changes: 3 additions & 0 deletions .import/Blue_Square.png-d16f1d6378ac4470e5e4c5fdfb3d6335.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source_md5="201c8d64f549e4cd5bfafead420971c8"
dest_md5="2f77245de30b1cc29db0463f8328eb31"

Binary file not shown.
4 changes: 2 additions & 2 deletions .import/Red_Square.png-770b8c2c1fe78febcf1c5cf3528e08fe.md5
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source_md5="470b78ce180a1fbae0f8601102da7565"
dest_md5="dcc2b8ffafffaa18192b0b38fdf856cb"
source_md5="e657dc9897d2f1b7a2d36ede40c50389"
dest_md5="53f1af83a9f8127f8ca5f335762ed1d6"

Binary file modified .import/Red_Square.png-770b8c2c1fe78febcf1c5cf3528e08fe.stex
Binary file not shown.
3 changes: 3 additions & 0 deletions .import/Red_Square.png-a8d761d5e77c7435746f77940263fa78.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source_md5="470b78ce180a1fbae0f8601102da7565"
dest_md5="dcc2b8ffafffaa18192b0b38fdf856cb"

Binary file not shown.
3 changes: 3 additions & 0 deletions .import/favicon.png-801e823cfc153ed89bbb828ce5cff222.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source_md5="47313fa4c47a9963fddd764e1ec6e4a8"
dest_md5="2ded9e7f9060e2b530aab678b135fc5b"

Binary file not shown.
Binary file modified Assets/Blue_Square.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/Red_Square.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 8 additions & 3 deletions Scenes/Levels/Level Components/Country.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ script = ExtResource( 1 )
script = ExtResource( 3 )

[node name="Label" type="Label" parent="."]
margin_left = -16.0
margin_top = -4.0
margin_right = 16.0
margin_left = -10.0
margin_top = -10.0
margin_right = 10.0
margin_bottom = 10.0
align = 1
valign = 3
autowrap = true
__meta__ = {
"_edit_use_anchors_": false
}

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource( 1 )

[node name="Tween" type="Tween" parent="."]
35 changes: 20 additions & 15 deletions Scripts/Levels/Level Components/Country.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ var num_reinforcements: int = 0

var flashing = false
var time_since_last_flash = 0
var flashing_period = 0.5
const flashing_period = 0.5
var flash_mask_sprite = null

# List of locations to move to to complete the attack animation.
const movement_speed = 0.2
const distance_to_stop_moving_at = 16
var locations_to_move_to = []
const destination_movement_duration = 0.2
const origin_movement_duration = 0.4

func save():
var save_dict = {}
Expand All @@ -43,7 +42,7 @@ func change_ownership_to(player):
func update_labels():
var label_text = str(num_troops)
if num_reinforcements > 0:
label_text += " + " + str(num_reinforcements)
label_text += " +" + str(num_reinforcements)
get_node("Label").text = label_text
belongs_to.update_labels()

Expand All @@ -62,17 +61,22 @@ func draw_line_to_country(selected_country):
new_line.add_point(Vector2(0,0))
new_line.add_point(selected_country.position - position)

func can_attack():
func get_attackable_countries():
var attackable_countries = []
for country in connected_countries:
if country.num_troops < num_troops and country.belongs_to != belongs_to:
return true
return false
attackable_countries.append(country)
return attackable_countries

func _input_event(viewport, event, shape_idx):
if get_tree().get_current_scene().get_name() == "Level Creator":
if event.is_action_just_released():
self.on_click(event)

func move_to(duration, destination):
get_node("Tween").interpolate_property(self, "position", position, destination, duration)
get_node("Tween").start()

func on_click(event):
# Level Creator Behaviour
if get_tree().get_current_scene().get_name() == "Level Creator":
Expand Down Expand Up @@ -141,8 +145,8 @@ func on_click(event):
var attacker = Game_Manager.selected_country
if (attacker in connected_countries) and (attacker.num_troops > num_troops):
# Movement animation
attacker.locations_to_move_to.append(position)
attacker.locations_to_move_to.append(attacker.position)
attacker.move_to(destination_movement_duration, position)
attacker.get_node("Tween").interpolate_callback(attacker, destination_movement_duration, "move_to", origin_movement_duration, attacker.position)

# Attack logic that changes troops and updates labels
num_troops = attacker.num_troops - num_troops
Expand Down Expand Up @@ -179,6 +183,7 @@ func on_click(event):
if event.button_index == BUTTON_RIGHT:
# Check that a reinforcement has been previously added to this country
if num_reinforcements > 0:
Game_Manager.curr_player.num_reinforcements += 1
num_reinforcements -= 1

update_labels()
Expand Down Expand Up @@ -281,8 +286,8 @@ func _process(delta):
time_since_last_flash = 0

# Moving to a spot if the locations_to_move_to list is non empty
if locations_to_move_to:
position = position.linear_interpolate(locations_to_move_to[0], movement_speed)
# Checking if the destination has been reached
if position.distance_to(locations_to_move_to[0]) < distance_to_stop_moving_at:
position = locations_to_move_to.pop_front()
# if locations_to_move_to:
# position = position.linear_interpolate(locations_to_move_to[0], movement_speed)
# # Checking if the destination has been reached
# if position.distance_to(locations_to_move_to[0]) < distance_to_stop_moving_at:
# position = locations_to_move_to.pop_front()
30 changes: 29 additions & 1 deletion Scripts/Levels/Level Main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,34 @@ remote func end_reinforcement_disable(hide_boolean):
get_node("CanvasLayer/End Reinforcement").show()
#######

# AI
#######
# We duplicate the existing countries so that modifications here do not propogate outside
func clone_country(country):
var new_country = Country.init(country.x, country.y, country.country_name, country.player)
new_country.num_troops = country.num_troops
return new_country

func extract_game_state():
var game_state = {}
for player in players.values():
game_state[player.color] = {}
for country in player.owner_countries:
game_state[player.color][country.country_name] = clone_country(country)
return game_state

func get_child_states(game_state, curr_player_color):
for country in game_state[curr_player_color]:
for attackable_country in country.get_attackable_countries():
pass

# The depth parameter is not how deep the function is currently,
# but how much deeper it should go
# minimax(extract_game_state(), 3, -INF, INF, true)
func minimax(game_state, depth, alpha, beta, maximizing_player):
pass
######

# Clear the player dictionary, rerandomise troop allocation and redo player turn order and country allocation
func reroll_spawn():
for player in players.values():
Expand Down Expand Up @@ -202,7 +230,7 @@ func add_random_countries(player, num_countries):

func is_attack_over():
for country in curr_player.owned_countries:
if country.can_attack():
if country.get_attackable_countries():
return false
return true

Expand Down
1 change: 1 addition & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ config/icon="res://icon.png"

window/size/width=1920
window/size/height=1080
window/size/fullscreen=true
window/stretch/mode="viewport"
window/stretch/aspect="keep"

Expand Down

0 comments on commit 9741d8d

Please sign in to comment.