-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.lua
More file actions
79 lines (67 loc) · 1.89 KB
/
Copy pathexample.lua
File metadata and controls
79 lines (67 loc) · 1.89 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import "CoreLibs/object"
import "CoreLibs/graphics"
import "CoreLibs/sprites"
import "CoreLibs/timer"
import "autotile"
local pd <const> = playdate
local gfx <const> = playdate.graphics
local seed, cutoff = 0, 0.4
local width, height = 10, 6
local at = Autotile("monochrome-tilemap", width, height)
-- Autotile Helper for Playdate SDK
-- Use this file as your `main.lua`. I also exported a build that has that for you.
-- Up and Down buttons to change the seed, Left and Right to adjust the cutoff
function UpdateNoise()
math.randomseed(seed)
-- Source: https://chrisdownie.net/software/2022/03/31/playdate-perlin-noise/
local repeatValue = 0 -- Don't repeat
local octaves = 1 -- Combine 5 Perlin values
local persistence = 0.5 -- Each value is weighed as half as much as the previous
local noises = gfx.perlinArray(
at.columns * at.rows,
math.random(), 1,
math.random(), 1,
0, 0,
repeatValue,
octaves,
persistence
)
at:setCallback(
noises, at.columns,
function(val)
if val > cutoff then
return Autotile.STATE.SOLID
else
return Autotile.STATE.EMPTY
end
end
)
end
local function initialize()
at:moveTo(200, 120)
UpdateNoise()
end
initialize()
function pd.update()
local updated = false
gfx.sprite.update()
pd.timer.updateTimers()
if pd.buttonJustPressed(pd.kButtonUp) then
updated = true
seed += 1
elseif pd.buttonJustPressed(pd.kButtonDown) then
updated = true
seed -= 1
end
if pd.buttonJustPressed(pd.kButtonLeft) then
updated = true
cutoff -= 0.01
elseif pd.buttonJustPressed(pd.kButtonRight) then
updated = true
cutoff += 0.01
end
if updated then
print("Seed:", seed, "Cutoff:", cutoff)
UpdateNoise()
end
end