protoype world gen based on input image
This commit is contained in:
parent
acf1ed5423
commit
30ec55066b
11 changed files with 188 additions and 32 deletions
BIN
art/buildings/residential/med/med20x20res001.png
Normal file
BIN
art/buildings/residential/med/med20x20res001.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.6 KiB |
34
art/buildings/residential/med/med20x20res001.png.import
Normal file
34
art/buildings/residential/med/med20x20res001.png.import
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://byy4k72uxx7sj"
|
||||||
|
path="res://.godot/imported/med20x20res001.png-eb243a76d9b6d5226915bed21b40d302.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://art/buildings/residential/med/med20x20res001.png"
|
||||||
|
dest_files=["res://.godot/imported/med20x20res001.png-eb243a76d9b6d5226915bed21b40d302.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
BIN
art/terrain/water.png
Normal file
BIN
art/terrain/water.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
34
art/terrain/water.png.import
Normal file
34
art/terrain/water.png.import
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://bor3gkli3s8eg"
|
||||||
|
path="res://.godot/imported/water.png-d342508468076a9dac2faa69a468b35f.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://art/terrain/water.png"
|
||||||
|
dest_files=["res://.godot/imported/water.png-d342508468076a9dac2faa69a468b35f.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
BIN
maps/tampere_10x10km_1000px.png
Normal file
BIN
maps/tampere_10x10km_1000px.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
34
maps/tampere_10x10km_1000px.png.import
Normal file
34
maps/tampere_10x10km_1000px.png.import
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://b3c1bddo2an1c"
|
||||||
|
path="res://.godot/imported/tampere_10x10km_1000px.png-d109810aa82500564790bd9658dd33b4.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://maps/tampere_10x10km_1000px.png"
|
||||||
|
dest_files=["res://.godot/imported/tampere_10x10km_1000px.png-d109810aa82500564790bd9658dd33b4.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
|
@ -1,11 +1,19 @@
|
||||||
[gd_scene load_steps=8 format=3 uid="uid://ciperl36hv26g"]
|
[gd_scene load_steps=12 format=3 uid="uid://ciperl36hv26g"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://scripts/Main.gd" id="1_ysxum"]
|
[ext_resource type="Script" path="res://scripts/Main.gd" id="1_ysxum"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://byy4k72uxx7sj" path="res://art/buildings/residential/med/med20x20res001.png" id="2_sfv1p"]
|
||||||
[ext_resource type="Script" path="res://scripts/Control.gd" id="3_1t1c8"]
|
[ext_resource type="Script" path="res://scripts/Control.gd" id="3_1t1c8"]
|
||||||
[ext_resource type="Script" path="res://scripts/World.gd" id="3_6q5ju"]
|
[ext_resource type="Script" path="res://scripts/World.gd" id="3_6q5ju"]
|
||||||
[ext_resource type="Texture2D" uid="uid://dakvtfpnjuwwl" path="res://art/placeholder/outdoors.png" id="3_yddbk"]
|
[ext_resource type="Texture2D" uid="uid://dakvtfpnjuwwl" path="res://art/placeholder/outdoors.png" id="3_yddbk"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://bor3gkli3s8eg" path="res://art/terrain/water.png" id="4_i5fj4"]
|
||||||
[ext_resource type="PackedScene" uid="uid://2we3txfr812u" path="res://scenes/Camera_zoom_2d.tscn" id="4_rx82t"]
|
[ext_resource type="PackedScene" uid="uid://2we3txfr812u" path="res://scenes/Camera_zoom_2d.tscn" id="4_rx82t"]
|
||||||
|
|
||||||
|
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_3q7ue"]
|
||||||
|
texture = ExtResource("2_sfv1p")
|
||||||
|
0:0/size_in_atlas = Vector2i(20, 20)
|
||||||
|
0:0/next_alternative_id = 2
|
||||||
|
0:0/0 = 0
|
||||||
|
|
||||||
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_s55i2"]
|
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_s55i2"]
|
||||||
texture = ExtResource("3_yddbk")
|
texture = ExtResource("3_yddbk")
|
||||||
0:0/0 = 0
|
0:0/0 = 0
|
||||||
|
@ -452,8 +460,15 @@ texture = ExtResource("3_yddbk")
|
||||||
14:2/size_in_atlas = Vector2i(4, 4)
|
14:2/size_in_atlas = Vector2i(4, 4)
|
||||||
14:2/0 = 0
|
14:2/0 = 0
|
||||||
|
|
||||||
|
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_bcy6h"]
|
||||||
|
texture = ExtResource("4_i5fj4")
|
||||||
|
0:0/0 = 0
|
||||||
|
|
||||||
[sub_resource type="TileSet" id="TileSet_t3bbo"]
|
[sub_resource type="TileSet" id="TileSet_t3bbo"]
|
||||||
|
terrain_set_0/mode = 0
|
||||||
sources/1 = SubResource("TileSetAtlasSource_s55i2")
|
sources/1 = SubResource("TileSetAtlasSource_s55i2")
|
||||||
|
sources/0 = SubResource("TileSetAtlasSource_3q7ue")
|
||||||
|
sources/2 = SubResource("TileSetAtlasSource_bcy6h")
|
||||||
|
|
||||||
[node name="Main" type="Node"]
|
[node name="Main" type="Node"]
|
||||||
script = ExtResource("1_ysxum")
|
script = ExtResource("1_ysxum")
|
||||||
|
@ -462,6 +477,13 @@ script = ExtResource("1_ysxum")
|
||||||
tile_set = SubResource("TileSet_t3bbo")
|
tile_set = SubResource("TileSet_t3bbo")
|
||||||
format = 2
|
format = 2
|
||||||
layer_0/name = "Buildings"
|
layer_0/name = "Buildings"
|
||||||
|
layer_1/name = "Terrain"
|
||||||
|
layer_1/enabled = true
|
||||||
|
layer_1/modulate = Color(1, 1, 1, 1)
|
||||||
|
layer_1/y_sort_enabled = false
|
||||||
|
layer_1/y_sort_origin = 0
|
||||||
|
layer_1/z_index = 0
|
||||||
|
layer_1/tile_data = PackedInt32Array()
|
||||||
script = ExtResource("3_6q5ju")
|
script = ExtResource("3_6q5ju")
|
||||||
|
|
||||||
[node name="CameraZoom2D" parent="World" instance=ExtResource("4_rx82t")]
|
[node name="CameraZoom2D" parent="World" instance=ExtResource("4_rx82t")]
|
||||||
|
@ -526,6 +548,7 @@ offset_right = 8.0
|
||||||
offset_bottom = 8.0
|
offset_bottom = 8.0
|
||||||
|
|
||||||
[node name="DebugInfo" type="Label" parent="UILayer/Control"]
|
[node name="DebugInfo" type="Label" parent="UILayer/Control"]
|
||||||
|
layout_mode = 0
|
||||||
offset_left = 568.0
|
offset_left = 568.0
|
||||||
offset_top = 24.0
|
offset_top = 24.0
|
||||||
offset_right = 928.0
|
offset_right = 928.0
|
||||||
|
|
|
@ -2,39 +2,40 @@
|
||||||
class_name CameraZoom2D
|
class_name CameraZoom2D
|
||||||
extends Camera2D
|
extends Camera2D
|
||||||
|
|
||||||
var _zoom_level : float = 1.0 : set = _set_zoom_level
|
var is_panning_camera = false
|
||||||
var is_dragging_camera = false
|
|
||||||
var tween
|
var tween
|
||||||
|
|
||||||
func _set_zoom_level(value: float) -> void:
|
func _set_camera_zoom_level(value: float) -> void:
|
||||||
_zoom_level = clamp(value, Globals.CAMERA_MIN_ZOOM_LEVEL, Globals.CAMERA_MAX_ZOOM_LEVEL)
|
Globals.CAMERA_ZOOM_LEVEL = clamp(value, Globals.CAMERA_MIN_ZOOM_LEVEL, Globals.CAMERA_MAX_ZOOM_LEVEL)
|
||||||
|
|
||||||
#interpolate frames between zoom levels to make zooming look smoother
|
#interpolate frames between zoom levels to make zooming look smoother
|
||||||
tween = get_tree().create_tween()
|
tween = get_tree().create_tween()
|
||||||
tween.tween_property(
|
tween.tween_property(
|
||||||
self,
|
self,
|
||||||
"zoom",
|
"zoom",
|
||||||
Vector2(_zoom_level, _zoom_level),
|
Vector2(Globals.CAMERA_ZOOM_LEVEL, Globals.CAMERA_ZOOM_LEVEL),
|
||||||
Globals.CAMERA_ZOOM_DURATION
|
Globals.CAMERA_ZOOM_DURATION
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func camera_zoom_in() -> void:
|
||||||
|
_set_camera_zoom_level(Globals.CAMERA_ZOOM_LEVEL - Globals.CAMERA_ZOOM_FACTOR)
|
||||||
|
|
||||||
func _unhandled_input(event):
|
func camera_zoom_out() -> void:
|
||||||
# camera zooming
|
_set_camera_zoom_level(Globals.CAMERA_ZOOM_LEVEL + Globals.CAMERA_ZOOM_DURATION)
|
||||||
if event.is_action_pressed("camera_zoom_in"):
|
|
||||||
_set_zoom_level(_zoom_level - Globals.CAMERA_ZOOM_FACTOR)
|
|
||||||
elif event.is_action_pressed("camera_zoom_out"):
|
|
||||||
_set_zoom_level(_zoom_level + Globals.CAMERA_ZOOM_DURATION)
|
|
||||||
|
|
||||||
# camera dragging
|
|
||||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
|
|
||||||
if !is_dragging_camera and event.pressed:
|
|
||||||
is_dragging_camera = true
|
|
||||||
if is_dragging_camera and !event.pressed:
|
|
||||||
is_dragging_camera = false
|
|
||||||
|
|
||||||
if event is InputEventMouseMotion and is_dragging_camera:
|
func _unhandled_input(event):
|
||||||
if self.position != event.position:
|
if event.is_action_pressed("camera_zoom_in"):
|
||||||
tween = get_tree().create_tween()
|
camera_zoom_in()
|
||||||
tween.tween_property(self, "property", Vector2(self.position, event.position), Globals.CAMERA_ZOOM_DURATION)
|
if event.is_action_pressed("camera_zoom_out"):
|
||||||
else:
|
camera_zoom_out()
|
||||||
self.position = event.position * Globals.CAMERA_DRAG_MULTI
|
|
||||||
|
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
|
||||||
|
if !is_panning_camera and event.pressed:
|
||||||
|
is_panning_camera = true
|
||||||
|
if is_panning_camera and !event.pressed:
|
||||||
|
is_panning_camera = false
|
||||||
|
|
||||||
|
if event is InputEventMouseMotion and is_panning_camera:
|
||||||
|
self.position -= event.relative * Globals.CAMERA_PAN_MULTI
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,11 @@ const TYPE_POWERPLANT = "powerplant"
|
||||||
const TYPE_ROADS = "roads"
|
const TYPE_ROADS = "roads"
|
||||||
const TYPE_DEMOLISH = "demolish"
|
const TYPE_DEMOLISH = "demolish"
|
||||||
|
|
||||||
const CAMERA_MIN_ZOOM_LEVEL: float = 0.5
|
# camera movement settings
|
||||||
|
var CAMERA_ZOOM_LEVEL : float = 1.0
|
||||||
|
|
||||||
|
const CAMERA_MIN_ZOOM_LEVEL: float = 0.1
|
||||||
const CAMERA_MAX_ZOOM_LEVEL: float = 2.0
|
const CAMERA_MAX_ZOOM_LEVEL: float = 2.0
|
||||||
const CAMERA_ZOOM_FACTOR: float = 0.1
|
const CAMERA_ZOOM_FACTOR: float = 0.1
|
||||||
const CAMERA_ZOOM_DURATION: float = 0.1
|
const CAMERA_ZOOM_DURATION: float = 0.1
|
||||||
const CAMERA_DRAG_MULTI:float = 2.0
|
const CAMERA_PAN_MULTI:float = 2.0
|
||||||
|
|
|
@ -8,12 +8,30 @@
|
||||||
|
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
var world_map: TileMap
|
||||||
func _ready():
|
|
||||||
|
func _init():
|
||||||
DisplayServer.window_set_size(
|
DisplayServer.window_set_size(
|
||||||
Vector2i(Globals.DEFAULT_X_RES, Globals.DEFAULT_Y_RES)
|
Vector2i(Globals.DEFAULT_X_RES, Globals.DEFAULT_Y_RES)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready():
|
||||||
|
generate_terrain()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
func _process(_delta):
|
func _process(_delta):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
func generate_terrain():
|
||||||
|
world_map = get_node("World")
|
||||||
|
var image = Image.new()
|
||||||
|
image.load("res://maps/tampere_10x10km_1000px.png")
|
||||||
|
|
||||||
|
for x in 1000:
|
||||||
|
for y in 1000:
|
||||||
|
# layer | position coords | tilemap id | coords of the tile at tilemap | alternative tile
|
||||||
|
if image.get_pixel(x, y) == Color(1,1,1,1):
|
||||||
|
world_map.set_cell(0, Vector2i(x, y), 2, Vector2i(0,0), 0)
|
||||||
|
|
|
@ -40,23 +40,32 @@ func _input(event):
|
||||||
|
|
||||||
|
|
||||||
func place_building_to_map():
|
func place_building_to_map():
|
||||||
|
# layer | position coords | tilemap id | coords of the tile at tilemap | alternative tile
|
||||||
|
|
||||||
match building_type:
|
match building_type:
|
||||||
Globals.TYPE_RESIDENTIAL:
|
Globals.TYPE_RESIDENTIAL:
|
||||||
tilemap = Vector2i(4,4)
|
tilemap = Vector2i(0,0)
|
||||||
|
set_cell(0, local_to_map(get_viewport().get_mouse_position()) , 0, tilemap, 0)
|
||||||
Globals.TYPE_COMMERCIAL:
|
Globals.TYPE_COMMERCIAL:
|
||||||
tilemap = Vector2i(4,12)
|
tilemap = Vector2i(4,12)
|
||||||
|
set_cell(0, local_to_map(get_viewport().get_mouse_position()) , 1, tilemap, 0)
|
||||||
Globals.TYPE_INDUSTRIAL:
|
Globals.TYPE_INDUSTRIAL:
|
||||||
tilemap = Vector2i(4,20)
|
tilemap = Vector2i(4,20)
|
||||||
|
set_cell(0, local_to_map(get_viewport().get_mouse_position()) , 1, tilemap, 0)
|
||||||
Globals.TYPE_ROADS:
|
Globals.TYPE_ROADS:
|
||||||
tilemap = Vector2i(14,2)
|
tilemap = Vector2i(14,2)
|
||||||
|
set_cell(0, local_to_map(get_viewport().get_mouse_position()) , 1, tilemap, 0)
|
||||||
Globals.TYPE_DEMOLISH:
|
Globals.TYPE_DEMOLISH:
|
||||||
tilemap = Vector2i(4,4)
|
tilemap = Vector2i(4,4)
|
||||||
|
set_cell(0, local_to_map(get_viewport().get_mouse_position()) , 1, tilemap, 0)
|
||||||
Globals.TYPE_SERVICES:
|
Globals.TYPE_SERVICES:
|
||||||
tilemap = Vector2i(4,8)
|
tilemap = Vector2i(4,8)
|
||||||
|
set_cell(0, local_to_map(get_viewport().get_mouse_position()) , 1, tilemap, 0)
|
||||||
Globals.TYPE_SOCIAL:
|
Globals.TYPE_SOCIAL:
|
||||||
tilemap = Vector2i(4,0)
|
tilemap = Vector2i(4,0)
|
||||||
|
set_cell(0, local_to_map(get_viewport().get_mouse_position()) , 1, tilemap, 0)
|
||||||
_: #default
|
_: #default
|
||||||
tilemap = Vector2i(16,16)
|
tilemap = Vector2i(16,16)
|
||||||
|
set_cell(0, local_to_map(get_viewport().get_mouse_position()) , 1, tilemap, 0)
|
||||||
|
|
||||||
set_cell(0, local_to_map(get_viewport().get_mouse_position()), 1, tilemap, 0)
|
# set_cell(0, local_to_map(get_viewport().get_mouse_position()) , 1, tilemap, 0)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue