-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.wu
116 lines (87 loc) · 1.89 KB
/
main.wu
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
module src
extern expose src (*)
extern print :: (a: string) -> {}
extern module math {
random :: (a: float, b: float) float -> 0
sqrt :: (a: float) float -> 0
}
love graphics setBackgroundColor(255, 200, 200)
window_width :: 800
window_height :: 600
struct point {
x: float
y: float
}
distance :: (a: point, b: point) float -> {
dx := a x - b x
dy := a y - b y
dx = dx^2
dy = dy^2
math sqrt(dx + dy)
}
struct square {
pos: point
size: point
speed: float
color: [float]
}
player := square {
pos: point {
x: window_width / 2 - 15
y: window_height / 2 - 15
}
size: point {
x: 30
y: 30
}
color: [200, 255, 200]
speed: 350
}
potato := square {
pos: point {
x: math random(0, window_width)
y: math random(0, window_height)
}
size: point {
x: 15
y: 15
}
speed: .5
color: [200, 200, 200]
}
love update = (dt: float) -> {
dx: float = 0
dy: float = 0
if love keyboard isDown("up") {
dy -= player speed * dt
}
if love keyboard isDown("down") {
dy += player speed * dt
}
if love keyboard isDown("left") {
dx -= player speed * dt
}
if love keyboard isDown("right") {
dx += player speed * dt
}
player pos x += dx
player pos y += dy
player pos x %= window_width
player pos y %= window_height
if (distance(player pos, potato pos) < (player size x)) {
potato pos x = math random(0, window_width)
potato pos y = math random(0, window_height)
player size x += 5
player size y += 5
}
}
cool_square :: (x: float, y: float, size: point, color: [float]) -> {
love graphics setColor(color[0], color[1], color[2])
love graphics rectangle("fill", x, y, size x, size y)
love graphics setColor(color[0] - 50, color[1] - 50, color[2] - 50)
love graphics rectangle("line", x, y, size x, size y)
}
love draw = () -> {
cool_square(potato pos x, potato pos y, potato size, potato color)
cool_square(player pos x, player pos y, player size, player color)
}