commit
8ea75b804b
@ -0,0 +1 @@ |
||||
|
@ -0,0 +1,3 @@ |
||||
source_md5="47313fa4c47a9963fddd764e1ec6e4a8" |
||||
dest_md5="26ea799ea0a3da9e753b3ebe822e0570" |
||||
|
Binary file not shown.
@ -0,0 +1,3 @@ |
||||
source_md5="3c4b2e760b618cd43b55a75688134b2d" |
||||
dest_md5="728b6ff521175af0599970c1256f57a8" |
||||
|
Binary file not shown.
@ -0,0 +1,3 @@ |
||||
source_md5="c1370c9e2b8471aa411a973ea2fd9168" |
||||
dest_md5="86866559caad2aae41518f2069cf64c7" |
||||
|
Binary file not shown.
After Width: | Height: | Size: 160 B |
@ -0,0 +1,35 @@ |
||||
[remap] |
||||
|
||||
importer="texture" |
||||
type="StreamTexture" |
||||
path="res://.import/testmap8x8.png-6d4d1b68a14366088bfedd41ca6774a4.stex" |
||||
metadata={ |
||||
"vram_texture": false |
||||
} |
||||
|
||||
[deps] |
||||
|
||||
source_file="res://assets/testmap8x8.png" |
||||
dest_files=[ "res://.import/testmap8x8.png-6d4d1b68a14366088bfedd41ca6774a4.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=false |
||||
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 |
||||
process/normal_map_invert_y=false |
||||
stream=false |
||||
size_limit=0 |
||||
detect_3d=true |
||||
svg/scale=1.0 |
After Width: | Height: | Size: 789 B |
@ -0,0 +1,35 @@ |
||||
[remap] |
||||
|
||||
importer="texture" |
||||
type="StreamTexture" |
||||
path="res://.import/tileset.png-c50288acd069fa293d7940a084811264.stex" |
||||
metadata={ |
||||
"vram_texture": false |
||||
} |
||||
|
||||
[deps] |
||||
|
||||
source_file="res://assets/tileset.png" |
||||
dest_files=[ "res://.import/tileset.png-c50288acd069fa293d7940a084811264.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=false |
||||
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 |
||||
process/normal_map_invert_y=false |
||||
stream=false |
||||
size_limit=0 |
||||
detect_3d=true |
||||
svg/scale=1.0 |
@ -0,0 +1,103 @@ |
||||
[gd_resource type="TileSet" load_steps=2 format=2] |
||||
|
||||
[ext_resource path="res://assets/tileset.png" type="Texture" id=1] |
||||
|
||||
[resource] |
||||
0/name = "grass" |
||||
0/texture = ExtResource( 1 ) |
||||
0/tex_offset = Vector2( 0, 0 ) |
||||
0/modulate = Color( 1, 1, 1, 1 ) |
||||
0/region = Rect2( 16, 0, 16, 16 ) |
||||
0/tile_mode = 0 |
||||
0/occluder_offset = Vector2( 0, 0 ) |
||||
0/navigation_offset = Vector2( 0, 0 ) |
||||
0/shape_offset = Vector2( 0, 0 ) |
||||
0/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 ) |
||||
0/shape_one_way = false |
||||
0/shape_one_way_margin = 0.0 |
||||
0/shapes = [ ] |
||||
0/z_index = 0 |
||||
1/name = "sea" |
||||
1/texture = ExtResource( 1 ) |
||||
1/tex_offset = Vector2( 0, 0 ) |
||||
1/modulate = Color( 1, 1, 1, 1 ) |
||||
1/region = Rect2( 32, 0, 16, 16 ) |
||||
1/tile_mode = 0 |
||||
1/occluder_offset = Vector2( 0, 0 ) |
||||
1/navigation_offset = Vector2( 0, 0 ) |
||||
1/shape_offset = Vector2( 0, 0 ) |
||||
1/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 ) |
||||
1/shape_one_way = false |
||||
1/shape_one_way_margin = 0.0 |
||||
1/shapes = [ ] |
||||
1/z_index = 0 |
||||
2/name = "deep sea" |
||||
2/texture = ExtResource( 1 ) |
||||
2/tex_offset = Vector2( 0, 0 ) |
||||
2/modulate = Color( 1, 1, 1, 1 ) |
||||
2/region = Rect2( 48, 0, 16, 16 ) |
||||
2/tile_mode = 0 |
||||
2/occluder_offset = Vector2( 0, 0 ) |
||||
2/navigation_offset = Vector2( 0, 0 ) |
||||
2/shape_offset = Vector2( 0, 0 ) |
||||
2/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 ) |
||||
2/shape_one_way = false |
||||
2/shape_one_way_margin = 0.0 |
||||
2/shapes = [ ] |
||||
2/z_index = 0 |
||||
3/name = "mountain" |
||||
3/texture = ExtResource( 1 ) |
||||
3/tex_offset = Vector2( 0, 0 ) |
||||
3/modulate = Color( 1, 1, 1, 1 ) |
||||
3/region = Rect2( 0, 16, 16, 16 ) |
||||
3/tile_mode = 0 |
||||
3/occluder_offset = Vector2( 0, 0 ) |
||||
3/navigation_offset = Vector2( 0, 0 ) |
||||
3/shape_offset = Vector2( 0, 0 ) |
||||
3/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 ) |
||||
3/shape_one_way = false |
||||
3/shape_one_way_margin = 0.0 |
||||
3/shapes = [ ] |
||||
3/z_index = 0 |
||||
4/name = "factory" |
||||
4/texture = ExtResource( 1 ) |
||||
4/tex_offset = Vector2( 0, 0 ) |
||||
4/modulate = Color( 1, 1, 1, 1 ) |
||||
4/region = Rect2( 0, 32, 16, 16 ) |
||||
4/tile_mode = 0 |
||||
4/occluder_offset = Vector2( 0, 0 ) |
||||
4/navigation_offset = Vector2( 0, 0 ) |
||||
4/shape_offset = Vector2( 0, 0 ) |
||||
4/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 ) |
||||
4/shape_one_way = false |
||||
4/shape_one_way_margin = 0.0 |
||||
4/shapes = [ ] |
||||
4/z_index = 0 |
||||
5/name = "army" |
||||
5/texture = ExtResource( 1 ) |
||||
5/tex_offset = Vector2( 0, 0 ) |
||||
5/modulate = Color( 1, 1, 1, 1 ) |
||||
5/region = Rect2( 16, 32, 16, 16 ) |
||||
5/tile_mode = 0 |
||||
5/occluder_offset = Vector2( 0, 0 ) |
||||
5/navigation_offset = Vector2( 0, 0 ) |
||||
5/shape_offset = Vector2( 0, 0 ) |
||||
5/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 ) |
||||
5/shape_one_way = false |
||||
5/shape_one_way_margin = 0.0 |
||||
5/shapes = [ ] |
||||
5/z_index = 0 |
||||
6/name = "boat" |
||||
6/texture = ExtResource( 1 ) |
||||
6/tex_offset = Vector2( 0, 0 ) |
||||
6/modulate = Color( 1, 1, 1, 1 ) |
||||
6/region = Rect2( 32, 32, 16, 16 ) |
||||
6/tile_mode = 0 |
||||
6/occluder_offset = Vector2( 0, 0 ) |
||||
6/navigation_offset = Vector2( 0, 0 ) |
||||
6/shape_offset = Vector2( 0, 0 ) |
||||
6/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 ) |
||||
6/shape_one_way = false |
||||
6/shape_one_way_margin = 0.0 |
||||
6/shapes = [ ] |
||||
6/z_index = 0 |
@ -0,0 +1,7 @@ |
||||
[gd_resource type="Environment" load_steps=2 format=2] |
||||
|
||||
[sub_resource type="ProceduralSky" id=1] |
||||
|
||||
[resource] |
||||
background_mode = 2 |
||||
background_sky = SubResource( 1 ) |
@ -0,0 +1,35 @@ |
||||
[remap] |
||||
|
||||
importer="texture" |
||||
type="StreamTexture" |
||||
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" |
||||
metadata={ |
||||
"vram_texture": false |
||||
} |
||||
|
||||
[deps] |
||||
|
||||
source_file="res://icon.png" |
||||
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.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 |
||||
process/normal_map_invert_y=false |
||||
stream=false |
||||
size_limit=0 |
||||
detect_3d=true |
||||
svg/scale=1.0 |
@ -0,0 +1,199 @@ |
||||
class_name Grid |
||||
extends Node2D |
||||
|
||||
var tileset_texture_2x: ImageTexture |
||||
var grid: Dictionary#<Vector2, TileInfo> |
||||
var Army = preload("res://prefabs/units/army/army.tscn") |
||||
onready var tilemap = $TileMap |
||||
onready var total_scale = $TileMap.scale * $TileMap.cell_size |
||||
var selected_thing |
||||
|
||||
var tiles = [ |
||||
{ |
||||
needs_boat = false, |
||||
collision = false, |
||||
tile_name = null |
||||
}, |
||||
{ |
||||
needs_boat = false, |
||||
collision = false, |
||||
tile_name = "grass" |
||||
}, |
||||
{ |
||||
needs_boat = true, |
||||
collision = false, |
||||
tile_name = "sea" |
||||
}, |
||||
{ |
||||
needs_boat = true, |
||||
collision = false, |
||||
tile_name = "deep sea" |
||||
}, |
||||
{ |
||||
needs_boat = false, |
||||
collision = true, |
||||
tile_name = "mountain" |
||||
}, |
||||
] |
||||
|
||||
var countries = [] |
||||
|
||||
func _setup_tile(v): |
||||
grid[v] = { |
||||
units = [], |
||||
boats = [], |
||||
country = 0, |
||||
factory = null, |
||||
needs_boat = false, |
||||
collision = false, |
||||
tile = null |
||||
} |
||||
|
||||
func set_country(v, country): |
||||
var old_country = grid[v].country |
||||
|
||||
var factory = grid[v].factory |
||||
if factory: |
||||
set_factory(v, false) |
||||
|
||||
grid[v].country = country |
||||
|
||||
if factory: |
||||
set_factory(v, true) |
||||
|
||||
update() |
||||
|
||||
func set_factory(v, factory): |
||||
grid[v].factory = factory |
||||
|
||||
if factory and not v in grid[v].country.factory_positions: |
||||
grid[v].country.factory_positions.append(v) |
||||
else: |
||||
grid[v].country.factory_positions.erase(v) |
||||
|
||||
if factory: |
||||
$Factories.set_cellv(v, $TileMap.tile_set.find_tile_by_name("factory")) |
||||
else: |
||||
$Factories.set_cellv(v, -1) |
||||
|
||||
func set_tile(v, tile): |
||||
grid[v].tile = tile |
||||
$TileMap.set_cellv(v, $TileMap.tile_set.find_tile_by_name(tile.tile_name)) |
||||
|
||||
func tile_have_boat_of_country(tile, country): |
||||
for boat in tile.boats: |
||||
if boat.country == country: |
||||
return true |
||||
|
||||
func tile_have_unit_of_country(tile, country): |
||||
for unit in tile.units: |
||||
if unit.country == country: |
||||
return true |
||||
|
||||
func add_unit(unit, v): |
||||
grid[v].units.append(unit) |
||||
unit.entity = Army.instance() |
||||
unit.entity.country = unit.country |
||||
unit.entity.position = v * total_scale + total_scale*0.5 |
||||
unit.grid = self |
||||
unit.entity.data = unit |
||||
unit.position = v |
||||
add_child(unit.entity) |
||||
|
||||
func unit_can_move_to(unit, destination): |
||||
var dest_tile = grid[destination] |
||||
if dest_tile.collision \ |
||||
or dest_tile.needs_boat and not tile_have_boat_of_country(dest_tile, unit.country) \ |
||||
or tile_have_unit_of_country(dest_tile, unit.country): |
||||
return false |
||||
return true |
||||
|
||||
func move_unit(unit, destination): |
||||
var v = $TileMap.world_to_map(unit.entity.position/tilemap.scale) |
||||
var dest_tile = grid[destination] |
||||
if not unit_can_move_to(unit, destination): |
||||
return false |
||||
grid[v].units.erase(unit) |
||||
grid[destination].units.append(unit) |
||||
unit.entity.position = destination * total_scale + total_scale*0.5 |
||||
unit.position = destination |
||||
return true |
||||
|
||||
func remove_unit(unit): |
||||
var v = $TileMap.world_to_map(unit.entity.position/tilemap.scale) |
||||
unit.entity.queue_free() |
||||
grid[v].units.erase(unit) |
||||
|
||||
func add_boat(v, unit): |
||||
grid[v].boats.append(unit) |
||||
update() |
||||
|
||||
func move_boat(v, v2, unit): |
||||
grid[v].boats.erase(unit) |
||||
grid[v2].boats.append(unit) |
||||
update() |
||||
|
||||
func setup(): |
||||
_setup_tileset_texture_2x() |
||||
_setup_map() |
||||
|
||||
func _setup_tileset_texture_2x(): |
||||
tileset_texture_2x = ImageTexture.new() |
||||
var image = preload("res://assets/tileset.png").get_data() |
||||
image.resize(image.get_width()*2, image.get_height()*2, Image.INTERPOLATE_NEAREST) |
||||
tileset_texture_2x.create_from_image(image) |
||||
|
||||
func _setup_map(): |
||||
var image = preload("res://assets/testmap8x8.png") |
||||
var data = image.get_data() |
||||
data.lock() |
||||
for x in 8: |
||||
for y in 8: |
||||
var v = Vector2(x,y) |
||||
var color = data.get_pixelv(v) |
||||
color = Vector3(color.r, color.g, color.b) * 255 |
||||
var tile = tiles[color.z] |
||||
|
||||
_setup_tile(v) |
||||
set_country(v, countries[color.x]) |
||||
set_factory(v, color.y == 1) #<<<< add to country |
||||
set_tile(v, tile) |
||||
grid[v].needs_boat = tile.needs_boat |
||||
grid[v].collision = tile.collision |
||||
data.unlock() |
||||
|
||||
func _process(delta): |
||||
if Input.is_action_just_pressed("pick_tile"): |
||||
var position = $TileMap.world_to_map(get_local_mouse_position()/$TileMap.scale) |
||||
|
||||
|
||||
func _get_atlas_from_tileset(tileset, name, texture): |
||||
var res = AtlasTexture.new() |
||||
res.atlas = texture |
||||
res.region = $TileMap.tile_set.tile_get_region( |
||||
$TileMap.tile_set.find_tile_by_name(name) |
||||
) |
||||
return res |
||||
|
||||
func _draw(): |
||||
var scale = $TileMap.scale * $TileMap.cell_size |
||||
var army_texture = _get_atlas_from_tileset($TileMap.tile_set, "army", tileset_texture_2x) |
||||
army_texture.region.position *= 2 |
||||
army_texture.region.size *= 2 |
||||
var boat_texture = _get_atlas_from_tileset($TileMap.tile_set, "boat", tileset_texture_2x) |
||||
boat_texture.region.position *= 2 |
||||
boat_texture.region.size *= 2 |
||||
|
||||
for x in 8: |
||||
for y in 8: |
||||
var v = Vector2(x, y) |
||||
var tile = grid[v] |
||||
draw_circle(v * scale + scale*3/4, 8, tile.country.color) |
||||
|
||||
var unit_position = Vector2(0, 0) |
||||
for boat in tile.boats: |
||||
draw_texture(boat_texture, v*scale + unit_position + total_scale*0.25, boat.country.color) |
||||
unit_position += Vector2(8, 8) |
||||
# for unit in tile.units: |
||||
# draw_texture(army_texture, v*scale + unit_position, unit.country.color) |
||||
# unit_position += Vector2(8, 8) |
@ -0,0 +1,21 @@ |
||||
[gd_scene load_steps=3 format=2] |
||||
|
||||
[ext_resource path="res://prefabs/grid/grid.gd" type="Script" id=1] |
||||
[ext_resource path="res://assets/tileset.tres" type="TileSet" id=2] |
||||
|
||||
[node name="Grid" type="Node2D"] |
||||
script = ExtResource( 1 ) |
||||
|
||||
[node name="TileMap" type="TileMap" parent="."] |
||||
show_behind_parent = true |
||||
scale = Vector2( 4, 4 ) |
||||
tile_set = ExtResource( 2 ) |
||||
cell_size = Vector2( 16, 16 ) |
||||
format = 1 |
||||
|
||||
[node name="Factories" type="TileMap" parent="."] |
||||
show_behind_parent = true |
||||
scale = Vector2( 4, 4 ) |
||||
tile_set = ExtResource( 2 ) |
||||
cell_size = Vector2( 16, 16 ) |
||||
format = 1 |
@ -0,0 +1,59 @@ |
||||
extends Area2D |
||||
|
||||
var data#unit data |
||||
onready var grid = data.grid |
||||
var country: Country |
||||
var current_turn_movable = true |
||||
onready var game = get_tree().current_scene |
||||
|
||||
func _on_Army_input_event(viewport, event, shape_idx): |
||||
if event is InputEventMouseButton: |
||||
if event.pressed and event.button_index == BUTTON_LEFT: |
||||
grid.selected_thing = self |
||||
|
||||
func _process(delta): |
||||
update() |
||||
if game.country_turn_id == country.id: |
||||
$Sprite.modulate = Color.white if current_turn_movable else Color.white.darkened(0.5) |
||||
else: |
||||
$Sprite.modulate = Color.white.darkened(0.25) |
||||
if not grid.selected_thing == self: |
||||
return |
||||
if Input.is_action_just_pressed("move"): |
||||
var pos = grid.tilemap.world_to_map(position/grid.tilemap.scale) |
||||
var mouse_pos = grid.tilemap.world_to_map(get_global_mouse_position()/grid.tilemap.scale) |
||||
|
||||
var dx = abs(floor(pos.x-mouse_pos.x)) |
||||
var dy = abs(floor(pos.y-mouse_pos.y)) |
||||
|
||||
if dx != dy and (dx == 1 or dy == 1): |
||||
if game.country_turn_id == country.id and current_turn_movable: |
||||
if grid.move_unit(data, mouse_pos): |
||||
current_turn_movable = false |
||||
|
||||
var conflict = false |
||||
for unit in grid.grid[mouse_pos].units: |
||||
if unit.country != country: |
||||
conflict = true |
||||
|
||||
if conflict: |
||||
resolve_conflict(grid.grid[mouse_pos].units) |
||||
else: |
||||
grid.set_country(mouse_pos, country) |
||||
|
||||
func resolve_conflict(armies): |
||||
var survivor = armies[randi() % len(armies)] |
||||
for army in armies: |
||||
if army != survivor: |
||||
army.country.remove_unit(army) |
||||
grid.set_country(survivor.position, survivor.country) |
||||
|
||||
func _draw(): |
||||
if grid.selected_thing == self: |
||||
draw_arc( |
||||
Vector2.ZERO, |
||||
16, |
||||
0, 2*PI, 32, |
||||
Color.yellow, |
||||
4 |
||||
) |
@ -0,0 +1,20 @@ |
||||
[gd_scene load_steps=4 format=2] |
||||
|
||||
[ext_resource path="res://assets/tileset.png" type="Texture" id=1] |
||||
[ext_resource path="res://prefabs/units/army/army.gd" type="Script" id=2] |
||||
|
||||
[sub_resource type="RectangleShape2D" id=1] |
||||
|
||||
[node name="Army" type="Area2D"] |
||||
script = ExtResource( 2 ) |
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] |
||||
shape = SubResource( 1 ) |
||||
|
||||
[node name="Sprite" type="Sprite" parent="."] |
||||
scale = Vector2( 2, 2 ) |
||||
texture = ExtResource( 1 ) |
||||
region_enabled = true |
||||
region_rect = Rect2( 16, 32, 16, 16 ) |
||||
|
||||
[connection signal="input_event" from="." to="." method="_on_Army_input_event"] |
@ -0,0 +1,52 @@ |
||||
; Engine configuration file. |
||||
; It's best edited using the editor UI and not directly, |
||||
; since the parameters that go here are not all obvious. |
||||
; |
||||
; Format: |
||||
; [section] ; section goes between [] |
||||
; param=value ; assign values to parameters |
||||
|
||||
config_version=4 |
||||
|
||||
_global_script_classes=[ { |
||||
"base": "Reference", |
||||
"class": "Country", |
||||
"language": "GDScript", |
||||
"path": "res://scenes/game/country.gd" |
||||
}, { |
||||
"base": "Node2D", |
||||
"class": "Grid", |
||||
"language": "GDScript", |
||||
"path": "res://prefabs/grid/grid.gd" |
||||
} ] |
||||
_global_script_class_icons={ |
||||
"Country": "", |
||||
"Grid": "" |
||||
} |
||||
|
||||
[application] |
||||
|
||||
config/name="Multilayer Multiplayer Risk Game" |
||||
run/main_scene="res://scenes/game/game.tscn" |
||||
config/icon="res://icon.png" |
||||
|
||||
[input] |
||||
|
||||
pick_tile={ |
||||
"deadzone": 0.5, |
||||
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null) |
||||
] |
||||
} |
||||
move={ |
||||
"deadzone": 0.5, |
||||
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":2,"pressed":false,"doubleclick":false,"script":null) |
||||
] |
||||
} |
||||
|
||||
[physics] |
||||
|
||||
common/enable_pause_aware_picking=true |
||||
|
||||
[rendering] |
||||
|
||||
environment/default_environment="res://default_env.tres" |
@ -0,0 +1,25 @@ |
||||
class_name Country |
||||
extends Reference |
||||
|
||||
var id |
||||
var name |
||||
var color |
||||
var money = 8 |
||||
var tile_positions |
||||
var armies = [] |
||||
var boats = [] |
||||
var factory_positions = [] |
||||
var grid |
||||
|
||||
func add_unit(unit, v): |
||||
unit.country = self |
||||
armies.append(unit) |
||||
grid.add_unit(unit, v) |
||||
|
||||
func remove_unit(unit): |
||||
armies.erase(unit) |
||||
grid.remove_unit(unit) |
||||
|
||||
|
||||
func compute_balance(): |
||||
money += len(factory_positions) - len(armies) - len(boats) |
@ -0,0 +1,48 @@ |
||||
extends Node2D |
||||
|
||||
var countries = [ |
||||
{ color = Color8(0, 0, 0, 0), name = "Transparent"}, |
||||
{ color = Color8(128, 0, 0), name = "Red"}, |
||||
{ color = Color8(128,128, 0), name = "Yellow"}, |
||||
{ color = Color8( 0,128, 0), name = "Green"}, |
||||
{ color = Color8( 0,128,128), name = "Cyan"}, |
||||
{ color = Color8( 0, 0,128), name = "Blue"}, |
||||
{ color = Color8(128, 0,128), name = "Purple"}, |
||||
{ color = Color8(128,128,128), name = "White"} |
||||
] |
||||
|
||||
var country_turn_id = 0 |
||||
|
||||
func _ready(): |
||||
randomize() |
||||
|
||||
var id = 0 |
||||
var countries2 = [] |
||||
for country in countries: |
||||
var country2 = Country.new() |
||||
country2.color = country.color |
||||
country2.id = id |
||||
country2.name = country.name |
||||
country2.grid = $Grid |
||||
countries2.append(country2) |
||||
id += 1 |
||||
countries = countries2 |
||||
_on_EndTurnButton_pressed() |
||||
|
||||
$Grid.countries = countries |
||||
$Grid.setup() |
||||
|
||||
countries[1].add_unit({}, Vector2(1,1)) |
||||
countries[2].add_unit({}, Vector2(1,2)) |
||||
|
||||
func _process(delta): |
||||
$CanvasLayer/Control/CountryMoneyLabel.text = str(countries[country_turn_id].money) + "$" |
||||
|
||||
func _on_EndTurnButton_pressed(): |
||||
for army in countries[country_turn_id].armies: |
||||
army.entity.current_turn_movable = true |
||||
countries[country_turn_id].compute_balance() |
||||
|
||||
country_turn_id += 1 |
||||
if country_turn_id == 8: country_turn_id = 1 |
||||
$CanvasLayer/Control/TurnLabel.text = countries[country_turn_id].name + "'s turn." |
@ -0,0 +1,47 @@ |
||||
[gd_scene load_steps=3 format=2] |
||||
|
||||
[ext_resource path="res://prefabs/grid/grid.tscn" type="PackedScene" id=1] |
||||
[ext_resource path="res://scenes/game/game.gd" type="Script" id=2] |
||||
|
||||
[node name="Game" type="Node2D"] |
||||
script = ExtResource( 2 ) |
||||
|
||||
[node name="Grid" parent="." instance=ExtResource( 1 )] |
||||
|
||||
[node name="CanvasLayer" type="CanvasLayer" parent="."] |
||||
|
||||
[node name="Control" type="Control" parent="CanvasLayer"] |
||||
anchor_right = 1.0 |
||||
anchor_bottom = 1.0 |
||||
margin_left = 10.0 |
||||
margin_top = 10.0 |
||||
margin_right = -10.0 |
||||
margin_bottom = -10.0 |
||||
|
||||
[node name="TurnLabel" type="Label" parent="CanvasLayer/Control"] |
||||
anchor_left = 1.0 |
||||
anchor_right = 1.0 |
||||
margin_left = -79.0 |
||||
margin_bottom = 14.0 |
||||
text = "TURN: ####" |
||||
align = 2 |
||||
|
||||
[node name="EndTurnButton" type="Button" parent="CanvasLayer/Control"] |
||||
anchor_left = 1.0 |
||||
anchor_top = 1.0 |
||||
anchor_right = 1.0 |
||||
anchor_bottom = 1.0 |
||||
margin_left = -79.0 |
||||
margin_top = -40.0 |
||||
text = "END TURN" |
||||
|
||||
[node name="CountryMoneyLabel" type="Label" parent="CanvasLayer/Control"] |
||||
anchor_left = 1.0 |
||||
anchor_right = 1.0 |
||||
margin_left = -79.0 |
||||
margin_top = 14.0 |
||||
margin_bottom = 28.0 |
||||
text = "?????$" |
||||
align = 2 |
||||
|
||||
[connection signal="pressed" from="CanvasLayer/Control/EndTurnButton" to="." method="_on_EndTurnButton_pressed"] |
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue