-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenemies.lua
More file actions
45 lines (40 loc) · 1.16 KB
/
enemies.lua
File metadata and controls
45 lines (40 loc) · 1.16 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
enemies = class{}
local timer = 0
local enemy_image = love.graphics.newImage('spritesheets/shipBeige_manned.png') -- Load the PNG image
function create_enemies()
local enemy={}
enemy.path = math.random(100, window_virtualheight/2)
enemy.rad = 15
enemy.x = window_virtualwidth/2 + enemy.path * math.cos(theta)
enemy.y = window_virtualheight/2 + enemy.path * math.sin(theta)
enemy.speed = 300
enemy.theta = math.random(0, 360)
enemy.time = 0
return enemy
end
all_enemies = {}
function enemies:update(dt)
timer = timer + dt
if(timer > 3) then
table.insert(all_enemies, create_enemies())
timer = 0
end
for k,v in pairs(all_enemies) do
v.x = window_virtualwidth/2 + v.path * math.cos(v.theta)
v.y = window_virtualheight/2 + v.path * math.sin(v.theta)
v.theta = v.theta + 1*dt
if(v.theta >= 360) then
v.theta = 0
end
if(v.time>15) then
table.remove(all_enemies, k)
end
v.time = v.time + dt
end
end
function enemies:draw()
for k,v in pairs(all_enemies) do
-- Draw the PNG image instead of a circle
love.graphics.draw(enemy_image, v.x, v.y,0,0.5,0.5)
end
end