Minor tweaking

WorldChunkRefactoring
Martin Felis 2022-10-07 16:14:05 +02:00
parent c3bca6b208
commit 4d391ff5b3
8 changed files with 52 additions and 27 deletions

View File

@ -9,22 +9,27 @@
config_version=4 config_version=4
_global_script_classes=[ { _global_script_classes=[ {
"base": "Node", "base": "Reference",
"class": "ClickableComponent", "class": "ClickableComponent",
"language": "GDScript", "language": "GDScript",
"path": "res://components/ClickableComponent.gd" "path": "res://components/ClickableComponent.gd"
}, { }, {
"base": "KinematicBody2D", "base": "Reference",
"class": "CollisionLine", "class": "CollisionLine",
"language": "GDScript", "language": "GDScript",
"path": "res://utils/CollisionLine.gd" "path": "res://utils/CollisionLine.gd"
}, { }, {
"base": "Node", "base": "Reference",
"class": "ColorComponent", "class": "ColorComponent",
"language": "GDScript", "language": "GDScript",
"path": "res://components/ColorComponent.gd" "path": "res://components/ColorComponent.gd"
}, { }, {
"base": "Resource", "base": "Resource",
"class": "GameTile",
"language": "GDScript",
"path": "res://utils/GameTile.gd"
}, {
"base": "Resource",
"class": "HexCell", "class": "HexCell",
"language": "GDScript", "language": "GDScript",
"path": "res://addons/gdhexgrid/HexCell.gd" "path": "res://addons/gdhexgrid/HexCell.gd"
@ -44,17 +49,12 @@ _global_script_classes=[ {
"language": "GDScript", "language": "GDScript",
"path": "res://utils/IslandGenerator.gd" "path": "res://utils/IslandGenerator.gd"
}, { }, {
"base": "Resource",
"class": "IslandTile",
"language": "GDScript",
"path": "res://utils/IslandTile.gd"
}, {
"base": "Object", "base": "Object",
"class": "SpringDamper", "class": "SpringDamper",
"language": "GDScript", "language": "GDScript",
"path": "res://utils/SpringDamper.gd" "path": "res://utils/SpringDamper.gd"
}, { }, {
"base": "Sprite", "base": "Reference",
"class": "TintedSpriteComponent", "class": "TintedSpriteComponent",
"language": "GDScript", "language": "GDScript",
"path": "res://components/TintedSpriteComponent.gd" "path": "res://components/TintedSpriteComponent.gd"
@ -63,11 +63,11 @@ _global_script_class_icons={
"ClickableComponent": "", "ClickableComponent": "",
"CollisionLine": "", "CollisionLine": "",
"ColorComponent": "", "ColorComponent": "",
"GameTile": "",
"HexCell": "", "HexCell": "",
"HexTile3D": "", "HexTile3D": "",
"Island": "", "Island": "",
"IslandGenerator": "", "IslandGenerator": "",
"IslandTile": "",
"SpringDamper": "", "SpringDamper": "",
"TintedSpriteComponent": "" "TintedSpriteComponent": ""
} }

View File

@ -26,6 +26,8 @@ func _ready():
func _process(delta): func _process(delta):
fps_label.text = "FPS: " + str(Performance.get_monitor(Performance.TIME_FPS)) fps_label.text = "FPS: " + str(Performance.get_monitor(Performance.TIME_FPS))
player_pos_label.text = "Pos: " + str(player.transform.origin) player_pos_label.text = "Pos: " + str(player.transform.origin)
# query world what is happening on
func on_island_tile_selected(island, tile): func on_island_tile_selected(island, tile):

View File

@ -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://entities/PlayerEntity.gd" type="Script" id=1]
[ext_resource path="res://scenes/HexGrid3DTest.gd" type="Script" id=2] [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://scenes/Island.tscn" type="PackedScene" id=4]
[ext_resource path="res://assets/water_diffuse.png" type="Texture" id=5] [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://components/MovableComponent.tscn" type="PackedScene" id=6]
[ext_resource path="res://scenes/World.gd" type="Script" id=7]
[sub_resource type="CapsuleMesh" id=4] [sub_resource type="CapsuleMesh" id=4]
radius = 0.2 radius = 0.2
@ -178,6 +179,7 @@ shape = SubResource( 5 )
max_speed = 3 max_speed = 3
[node name="World" type="Spatial" parent="."] [node name="World" type="Spatial" parent="."]
script = ExtResource( 7 )
[node name="Scene" type="Spatial" parent="World"] [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 ) transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -12.2668, 0, 0 )
[node name="Water" type="Spatial" parent="."] [node name="Water" type="Spatial" parent="."]
visible = false
[node name="Water" type="MeshInstance" parent="Water"] [node name="Water" type="MeshInstance" parent="Water"]
transform = Transform( 10, 0, 0, 0, 10, 0, 0, 0, 10, 0, -0.1, 0 ) transform = Transform( 10, 0, 0, 0, 10, 0, 0, 0, 10, 0, -0.1, 0 )

View File

@ -11,13 +11,13 @@ signal tile_mouse_entered
#var cube_coords = Vector3(0, 0, 0) setget set_cube_coords, get_cube_coords #var cube_coords = Vector3(0, 0, 0) setget set_cube_coords, get_cube_coords
func set_tiletype(type): func set_tiletype(type):
var IslandTile = load("res://utils/IslandTile.gd").new() var GameTile = load("res://utils/GameTile.gd").new()
var mesh = $Mesh var mesh = $Mesh
if type == IslandTile.TileType.Sand: if type == GameTile.TileType.Sand:
mesh.set_surface_material(0, preload("res://materials/SandTile.tres")) 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")) mesh.set_surface_material(0, preload("res://materials/GrassTile.tres"))
else: else:
mesh.set_surface_material(0, preload("res://materials/DeepGrassTile.tres")) mesh.set_surface_material(0, preload("res://materials/DeepGrassTile.tres"))

View File

@ -2,7 +2,7 @@ tool
extends Spatial extends Spatial
class_name Island 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 generate: bool = false setget do_generate
export var level_size: int = 10 export var level_size: int = 10
@ -19,15 +19,15 @@ func reset():
node.queue_free() 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 hexgrid = preload("res://addons/gdhexgrid/HexGrid.gd").new()
var HexTile3D = preload("res://scenes/HexTile3D.tscn") var HexTile3D = preload("res://scenes/HexTile3D.tscn")
var tile = HexTile3D.instance() var tile = HexTile3D.instance()
var pos = hexgrid.get_hex_center_from_offset(hex.offset_coords) var pos = hexgrid.get_hex_center_from_offset(game_tile.offset_coords)
var height = 0.0 if hex.type == IslandTile.TileType.Sand else 0.1 + rand_range(0.0, 0.05) 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.transform.origin = Vector3(pos.x, height, pos.y)
tile.connect("tile_selected", self, "on_tile_selected") tile.connect("tile_selected", self, "on_tile_selected")
tile.connect("tile_mouse_entered", self, "on_tile_hover") tile.connect("tile_mouse_entered", self, "on_tile_hover")

18
scenes/World.gd Normal file
View File

@ -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

View File

@ -1,7 +1,7 @@
extends "res://addons/gdhexgrid/HexCell.gd" 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 var type = TileType.Sand

View File

@ -1,14 +1,15 @@
class_name IslandGenerator class_name IslandGenerator
extends Node extends Node
var IslandTile = preload("res://utils/IslandTile.gd") var GameTile = load("res://utils/GameTile.gd")
var HexCell = preload("res://addons/gdhexgrid/HexCell.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) tile.fromHexCell(hex)
return tile return tile
func random_walk(walk_size): func random_walk(walk_size):
var hexgrid = preload("res://addons/gdhexgrid/HexGrid.gd").new() var hexgrid = preload("res://addons/gdhexgrid/HexGrid.gd").new()
@ -38,6 +39,7 @@ func random_walk(walk_size):
return tiles return tiles
func extrude_tiles(tiles): func extrude_tiles(tiles):
var old_tiles = tiles var old_tiles = tiles
@ -59,12 +61,12 @@ func extrude_tiles(tiles):
func mark_sand_tiles(tiles): func mark_sand_tiles(tiles):
for tile in tiles.values(): 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() var tile_neighbours = tile.get_all_adjacent()
for neighbour in tile_neighbours: for neighbour in tile_neighbours:
if not neighbour.offset_coords in tiles.keys(): if not neighbour.offset_coords in tiles.keys():
tile.type = IslandTile.TileType.Sand tile.type = GameTile.TileType.Sand
break break
return tiles return tiles