Browse Source

Initial commit - Only supports world generation

pull/1/head
Ryan Reed 1 year ago
commit
11c4c91875
7 changed files with 158 additions and 0 deletions
  1. +36
    -0
      .gitignore
  2. +0
    -0
      README.md
  3. +1
    -0
      icon.svg
  4. +37
    -0
      icon.svg.import
  5. +24
    -0
      project.godot
  6. +46
    -0
      world.gd
  7. +14
    -0
      world.tscn

+ 36
- 0
.gitignore View File

@ -0,0 +1,36 @@
# ---> Godot
# Godot-specific ignores
.import/
export.cfg
export_presets.cfg
.godot/
# Imported translations (automatically generated from CSV files)
*.translation
# Mono-specific ignores
.mono/
data_*/
# Misc
tmp/
# ---> Vim
# Swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]
# Session
Session.vim
Sessionx.vim
# Temporary
.netrwhist
*~
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~

+ 0
- 0
README.md View File


+ 1
- 0
icon.svg View File

@ -0,0 +1 @@
<svg height="128" width="128" xmlns="http://www.w3.org/2000/svg"><rect x="2" y="2" width="124" height="124" rx="14" fill="#363d52" stroke="#212532" stroke-width="4"/><g transform="scale(.101) translate(122 122)"><g fill="#fff"><path d="M105 673v33q407 354 814 0v-33z"/><path fill="#478cbf" d="m105 673 152 14q12 1 15 14l4 67 132 10 8-61q2-11 15-15h162q13 4 15 15l8 61 132-10 4-67q3-13 15-14l152-14V427q30-39 56-81-35-59-83-108-43 20-82 47-40-37-88-64 7-51 8-102-59-28-123-42-26 43-46 89-49-7-98 0-20-46-46-89-64 14-123 42 1 51 8 102-48 27-88 64-39-27-82-47-48 49-83 108 26 42 56 81zm0 33v39c0 276 813 276 813 0v-39l-134 12-5 69q-2 10-14 13l-162 11q-12 0-16-11l-10-65H447l-10 65q-4 11-16 11l-162-11q-12-3-14-13l-5-69z"/><path d="M483 600c3 34 55 34 58 0v-86c-3-34-55-34-58 0z"/><circle cx="725" cy="526" r="90"/><circle cx="299" cy="526" r="90"/></g><g fill="#414042"><circle cx="307" cy="532" r="60"/><circle cx="717" cy="532" r="60"/></g></g></svg>

+ 37
- 0
icon.svg.import View File

@ -0,0 +1,37 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://c2vm5pfsamed4"
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://icon.svg"
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.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
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false

+ 24
- 0
project.godot View File

@ -0,0 +1,24 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters
config_version=5
[application]
config/name="Conway's Game of Life"
config/features=PackedStringArray("4.1", "Forward Plus")
config/icon="res://icon.svg"
[input]
Pause={
"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":32,"key_label":0,"unicode":32,"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":4194313,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}

+ 46
- 0
world.gd View File

@ -0,0 +1,46 @@
## Conway's Game of Life
## Rules:
## 1. Any cell with >2 neighbors survives
## 2. Any dead cell with 3 live neighbors becomes alive
## 3. All other cells die (all dead cells remaing dead)
extends Node2D
@export var world_seed: int
@export var cell_size: Vector2 = Vector2(16, 16)
@export var cell_texture: Texture2D
@export var world_size: Vector2 = Vector2(128, 128)
var cell_instance
var generation: int = 1
var world: Array = []
func _ready() -> void:
if world_seed: seed(world_seed)
generate_world()
# Create the cell using the rendering server
func create_cell(location: Vector2) -> RID:
var rs = RenderingServer
cell_instance = rs.canvas_item_create()
rs.canvas_item_set_parent(cell_instance, get_canvas_item())
var rect: Rect2 = Rect2(-cell_size.x/2, -cell_size.y/2, cell_size.x, cell_size.y) # Centered with cell size
rs.canvas_item_add_texture_rect(cell_instance, rect, cell_texture)
var location_fixed = Vector2(location.x * cell_size.x, location.y * cell_size.y)
var trans = Transform2D(0, location_fixed)
rs.canvas_item_set_transform(cell_instance, trans)
return cell_instance
## Generate the world with the initial cells
func generate_world() -> void:
for x in range(world_size.x):
world.append([])
for y in range(world_size.y):
if randi_range(0, 1):
world[x].append(create_cell(Vector2(x, y)))
else:
world[x].append(0)

+ 14
- 0
world.tscn View File

@ -0,0 +1,14 @@
[gd_scene load_steps=3 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"]
[node name="World" type="Node2D"]
script = ExtResource("1_wavft")
world_seed = 123
cell_texture = ExtResource("2_8r6bn")
[node name="CanvasLayer" type="CanvasLayer" parent="."]
[node name="Camera2D" type="Camera2D" parent="."]
position = Vector2(576, 320)

Loading…
Cancel
Save