-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeteor.lua
81 lines (65 loc) · 1.68 KB
/
meteor.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
71
72
73
74
75
76
77
78
79
80
81
require 'util'
require 'assets'
Meteor = {}
Meteor.__index = Meteor
Meteor.sprite = assets:getImage("art/backgrounds/meteor-1.png")
Meteor.speed = 200
Meteor.y = -30
Meteor.w = 42
Meteor.h = 39
Meteor.type = "meteor"
--flags
Meteor.will_destroy = false
Meteor.will_explode = false
function Meteor.new(gamestate, x)
local self = {}
setmetatable(self,Meteor)
self.gamestate = gamestate
self.x = x
self.gamestate.world:add(self, self.x, self.y, self.w, self.h)
return self
end
function Meteor:update(dt, i)
local goalY = self.y + (self.speed * dt)
local actualX, actualY, cols, len = self.gamestate.world:move(self, self.x,
goalY, self.bump_filter)
self.x = actualX
self.y = actualY
for i=1,len do
local other = cols[i].other
if other.type == "player" and not other.will_destroy then
other:destroy()
self.will_destroy = true
self:explode()
break
end
end
if self.y > self.gamestate.height then
self.will_destroy = true
end
if self.will_explode then
self:_explode()
end
if self.will_destroy then
self:_destroy(i)
end
self.will_destroy = false
end
function Meteor:draw()
love.graphics.draw(self.sprite, round(self.x), round(self.y))
end
function Meteor:explode()
self.will_explode = true
self.will_destroy = true
end
function Meteor:_explode()
table.insert(self.gamestate.fx, Explosion.new(self.gamestate,
self.x + 8, self.y + 4))
end
function Meteor:_destroy(i)
table.remove(self.gamestate.bads, i)
self.gamestate.world:remove(self)
end
function Meteor:bump_filter(other)
return "cross"
end