diff --git a/fonts/Roboto/NOTICE.txt b/fonts/Roboto/NOTICE.txt new file mode 100644 index 0000000..2df9f2e --- /dev/null +++ b/fonts/Roboto/NOTICE.txt @@ -0,0 +1 @@ +You may use the materials in this file without restriction to develop your apps and to use in your apps. \ No newline at end of file diff --git a/fonts/Roboto/Roboto-Black.ttf b/fonts/Roboto/Roboto-Black.ttf new file mode 100644 index 0000000..86ec2b2 Binary files /dev/null and b/fonts/Roboto/Roboto-Black.ttf differ diff --git a/fonts/Roboto/Roboto-BlackItalic.ttf b/fonts/Roboto/Roboto-BlackItalic.ttf new file mode 100644 index 0000000..1904c99 Binary files /dev/null and b/fonts/Roboto/Roboto-BlackItalic.ttf differ diff --git a/fonts/Roboto/Roboto-Bold.ttf b/fonts/Roboto/Roboto-Bold.ttf new file mode 100644 index 0000000..91ec212 Binary files /dev/null and b/fonts/Roboto/Roboto-Bold.ttf differ diff --git a/fonts/Roboto/Roboto-BoldCondensed.ttf b/fonts/Roboto/Roboto-BoldCondensed.ttf new file mode 100644 index 0000000..d7ea883 Binary files /dev/null and b/fonts/Roboto/Roboto-BoldCondensed.ttf differ diff --git a/fonts/Roboto/Roboto-BoldCondensedItalic.ttf b/fonts/Roboto/Roboto-BoldCondensedItalic.ttf new file mode 100644 index 0000000..3c9635a Binary files /dev/null and b/fonts/Roboto/Roboto-BoldCondensedItalic.ttf differ diff --git a/fonts/Roboto/Roboto-BoldItalic.ttf b/fonts/Roboto/Roboto-BoldItalic.ttf new file mode 100644 index 0000000..4013bf8 Binary files /dev/null and b/fonts/Roboto/Roboto-BoldItalic.ttf differ diff --git a/fonts/Roboto/Roboto-Condensed.ttf b/fonts/Roboto/Roboto-Condensed.ttf new file mode 100644 index 0000000..6e7575a Binary files /dev/null and b/fonts/Roboto/Roboto-Condensed.ttf differ diff --git a/fonts/Roboto/Roboto-CondensedItalic.ttf b/fonts/Roboto/Roboto-CondensedItalic.ttf new file mode 100644 index 0000000..5ed712c Binary files /dev/null and b/fonts/Roboto/Roboto-CondensedItalic.ttf differ diff --git a/fonts/Roboto/Roboto-Italic.ttf b/fonts/Roboto/Roboto-Italic.ttf new file mode 100644 index 0000000..9f49ffd Binary files /dev/null and b/fonts/Roboto/Roboto-Italic.ttf differ diff --git a/fonts/Roboto/Roboto-Light.ttf b/fonts/Roboto/Roboto-Light.ttf new file mode 100644 index 0000000..d43e943 Binary files /dev/null and b/fonts/Roboto/Roboto-Light.ttf differ diff --git a/fonts/Roboto/Roboto-LightItalic.ttf b/fonts/Roboto/Roboto-LightItalic.ttf new file mode 100644 index 0000000..c11442c Binary files /dev/null and b/fonts/Roboto/Roboto-LightItalic.ttf differ diff --git a/fonts/Roboto/Roboto-Medium.ttf b/fonts/Roboto/Roboto-Medium.ttf new file mode 100644 index 0000000..8798341 Binary files /dev/null and b/fonts/Roboto/Roboto-Medium.ttf differ diff --git a/fonts/Roboto/Roboto-MediumItalic.ttf b/fonts/Roboto/Roboto-MediumItalic.ttf new file mode 100644 index 0000000..5e86637 Binary files /dev/null and b/fonts/Roboto/Roboto-MediumItalic.ttf differ diff --git a/fonts/Roboto/Roboto-Regular.ttf b/fonts/Roboto/Roboto-Regular.ttf new file mode 100644 index 0000000..7d9a6c4 Binary files /dev/null and b/fonts/Roboto/Roboto-Regular.ttf differ diff --git a/fonts/Roboto/Roboto-Thin.ttf b/fonts/Roboto/Roboto-Thin.ttf new file mode 100644 index 0000000..861d63a Binary files /dev/null and b/fonts/Roboto/Roboto-Thin.ttf differ diff --git a/fonts/Roboto/Roboto-ThinItalic.ttf b/fonts/Roboto/Roboto-ThinItalic.ttf new file mode 100644 index 0000000..e65145f Binary files /dev/null and b/fonts/Roboto/Roboto-ThinItalic.ttf differ diff --git a/fonts/Roboto/Roboto_Specimen_Book.pdf b/fonts/Roboto/Roboto_Specimen_Book.pdf new file mode 100644 index 0000000..594a366 Binary files /dev/null and b/fonts/Roboto/Roboto_Specimen_Book.pdf differ diff --git a/project.godot b/project.godot index 9f40be6..56fec97 100644 --- a/project.godot +++ b/project.godot @@ -10,7 +10,6 @@ config_version=4 _global_script_classes=[ ] _global_script_class_icons={ - } [application] diff --git a/scenes/Game.tscn b/scenes/Game.tscn index 6226c83..d93e7e1 100644 --- a/scenes/Game.tscn +++ b/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 ) diff --git a/scenes/HexTile.gd b/scenes/HexTile.gd index 60ceabc..53c136a 100644 --- a/scenes/HexTile.gd +++ b/scenes/HexTile.gd @@ -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 diff --git a/scenes/World.gd b/scenes/World.gd index 8f3a830..5413080 100644 --- a/scenes/World.gd +++ b/scenes/World.gd @@ -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)