Browse Source

Cleanup and renaming of the camera script

master
Ryan Reed 1 year ago
parent
commit
a8bdc15c71
3 changed files with 14 additions and 20 deletions
  1. +7
    -12
      scenes/camera.gd
  2. +4
    -3
      scenes/conway.gd
  3. +3
    -5
      scenes/conway.tscn

scenes/camera_view.gd → scenes/camera.gd View File

@ -1,9 +1,8 @@
extends Node2D
extends Camera2D
@export var zoom_increment: Vector2 = Vector2(0.1, 0.1)
@export var move_speed: int = 250
@onready var camera: Camera2D = $Camera2D
@export var move_speed: int = 250
@export var zoom_increment: Vector2 = Vector2(0.1, 0.1)
func _process(delta: float) -> void: func _process(delta: float) -> void:
@ -14,13 +13,9 @@ func _process(delta: float) -> void:
position += Vector2(velocity_x, velocity_y) position += Vector2(velocity_x, velocity_y)
func _unhandled_input(event: InputEvent) -> void: func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("Reset Zoom"):
zoom = Vector2.ONE
if event.is_action_pressed("Zoom In"): if event.is_action_pressed("Zoom In"):
camera.zoom += zoom_increment
zoom += zoom_increment
if event.is_action_pressed("Zoom Out"): if event.is_action_pressed("Zoom Out"):
camera.zoom -= zoom_increment
if event.is_action_pressed("Reset Zoom"):
camera.zoom = Vector2.ONE
func update_position(pos: Vector2) -> void:
camera.position = pos
zoom -= zoom_increment

+ 4
- 3
scenes/conway.gd View File

@ -29,7 +29,7 @@ enum CellStates {
@onready var messages_label: Label = $UI/Messages/Label @onready var messages_label: Label = $UI/Messages/Label
## Other ## Other
@onready var camera: Node2D = $CameraView
@onready var camera: Camera2D = $Camera
@onready var generation_timer: Timer = $GenerationTimer @onready var generation_timer: Timer = $GenerationTimer
@export var world_seed: int ## The seed utilized for generation of the world @export var world_seed: int ## The seed utilized for generation of the world
@ -106,10 +106,11 @@ func start_conway() -> void:
debug_living_cells_counter.text = "Living Cells: %s" % total_living debug_living_cells_counter.text = "Living Cells: %s" % total_living
# Center the camera on the world # Center the camera on the world
camera.update_position(Vector2(
camera.position = Vector2(
world_size.x * cell_size.x / 2, world_size.x * cell_size.x / 2,
world_size.y * cell_size.y / 2 world_size.y * cell_size.y / 2
))
)
camera.zoom = Vector2.ONE
if not is_paused: generation_timer.start() if not is_paused: generation_timer.start()


+ 3
- 5
scenes/conway.tscn View File

@ -2,7 +2,7 @@
[ext_resource type="Script" path="res://scenes/conway.gd" id="1_1gvb0"] [ext_resource type="Script" path="res://scenes/conway.gd" id="1_1gvb0"]
[ext_resource type="Texture2D" uid="uid://c2vm5pfsamed4" path="res://assets/icon.svg" id="2_l6fa6"] [ext_resource type="Texture2D" uid="uid://c2vm5pfsamed4" path="res://assets/icon.svg" id="2_l6fa6"]
[ext_resource type="Script" path="res://scenes/camera_view.gd" id="3_avkud"]
[ext_resource type="Script" path="res://scenes/camera.gd" id="3_e0v0d"]
[ext_resource type="Texture2D" uid="uid://b8gggrriib8n" path="res://assets/refresh.png" id="4_hmfh6"] [ext_resource type="Texture2D" uid="uid://b8gggrriib8n" path="res://assets/refresh.png" id="4_hmfh6"]
[node name="World" type="Node2D"] [node name="World" type="Node2D"]
@ -10,11 +10,9 @@ position = Vector2(-152, 0)
script = ExtResource("1_1gvb0") script = ExtResource("1_1gvb0")
cell_texture = ExtResource("2_l6fa6") cell_texture = ExtResource("2_l6fa6")
[node name="CameraView" type="Node2D" parent="."]
script = ExtResource("3_avkud")
[node name="Camera2D" type="Camera2D" parent="CameraView"]
[node name="Camera" type="Camera2D" parent="."]
position = Vector2(464, 200) position = Vector2(464, 200)
script = ExtResource("3_e0v0d")
[node name="GenerationTimer" type="Timer" parent="."] [node name="GenerationTimer" type="Timer" parent="."]
wait_time = 0.05 wait_time = 0.05


Loading…
Cancel
Save