From 4d391ff5b364dd77d95b3d8db6296c01c007b333 Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Fri, 7 Oct 2022 16:14:05 +0200 Subject: [PATCH] Minor tweaking --- project.godot | 20 ++++++++++---------- scenes/HexGrid3DTest.gd | 2 ++ scenes/HexGrid3DTest.tscn | 5 ++++- scenes/HexTile3D.gd | 6 +++--- scenes/Island.gd | 10 +++++----- scenes/World.gd | 18 ++++++++++++++++++ utils/{IslandTile.gd => GameTile.gd} | 4 ++-- utils/IslandGenerator.gd | 14 ++++++++------ 8 files changed, 52 insertions(+), 27 deletions(-) create mode 100644 scenes/World.gd rename utils/{IslandTile.gd => GameTile.gd} (86%) diff --git a/project.godot b/project.godot index f15be5c..7256191 100644 --- a/project.godot +++ b/project.godot @@ -9,22 +9,27 @@ config_version=4 _global_script_classes=[ { -"base": "Node", +"base": "Reference", "class": "ClickableComponent", "language": "GDScript", "path": "res://components/ClickableComponent.gd" }, { -"base": "KinematicBody2D", +"base": "Reference", "class": "CollisionLine", "language": "GDScript", "path": "res://utils/CollisionLine.gd" }, { -"base": "Node", +"base": "Reference", "class": "ColorComponent", "language": "GDScript", "path": "res://components/ColorComponent.gd" }, { "base": "Resource", +"class": "GameTile", +"language": "GDScript", +"path": "res://utils/GameTile.gd" +}, { +"base": "Resource", "class": "HexCell", "language": "GDScript", "path": "res://addons/gdhexgrid/HexCell.gd" @@ -44,17 +49,12 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://utils/IslandGenerator.gd" }, { -"base": "Resource", -"class": "IslandTile", -"language": "GDScript", -"path": "res://utils/IslandTile.gd" -}, { "base": "Object", "class": "SpringDamper", "language": "GDScript", "path": "res://utils/SpringDamper.gd" }, { -"base": "Sprite", +"base": "Reference", "class": "TintedSpriteComponent", "language": "GDScript", "path": "res://components/TintedSpriteComponent.gd" @@ -63,11 +63,11 @@ _global_script_class_icons={ "ClickableComponent": "", "CollisionLine": "", "ColorComponent": "", +"GameTile": "", "HexCell": "", "HexTile3D": "", "Island": "", "IslandGenerator": "", -"IslandTile": "", "SpringDamper": "", "TintedSpriteComponent": "" } diff --git a/scenes/HexGrid3DTest.gd b/scenes/HexGrid3DTest.gd index 4fe8e76..d487099 100644 --- a/scenes/HexGrid3DTest.gd +++ b/scenes/HexGrid3DTest.gd @@ -26,6 +26,8 @@ func _ready(): func _process(delta): fps_label.text = "FPS: " + str(Performance.get_monitor(Performance.TIME_FPS)) player_pos_label.text = "Pos: " + str(player.transform.origin) + + # query world what is happening on func on_island_tile_selected(island, tile): diff --git a/scenes/HexGrid3DTest.tscn b/scenes/HexGrid3DTest.tscn index 1d315a1..91a1bdb 100644 --- a/scenes/HexGrid3DTest.tscn +++ b/scenes/HexGrid3DTest.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=12 format=2] +[gd_scene load_steps=13 format=2] [ext_resource path="res://entities/PlayerEntity.gd" type="Script" id=1] [ext_resource path="res://scenes/HexGrid3DTest.gd" type="Script" id=2] @@ -6,6 +6,7 @@ [ext_resource path="res://scenes/Island.tscn" type="PackedScene" id=4] [ext_resource path="res://assets/water_diffuse.png" type="Texture" id=5] [ext_resource path="res://components/MovableComponent.tscn" type="PackedScene" id=6] +[ext_resource path="res://scenes/World.gd" type="Script" id=7] [sub_resource type="CapsuleMesh" id=4] radius = 0.2 @@ -178,6 +179,7 @@ shape = SubResource( 5 ) max_speed = 3 [node name="World" type="Spatial" parent="."] +script = ExtResource( 7 ) [node name="Scene" type="Spatial" parent="World"] @@ -189,6 +191,7 @@ max_speed = 3 transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -12.2668, 0, 0 ) [node name="Water" type="Spatial" parent="."] +visible = false [node name="Water" type="MeshInstance" parent="Water"] transform = Transform( 10, 0, 0, 0, 10, 0, 0, 0, 10, 0, -0.1, 0 ) diff --git a/scenes/HexTile3D.gd b/scenes/HexTile3D.gd index 4b3eddb..8020e46 100644 --- a/scenes/HexTile3D.gd +++ b/scenes/HexTile3D.gd @@ -11,13 +11,13 @@ signal tile_mouse_entered #var cube_coords = Vector3(0, 0, 0) setget set_cube_coords, get_cube_coords func set_tiletype(type): - var IslandTile = load("res://utils/IslandTile.gd").new() + var GameTile = load("res://utils/GameTile.gd").new() var mesh = $Mesh - if type == IslandTile.TileType.Sand: + if type == GameTile.TileType.Sand: mesh.set_surface_material(0, preload("res://materials/SandTile.tres")) - elif type == IslandTile.TileType.Grass: + elif type == GameTile.TileType.Grass: mesh.set_surface_material(0, preload("res://materials/GrassTile.tres")) else: mesh.set_surface_material(0, preload("res://materials/DeepGrassTile.tres")) diff --git a/scenes/Island.gd b/scenes/Island.gd index bd854f8..fdf9a00 100644 --- a/scenes/Island.gd +++ b/scenes/Island.gd @@ -2,7 +2,7 @@ tool extends Spatial class_name Island -onready var IslandTile = preload("res://utils/IslandTile.gd") +onready var GameTile = preload("res://utils/GameTile.gd") export var generate: bool = false setget do_generate export var level_size: int = 10 @@ -19,15 +19,15 @@ func reset(): node.queue_free() -func create_tile_for_hex(hex): +func create_tile_for_hex(game_tile): var hexgrid = preload("res://addons/gdhexgrid/HexGrid.gd").new() var HexTile3D = preload("res://scenes/HexTile3D.tscn") var tile = HexTile3D.instance() - var pos = hexgrid.get_hex_center_from_offset(hex.offset_coords) - var height = 0.0 if hex.type == IslandTile.TileType.Sand else 0.1 + rand_range(0.0, 0.05) + var pos = hexgrid.get_hex_center_from_offset(game_tile.offset_coords) + var height = 0.0 if game_tile.type == GameTile.TileType.Sand else 0.1 + rand_range(0.0, 0.05) - tile.set_tiletype(hex.type) + tile.set_tiletype(game_tile.type) tile.transform.origin = Vector3(pos.x, height, pos.y) tile.connect("tile_selected", self, "on_tile_selected") tile.connect("tile_mouse_entered", self, "on_tile_hover") diff --git a/scenes/World.gd b/scenes/World.gd new file mode 100644 index 0000000..a3eaeba --- /dev/null +++ b/scenes/World.gd @@ -0,0 +1,18 @@ +extends Spatial + +var GameTile = load("res://utils/GameTile.gd") +var HexCell = preload("res://addons/gdhexgrid/HexCell.gd") + +var has_tiles_initialized = false +export var size = [200, 200] + +func _ready(): + pass + + +func create_ocean_tiles(): + + var islands + pass + + diff --git a/utils/IslandTile.gd b/utils/GameTile.gd similarity index 86% rename from utils/IslandTile.gd rename to utils/GameTile.gd index 6f2ac63..e4efe57 100644 --- a/utils/IslandTile.gd +++ b/utils/GameTile.gd @@ -1,7 +1,7 @@ extends "res://addons/gdhexgrid/HexCell.gd" -class_name IslandTile +class_name GameTile -enum TileType { Sand, Grass, DeepGrass, Rock } +enum TileType { Sand, Grass, DeepGrass, Rock, Water } var type = TileType.Sand diff --git a/utils/IslandGenerator.gd b/utils/IslandGenerator.gd index cd4ff75..2e8a84e 100644 --- a/utils/IslandGenerator.gd +++ b/utils/IslandGenerator.gd @@ -1,14 +1,15 @@ class_name IslandGenerator extends Node -var IslandTile = preload("res://utils/IslandTile.gd") +var GameTile = load("res://utils/GameTile.gd") var HexCell = preload("res://addons/gdhexgrid/HexCell.gd") -func hex_cell_to_island_tile (hex: HexCell) -> IslandTile: - var tile = IslandTile.new() + +func hex_cell_to_island_tile (hex: HexCell) -> GameTile: + var tile = GameTile.new() tile.fromHexCell(hex) return tile - + func random_walk(walk_size): var hexgrid = preload("res://addons/gdhexgrid/HexGrid.gd").new() @@ -38,6 +39,7 @@ func random_walk(walk_size): return tiles + func extrude_tiles(tiles): var old_tiles = tiles @@ -59,12 +61,12 @@ func extrude_tiles(tiles): func mark_sand_tiles(tiles): for tile in tiles.values(): - tile.type = IslandTile.TileType.Grass if randi() % 2 else IslandTile.TileType.DeepGrass + tile.type = GameTile.TileType.Grass if randi() % 2 else GameTile.TileType.DeepGrass var tile_neighbours = tile.get_all_adjacent() for neighbour in tile_neighbours: if not neighbour.offset_coords in tiles.keys(): - tile.type = IslandTile.TileType.Sand + tile.type = GameTile.TileType.Sand break return tiles