-
Notifications
You must be signed in to change notification settings - Fork 0
/
alienattack.lua
70 lines (50 loc) · 1.32 KB
/
alienattack.lua
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
push = require "push"
Class = require 'Class'
-- laser class
alienlaser = Class{}
function alienlaser:init(x, y)
self.x = x
self.y = y
self.image = love.graphics.newImage("sprites/Laser.png")
self.width = self.image:getWidth()
self.height = self.image:getHeight()
self.hit = false
end
function alienlaser:render()
if self.hit == false then
self.y = self.y + 10
love.graphics.draw(self.image, self.x, self.y, 0, 1, 1, self.width, self.height)
end
end
-- attack class
alienattack = Class{}
function alienattack:init(x, y)
self.x = x
self.y = y
self.image = love.graphics.newImage("sprites/Alien.png")
self.width = self.image:getWidth()
self.height = self.image:getHeight()
self.hit = false
self.alienlasers = { }
end
function alienattack:render()
if self.hit == true then
return
elseif self.hit == false then
for count = 1, table.getn(self.alienlasers) do
self.alienlasers[count]:render()
end
love.graphics.draw(self.image, self.x, self.y, 0, 1, 1, self.width, self.height)
n1 = math.random (1, 100)
n2 = math.random (1, 100)
if n1 == n2 then
table.insert(self.alienlasers, alienlaser(self.x,self.y+30))
end
end
end
function alienattack:check(laser)
if laser.y-20 == self.y and laser.x > self.x-40 and laser.x < self.x+40 and self.hit == false then
self.hit = true
return true
end
end