generated from krampus/template-godot4
adds demolitions building
All checks were successful
linting & formatting / build (push) Successful in 26s
All checks were successful
linting & formatting / build (push) Successful in 26s
This commit is contained in:
parent
545bf25f07
commit
627c2b38e6
@ -15,6 +15,7 @@ var tiles: Dictionary[Vector2i, Tile] = {}
|
||||
var buildings: Dictionary[Vector2i, Building] = {}
|
||||
var active_building: Building
|
||||
var active_tile: Tile
|
||||
var is_destroying_building: bool = false
|
||||
var current_map_coord: Vector2i
|
||||
var prev_map_coord: Vector2i
|
||||
var is_controlling_camera: bool = false
|
||||
@ -39,12 +40,19 @@ func _input(event: InputEvent) -> void:
|
||||
active_tile.position = tile_map.map_to_local(current_map_coord)
|
||||
if active_building != null:
|
||||
active_building.position = tile_map.map_to_local(current_map_coord)
|
||||
if is_destroying_building:
|
||||
if buildings.has(current_map_coord):
|
||||
buildings[current_map_coord].show_bomb()
|
||||
if prev_map_coord != current_map_coord and buildings.has(prev_map_coord):
|
||||
buildings[prev_map_coord].hide_bomb()
|
||||
prev_map_coord = current_map_coord
|
||||
if event.is_action_pressed("select"):
|
||||
if active_tile != null:
|
||||
place_active_tile()
|
||||
elif active_building != null:
|
||||
place_active_building()
|
||||
if is_destroying_building:
|
||||
destroy_current_building()
|
||||
_handle_building_rotation(event)
|
||||
_handle_spawn_rotation(event)
|
||||
|
||||
@ -63,6 +71,8 @@ func set_active_building(building: Building) -> void:
|
||||
active_building.player = Globals.board_game.current_board_state.current_player
|
||||
active_building.modulate = Color(1, 1, 1, 0.5)
|
||||
active_building.is_placing = true
|
||||
if active_building is PostOffice:
|
||||
active_building.place()
|
||||
|
||||
|
||||
func place_active_tile() -> void:
|
||||
@ -128,28 +138,37 @@ func place_active_building() -> void:
|
||||
active_building = null
|
||||
|
||||
|
||||
func destroy_current_building() -> void:
|
||||
if buildings.has(current_map_coord):
|
||||
var building = buildings[current_map_coord]
|
||||
if building is not Home and building is not HQ:
|
||||
remove_building(building)
|
||||
Globals.board_game.current_board_state.buildings_to_destroy -= 1
|
||||
|
||||
|
||||
func remove_home(player: Player) -> void:
|
||||
for coord in buildings.keys():
|
||||
var building = buildings[coord]
|
||||
if building is Home and building.player.id == player.id:
|
||||
remove_building(coord, building)
|
||||
remove_building(building)
|
||||
|
||||
|
||||
func remove_hq(player: Player) -> void:
|
||||
for coord in buildings.keys():
|
||||
var building = buildings[coord]
|
||||
if building is HQ and building.player.id == player.id:
|
||||
remove_building(coord, building)
|
||||
remove_building(building)
|
||||
|
||||
|
||||
func remove_building(coord: Vector2i, building: Building) -> void:
|
||||
func remove_building(building: Building) -> void:
|
||||
for coord in building.get_tile_coords():
|
||||
buildings.erase(coord)
|
||||
building.free()
|
||||
var ground: Ground = GROUND.instantiate()
|
||||
board_state.add_child(ground)
|
||||
ground.position = tile_map.map_to_local(coord)
|
||||
ground.coords = coord
|
||||
tiles[coord] = ground
|
||||
building.free()
|
||||
|
||||
|
||||
func _handle_building_rotation(event: InputEvent) -> void:
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
class_name Citizen extends CharacterBody2D
|
||||
|
||||
enum Status { NONE, DRUNK, ARMED, CAFFEINATED }
|
||||
enum Status { NONE, DRUNK, ARMED, CAFFEINATED, PACKAGED }
|
||||
|
||||
const DRUNK_ICON = preload("uid://28x2e52skdt1")
|
||||
const COFFEE_ICON = preload("uid://0644a3psplk8")
|
||||
const ARMED_ICON = preload("uid://cn8biugbtcns5")
|
||||
const PACKAGE_ICON = preload("uid://drhv16h2tgoju")
|
||||
|
||||
var direction: Board.Direction:
|
||||
set(new_direction):
|
||||
@ -29,6 +30,7 @@ var money: int = 0
|
||||
var money_label_tween: Tween
|
||||
var tiles_visited: Dictionary[Tile, int] = {}
|
||||
var buildings_visited: Dictionary[Building, int] = {}
|
||||
var package_distance: int = 0
|
||||
|
||||
var _statuses: Array[Status] = []
|
||||
|
||||
@ -61,6 +63,8 @@ func add_status(status: Status) -> void:
|
||||
status_container.add_child(COFFEE_ICON.instantiate())
|
||||
Status.ARMED:
|
||||
status_container.add_child(ARMED_ICON.instantiate())
|
||||
Status.PACKAGED:
|
||||
status_container.add_child(PACKAGE_ICON.instantiate())
|
||||
|
||||
|
||||
func remove_status(status: Status) -> void:
|
||||
@ -186,6 +190,8 @@ func handle_tile_area_exited(_area: Area2D):
|
||||
if direction != Board.Direction.NONE:
|
||||
direction = Board.Direction.NONE
|
||||
return
|
||||
if get_status_count(Citizen.Status.PACKAGED) > 0:
|
||||
package_distance += 1
|
||||
if !direction_queue.is_empty():
|
||||
direction = direction_queue.pop_front()
|
||||
elif Globals.board_game.board.buildings.has(current_tile_coords):
|
||||
|
||||
@ -18,6 +18,21 @@ var tile_rotation: Board.Direction = Board.Direction.UP
|
||||
@onready var bomb_sprite: Sprite2D = %BombSprite
|
||||
|
||||
|
||||
func can_citizen_enter(_coord: Vector2i, _direction: Board.Direction) -> bool:
|
||||
print("The extending class has to implement this!")
|
||||
return false
|
||||
|
||||
|
||||
func get_tile_coords() -> Array[Vector2i]:
|
||||
print("The extending class has to implement this!")
|
||||
return []
|
||||
|
||||
|
||||
func get_direction_queue(_citizen: Citizen) -> Array[Board.Direction]:
|
||||
print("The extending class has to implement this!")
|
||||
return []
|
||||
|
||||
|
||||
func building_entered(body: Node2D) -> void:
|
||||
if body is Citizen:
|
||||
print("Activate building effect!")
|
||||
|
||||
@ -22,7 +22,7 @@ region = Rect2(16, 16, 16, 16)
|
||||
atlas = ExtResource("2_gnrqc")
|
||||
region = Rect2(0, 16, 16, 16)
|
||||
|
||||
[node name="Demolitions" type="Node2D" unique_id=746270571]
|
||||
[node name="Demolitions" type="Node2D" unique_id=746270571 groups=["PostTurnActions"]]
|
||||
process_mode = 3
|
||||
script = ExtResource("1_veblj")
|
||||
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
[gd_scene format=3 uid="uid://cn8biugbtcns5"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://cfo7jpjxnw5m8" path="res://assets/shotgun/shotgun_1.png" id="1_2kv2h"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_af8ve"]
|
||||
atlas = ExtResource("1_2kv2h")
|
||||
region = Rect2(1, 12, 28, 9)
|
||||
|
||||
[node name="ArmedIcon" type="TextureRect" unique_id=585475146]
|
||||
texture_filter = 1
|
||||
custom_minimum_size = Vector2(10, 10)
|
||||
texture = SubResource("AtlasTexture_af8ve")
|
||||
expand_mode = 5
|
||||
stretch_mode = 5
|
||||
flip_h = true
|
||||
@ -1,13 +0,0 @@
|
||||
[gd_scene format=3 uid="uid://0644a3psplk8"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://nne5hv8t0sks" path="res://assets/coffee/AssetPack_V01_FREE.png" id="1_ikgws"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_af8ve"]
|
||||
atlas = ExtResource("1_ikgws")
|
||||
region = Rect2(32, 16, 16, 16)
|
||||
|
||||
[node name="CoffeeIcon" type="TextureRect" unique_id=585475146]
|
||||
texture_filter = 1
|
||||
custom_minimum_size = Vector2(10, 10)
|
||||
texture = SubResource("AtlasTexture_af8ve")
|
||||
expand_mode = 3
|
||||
@ -1,11 +0,0 @@
|
||||
[gd_scene format=3 uid="uid://28x2e52skdt1"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://cm0k0h7fakj7m" path="res://assets/beer/beer.png" id="1_1d2oi"]
|
||||
|
||||
[node name="DrunkIcon" type="TextureRect" unique_id=967704941]
|
||||
z_index = 1
|
||||
texture_filter = 1
|
||||
custom_minimum_size = Vector2(10, 10)
|
||||
texture = ExtResource("1_1d2oi")
|
||||
expand_mode = 1
|
||||
stretch_mode = 4
|
||||
@ -12,7 +12,7 @@ var buildings: Array[Building] = []
|
||||
var players_passed: int = 0
|
||||
var real_estate_market: Array[Building] = []
|
||||
var spawn_placements: int = 0
|
||||
var buildings_destroyed: int = 0
|
||||
var buildings_to_destroy: int = 0
|
||||
var citizens_starting_money: int = 0
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@ func serialize() -> Dictionary:
|
||||
result["state"] = state
|
||||
result["players_passed"] = players_passed
|
||||
result["spawn_placements"] = spawn_placements
|
||||
result["buildings_destroyed"] = buildings_destroyed
|
||||
result["buildings_to_destroy"] = buildings_to_destroy
|
||||
result["citizens_starting_money"] = citizens_starting_money
|
||||
result["current_player"] = current_player.serialize()
|
||||
result["players"] = []
|
||||
@ -61,7 +61,7 @@ static func deserialize(data: Dictionary) -> BoardState:
|
||||
result.state = data["state"]
|
||||
result.players_passed = data["players_passed"]
|
||||
result.spawn_placements = data["spawn_placements"]
|
||||
result.buildings_destroyed = data["buildings_destroyed"]
|
||||
result.buildings_to_destroy = data["buildings_to_destroy"]
|
||||
result.citizens_starting_money = data["citizens_starting_money"]
|
||||
result.current_player = Player.deserialize(data["current_player"])
|
||||
for p in data["players"]:
|
||||
|
||||
@ -17,6 +17,7 @@ const SHOP_SCENE = preload("uid://dbn63mv0peqf")
|
||||
const CHURCH_SCENE = preload("uid://brn0nbkela0m4")
|
||||
const CITY_HALL_SCENE = preload("uid://dtnejoimqiu0o")
|
||||
const DEMOLITIONS_SCENE = preload("uid://dvmglvbersupv")
|
||||
const POST_OFFICE_SCENE = preload("uid://bpi8owv5lxyjy")
|
||||
|
||||
const BASE_DECK = [
|
||||
BANK_SCENE,
|
||||
@ -28,9 +29,12 @@ const BASE_DECK = [
|
||||
OFFICE_SCENE,
|
||||
SHOP_SCENE,
|
||||
CHURCH_SCENE,
|
||||
CITY_HALL_SCENE
|
||||
CITY_HALL_SCENE,
|
||||
DEMOLITIONS_SCENE
|
||||
]
|
||||
|
||||
const WINNING_MONEY_AMOUNT: int = 200
|
||||
|
||||
var citizen_count: int = 0:
|
||||
set(value):
|
||||
#print(value)
|
||||
@ -177,9 +181,11 @@ func start_day() -> void:
|
||||
await all_players_ready_for_day_start
|
||||
|
||||
if current_board_state.state == BoardState.State.DESTROYING_BUILDINGS:
|
||||
if current_board_state.buildings_destroyed > 0:
|
||||
if current_board_state.buildings_to_destroy > 0:
|
||||
if current_board_state.current_player.id == Globals.game.this_player.id:
|
||||
print("here")
|
||||
board.is_destroying_building = true
|
||||
return
|
||||
current_board_state.state = BoardState.State.DRAFT
|
||||
|
||||
if current_board_state.state == BoardState.State.PLACING_SPAWNS:
|
||||
if current_board_state.spawn_placements > 0:
|
||||
@ -199,7 +205,7 @@ func start_day() -> void:
|
||||
|
||||
seed(Globals.game.sum_player_ids())
|
||||
deck.shuffle()
|
||||
# deck.push_front(DEMOLITIONS_SCENE.instantiate())
|
||||
#deck.push_front(POST_OFFICE_SCENE.instantiate())
|
||||
var turn_index := current_board_state.get_this_player_index()
|
||||
controls.give_hand(deck.slice(0 + (3 * turn_index), 3 + (3 * turn_index)))
|
||||
controls.set_info()
|
||||
@ -231,7 +237,7 @@ func handle_board_state_changed() -> void:
|
||||
pending_board_state = BoardState.new()
|
||||
pending_board_state.day = current_board_state.day
|
||||
pending_board_state.spawn_placements = current_board_state.spawn_placements
|
||||
pending_board_state.buildings_destroyed = current_board_state.buildings_destroyed
|
||||
pending_board_state.buildings_to_destroy = current_board_state.buildings_to_destroy
|
||||
if (
|
||||
current_board_state.state != BoardState.State.DRAFT
|
||||
and current_board_state.state != BoardState.State.PLACING_SPAWNS
|
||||
@ -270,19 +276,14 @@ func handle_pass() -> void:
|
||||
advance_board_state.rpc(current_board_state.serialize())
|
||||
|
||||
|
||||
func _reset_turn() -> void:
|
||||
pending_board_state = null
|
||||
update_board_state.rpc(original_board_state.serialize())
|
||||
|
||||
|
||||
func handle_citizens_finished() -> void:
|
||||
for child in board.board_state.get_children():
|
||||
if child.get_groups().has("PostTurnActions"):
|
||||
child.handle_post_turn_actions()
|
||||
is_playing_day = false
|
||||
controls._reset_turn()
|
||||
controls.reset_turn()
|
||||
var winning_player_idx = current_board_state.players.find_custom(
|
||||
func(p: Player) -> bool: return p.money >= 100
|
||||
func(p: Player) -> bool: return p.money >= WINNING_MONEY_AMOUNT
|
||||
)
|
||||
if winning_player_idx != -1:
|
||||
game_over.set_winning_player(current_board_state.players[winning_player_idx])
|
||||
@ -309,9 +310,9 @@ func queue_spawn_placement(num_placements: int) -> void:
|
||||
current_board_state.state = BoardState.State.PLACING_SPAWNS
|
||||
|
||||
|
||||
func queue_building_destruction(num_placements: int) -> void:
|
||||
current_board_state.spawn_placements += num_placements * current_board_state.players.size()
|
||||
current_board_state.state = BoardState.State.PLACING_SPAWNS
|
||||
func queue_building_destruction(num: int) -> void:
|
||||
current_board_state.buildings_to_destroy += num * current_board_state.players.size()
|
||||
current_board_state.state = BoardState.State.DESTROYING_BUILDINGS
|
||||
|
||||
|
||||
func sell_building_permit() -> void:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user