Added drawing of islands
parent
00ff356b9f
commit
5fe013f128
|
@ -0,0 +1 @@
|
|||
You may use the materials in this file without restriction to develop your apps and to use in your apps.
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -10,7 +10,6 @@ config_version=4
|
|||
|
||||
_global_script_classes=[ ]
|
||||
_global_script_class_icons={
|
||||
|
||||
}
|
||||
|
||||
[application]
|
||||
|
|
108
scenes/Game.tscn
108
scenes/Game.tscn
|
@ -1,10 +1,23 @@
|
|||
[gd_scene load_steps=6 format=2]
|
||||
[gd_scene load_steps=12 format=2]
|
||||
|
||||
[ext_resource path="res://scenes/World.gd" type="Script" id=1]
|
||||
[ext_resource path="res://scenes/HexTile.gd" type="Script" id=2]
|
||||
[ext_resource path="res://assets/pirate.svg" type="Texture" id=3]
|
||||
[ext_resource path="res://scenes/FPSValue.gd" type="Script" id=4]
|
||||
[ext_resource path="res://scenes/pirate.gd" type="Script" id=5]
|
||||
[ext_resource path="res://fonts/Roboto/Roboto-Regular.ttf" type="DynamicFontData" id=6]
|
||||
[ext_resource path="res://scenes/Island.gd" type="Script" id=7]
|
||||
[ext_resource path="res://scenes/GridHighlight.gd" type="Script" id=8]
|
||||
|
||||
[sub_resource type="DynamicFont" id=1]
|
||||
size = 27
|
||||
font_data = ExtResource( 6 )
|
||||
|
||||
[sub_resource type="Theme" id=2]
|
||||
default_font = SubResource( 1 )
|
||||
|
||||
[sub_resource type="ButtonGroup" id=3]
|
||||
resource_name = "TileTypeGroup"
|
||||
|
||||
[node name="GameRoot" type="Node"]
|
||||
|
||||
|
@ -14,34 +27,38 @@ script = ExtResource( 1 )
|
|||
[node name="Camera" type="Camera2D" parent="World"]
|
||||
current = true
|
||||
|
||||
[node name="HexGridDrawer" type="Node" parent="World"]
|
||||
[node name="GridDrawer" type="Node2D" parent="World"]
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="GridHighlight" type="Node2D" parent="World"]
|
||||
script = ExtResource( 8 )
|
||||
|
||||
[node name="UI" type="CanvasLayer" parent="World"]
|
||||
|
||||
[node name="TopContainer" type="HBoxContainer" parent="World/UI"]
|
||||
margin_right = 40.0
|
||||
margin_bottom = 40.0
|
||||
anchor_right = 1.0
|
||||
margin_bottom = 20.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Button" type="Button" parent="World/UI/TopContainer"]
|
||||
margin_right = 55.0
|
||||
[node name="EditIslandButton" type="CheckButton" parent="World/UI/TopContainer"]
|
||||
margin_right = 147.0
|
||||
margin_bottom = 40.0
|
||||
text = "Reload"
|
||||
pressed = true
|
||||
text = "Edit Island"
|
||||
|
||||
[node name="Offset" type="Label" parent="World/UI/TopContainer"]
|
||||
margin_left = 59.0
|
||||
margin_left = 151.0
|
||||
margin_top = 13.0
|
||||
margin_right = 106.0
|
||||
margin_right = 198.0
|
||||
margin_bottom = 27.0
|
||||
text = "Offset: "
|
||||
|
||||
[node name="OffsetValue" type="Label" parent="World/UI/TopContainer"]
|
||||
margin_left = 110.0
|
||||
margin_left = 202.0
|
||||
margin_top = 13.0
|
||||
margin_right = 130.0
|
||||
margin_right = 222.0
|
||||
margin_bottom = 27.0
|
||||
text = "0,0"
|
||||
__meta__ = {
|
||||
|
@ -49,16 +66,16 @@ __meta__ = {
|
|||
}
|
||||
|
||||
[node name="Zoom" type="Label" parent="World/UI/TopContainer"]
|
||||
margin_left = 134.0
|
||||
margin_left = 226.0
|
||||
margin_top = 13.0
|
||||
margin_right = 183.0
|
||||
margin_right = 275.0
|
||||
margin_bottom = 27.0
|
||||
text = " Zoom: "
|
||||
|
||||
[node name="ZoomValue" type="Label" parent="World/UI/TopContainer"]
|
||||
margin_left = 187.0
|
||||
margin_left = 279.0
|
||||
margin_top = 13.0
|
||||
margin_right = 207.0
|
||||
margin_right = 299.0
|
||||
margin_bottom = 27.0
|
||||
text = "0.0"
|
||||
__meta__ = {
|
||||
|
@ -66,36 +83,78 @@ __meta__ = {
|
|||
}
|
||||
|
||||
[node name="HexCoord" type="Label" parent="World/UI/TopContainer"]
|
||||
margin_left = 211.0
|
||||
margin_left = 303.0
|
||||
margin_top = 13.0
|
||||
margin_right = 285.0
|
||||
margin_right = 377.0
|
||||
margin_bottom = 27.0
|
||||
text = " HexCoord: "
|
||||
|
||||
[node name="HexCoordValue" type="Label" parent="World/UI/TopContainer"]
|
||||
margin_left = 289.0
|
||||
margin_left = 381.0
|
||||
margin_top = 13.0
|
||||
margin_right = 317.0
|
||||
margin_right = 409.0
|
||||
margin_bottom = 27.0
|
||||
text = "(0,0)"
|
||||
|
||||
[node name="VSeparator" type="VSeparator" parent="World/UI/TopContainer"]
|
||||
margin_left = 321.0
|
||||
margin_right = 325.0
|
||||
margin_left = 413.0
|
||||
margin_right = 417.0
|
||||
margin_bottom = 40.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="FPSValue" type="Label" parent="World/UI/TopContainer"]
|
||||
margin_left = 329.0
|
||||
margin_left = 421.0
|
||||
margin_top = 13.0
|
||||
margin_right = 337.0
|
||||
margin_right = 429.0
|
||||
margin_bottom = 27.0
|
||||
text = "0"
|
||||
align = 2
|
||||
script = ExtResource( 4 )
|
||||
|
||||
[node name="TileTypes" type="VBoxContainer" parent="World/UI"]
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_left = -82.0
|
||||
theme = SubResource( 2 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="NoneButton" type="Button" parent="World/UI/TileTypes"]
|
||||
margin_right = 82.0
|
||||
margin_bottom = 39.0
|
||||
rect_pivot_offset = Vector2( -1239.87, 282.07 )
|
||||
toggle_mode = true
|
||||
group = SubResource( 3 )
|
||||
text = "None"
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="SandButton" type="Button" parent="World/UI/TileTypes"]
|
||||
margin_top = 43.0
|
||||
margin_right = 82.0
|
||||
margin_bottom = 82.0
|
||||
rect_pivot_offset = Vector2( -1239.87, 282.07 )
|
||||
toggle_mode = true
|
||||
group = SubResource( 3 )
|
||||
text = "Sand"
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="GrassButton" type="Button" parent="World/UI/TileTypes"]
|
||||
margin_top = 86.0
|
||||
margin_right = 82.0
|
||||
margin_bottom = 125.0
|
||||
rect_pivot_offset = Vector2( -1239.87, 282.07 )
|
||||
toggle_mode = true
|
||||
group = SubResource( 3 )
|
||||
text = "Grass"
|
||||
|
||||
[node name="PlayerChar" type="KinematicBody2D" parent="World"]
|
||||
script = ExtResource( 5 )
|
||||
|
||||
|
@ -104,3 +163,6 @@ scale = Vector2( 0.45498, 0.45498 )
|
|||
texture = ExtResource( 3 )
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="World/PlayerChar"]
|
||||
|
||||
[node name="Island" type="Node" parent="World"]
|
||||
script = ExtResource( 7 )
|
||||
|
|
|
@ -36,3 +36,10 @@ func set_hex_scale(scale):
|
|||
TileType.Sand: SandColors,
|
||||
TileType.Grass: GrassColors
|
||||
}
|
||||
|
||||
func get_tile_color (type_name: String):
|
||||
match type_name:
|
||||
"None": return HexColors[TileType.None]
|
||||
"Sand": return HexColors[TileType.Sand]
|
||||
"Grass": return HexColors[TileType.Grass]
|
||||
_ : return null
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
extends Node2D
|
||||
|
||||
onready var HexGridDrawer = get_node("HexGridDrawer")
|
||||
onready var EditIslandButton = get_node("UI/TopContainer/EditIslandButton")
|
||||
onready var TileTypes = get_node("UI/TileTypes")
|
||||
onready var NoneButton = get_node("UI/TileTypes/NoneButton")
|
||||
onready var GridDrawer = get_node("GridDrawer")
|
||||
onready var WorldCamera = get_node("Camera")
|
||||
onready var OffsetValueLabel = get_node("UI/TopContainer/OffsetValue")
|
||||
onready var ZoomValueLabel = get_node("UI/TopContainer/ZoomValue")
|
||||
|
@ -17,6 +20,7 @@ var hex_hover = Vector2.ZERO
|
|||
var is_dragging = false
|
||||
var drag_start = null
|
||||
var target = Vector2()
|
||||
var tile_data = {}
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
|
@ -24,9 +28,13 @@ func _ready():
|
|||
|
||||
# Set player starting position
|
||||
PlayerChar.position = HexGrid.get_hex_center(Vector2(0,0))
|
||||
HexGridDrawer.hex_scale = Vector2(hex_size, hex_size)
|
||||
GridDrawer.hex_scale = Vector2(hex_size, hex_size)
|
||||
|
||||
func _draw():
|
||||
draw_grid()
|
||||
draw_tiles()
|
||||
|
||||
func draw_grid():
|
||||
var view_grid_corners = calc_grid_view_rect()
|
||||
|
||||
var tl_tile_coords = HexGrid.get_hex_center(view_grid_corners[0])
|
||||
|
@ -44,12 +52,16 @@ func _draw():
|
|||
var dy = (c % 2) * sqrt(3) * 0.25 * hex_size #(c % 2) * sqrt(3) * hex_size * 0.75
|
||||
for r in range (nr):
|
||||
draw_set_transform(tl_tile_coords + Vector2(dx, r * hex_size * sqrt(3) * 0.5 + dy), 0, Vector2.ONE)
|
||||
draw_polygon (HexGridDrawer.HexPoints, HexGridDrawer.HexColors[HexGridDrawer.TileType.None])
|
||||
draw_polyline(HexGridDrawer.HexPoints, "#888", 1 * WorldCamera.zoom.x)
|
||||
draw_polyline(GridDrawer.HexPoints, "#888", 1 * WorldCamera.zoom.x)
|
||||
|
||||
var coords = HexGrid.get_hex_center (hex_hover)
|
||||
draw_set_transform(coords, 0, Vector2.ONE)
|
||||
draw_polyline(HexGridDrawer.HexPoints, "#f00", 2 * WorldCamera.zoom.x)
|
||||
draw_polyline(GridDrawer.HexPoints, "#f00", 2 * WorldCamera.zoom.x)
|
||||
|
||||
func draw_tiles():
|
||||
for coord in tile_data.keys():
|
||||
draw_set_transform (coord, 0, Vector2.ONE)
|
||||
draw_polygon(GridDrawer.HexPoints, GridDrawer.get_tile_color(tile_data[coord]))
|
||||
|
||||
func screen_to_world(pos: Vector2):
|
||||
pos = pos - OS.get_window_safe_area().size * 0.5
|
||||
|
@ -71,12 +83,40 @@ func calc_grid_view_rect():
|
|||
var bottom_right = screen_to_hex (view_br)
|
||||
return [top_left, top_right, bottom_left, bottom_right]
|
||||
|
||||
func _unhandled_input(event):
|
||||
func handle_game_event(event):
|
||||
if event is InputEventMouseButton:
|
||||
# Move main character
|
||||
if event.pressed and event.button_index == BUTTON_LEFT:
|
||||
PlayerChar.target = HexGrid.get_hex_center(screen_to_hex(event.position))
|
||||
|
||||
return true
|
||||
|
||||
func handle_editor_event(event):
|
||||
if event is InputEventMouseButton:
|
||||
# Move main character
|
||||
if event.pressed and event.button_index == BUTTON_LEFT:
|
||||
var pressed_button = NoneButton.group.get_pressed_button()
|
||||
var tile_type = "None"
|
||||
if pressed_button:
|
||||
tile_type = pressed_button.text
|
||||
|
||||
|
||||
var hex_coord = HexGrid.get_hex_center(screen_to_hex(event.position))
|
||||
if tile_type != "None":
|
||||
tile_data[hex_coord] = tile_type
|
||||
elif hex_coord in tile_data.keys():
|
||||
tile_data.erase(hex_coord)
|
||||
|
||||
return true
|
||||
|
||||
|
||||
func _unhandled_input(event):
|
||||
if event is InputEventMouseButton:
|
||||
if EditIslandButton.pressed:
|
||||
if handle_editor_event (event):
|
||||
return
|
||||
elif handle_game_event(event):
|
||||
return
|
||||
|
||||
# Move camera
|
||||
if event.pressed and event.button_index == 2:
|
||||
is_dragging = true
|
||||
|
@ -85,7 +125,7 @@ func _unhandled_input(event):
|
|||
is_dragging = false
|
||||
|
||||
# Zoom Camera
|
||||
if event.pressed and event.button_index == BUTTON_WHEEL_DOWN and event.pressed:
|
||||
if event.pressed and event.button_index == BUTTON_WHEEL_DOWN and event.pressed and WorldCamera.zoom.y < 3.5:
|
||||
WorldCamera.zoom = WorldCamera.zoom * 1.0 / 0.8
|
||||
elif event.button_index == BUTTON_WHEEL_UP and event.pressed:
|
||||
WorldCamera.zoom = WorldCamera.zoom * 0.8
|
||||
|
@ -96,7 +136,9 @@ func _unhandled_input(event):
|
|||
else:
|
||||
hex_hover = screen_to_hex(event.position)
|
||||
HexCoordValueLabel.text = str(hex_hover)
|
||||
|
||||
update()
|
||||
|
||||
|
||||
OffsetValueLabel.text = str(WorldCamera.offset)
|
||||
ZoomValueLabel.text = str(WorldCamera.zoom)
|
||||
|
|
Loading…
Reference in New Issue