-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.lua
More file actions
128 lines (108 loc) · 2.9 KB
/
main.lua
File metadata and controls
128 lines (108 loc) · 2.9 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
v = Vec2(160, 120)
function init()
set_screen_mode(ScreenMode.hires)
blit.debug("hello world")
screen.load_sprites("dingbads.bin")
local point = Point(10, 10);
point.x = 1
point.y = 2
point = Point(point.x, point.y)
local vec2 = Vec2(10, 10);
vec2.x = 1
vec2.y = 2
vec2 = Vec2(vec2.x, vec2.y)
local rect = Rect(0, 0, 10, 10)
rect:contains(Point(5, 5))
w = rect.size.w
h = rect.size.h
result = Rect(5, 4, 6, 6):intersection(Rect(4, 4, 6, 3))
print(result.x, result.y, result.w, result.h)
result = Rect(5, 5, 10, 10)
result:inflate(1)
print(result.x, result.y, result.w, result.h)
clamp_point = Point(3, 3)
clamped_point = Rect(5, 5, 10, 10):clamp(clamp_point)
print(clamped_point.x, clamped_point.y)
local vecA = Vec2(10, 10)
local vecB = Vec2(10, 10)
dot = vecA:dot(vecB)
cross = vecA:cross(vecB)
angle = vecA:angle(vecB)
local size = Size(10, 10);
size.w = 1
size.h = 2
size = Size(size.w, size.h)
local pen = Pen(128, 255, 64);
pen.r = 1
pen.g = 2
pen.b = 3
pen.a = 4
pen = Pen(pen.r, pen.g, pen.b)
pen = Pen(pen.r, pen.g, pen.b, pen.a)
-- force "unknown property" error
-- TODO make this more idiomatic of Lua
point.z = 1
end
function update(time)
v.x = 160 + 160 * joystick.x
v.y = 120 + 120 * joystick.y
end
function random_sprites(time)
local p = Point(v)
local x = p.x + math.random(-50, 50)
local y = p.y + math.random(-50, 50)
local i = math.random(0, 63)
screen.sprite(i, Point(x, y))
end
function random_pixels(time)
local r = math.random(0, 255)
local g = math.random(0, 255)
local b = math.random(0, 255)
screen.pen = Pen(r, g, b)
local x = math.random(0, 319)
local y = math.random(0, 239)
screen.pixel(Point(x, y))
end
function random_rects(time)
local r = math.random(0, 255)
local g = math.random(0, 255)
local b = math.random(0, 255)
screen.pen = Pen(r, g, b)
local x = math.random(0, 319)
local y = math.random(0, 239)
local w = math.random(0, 319 - x)
local h = math.random(0, 239 - y)
screen.rectangle(Rect(Point(x, y), Size(w, h)))
end
function intersection_test(time)
p = Point(v) -- convert Vec2 to Point
screen.pen = Pen(0, 0, 0)
screen.clear()
screen.pen = Pen(255, 0, 0)
screen.pixel(p)
local x = math.random(0, 319)
local y = math.random(0, 239)
local w = math.random(0, 319 - x)
local h = math.random(0, 239 - y)
local r = Rect(Point(x, y), Size(w, h))
if r:contains(p) then
screen.pen = Pen(255, 0, 0)
else
screen.pen = Pen(0, 0, 255)
end
screen.rectangle(r)
end
function render(time)
for n = 1, 10, 1
do
random_rects(time)
end
for n = 1, 100, 1
do
random_pixels(time)
end
for n = 1, 50, 1
do
random_sprites(time)
end
end