Compare commits
9 Commits
cdcc23c50a
...
langtons-a
| Author | SHA1 | Date | |
|---|---|---|---|
| b3d488e031 | |||
| 9156f8b979 | |||
| ef75320c81 | |||
| 6ab83e0f34 | |||
| 408ed71722 | |||
| fa6e5d9582 | |||
| bee8cdeeef | |||
| a49f55b694 | |||
| 25ec8d2585 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -35,6 +35,7 @@
|
||||
# ---> Godot
|
||||
# Godot 4+ specific ignores
|
||||
.godot/
|
||||
addons/
|
||||
|
||||
# Godot-specific ignores
|
||||
.import/
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://uqy71st3rbdr"
|
||||
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/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
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/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
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
|
||||
@@ -1,5 +0,0 @@
|
||||
extends Control
|
||||
|
||||
|
||||
func _on_play_button_pressed() -> void:
|
||||
get_tree().change_scene_to_file("res://molecular_stag.tscn")
|
||||
@@ -1 +0,0 @@
|
||||
uid://dxc66bci2ivrj
|
||||
@@ -1,36 +0,0 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://drgv154ei1vrl"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dxc66bci2ivrj" path="res://main_menu.gd" id="1_06t4h"]
|
||||
|
||||
[sub_resource type="LabelSettings" id="LabelSettings_rhts7"]
|
||||
font_size = 64
|
||||
|
||||
[node name="MainMenu" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_06t4h")
|
||||
|
||||
[node name="PlayButton" type="Button" parent="."]
|
||||
layout_mode = 0
|
||||
offset_left = 448.0
|
||||
offset_top = 256.0
|
||||
offset_right = 768.0
|
||||
offset_bottom = 314.0
|
||||
text = "Play"
|
||||
|
||||
[node name="MainMenuText" type="Label" parent="."]
|
||||
layout_mode = 0
|
||||
offset_left = 320.0
|
||||
offset_top = 32.0
|
||||
offset_right = 904.0
|
||||
offset_bottom = 151.0
|
||||
text = "The Main Menu"
|
||||
label_settings = SubResource("LabelSettings_rhts7")
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
[connection signal="pressed" from="PlayButton" to="." method="_on_play_button_pressed"]
|
||||
@@ -1,8 +0,0 @@
|
||||
[gd_scene format=3 uid="uid://b55w56d4twno1"]
|
||||
|
||||
[node name="MolecularStag" type="Node2D"]
|
||||
|
||||
[node name="Label" type="Label" parent="."]
|
||||
offset_right = 40.0
|
||||
offset_bottom = 23.0
|
||||
text = "Debug: You made it into the game!"
|
||||
@@ -1,16 +0,0 @@
|
||||
; 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="EvolveDieRepeat"
|
||||
run/main_scene="uid://drgv154ei1vrl"
|
||||
config/features=PackedStringArray("4.5", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
@@ -1,3 +1,4 @@
|
||||
# Godot 4+ specific ignores
|
||||
.godot/
|
||||
/android/
|
||||
project.godot
|
||||
*.import
|
||||
4
langtons-ant/TODO
Normal file
4
langtons-ant/TODO
Normal file
@@ -0,0 +1,4 @@
|
||||
UI -> toggleButton so camera follows ant
|
||||
-> reset camera button
|
||||
-> pause button
|
||||
dynamically generate tile colours (using a big palette for indexing maybe?) this probably needs to be a shader.
|
||||
89
langtons-ant/ant.gd
Normal file
89
langtons-ant/ant.gd
Normal file
@@ -0,0 +1,89 @@
|
||||
extends Sprite2D
|
||||
|
||||
var pos: Vector2i = Vector2i(0,0)
|
||||
var dir: TileSet.CellNeighbor = TileSet.CELL_NEIGHBOR_RIGHT_SIDE
|
||||
@onready var tiles: TileMapLayer = get_node("../TileMapLayer")
|
||||
@export var randomRules: bool = true
|
||||
|
||||
var curDir: Dictionary = {
|
||||
0: TileSet.CELL_NEIGHBOR_RIGHT_SIDE,
|
||||
1: TileSet.CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE,
|
||||
2: TileSet.CELL_NEIGHBOR_BOTTOM_LEFT_SIDE,
|
||||
3: TileSet.CELL_NEIGHBOR_LEFT_SIDE,
|
||||
4: TileSet.CELL_NEIGHBOR_TOP_LEFT_SIDE,
|
||||
5: TileSet.CELL_NEIGHBOR_TOP_RIGHT_SIDE,
|
||||
}
|
||||
|
||||
var curInt: Dictionary = {
|
||||
TileSet.CELL_NEIGHBOR_RIGHT_SIDE: 0,
|
||||
TileSet.CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE: 1,
|
||||
TileSet.CELL_NEIGHBOR_BOTTOM_LEFT_SIDE: 2,
|
||||
TileSet.CELL_NEIGHBOR_LEFT_SIDE: 3,
|
||||
TileSet.CELL_NEIGHBOR_TOP_LEFT_SIDE: 4,
|
||||
TileSet.CELL_NEIGHBOR_TOP_RIGHT_SIDE: 5,
|
||||
}
|
||||
|
||||
var antProgram: Array[Vector2i] = [
|
||||
Vector2i(2, 1),
|
||||
Vector2i(0, 2),
|
||||
Vector2i(3, 3),
|
||||
Vector2i(1, 4),
|
||||
Vector2i(1, 5),
|
||||
Vector2i(2, 0),
|
||||
]
|
||||
|
||||
func randomTileset() -> void:
|
||||
var rng = RandomNumberGenerator.new()
|
||||
antProgram = []
|
||||
var s: int = rng.randi_range(10, 99)
|
||||
for i in range(0, s):
|
||||
antProgram.append(Vector2i(rng.randi_range(1, 4), (i+1)%s))
|
||||
|
||||
|
||||
func getNextStep(tile: int) -> Vector2i:
|
||||
if tile > antProgram.size():
|
||||
return Vector2i(0,0)
|
||||
else:
|
||||
return antProgram.get(tile)
|
||||
|
||||
func _ready() -> void:
|
||||
self.set_z_index(1)
|
||||
self.set_frame(curInt[dir])
|
||||
if randomRules:
|
||||
randomTileset()
|
||||
tiles.set_tile(pos, tiles.get_tile_colour(pos))
|
||||
move(dir)
|
||||
|
||||
# update loop:
|
||||
# move in dir
|
||||
# get tile col, change dir based on col
|
||||
# paint tile col
|
||||
func update() -> void:
|
||||
move(dir)
|
||||
pos = tiles.get_neighbor_cell(pos, dir)
|
||||
|
||||
var tile: int = tiles.get_tile_colour(pos)
|
||||
var res = getNextStep(tile)
|
||||
dir = curDir[(curInt[dir] + tiles.numTiles + res.x) % tiles.numTiles]
|
||||
self.set_frame(curInt[dir])
|
||||
|
||||
tiles.set_tile(pos, res.y % tiles.numTiles)
|
||||
|
||||
func move(to: TileSet.CellNeighbor) -> void:
|
||||
var delta: Vector2
|
||||
match to:
|
||||
TileSet.CELL_NEIGHBOR_RIGHT_SIDE:
|
||||
delta = Vector2(tiles.texSize.x, 0)
|
||||
TileSet.CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE:
|
||||
delta = Vector2(tiles.texSize.x/2, tiles.texSize.y/4*3)
|
||||
TileSet.CELL_NEIGHBOR_BOTTOM_LEFT_SIDE:
|
||||
delta = Vector2(-tiles.texSize.x/2, tiles.texSize.y/4*3)
|
||||
TileSet.CELL_NEIGHBOR_LEFT_SIDE:
|
||||
delta = Vector2(-tiles.texSize.x, 0)
|
||||
TileSet.CELL_NEIGHBOR_TOP_LEFT_SIDE:
|
||||
delta = Vector2(-tiles.texSize.x/2, -tiles.texSize.y/4*3)
|
||||
TileSet.CELL_NEIGHBOR_TOP_RIGHT_SIDE:
|
||||
delta = Vector2(tiles.texSize.x/2, -tiles.texSize.y/4*3)
|
||||
_:
|
||||
delta = Vector2(0,0)
|
||||
self.translate(delta)
|
||||
1
langtons-ant/ant.gd.uid
Normal file
1
langtons-ant/ant.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b6ll30b7xtwal
|
||||
BIN
langtons-ant/assets/ant.png
Normal file
BIN
langtons-ant/assets/ant.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.9 KiB |
BIN
langtons-ant/assets/tiles.png
Normal file
BIN
langtons-ant/assets/tiles.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
41
langtons-ant/camera.gd
Normal file
41
langtons-ant/camera.gd
Normal file
@@ -0,0 +1,41 @@
|
||||
extends Camera2D
|
||||
|
||||
@export var minZoom := 0.01
|
||||
@export var maxZoom := 2.0
|
||||
@export var zoomFactor := 0.1
|
||||
@export var zoomDuration := 0.2
|
||||
var zoomLevel: float = 1
|
||||
var dragging: bool = false
|
||||
|
||||
func _ready():
|
||||
pass
|
||||
|
||||
func _input(event):
|
||||
if event.is_action_pressed("zoomIn"):
|
||||
setZoomLevel(zoomLevel + zoomFactor)
|
||||
elif event.is_action_pressed("zoomOut"):
|
||||
setZoomLevel(zoomLevel - zoomFactor)
|
||||
elif event.is_action_pressed("resetCamera"):
|
||||
reset()
|
||||
|
||||
func _unhandled_input(event):
|
||||
if event is InputEventMouseButton:
|
||||
if event.get_button_index() == 1:
|
||||
dragging = event.is_pressed()
|
||||
elif event is InputEventMouseMotion:
|
||||
if dragging:
|
||||
self.global_position -= event.get_relative() * 1/zoomLevel
|
||||
|
||||
|
||||
func setZoomLevel(level: float, mouse_world_position = self.get_global_mouse_position()):
|
||||
var old_zoomLevel = zoomLevel
|
||||
zoomLevel = clampf(level, minZoom, maxZoom)
|
||||
|
||||
var direction = (mouse_world_position - global_position)
|
||||
var new_position = self.global_position + direction - ((direction) / (zoomLevel/old_zoomLevel))
|
||||
|
||||
zoom = Vector2(zoomLevel, zoomLevel)
|
||||
self.global_position = new_position
|
||||
|
||||
func reset():
|
||||
self.global_position = Vector2(0, 0)
|
||||
1
langtons-ant/camera.gd.uid
Normal file
1
langtons-ant/camera.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bqjbnbfd7jlob
|
||||
24
langtons-ant/grid.gd
Normal file
24
langtons-ant/grid.gd
Normal file
@@ -0,0 +1,24 @@
|
||||
extends Node2D
|
||||
|
||||
var t: float = -1
|
||||
var paused: bool = false
|
||||
@export var stepSize: float = 20
|
||||
@export var ant: Sprite2D
|
||||
@export var tiles: TileMapLayer
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass
|
||||
|
||||
func _input(event):
|
||||
if event.is_action_pressed("togglePause"):
|
||||
paused = !paused
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
if paused: return
|
||||
|
||||
t += delta
|
||||
if (t > stepSize/1000):
|
||||
t = 0
|
||||
ant.update()
|
||||
1
langtons-ant/grid.gd.uid
Normal file
1
langtons-ant/grid.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://by3d3t5ymxl3m
|
||||
50
langtons-ant/grid.tscn
Normal file
50
langtons-ant/grid.tscn
Normal file
@@ -0,0 +1,50 @@
|
||||
[gd_scene load_steps=9 format=3 uid="uid://b6xi32r3co6md"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://by3d3t5ymxl3m" path="res://grid.gd" id="1_bghhw"]
|
||||
[ext_resource type="Script" uid="uid://b6ll30b7xtwal" path="res://ant.gd" id="1_ebq2e"]
|
||||
[ext_resource type="Texture2D" uid="uid://ykvioy4g357o" path="res://assets/ant.png" id="3_sle3t"]
|
||||
[ext_resource type="Texture2D" uid="uid://b8dilj6w2vq2l" path="res://assets/tiles.png" id="4_fqc2p"]
|
||||
[ext_resource type="Script" uid="uid://cqxfmo3hixad1" path="res://tile_map_layer.gd" id="5_fqc2p"]
|
||||
[ext_resource type="Script" uid="uid://bqjbnbfd7jlob" path="res://camera.gd" id="6_g2qvd"]
|
||||
|
||||
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_g2qvd"]
|
||||
texture = ExtResource("4_fqc2p")
|
||||
texture_region_size = Vector2i(32, 32)
|
||||
0:0/0 = 0
|
||||
1:0/0 = 0
|
||||
0:1/0 = 0
|
||||
1:1/0 = 0
|
||||
0:2/0 = 0
|
||||
1:2/0 = 0
|
||||
0:3/0 = 0
|
||||
1:3/0 = 0
|
||||
0:4/0 = 0
|
||||
0:5/0 = 0
|
||||
|
||||
[sub_resource type="TileSet" id="TileSet_05i0m"]
|
||||
tile_shape = 3
|
||||
tile_size = Vector2i(32, 32)
|
||||
sources/0 = SubResource("TileSetAtlasSource_g2qvd")
|
||||
|
||||
[node name="Grid" type="Node2D" node_paths=PackedStringArray("ant", "tiles")]
|
||||
script = ExtResource("1_bghhw")
|
||||
stepSize = 1.0
|
||||
ant = NodePath("Ant")
|
||||
tiles = NodePath("TileMapLayer")
|
||||
|
||||
[node name="TileMapLayer" type="TileMapLayer" parent="."]
|
||||
tile_set = SubResource("TileSet_05i0m")
|
||||
collision_enabled = false
|
||||
script = ExtResource("5_fqc2p")
|
||||
|
||||
[node name="Ant" type="Sprite2D" parent="."]
|
||||
position = Vector2(-15.999998, 14.999998)
|
||||
scale = Vector2(0.8, 0.8)
|
||||
texture = ExtResource("3_sle3t")
|
||||
vframes = 6
|
||||
script = ExtResource("1_ebq2e")
|
||||
|
||||
[node name="Camera" type="Camera2D" parent="."]
|
||||
position = Vector2(-3.8146973e-06, -8)
|
||||
scale = Vector2(0.79999983, 0.79999983)
|
||||
script = ExtResource("6_g2qvd")
|
||||
|
Before Width: | Height: | Size: 995 B After Width: | Height: | Size: 995 B |
43
langtons-ant/project.godot
Normal file
43
langtons-ant/project.godot
Normal file
@@ -0,0 +1,43 @@
|
||||
; 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="New Game Project"
|
||||
run/main_scene="res://grid.tscn"
|
||||
config/features=PackedStringArray("4.5", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[editor_plugins]
|
||||
|
||||
enabled=PackedStringArray("res://addons/godot-vim/plugin.cfg")
|
||||
|
||||
[input]
|
||||
|
||||
zoomIn={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":4,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
zoomOut={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":5,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
togglePause={
|
||||
"deadzone": 0.2,
|
||||
"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,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
resetCamera={
|
||||
"deadzone": 0.2,
|
||||
"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":82,"physical_keycode":0,"key_label":0,"unicode":114,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
22
langtons-ant/tile_map_layer.gd
Normal file
22
langtons-ant/tile_map_layer.gd
Normal file
@@ -0,0 +1,22 @@
|
||||
extends TileMapLayer
|
||||
|
||||
var tiles: Dictionary = {}
|
||||
@onready var numTiles: int = get_tile_set().get_source(0).get_tiles_count()
|
||||
#@onready var texSize: Vector2 = get_tile_set().get_tile_texture(get_tile_set().get_tile_id(0))
|
||||
@onready var texSize: Vector2 = Vector2(32, 32) # TODO: get from tileSet
|
||||
@export var randomColors: bool = true
|
||||
var stateColMap: Dictionary = {
|
||||
}
|
||||
var rng: RandomNumberGenerator = RandomNumberGenerator.new()
|
||||
|
||||
func get_tile_colour(pos: Vector2i) -> int:
|
||||
return tiles.get_or_add(pos, 0)
|
||||
|
||||
# TODO: state should be an enum probably
|
||||
func set_tile(pos: Vector2i, state: int) -> void:
|
||||
self.set_cell(pos, 0, Vector2i(0, state%numTiles))
|
||||
if randomColors:
|
||||
var col: Color = stateColMap.get_or_add(state, Color(rng.randf(), rng.randf(), rng.randf(), 1))
|
||||
self.get_cell_tile_data(pos).set_modulate(col)
|
||||
tiles.erase(pos)
|
||||
tiles.get_or_add(pos, state)
|
||||
1
langtons-ant/tile_map_layer.gd.uid
Normal file
1
langtons-ant/tile_map_layer.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cqxfmo3hixad1
|
||||
Reference in New Issue
Block a user