-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
68 lines (57 loc) · 1.65 KB
/
main.lua
File metadata and controls
68 lines (57 loc) · 1.65 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
ac = 0.1
vel = 0
laser_amounts = 0
cat_amounts = 5
function Init()
for i = 1, cat_amounts do
InitEntity("cat" .. i, "cat.png", 100 + i * 300, 100 + i * 10)
end
end
function Update()
Move("pop", 3, 3)
if KeyDown(KEY_W) or KeyDown(KEY_UP) then
Move("player", 0, -1000*deltaTime)
end
if KeyDown(KEY_A) or KeyDown(KEY_LEFT) then
Move("player", -1000*deltaTime, 0)
end
if KeyDown(KEY_S) or KeyDown(KEY_DOWN) then
Move("player", 0, 1000*deltaTime)
end
if KeyDown(KEY_D) or KeyDown(KEY_RIGHT) then
Move("player", 1000*deltaTime, 0)
end
if KeyPressed(KEY_R) or KeyPressed(KEY_SPACE) then
laser_amounts = laser_amounts + 1
InitEntity("laser" .. laser_amounts, "laser.png", GetX("player")+GetWidth("player")/2, GetY("player"))
end
for i = 1, laser_amounts do
Move("laser" .. i, 0, -10)
end
-- Track cats to remove
local to_remove = {}
for j = 1, cat_amounts do
for i = 1, laser_amounts do
if Collision("cat" .. j, "laser" .. i) then
table.insert(to_remove, j)
break -- Stop checking more lasers for this cat
end
end
end
-- Remove all cats marked for deletion
for _, j in ipairs(to_remove) do
Kill("cat" .. j)
end
if KeyDown(KEY_T) then
InitEntity("cat"..cat_amounts, "cat.png", 100, 100)
cat_amounts = cat_amounts + 1
end
if KeyPressed(KEY_P) then
Kill("player")
end
end
function Draw()
for j = 1, cat_amounts do
rec(GetX("cat"..j), GetY("cat"..j), GetWidth("cat"..j), GetHeight("cat"..j), GREEN)
end
end