gdritter repos dr-parrot / 64846bd
Very basic scaffolding Getty Ritter 7 years ago
34 changed file(s) with 104 addition(s) and 0 deletion(s). Collapse all Expand all
1 state = {}
2 sprites = {}
3
4 difficulty = 5;
5
6 function random_color()
7 local choices = {'red', 'green', 'blue'}
8 return choices[math.floor(math.random() * 3 + 1)]
9 end
10
11 function love.load()
12 state.t = 0
13 state.frame = 0
14 state.board = {}
15
16 local choices = {'red', 'green', 'blue'}
17 for x = 0, 7 do
18 state.board[x] = {}
19 for y = 0, 15 do
20 local choice = math.floor(math.random() * 6)
21 if y < difficulty then
22 state.board[x][y] = choices[choice]
23 else
24 state.board[x][y] = nil
25 end
26 end
27 end
28
29 for _, color in pairs({'red', 'green', 'blue'}) do
30 sprites[color] = {}
31 for n = 0, 9 do
32 sprites[color][n] =
33 love.graphics.newImage('sprites/' .. color .. '_' .. n .. '.png')
34 end
35 sprites[color]['pill'] =
36 love.graphics.newImage('sprites/pill_' .. color .. '.png')
37 end
38
39 love.window.setMode(8 * 24, 16 * 24)
40 end
41
42 function love.update()
43 state.t = state.t + 1
44 if state.t % 2 == 0 then
45 state.frame = state.frame + 1
46 end
47 if state.t % 64 == 0 then
48 if state.current then
49 state.current[1][3] = state.current[1][3] - 1
50 state.current[2][3] = state.current[2][3] - 1
51 else
52 state.current = {{random_color(), 3, 15, 'l'},
53 {random_color(), 4, 15, 'r'}}
54 end
55 end
56 end
57
58 function love.keypressed(key)
59 if key == 'q' then
60 love.event.quit()
61 elseif key == 'left' and state.current and state.current[1][2] > 0 then
62 state.current[1][2] = state.current[1][2] - 1
63 state.current[2][2] = state.current[2][2] - 1
64 elseif key == 'right' and state.current and state.current[1][2] < 7 then
65 state.current[1][2] = state.current[1][2] + 1
66 state.current[2][2] = state.current[2][2] + 1
67 elseif key == 'down' and state.current then
68 state.current[1][3] = state.current[1][3] - 1
69 state.current[2][3] = state.current[2][3] - 1
70 end
71 end
72
73 function rot(x, y, r)
74 if r == 'u' then
75 return x, y, 0
76 elseif r == 'r' then
77 return x + 24, y, (math.pi / 2)
78 elseif r == 'd' then
79 return x + 24, y + 24, math.pi
80 elseif r == 'l' then
81 return x, y + 24, math.pi * 1.5
82 end
83 end
84
85 function love.draw()
86 love.graphics.setColor(255, 255, 255)
87 love.graphics.rectangle('fill', 0, 0, 8 * 24, 16 * 24)
88
89 for x = 0, 7 do
90 for y = 0, 15 do
91 local c = state.board[x][y]
92 if c then
93 love.graphics.draw(sprites[c][state.frame % 10], x * 24, (24 * 15) - y * 24)
94 end
95 end
96 end
97
98 if state.current then
99 for _, p in pairs(state.current) do
100 local x, y, r = rot(p[2] * 24, (24 * 15) - p[3] * 24, p[4])
101 love.graphics.draw(sprites[p[1]]['pill'], x, y, r)
102 end
103 end
104 end
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown