turn system includes players

master
potatoxel 7 months ago
parent e6daff3738
commit 9e141165f1
  1. 35
      prefabs/units/army/army.gd
  2. 35
      prefabs/units/boat/boat.gd
  3. 8
      project.godot
  4. 122
      scenes/game/game.gd
  5. 10
      scenes/game/player.gd

@ -12,23 +12,24 @@ func get_tile_position():
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 and dy <= 1:
if game.country_turn_id == country.id and current_turn_movable:
if grid.move_unit(data, mouse_pos):
current_turn_movable = false
if game.turn.layer == "country":
if game.turn.object == country:
$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 and dy <= 1:
if game.turn.object == country and current_turn_movable:
if grid.move_unit(data, mouse_pos):
current_turn_movable = false
func _draw():
if grid.selected_thing == self:

@ -12,23 +12,24 @@ func get_tile_position():
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 = get_tile_position()
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 and dy <= 1:
if game.country_turn_id == country.id and current_turn_movable:
if grid.move_boat(data, mouse_pos):
current_turn_movable = false
if game.turn.layer == "country":
if game.turn.object == country:
$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 = get_tile_position()
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 and dy <= 1:
if game.turn.object == country and current_turn_movable:
if grid.move_boat(data, mouse_pos):
current_turn_movable = false
func _draw():
if grid.selected_thing == self:

@ -28,12 +28,18 @@ _global_script_classes=[ {
"class": "Grid",
"language": "GDScript",
"path": "res://prefabs/grid/grid.gd"
}, {
"base": "Reference",
"class": "Player",
"language": "GDScript",
"path": "res://scenes/game/player.gd"
} ]
_global_script_class_icons={
"Army": "",
"Boat": "",
"Country": "",
"Grid": ""
"Grid": "",
"Player": ""
}
[application]

@ -11,13 +11,35 @@ var countries = [
{ color = Color8(128,128,128), name = "White"}
]
var country_turn_id = 0
var players = []
var turn_id = -1
var turns = []
var turn
var player_count = 3
var button_selected = null
var mouse_click_mode = null
func _ready():
randomize()
_setup_players()
_setup_countries()
_setup_turns()
turn = turns[turn_id]
_on_EndTurnButton_pressed()
func _setup_players():
var id = 0
for player_id in player_count:
var player = Player.new()
player.id = player_id
player.name = str(player_id)
players.append(player)
func _setup_countries():
var id = 0
var countries2 = []
for country in countries:
@ -29,7 +51,6 @@ func _ready():
countries2.append(country2)
id += 1
countries = countries2
_on_EndTurnButton_pressed()
$Grid.countries = countries
$Grid.setup()
@ -37,21 +58,45 @@ func _ready():
countries[1].add_unit({}, Vector2(1,1))
countries[2].add_unit({}, Vector2(1,2))
func _setup_turns():
for player in players:
turns.append({
layer = "player",
id = player.id,
object = player
})
for country in countries:
if country.id == 0: continue
turns.append({
layer = "country",
id = country.id,
object = country
})
func _process(delta):
$CanvasLayer/Control/VBoxContainer/CountryMoneyLabel.text = str(countries[country_turn_id].money) + "$"
$CanvasLayer/Control/VBoxContainer/StockPriceLabel.text = "STOCK PRICE: " + str(countries[country_turn_id].stock_price) + "$"
$CanvasLayer/Control/VBoxContainer/CountryMoneyLabel.text = str(turns[turn_id].object.money) + "$"
if turn.layer == "country":
$CanvasLayer/Control/VBoxContainer/StockPriceLabel.text = "STOCK PRICE: " + str(turn.object.stock_price) + "$"
$CanvasLayer/Control/VBoxContainer/StockPriceLabel.visible = turn.layer == "country"
$CanvasLayer/Control/VBoxContainer/BuyFactory.visible = turn.layer == "country"
$CanvasLayer/Control/VBoxContainer/BuyArmy.visible = turn.layer == "country"
$CanvasLayer/Control/VBoxContainer/BuyBoat.visible = turn.layer == "country"
func _on_EndTurnButton_pressed():
for army in countries[country_turn_id].armies:
army.entity.current_turn_movable = true
for boat in countries[country_turn_id].boats:
boat.entity.current_turn_movable = true
countries[country_turn_id].compute_balance()
if turn.layer == "country":
for army in turn.object.armies:
army.entity.current_turn_movable = true
for boat in turn.object.boats:
boat.entity.current_turn_movable = true
turn.object.compute_balance()
$Grid.selected_thing = null
country_turn_id += 1
if country_turn_id == 8: country_turn_id = 1
$CanvasLayer/Control/VBoxContainer/TurnLabel.text = countries[country_turn_id].name + "'s turn."
turn_id += 1
if turn_id == len(turns): turn_id = 0
turn = turns[turn_id]
$CanvasLayer/Control/VBoxContainer/TurnLabel.text = turn.object.name + "'s turn."
func _on_BuyFactory_pressed():
@ -74,32 +119,33 @@ func _on_BuyBoat_pressed():
func _on_Grid_tile_pressed(v):
var country = countries[country_turn_id]
var tile = $Grid.grid[v]
match mouse_click_mode:
"buy_factory":
if country.money >= 5 and tile.country == country and not tile.needs_boat and not tile.factory:
country.money -= 5
$Grid.set_factory(v, true)
"buy_army":
if country.money >= 3 and tile.country == country and tile.factory and len(tile.units) == 0:
country.money -= 3
country.add_unit({}, v)
"buy_boat":
if country.money >= 3 and $Grid.has_adjacent_factory(v, country) and tile.needs_boat and len(tile.boats) == 0:
country.money -= 3
country.add_boat({}, v)
null:
if $Grid.selected_thing is Boat and $Grid.selected_thing.get_tile_position() == v or len(tile.boats) == 0:
for army in tile.units:
if army.country == country:
$Grid.selected_thing = army.entity
break
else:
for boat in tile.boats:
if boat.country == country:
$Grid.selected_thing = boat.entity
break
if turn.layer == "country":
var country = turn.object
var tile = $Grid.grid[v]
match mouse_click_mode:
"buy_factory":
if country.money >= 5 and tile.country == country and not tile.needs_boat and not tile.factory:
country.money -= 5
$Grid.set_factory(v, true)
"buy_army":
if country.money >= 3 and tile.country == country and tile.factory and len(tile.units) == 0:
country.money -= 3
country.add_unit({}, v)
"buy_boat":
if country.money >= 3 and $Grid.has_adjacent_factory(v, country) and tile.needs_boat and len(tile.boats) == 0:
country.money -= 3
country.add_boat({}, v)
null:
if $Grid.selected_thing is Boat and $Grid.selected_thing.get_tile_position() == v or len(tile.boats) == 0:
for army in tile.units:
if army.country == country:
$Grid.selected_thing = army.entity
break
else:
for boat in tile.boats:
if boat.country == country:
$Grid.selected_thing = boat.entity
break
func _input(event):
if event is InputEventMouseButton:

@ -0,0 +1,10 @@
class_name Player
extends Reference
var id
var name
var money = 8
var stocks = [] #Array of numbers stock[country_id] = stock_amount
func compute_balance():
pass
Loading…
Cancel
Save