mirror of
https://github.com/tonytins/citylimits
synced 2025-06-25 09:24:44 -04:00
Merged varies scenes into game scene
- Merged GUI and world scenes into game scene with the GUI existing on a canvas layer - Ported over camera movement script
This commit is contained in:
parent
f5c7355d5a
commit
8a40969703
6 changed files with 171 additions and 113 deletions
65
scripts/cameramovement.gd
Normal file
65
scripts/cameramovement.gd
Normal file
|
@ -0,0 +1,65 @@
|
|||
extends Camera2D
|
||||
|
||||
export var panSpeed = 10.0
|
||||
export var speed = 25.0
|
||||
export var zoomspeed = 50.0
|
||||
export var zoommargin = 0.3
|
||||
|
||||
export var zoomMin = 0.5
|
||||
export var zoomMax = 3.0
|
||||
export var marginX = 200.0
|
||||
export var marginY = 100.0
|
||||
|
||||
var mousepos = Vector2()
|
||||
var zoompos = Vector2()
|
||||
var zoomfactor = 1.0
|
||||
|
||||
|
||||
func _ready():
|
||||
pass
|
||||
|
||||
|
||||
func _process(delta):
|
||||
# Smooth Movement
|
||||
var inputx = (int(Input.is_action_pressed("ui_right")) - int(Input.is_action_pressed("ui_left")))
|
||||
var inputy = (int(Input.is_action_pressed("ui_down")) - int(Input.is_action_pressed("ui_up")))
|
||||
position.x = lerp(position.x, position.x + inputx * speed * zoom.x, speed * delta)
|
||||
position.y = lerp(position.y, position.y + inputy * speed * zoom.y, speed * delta)
|
||||
|
||||
# Edge scrolling via. Ctrl + Right Click
|
||||
if Input.is_key_pressed(KEY_CONTROL):
|
||||
# check mouse postion
|
||||
if mousepos.x < marginX:
|
||||
position.x = lerp(position.x, position.x - abs(mousepos.x - marginX) / marginX * panSpeed * zoom.x, panSpeed * delta)
|
||||
elif mousepos.x > OS.window_size.x - marginX:
|
||||
position.x = lerp(position.x, position.x + abs(mousepos.x - OS.window_size.x + marginX) / marginX * panSpeed * zoom.x, panSpeed * delta)
|
||||
|
||||
if mousepos.y < marginY:
|
||||
position.y = lerp(position.y, position.y - abs(mousepos.y - marginY) / marginY * panSpeed * zoom.y, panSpeed * delta)
|
||||
elif mousepos.y > OS.window_size.y - marginY:
|
||||
position.y = lerp(position.y, position.y + abs(mousepos.y - OS.window_size.y + marginX) / marginX * panSpeed * zoom.y, panSpeed * delta)
|
||||
|
||||
# Zooming
|
||||
zoom.x = lerp(zoom.x, zoom.x * zoomfactor, zoomspeed * delta)
|
||||
zoom.y = lerp(zoom.y, zoom.y * zoomfactor, zoomspeed * delta)
|
||||
|
||||
zoom.x = clamp(zoom.x, zoomMin, zoomMax)
|
||||
zoom.y = clamp(zoom.y, zoomMin, zoomMax)
|
||||
|
||||
func _input(event):
|
||||
if abs(zoompos.x - get_global_mouse_position().x) > zoommargin:
|
||||
zoomfactor = 1.0
|
||||
if abs(zoompos.y - get_global_mouse_position().y) > zoommargin:
|
||||
zoomfactor = 1.0
|
||||
|
||||
if event is InputEventMouseButton:
|
||||
if event.is_pressed():
|
||||
if event.button_index == BUTTON_WHEEL_UP:
|
||||
zoomfactor -= 0.01
|
||||
zoompos = get_global_mouse_position()
|
||||
if event.button_index == BUTTON_WHEEL_DOWN:
|
||||
zoomfactor += 0.01
|
||||
zoompos = get_global_mouse_position()
|
||||
|
||||
if event is InputEventMouse:
|
||||
mousepos = event.position
|
|
@ -1,7 +1,7 @@
|
|||
extends Panel
|
||||
|
||||
func _ready():
|
||||
$CityMenus/CityNameLbl.text = CityData.city_name
|
||||
$citymenus/citynamelbl.text = CityData.city_name
|
||||
|
||||
func _process(delta):
|
||||
$CityStatus/MoneyLbl.text = str(CityData.budget)
|
||||
$citystatus/moneylbl.text = str(CityData.budget)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
extends Node
|
||||
extends Node2D
|
||||
|
||||
var noise: OpenSimplexNoise
|
||||
var map_size = Vector2(80, 60)
|
||||
|
@ -20,14 +20,14 @@ func make_terrian_map():
|
|||
for y in map_size.y:
|
||||
var a = noise.get_noise_2d(x, y)
|
||||
if a < terrian_cap:
|
||||
$Terrian.set_cell(x, y, 0)
|
||||
$terrian.set_cell(x, y, 0)
|
||||
|
||||
$Terrian.update_bitmask_region(Vector2(0.0, 0.0), Vector2(map_size.x, map_size.y))
|
||||
$terrian.update_bitmask_region(Vector2(0.0, 0.0), Vector2(map_size.x, map_size.y))
|
||||
|
||||
func make_water():
|
||||
for x in map_size.x:
|
||||
for y in map_size.y:
|
||||
if $Terrian.get_cell(x, y):
|
||||
$Water.set_cell(x, y, 0)
|
||||
if $terrian.get_cell(x, y):
|
||||
$water.set_cell(x, y, 0)
|
||||
|
||||
$Water.update_bitmask_region(Vector2(0.0, 0.0), Vector2(map_size.x, map_size.y))
|
||||
$water.update_bitmask_region(Vector2(0.0, 0.0), Vector2(map_size.x, map_size.y))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue