-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.gd
56 lines (44 loc) · 1.45 KB
/
main.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
extends Node2D
@onready var timer := $Timer
@onready var world := $World
@onready var viewer := $Viewer
var started := false
var playing := false
var tile_size := 32
var target := Vector2.ZERO
var changes: int
func _ready():
viewer.change_speed(timer.wait_time / 0.5)
viewer.update_zoom()
target = floor(get_global_mouse_position() / Vector2(tile_size, tile_size))
viewer.update_target(target)
viewer.update_playing(playing)
viewer.update_changes(world.uncommitted())
func _input(event):
target = floor(get_global_mouse_position() / Vector2(tile_size, tile_size))
viewer.update_target(target)
if Input.is_action_just_released("faster"):
timer.wait_time /= 2
viewer.change_speed(1 / (timer.wait_time / 0.5))
if Input.is_action_just_released("slower"):
timer.wait_time *= 2
viewer.change_speed(1 / (timer.wait_time / 0.5))
if Input.is_action_just_released("play"):
playing = !playing
timer.start()
viewer.update_playing(playing)
viewer.update_commits(len(world.get_used_cells(1)), true)
world.clear_layer(1)
if Input.is_action_just_released("next"):
world.update()
if not playing:
if Input.is_action_just_released("add"):
world.set_cell(1, target, 0, Vector2i(0, 0))
if Input.is_action_just_released("remove"):
world.set_cell(1, target)
if Input.is_action_just_released("commit"):
viewer.update_commits(world.commit(), false)
viewer.update_changes(world.uncommitted())
func _on_timer_timeout():
if playing:
world.update()