Init commit, generate hex layouts
This commit is contained in:
31
Scripts/Board.gd
Normal file
31
Scripts/Board.gd
Normal file
@@ -0,0 +1,31 @@
|
||||
extends Node2D
|
||||
|
||||
class_name Board
|
||||
|
||||
const Y_OFFSET = Vector2(Hex.HALFWIDTH, Hex.HEIGHT)
|
||||
const X_OFFSET = Vector2(Hex.WIDTH, 0)
|
||||
|
||||
export(Array, Vector2) var indices = [Vector2.ZERO]
|
||||
export(Dictionary) var distribution = {
|
||||
"hills": 0,
|
||||
"forest": 0,
|
||||
"mountains": 0,
|
||||
"fields": 0,
|
||||
"pasture": 0,
|
||||
"desert": 1,
|
||||
}
|
||||
|
||||
func _ready():
|
||||
var tiles = []
|
||||
for tile in distribution:
|
||||
for _i in range(distribution[tile]):
|
||||
tiles.append(tile)
|
||||
randomize()
|
||||
tiles.shuffle()
|
||||
for index in indices:
|
||||
var hex = Hex.new()
|
||||
hex.name = "Hex#%d#%d" % [index.x, index.y]
|
||||
hex.translate(X_OFFSET * index.x)
|
||||
hex.translate(Y_OFFSET * index.y)
|
||||
add_child(hex)
|
||||
hex.type = tiles.pop_front()
|
||||
30
Scripts/Hex.gd
Normal file
30
Scripts/Hex.gd
Normal file
@@ -0,0 +1,30 @@
|
||||
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
|
||||
|
||||
func _ready():
|
||||
var sprite = Sprite.new()
|
||||
sprite.texture = TEXTURE_MAP[type]
|
||||
sprite.name = "Img"
|
||||
add_child(sprite)
|
||||
|
||||
func set_type(newtype):
|
||||
$Img.texture = TEXTURE_MAP[newtype]
|
||||
type = newtype
|
||||
Reference in New Issue
Block a user