6 Commits
v1.5 ... master

9 changed files with 68 additions and 50 deletions
Split View
  1. +2
    -1
      README.md
  2. +0
    -0
      assets/icon.svg
  3. +3
    -3
      assets/icon.svg.import
  4. +26
    -2
      project.godot
  5. +21
    -0
      scenes/camera.gd
  6. +7
    -14
      scenes/conway.gd
  7. +9
    -12
      scenes/conway.tscn
  8. +0
    -10
      scenes/fps_counter/fps_counter.gd
  9. +0
    -8
      scenes/fps_counter/fps_counter.tscn

+ 2
- 1
README.md View File

@ -2,5 +2,6 @@
My attempt at a [Conway's Game of Life](https://en.wikipedia.org/wiki/Conway's_Game_of_Life) simulation using Godot 4
The project is also utilizing a RenderingServer to generate the cells.
The project is also utilizing a RenderingServer to generate the cells. This might be overkill but though it would be fun to try.
The project is over engineered but what isn't?

icon.svg → assets/icon.svg View File


icon.svg.import → assets/icon.svg.import View File

@ -3,15 +3,15 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://c2vm5pfsamed4"
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
path="res://.godot/imported/icon.svg-56083ea2a1f1a4f1e49773bdc6d7826c.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://icon.svg"
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]
source_file="res://assets/icon.svg"
dest_files=["res://.godot/imported/icon.svg-56083ea2a1f1a4f1e49773bdc6d7826c.ctex"]
[params]

+ 26
- 2
project.godot View File

@ -11,9 +11,9 @@ config_version=5
[application]
config/name="Conway's Game of Life"
run/main_scene="res://world.tscn"
run/main_scene="res://scenes/conway.tscn"
config/features=PackedStringArray("4.1", "Forward Plus")
config/icon="res://icon.svg"
config/icon="res://assets/icon.svg"
[input]
@ -51,3 +51,27 @@ Menu={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":82,"key_label":0,"unicode":114,"echo":false,"script":null)
]
}
Left={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
Right={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
Up={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
Down={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}

+ 21
- 0
scenes/camera.gd View File

@ -0,0 +1,21 @@
extends Camera2D
@export var move_speed: int = 250
@export var zoom_increment: Vector2 = Vector2(0.1, 0.1)
func _process(delta: float) -> void:
var input_dir := Input.get_vector("Left", "Right", "Up", "Down")
var velocity_y = input_dir.y * move_speed * delta
var velocity_x = input_dir.x * move_speed * delta
position += Vector2(velocity_x, velocity_y)
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("Reset Zoom"):
zoom = Vector2.ONE
if event.is_action_pressed("Zoom In"):
zoom += zoom_increment
if event.is_action_pressed("Zoom Out"):
zoom -= zoom_increment

world.gd → scenes/conway.gd View File

@ -29,7 +29,7 @@ enum CellStates {
@onready var messages_label: Label = $UI/Messages/Label
## Other
@onready var camera: Camera2D = $Camera2D
@onready var camera: Camera2D = $Camera
@onready var generation_timer: Timer = $GenerationTimer
@export var world_seed: int ## The seed utilized for generation of the world
@ -37,8 +37,6 @@ enum CellStates {
@export var cell_texture: Texture2D ## Testure for each cell
@export var world_size: Vector2 = Vector2(32, 32) ## The size of the world
@export var zoom_increment: Vector2 = Vector2(0.1, 0.1)
var cell_instance
var evolution_is_stalled: bool = false
var generation: int = 1
@ -78,13 +76,6 @@ func _input(event: InputEvent) -> void:
update_generation_ui()
generation_ui.visible = is_paused
if event.is_action_pressed("Zoom In"):
camera.zoom += zoom_increment
if event.is_action_pressed("Zoom Out"):
camera.zoom -= zoom_increment
if event.is_action_pressed("Reset Zoom"):
camera.zoom = Vector2.ONE
#
# UI
@ -106,6 +97,7 @@ func update_generation_ui() -> void:
func start_conway() -> void:
clear_world()
generate_world()
update_previous_generation_hashes()
generation = 1
evolution_is_stalled = false
@ -114,8 +106,11 @@ func start_conway() -> void:
debug_living_cells_counter.text = "Living Cells: %s" % total_living
# Center the camera on the world
camera.position.x = world_size.x * cell_size.x / 2
camera.position.y = world_size.y * cell_size.y / 2
camera.position = Vector2(
world_size.x * cell_size.x / 2,
world_size.y * cell_size.y / 2
)
camera.zoom = Vector2.ONE
if not is_paused: generation_timer.start()
@ -270,8 +265,6 @@ func generate_world() -> void:
cell_states[x][y] = is_alive
cell_ids[x][y] = create_cell(Vector2(x, y), bool(is_alive))
update_previous_generation_hashes()
func _on_generation_timer_timeout() -> void:
process_generation()

world.tscn → scenes/conway.tscn View File

@ -1,17 +1,18 @@
[gd_scene load_steps=5 format=3 uid="uid://d3twfk56sjf2m"]
[ext_resource type="Script" path="res://world.gd" id="1_wavft"]
[ext_resource type="Texture2D" uid="uid://c2vm5pfsamed4" path="res://icon.svg" id="2_8r6bn"]
[ext_resource type="PackedScene" uid="uid://cy6vsgu8o0rad" path="res://scenes/fps_counter/fps_counter.tscn" id="3_ves6s"]
[ext_resource type="Texture2D" uid="uid://b8gggrriib8n" path="res://assets/refresh.png" id="4_fcljs"]
[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="Script" path="res://scenes/camera.gd" id="3_e0v0d"]
[ext_resource type="Texture2D" uid="uid://b8gggrriib8n" path="res://assets/refresh.png" id="4_hmfh6"]
[node name="World" type="Node2D"]
position = Vector2(-152, 0)
script = ExtResource("1_wavft")
cell_texture = ExtResource("2_8r6bn")
script = ExtResource("1_1gvb0")
cell_texture = ExtResource("2_l6fa6")
[node name="Camera2D" type="Camera2D" parent="."]
[node name="Camera" type="Camera2D" parent="."]
position = Vector2(464, 200)
script = ExtResource("3_e0v0d")
[node name="GenerationTimer" type="Timer" parent="."]
wait_time = 0.05
@ -44,10 +45,6 @@ offset_bottom = 116.0
[node name="VBoxContainer" type="VBoxContainer" parent="UI/Debug"]
layout_mode = 2
[node name="FPSCounter" parent="UI/Debug/VBoxContainer" instance=ExtResource("3_ves6s")]
layout_mode = 2
text = "FPS: 0"
[node name="WorldSeed" type="Label" parent="UI/Debug/VBoxContainer"]
layout_mode = 2
text = "World Seed: 0"
@ -94,7 +91,7 @@ text = "Seed"
[node name="Generate" type="Button" parent="UI/WorldGeneration/VBoxContainer/Seed"]
self_modulate = Color(0.501961, 0.501961, 0.501961, 1)
layout_mode = 2
icon = ExtResource("4_fcljs")
icon = ExtResource("4_hmfh6")
[node name="Input" type="LineEdit" parent="UI/WorldGeneration/VBoxContainer/Seed"]
custom_minimum_size = Vector2(200, 0)

+ 0
- 10
scenes/fps_counter/fps_counter.gd View File

@ -1,10 +0,0 @@
extends Label
@export var include_label: bool = true
@onready var label_prepend: String = "FPS: " if include_label else ""
func _process(_delta: float) -> void:
text = label_prepend + str(Engine.get_frames_per_second())

+ 0
- 8
scenes/fps_counter/fps_counter.tscn View File

@ -1,8 +0,0 @@
[gd_scene load_steps=2 format=3 uid="uid://cy6vsgu8o0rad"]
[ext_resource type="Script" path="res://scenes/fps_counter/fps_counter.gd" id="1_vn43a"]
[node name="FPSCounter" type="Label"]
offset_right = 40.0
offset_bottom = 23.0
script = ExtResource("1_vn43a")

Loading…
Cancel
Save