feat: add 30x20 demo map and chest interaction
This commit is contained in:
@@ -22,7 +22,10 @@ func get_context_target() -> StringName:
|
||||
return &"exit_reached"
|
||||
if map.get_cell(player.cell) == GridMapState.CellKind.STAIRS:
|
||||
return &"stairs"
|
||||
for direction in [Vector2i.UP, Vector2i.RIGHT, Vector2i.DOWN, Vector2i.LEFT, Vector2i(1, -1), Vector2i(1, 1), Vector2i(-1, 1), Vector2i(-1, -1)]:
|
||||
for direction in InteractionResolverType.TARGET_OFFSETS:
|
||||
if map.get_cell(player.cell + direction) == GridMapState.CellKind.CHEST:
|
||||
return &"chest"
|
||||
for direction in InteractionResolverType.TARGET_OFFSETS:
|
||||
if map.get_cell(player.cell + direction) == GridMapState.CellKind.CLOSED_DOOR:
|
||||
return &"closed_door"
|
||||
return &""
|
||||
|
||||
@@ -25,8 +25,8 @@ func is_inside(cell: Vector2i) -> bool:
|
||||
|
||||
func is_walkable(cell: Vector2i) -> bool:
|
||||
var kind := get_cell(cell)
|
||||
return kind == CellKind.FLOOR or kind == CellKind.CHEST or kind == CellKind.STAIRS
|
||||
return kind == CellKind.FLOOR or kind == CellKind.STAIRS
|
||||
|
||||
func is_opaque(cell: Vector2i) -> bool:
|
||||
var kind := get_cell(cell)
|
||||
return kind == CellKind.WALL or kind == CellKind.CLOSED_DOOR
|
||||
return kind == CellKind.WALL or kind == CellKind.CLOSED_DOOR or kind == CellKind.CHEST
|
||||
|
||||
@@ -24,7 +24,14 @@ static func resolve(state: GameState) -> Array[TurnResult]:
|
||||
TurnResolverType.append_enemy_response(state, results)
|
||||
return results
|
||||
|
||||
var door_cell := _find_closed_door(state)
|
||||
var chest_cell := _find_cell_of_kind(state, GridMapState.CellKind.CHEST)
|
||||
if chest_cell.x >= 0:
|
||||
state.map.set_cell(chest_cell, GridMapState.CellKind.FLOOR)
|
||||
results.append(TurnResultType.new(state.player.id, &"chest_opened", state.player.cell, chest_cell, &"", 0, "You open the chest."))
|
||||
TurnResolverType.append_enemy_response(state, results)
|
||||
return results
|
||||
|
||||
var door_cell := _find_cell_of_kind(state, GridMapState.CellKind.CLOSED_DOOR)
|
||||
if door_cell.x >= 0:
|
||||
state.map.set_cell(door_cell, GridMapState.CellKind.FLOOR)
|
||||
results.append(TurnResultType.new(state.player.id, &"door_opened", state.player.cell, door_cell, &"", 0, "You open the door."))
|
||||
@@ -34,9 +41,9 @@ static func resolve(state: GameState) -> Array[TurnResult]:
|
||||
results.append(TurnResultType.new(state.player.id, &"nothing_to_interact", state.player.cell, state.player.cell, &"", 0, "Nothing to interact with."))
|
||||
return results
|
||||
|
||||
static func _find_closed_door(state: GameState) -> Vector2i:
|
||||
static func _find_cell_of_kind(state: GameState, kind: GridMapState.CellKind) -> Vector2i:
|
||||
for offset in TARGET_OFFSETS:
|
||||
var cell := state.player.cell + offset
|
||||
if state.map.get_cell(cell) == GridMapState.CellKind.CLOSED_DOOR:
|
||||
if state.map.get_cell(cell) == kind:
|
||||
return cell
|
||||
return Vector2i(-1, -1)
|
||||
|
||||
+30
-15
@@ -51,8 +51,9 @@ func _capture_visual_check(capture_mode: String) -> void:
|
||||
get_tree().quit(0 if result == OK else 1)
|
||||
|
||||
func _prepare_exit_capture_state() -> void:
|
||||
game_state.map.set_cell(Vector2i(2, 1), GridMapStateType.CellKind.FLOOR)
|
||||
game_state.player.cell = Vector2i(9, 7)
|
||||
game_state.map.set_cell(Vector2i(4, 10), GridMapStateType.CellKind.FLOOR)
|
||||
game_state.map.set_cell(Vector2i(4, 7), GridMapStateType.CellKind.FLOOR)
|
||||
game_state.player.cell = Vector2i(18, 4)
|
||||
_process_interact()
|
||||
_sync_camera_to_player()
|
||||
|
||||
@@ -139,21 +140,35 @@ func _show_damage_feedback(results: Array[TurnResult]) -> void:
|
||||
player_view.show_damage(result.damage)
|
||||
|
||||
func _create_initial_state() -> GameState:
|
||||
var map := GridMapStateType.new(Vector2i(12, 10), GridMapStateType.CellKind.FLOOR)
|
||||
for x in range(map.size.x):
|
||||
map.set_cell(Vector2i(x, 0), GridMapStateType.CellKind.WALL)
|
||||
map.set_cell(Vector2i(x, map.size.y - 1), GridMapStateType.CellKind.WALL)
|
||||
for y in range(map.size.y):
|
||||
map.set_cell(Vector2i(0, y), GridMapStateType.CellKind.WALL)
|
||||
map.set_cell(Vector2i(map.size.x - 1, y), GridMapStateType.CellKind.WALL)
|
||||
map.set_cell(Vector2i(1, 2), GridMapStateType.CellKind.WALL)
|
||||
map.set_cell(Vector2i(2, 1), GridMapStateType.CellKind.CLOSED_DOOR)
|
||||
map.set_cell(Vector2i(8, 3), GridMapStateType.CellKind.CHEST)
|
||||
map.set_cell(Vector2i(9, 7), GridMapStateType.CellKind.STAIRS)
|
||||
var player := ActorStateType.new(&"player", Vector2i(2, 2), 12, 3)
|
||||
var goblin := ActorStateType.new(&"goblin", Vector2i(4, 2), 6, 2)
|
||||
var map := GridMapStateType.new(Vector2i(30, 20), GridMapStateType.CellKind.WALL)
|
||||
_carve_room(map, Rect2i(2, 12, 6, 5))
|
||||
_carve_room(map, Rect2i(2, 4, 7, 7))
|
||||
_carve_room(map, Rect2i(10, 2, 10, 6))
|
||||
_carve_room(map, Rect2i(21, 5, 7, 8))
|
||||
_carve_vertical_corridor(map, 4, 10, 12)
|
||||
_carve_horizontal_corridor(map, 8, 10, 6)
|
||||
_carve_horizontal_corridor(map, 18, 21, 6)
|
||||
_carve_vertical_corridor(map, 18, 4, 6)
|
||||
map.set_cell(Vector2i(4, 11), GridMapStateType.CellKind.CLOSED_DOOR)
|
||||
map.set_cell(Vector2i(4, 7), GridMapStateType.CellKind.CHEST)
|
||||
map.set_cell(Vector2i(18, 4), GridMapStateType.CellKind.STAIRS)
|
||||
var player := ActorStateType.new(&"player", Vector2i(4, 12), 12, 3)
|
||||
var goblin := ActorStateType.new(&"goblin", Vector2i(24, 8), 6, 2)
|
||||
return GameStateType.new(map, player, {&"goblin": goblin})
|
||||
|
||||
func _carve_room(map: GridMapState, room: Rect2i) -> void:
|
||||
for y in range(room.position.y, room.end.y):
|
||||
for x in range(room.position.x, room.end.x):
|
||||
map.set_cell(Vector2i(x, y), GridMapStateType.CellKind.FLOOR)
|
||||
|
||||
func _carve_horizontal_corridor(map: GridMapState, from_x: int, to_x: int, y: int) -> void:
|
||||
for x in range(from_x, to_x + 1):
|
||||
map.set_cell(Vector2i(x, y), GridMapStateType.CellKind.FLOOR)
|
||||
|
||||
func _carve_vertical_corridor(map: GridMapState, x: int, from_y: int, to_y: int) -> void:
|
||||
for y in range(from_y, to_y + 1):
|
||||
map.set_cell(Vector2i(x, y), GridMapStateType.CellKind.FLOOR)
|
||||
|
||||
func _configure_camera() -> void:
|
||||
var map_size := game_state.map.size * TILE_SIZE
|
||||
camera.limit_left = $World.position.x
|
||||
|
||||
@@ -2,6 +2,7 @@ class_name GameHud
|
||||
extends CanvasLayer
|
||||
|
||||
const DOOR_PROMPT := "Espace — Ouvrir la porte"
|
||||
const CHEST_PROMPT := "Espace — Ouvrir le coffre"
|
||||
const STAIRS_PROMPT := "Espace — Descendre l’escalier"
|
||||
const EXIT_REACHED_PROMPT := "Sortie atteinte — prochain étage bientôt disponible"
|
||||
|
||||
@@ -32,6 +33,8 @@ func get_context_prompt() -> String:
|
||||
if _state == null:
|
||||
return ""
|
||||
match _state.get_context_target():
|
||||
&"chest":
|
||||
return CHEST_PROMPT
|
||||
&"closed_door":
|
||||
return DOOR_PROMPT
|
||||
&"stairs":
|
||||
|
||||
Reference in New Issue
Block a user