class_name MapView extends Node2D ## Draws the terrain of the shared world. The colours are placeholders until ## a style is chosen from the samples of plan M1d. const CRACK_COLOR := Color(0.1, 0.08, 0.06, 0.8) var session: GwSession func _draw() -> void: if session == null or not session.is_running(): return var width := session.map_width() var height := session.map_height() var terrain := session.terrain_codes() var damage := session.damage_codes() var size := GridMotion.TILE_SIZE for y in height: for x in width: var index := y * width + x var rect := Rect2(x * size, y * size, size, size) draw_rect(rect, color_of(terrain[index])) if damage[index] > 0: _draw_cracks(rect, damage[index]) ## The placeholder colour of a terrain code. static func color_of(terrain: int) -> Color: if terrain == GwSession.TERRAIN_GROUND: return Color(0.42, 0.36, 0.28) if terrain == GwSession.TERRAIN_SOFT_ROCK: return Color(0.56, 0.55, 0.52) if terrain == GwSession.TERRAIN_HARD_ROCK: return Color(0.33, 0.33, 0.37) if terrain == GwSession.TERRAIN_BEDROCK: return Color(0.12, 0.12, 0.14) return Color.MAGENTA ## One crack line for every hit the tile has taken. func _draw_cracks(rect: Rect2, hits: int) -> void: var inset := rect.grow(-3.0) for line in hits: var share := (line + 1.0) / (hits + 1.0) var from := Vector2(inset.position.x, inset.position.y + inset.size.y * share) var to := Vector2(inset.end.x, inset.position.y + inset.size.y * (1.0 - share)) draw_line(from, to, CRACK_COLOR, 1.0)