initial commit

This commit is contained in:
2020-05-09 12:45:05 +02:00
commit a3549d357b
46 changed files with 3051 additions and 0 deletions

View File

@ -0,0 +1,94 @@
extends Spatial
var _is_free
var _x
var _y
var _neighbours
var _map
func _ready():
_is_free = true
_map = get_node("/root/Game_manager/Map")
func set_coordinates(x, y):
_x = x
_y = y
func _on_Area_input_event(camera, event, click_position, click_normal, shape_idx):
if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT and event.pressed:
get_node("/root/Game_manager/Mouse_controller").left_click_on_hex(self)
if event.button_index == BUTTON_RIGHT and event.pressed:
get_node("/root/Game_manager/Mouse_controller").right_click_on_hex(self)
func set_color(color_id):
# TODO: make color better?
var material = SpatialMaterial.new()
material.albedo_color = Color(1, 0, 1)
$Cylinder.set_surface_material(0, material)
func occupy_hex():
_is_free = false
func is_free():
return _is_free
func is_any_neighbour_free():
var is_free = false
for neighbour in get_neighbours():
if neighbour.is_free():
is_free = true
continue
return is_free
func get_neighbours():
if _neighbours == null:
_neighbours = []
# left neighbour
if _x > 0:
_neighbours.append(_map.get_hex_at(_x - 1, _y))
# odd-row, starting below
##########
if _y % 2 == 0:
# top left neighbour if(y%2)
if _x > 0 && _y < _map._map_height - 1:
_neighbours.append(_map.get_hex_at(_x - 1, _y + 1))
# top right neighbour if(y%2)
if _y < _map._map_height - 1:
_neighbours.append(_map.get_hex_at(_x, _y + 1))
# bottom right neighbour if(y%2)
if _y > 0:
_neighbours.append(_map.get_hex_at(_x, _y - 1));
# bottom left neighbour if(y%2)
if _x > 0 && _y > 0:
_neighbours.append(_map.get_hex_at(_x - 1, _y - 1));
##########
else:
# top left neighbour
if _y < _map._map_height - 1:
_neighbours.append(_map.get_hex_at(_x, _y + 1));
# top right neighbour
if _x < _map._map_width - 1 && _y < _map._map_height - 1:
_neighbours.append(_map.get_hex_at(_x + 1, _y + 1))
# bottom right neighbour
if _x < _map._map_width - 1 && _y > 0:
_neighbours.append(_map.get_hex_at(_x + 1, _y - 1))
# bottom left neighbour
if _y > 0:
_neighbours.append(_map.get_hex_at(_x, _y - 1))
##########
## right neighbour
if _x < _map._map_width - 1:
_neighbours.append(_map.get_hex_at(_x + 1, _y))
return _neighbours

View File

@ -0,0 +1,22 @@
[gd_scene load_steps=5 format=2]
[ext_resource path="res://Material/hex.dae" type="PackedScene" id=1]
[ext_resource path="res://Scenes/Matchmaking/Game/Map/Hex.gd" type="Script" id=2]
[sub_resource type="SpatialMaterial" id=1]
albedo_color = Color( 0, 0.27451, 1, 1 )
[sub_resource type="CylinderShape" id=2]
radius = 0.986306
[node name="Hex" instance=ExtResource( 1 )]
script = ExtResource( 2 )
[node name="Cylinder" parent="." index="0"]
material/0 = SubResource( 1 )
[node name="Area" type="Area" parent="Cylinder" index="0"]
[node name="CollisionShape" type="CollisionShape" parent="Cylinder/Area" index="0"]
shape = SubResource( 2 )
[connection signal="input_event" from="Cylinder/Area" to="." method="_on_Area_input_event"]

View File

@ -0,0 +1,49 @@
extends Spatial
export var _map_width = 12
export var _map_height = 8
var _width_offset = 2.0
var _height_offset = 2.0 * 0.75
var gap = 0.1
var _hexes = []
func _ready():
add_gap_between_hexes()
generate_map()
func calculate_world_position(grid_position):
var offset = 0
if int(grid_position.y) % 2 != 0:
offset = _width_offset / 2
var x = grid_position.x * _width_offset + offset
var z = grid_position.y * _height_offset
return Vector3(x, 0, z)
func add_gap_between_hexes():
_width_offset += _width_offset * gap
_height_offset += _height_offset * gap
func generate_map():
for x in range(0, _map_width):
_hexes.append([])
_hexes[x].resize(_map_height)
for y in range(0, _map_height):
var hex_node = load("res://Scenes/Matchmaking/Game/Map/Hex.tscn").instance()
hex_node.set_coordinates(x, y)
var position = (calculate_world_position(Vector2(x,y)))
hex_node.name = "hex_%d_%d" % [x, y]
hex_node.translation = position
add_child(hex_node)
_hexes[x][y] = hex_node
func get_hex_at(x, y):
return _hexes[x][y]

View File

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Scenes/Matchmaking/Game/Map/Map.gd" type="Script" id=1]
[node name="Map" type="Spatial"]
script = ExtResource( 1 )