hexland/Scripts/Hex.gd

33 lines
743 B
GDScript

extends Node2D
class_name Hex
const WIDTH = 220
const HEIGHT = 190
const HALFWIDTH = WIDTH / 2
const HALFHEIGHT = HEIGHT / 2
const TEXTURE_MAP = {
"hills": preload("res://Assets/brick-hex.png"),
"forest": preload("res://Assets/wood-hex.png"),
"mountains": preload("res://Assets/stone-hex.png"),
"fields": preload("res://Assets/wheat-hex.png"),
"pasture": preload("res://Assets/sheep-hex.png"),
"desert": preload("res://Assets/desert-hex.png"),
}
var type = "desert" setget set_type
var index = Vector2.ZERO
func _ready():
$Image.texture = TEXTURE_MAP[type]
func _process(_delta):
if Debug.on:
$DebugLabel.text = "(%+d, %+d)" % [index.x, index.y]
func set_type(newtype):
$Image.texture = TEXTURE_MAP[newtype]
type = newtype