Cyclone-Tracker/worldManager.gd

106 lines
2.8 KiB
GDScript3
Raw Permalink Normal View History

2025-06-30 20:47:54 +10:00
extends Node2D
@export var camera : Camera2D
@export var map : Sprite2D
2025-07-04 15:14:59 +10:00
@export var cyclone_holder : Node2D
@export var speed_slider : HSlider
@export var speed_label : Label
@export var file_picker : FileDialog
2025-07-04 17:53:08 +10:00
@export var spawner_prop : Node2D
@export var walls_node : Node2D
var walls_active = true
@export var walls_button : Button
2025-06-30 20:47:54 +10:00
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
2025-07-04 15:14:59 +10:00
#check_edges()
update_zoom()
update_ui()
2025-06-30 20:47:54 +10:00
func check_edges():
#var right_center = map.global_position + Vector2(map.texture.get_width(), 0)
#var top_center = map.global_position + Vector2(0, map.texture.get_height())
var map_top : float = map.global_position.y + map.texture.get_height()
var map_bottom : float = map.global_position.y - map.texture.get_height()
var map_right : float = map.global_position.x + map.texture.get_width()
var map_left : float = map.global_position.x - map.texture.get_width()
2025-07-04 15:14:59 +10:00
#print("Top: " + str(map_top))
#print("Bottom: " + str(map_top))
#print("Left: " + str(map_top))
#print("Right: " + str(map_top))
2025-06-30 20:47:54 +10:00
2025-07-04 15:14:59 +10:00
#for cyclone in cyclones:
#pass
2025-06-30 20:47:54 +10:00
pass
2025-07-04 15:14:59 +10:00
func update_zoom():
#print(1/camera.zoom.x)
var scale_level : float = clampf(1/camera.zoom.x,0,1)
for cyclone in cyclone_holder.get_children():
cyclone.visuals.scale = Vector2(scale_level,scale_level)
func update_ui():
var selected_speed : float = speed_slider.value
var actual_speed : float
# 3=1.0x, 2=0.5x, 1=0.25x, 0=0.0x, 4=2x 5=3x 6=4x
match int(selected_speed):
0:
actual_speed = 0.0001
1:
actual_speed = 0.25
2:
actual_speed = 0.5
3:
actual_speed = 1
4:
actual_speed = 2
5:
actual_speed = 4
6:
actual_speed = 8
speed_label.text = "Speed: " + str(round(actual_speed*100)/100) + "x"
Engine.time_scale = actual_speed
2025-07-04 17:53:08 +10:00
if(walls_active):
walls_button.text = "Toggle Walls: On"
walls_node.position.x = 0
else:
walls_button.text = "Toggle Walls: Off"
walls_node.position.x = 1000000
2025-07-04 15:14:59 +10:00
func _on_load_image_pressed() -> void:
file_picker.show()
func _on_file_dialog_file_selected(path: String) -> void:
var new_image : Image = Image.load_from_file(path)
var image_texture : ImageTexture = ImageTexture.create_from_image(new_image)
map.texture = image_texture
2025-07-04 17:53:08 +10:00
func _on_spawn_pressed() -> void:
spawner_prop.loaded = !spawner_prop.loaded
func _on_cyclone_spawner_spawn(spawn_position: Vector2) -> void:
var new_cyclone : Node2D = load("res://Prefabs/cyclone.tscn").instantiate()
new_cyclone.global_position = spawn_position
cyclone_holder.add_child(new_cyclone)
func _on_walls_pressed() -> void:
walls_active = !walls_active
func _on_exit_pressed() -> void:
get_tree().quit()