feat: add S1 walking skeleton

This commit is contained in:
goose
2026-09-30 20:11:16 -04:00
parent fb52208a06
commit d18c8e26fa
252 changed files with 21191 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
class_name ActorState
extends RefCounted
var id: StringName
var cell: Vector2i
var hit_points: int
var max_hit_points: int
var attack_damage: int
func _init(new_id: StringName, new_cell: Vector2i, new_hit_points: int, new_attack_damage: int) -> void:
id = new_id
cell = new_cell
hit_points = new_hit_points
max_hit_points = new_hit_points
attack_damage = new_attack_damage
func is_alive() -> bool:
return hit_points > 0
+1
View File
@@ -0,0 +1 @@
uid://bcv8k6trgcwpv
+35
View File
@@ -0,0 +1,35 @@
class_name GameState
extends RefCounted
const TurnResolverType = preload("res://scripts/domain/turn_resolver.gd")
var player: ActorState
var enemies: Dictionary[StringName, ActorState]
var map: GridMapState
var visible_cells: Dictionary[Vector2i, bool] = {}
var explored_cells: Dictionary[Vector2i, bool] = {}
func _init(new_map: GridMapState, new_player: ActorState, new_enemies: Dictionary[StringName, ActorState]) -> void:
map = new_map
player = new_player
enemies = new_enemies
update_exploration()
func try_player_action(direction: Vector2i) -> Array[TurnResult]:
var results := TurnResolverType.resolve_player_action(self, direction)
update_exploration()
return results
func compute_visible_cells(origin: Vector2i, radius: int) -> Dictionary[Vector2i, bool]:
var visible: Dictionary[Vector2i, bool] = {}
for y in range(origin.y - radius, origin.y + radius + 1):
for x in range(origin.x - radius, origin.x + radius + 1):
var cell := Vector2i(x, y)
if map.is_inside(cell) and origin.distance_to(cell) <= radius:
visible[cell] = true
return visible
func update_exploration() -> void:
visible_cells = compute_visible_cells(player.cell, 6)
for cell in visible_cells:
explored_cells[cell] = true
+1
View File
@@ -0,0 +1 @@
uid://l7gu65bsx57o
+32
View File
@@ -0,0 +1,32 @@
class_name GridMapState
extends RefCounted
const TILE_SIZE := Vector2i(32, 32)
enum CellKind { FLOOR, WALL, CLOSED_DOOR, CHEST, STAIRS }
var size: Vector2i
var _cells: Dictionary[Vector2i, CellKind] = {}
func _init(new_size: Vector2i, fill: CellKind = CellKind.FLOOR) -> void:
size = new_size
for y in range(size.y):
for x in range(size.x):
_cells[Vector2i(x, y)] = fill
func set_cell(cell: Vector2i, kind: CellKind) -> void:
if is_inside(cell):
_cells[cell] = kind
func get_cell(cell: Vector2i) -> CellKind:
return _cells.get(cell, CellKind.WALL)
func is_inside(cell: Vector2i) -> bool:
return cell.x >= 0 and cell.y >= 0 and cell.x < size.x and cell.y < size.y
func is_walkable(cell: Vector2i) -> bool:
var kind := get_cell(cell)
return kind == CellKind.FLOOR or kind == CellKind.CHEST or kind == CellKind.STAIRS
func is_opaque(cell: Vector2i) -> bool:
var kind := get_cell(cell)
return kind == CellKind.WALL or kind == CellKind.CLOSED_DOOR
+1
View File
@@ -0,0 +1 @@
uid://dfmm2nqwdoel1
+53
View File
@@ -0,0 +1,53 @@
class_name TurnResolver
extends RefCounted
const TurnResultType = preload("res://scripts/domain/turn_result.gd")
static func resolve_player_action(state: GameState, direction: Vector2i) -> Array[TurnResult]:
var results: Array[TurnResult] = []
if direction == Vector2i.ZERO:
return results
var player: ActorState = state.player
var destination: Vector2i = player.cell + direction
var enemy: ActorState = _enemy_at(state, destination)
if enemy != null:
enemy.hit_points -= player.attack_damage
results.append(TurnResultType.new(player.id, &"melee", player.cell, destination, enemy.id, player.attack_damage, "You strike the goblin for %d." % player.attack_damage))
if not enemy.is_alive():
state.enemies.erase(enemy.id)
results.append(TurnResultType.new(enemy.id, &"enemy_defeated", enemy.cell, enemy.cell, player.id, 0, "The goblin is defeated."))
else:
_append_enemy_response(state, results)
return results
if not state.map.is_walkable(destination):
results.append(TurnResultType.new(player.id, &"blocked", player.cell, destination, &"", 0, "Your way is blocked."))
return results
var from: Vector2i = player.cell
player.cell = destination
results.append(TurnResultType.new(player.id, &"moved", from, destination, &"", 0, "You move to (%d, %d)." % [destination.x, destination.y]))
_append_enemy_response(state, results)
return results
static func _enemy_at(state: GameState, cell: Vector2i) -> ActorState:
for enemy: ActorState in state.enemies.values():
if enemy.cell == cell:
return enemy
return null
static func _append_enemy_response(state: GameState, results: Array[TurnResult]) -> void:
for enemy: ActorState in state.enemies.values():
var delta: Vector2i = state.player.cell - enemy.cell
if abs(delta.x) + abs(delta.y) == 1:
state.player.hit_points = max(0, state.player.hit_points - enemy.attack_damage)
results.append(TurnResultType.new(enemy.id, &"enemy_melee", enemy.cell, state.player.cell, state.player.id, enemy.attack_damage, "The goblin hits you for %d." % enemy.attack_damage))
return
var step: Vector2i = Vector2i(int(sign(delta.x)), int(sign(delta.y)))
if abs(delta.x) >= abs(delta.y):
step.y = 0
else:
step.x = 0
var target: Vector2i = enemy.cell + step
if state.map.is_walkable(target) and target != state.player.cell and _enemy_at(state, target) == null:
var from: Vector2i = enemy.cell
enemy.cell = target
results.append(TurnResultType.new(enemy.id, &"enemy_moved", from, target, &"", 0, "The goblin moves."))
+1
View File
@@ -0,0 +1 @@
uid://dbd7lcsp1kfkl
+19
View File
@@ -0,0 +1,19 @@
class_name TurnResult
extends RefCounted
var actor_id: StringName
var kind: StringName
var from_cell: Vector2i
var to_cell: Vector2i
var target_id: StringName
var damage: int
var message: String
func _init(new_actor_id: StringName, new_kind: StringName, from: Vector2i, to: Vector2i, target: StringName = &"", amount: int = 0, text: String = "") -> void:
actor_id = new_actor_id
kind = new_kind
from_cell = from
to_cell = to
target_id = target
damage = amount
message = text
+1
View File
@@ -0,0 +1 @@
uid://g2rbece1qsu4