Spielfeld über Art zeichnen

Karte, Figuren und Zielmarke zeichnet jetzt Art. Die Karte zeichnet in
Blöcken von 16 mal 16 Kacheln und nach einem Treffer nur die Blöcke um
die Kachel neu; jede Kachel kennt ihre Nachbarn. Figuren stehen
aufrecht in ihrer Kachel, schreiten und schauen in die Richtung, in die
sie gehen. Der eigene Schlag zeigt seine Splitter sofort, auch als Gast,
und die Namen über fremden Figuren werden in Bildschirmgröße gezeichnet
und bleiben scharf.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
Steven Wroblewski
2026-10-02 11:49:18 +02:00
parent 9921aba63a
commit d2a7973022
10 changed files with 422 additions and 64 deletions
+30 -6
View File
@@ -40,6 +40,8 @@ var session: GwSession
## The network connection of an open world or a guest, or null.
var link: SessionLink
var clock: TickClock
## The style the playing field is drawn in.
var art: Art
var menu: Menu
var map_view: MapView
var marker: TileMarker
@@ -75,13 +77,19 @@ func _ready() -> void:
if _player_key.is_empty():
push_warning("the player key cannot be read: %s" % error_string(store.last_read_error))
clock = TickClock.new(GwSession.TICKS_PER_SECOND)
art = Art.new()
art.load_overrides(Art.OVERRIDE_DIR)
map_view = MapView.new()
map_view.art = art
add_child(map_view)
marker = TileMarker.new()
marker.art = art
add_child(marker)
figures = Figures.new()
figures.art = art
add_child(figures)
avatar = Avatar.new()
avatar.art = art
add_child(avatar)
var camera := Camera2D.new()
camera.zoom = CAMERA_ZOOM
@@ -200,8 +208,9 @@ func _show_world() -> void:
for node: Node2D in [avatar, marker, figures]:
node.show()
map_view.session = session
map_view.queue_redraw()
map_view.reload()
figures.session = session
avatar.player = session.local_player()
figures.clear()
avatar.is_walkable = session.is_walkable
avatar.position = GridMotion.tile_center(session.spawn_point())
@@ -230,7 +239,7 @@ func _leave(message: String) -> void:
link = null
session = null
map_view.session = null
map_view.queue_redraw()
map_view.reload()
avatar.is_walkable = Callable()
figures.clear()
_show_menu(message)
@@ -295,7 +304,7 @@ func _on_notice(notice: Dictionary) -> void:
if notice["resync"]:
resyncs += 1
_keep_diverged_recording()
map_view.queue_redraw()
map_view.reload()
hud.show_stone(session.item_count(GwSession.ITEM_STONE))
hud.flash("RESYNCED")
else:
@@ -390,8 +399,16 @@ func _apply(events: Array[Dictionary]) -> void:
var local := session.local_player()
for event in events:
match event["type"]:
"tile_hit", "tile_changed":
map_view.queue_redraw()
"tile_hit":
var tile := Vector2i(event["x"], event["y"])
map_view.refresh_tile(tile)
# The own hits showed their burst when they were made.
if event["player"] != local:
map_view.hit(tile)
"tile_changed":
var tile := Vector2i(event["x"], event["y"])
map_view.refresh_tile(tile)
map_view.hit(tile)
"item_gained":
if event["player"] == local:
hud.show_stone(session.item_count(GwSession.ITEM_STONE))
@@ -401,6 +418,9 @@ func _apply(events: Array[Dictionary]) -> void:
"player_joined":
if event["player"] != local:
hud.flash("PLAYER_JOINED", [session.player_name(event["player"])])
else:
avatar.player = local
avatar.queue_redraw()
_update_status()
"player_left":
figures.forget(event["player"])
@@ -422,7 +442,9 @@ func _try_dig() -> void:
dig_at(marker.tile)
## Queues a pickaxe hit on `tile`, at most once per cooldown. The caller must
## Queues a pickaxe hit on `tile`, at most once per cooldown, and shows its
## burst of chips at once: the hit itself lands with a later tick, which for a
## guest comes back from the host only after the round trip. The caller must
## check the reach: figures move outside the lockstep, so the core does not
## know where the figure is. The core checks the cooldown, the tile, its
## terrain, the tool tier and the free space in the inventory.
@@ -431,6 +453,8 @@ func dig_at(tile: Vector2i) -> void:
return
session.dig(tile.x, tile.y)
_next_dig_tick = session.tick() + GwSession.DIG_COOLDOWN_TICKS
if session.terrain_at(tile.x, tile.y) != GwSession.TERRAIN_GROUND:
map_view.hit(tile)
## Writes the running world as the save. Returns false if nothing was