-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGrissSystem.lua
138 lines (101 loc) · 2.92 KB
/
GrissSystem.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
local GrissSystem = class("GrissSystem")
local BrokenPlate = require "entities/BrokenPlate"
local wallgriss = Resources.static:getImage("griss_sheet.png")
local wallQuad = {}
for i=1,7 do
wallQuad[i] = love.graphics.newQuad((i-1)*32, 0, 32, 32, 224, 32)
end
local floorgriss = Resources.static:getImage("griss_floor_sheet.png")
local floorQuad = {}
for i=1,7 do
floorQuad[i] = love.graphics.newQuad((i-1)*32, 0, 32, 32, 224, 32)
end
function GrissSystem:initialize(scene)
self.scene = scene
self.brokenBullets = {}
self.plates = {}
self.walls = {}
self.floor = {}
end
function GrissSystem:addFloor(customer,bullet,coll)
local tmp = {}
tmp.x = customer.x
tmp.y = customer.y
tmp.r = math.random()*2*math.pi
tmp.q = floorQuad[love.math.random(1,7)]
table.insert(self.floor,tmp)
end
function GrissSystem:addWall(wall,bullet,coll)
local tmp = {}
local lvl = self.scene.level
local halfSquare = SquareSize/2
local t,r,b,l = halfSquare,lvl.width-halfSquare,lvl.height-halfSquare,halfSquare
if bullet.x < lvl.width/2 then
if math.abs(bullet.x-l) < math.min(math.abs(bullet.y-t),math.abs(bullet.y-b)) then
tmp.o = -math.pi/2
tmp.y = bullet.y
tmp.x = l
elseif bullet.y < lvl.height/2 then
tmp.y = t
tmp.x = bullet.x
else
tmp.o = -math.pi
tmp.y = b
tmp.x = bullet.x
end
else
if math.abs(bullet.x-r) < math.min(math.abs(bullet.y-t),math.abs(bullet.y-b)) then
tmp.o = math.pi/2
tmp.y = bullet.y
tmp.x = r
elseif bullet.y < lvl.height/2 then
tmp.y = t
tmp.x = bullet.x
else
tmp.o = -math.pi
tmp.y = b
tmp.x = bullet.x
end
end
tmp.q = wallQuad[love.math.random(1,7)]
table.insert(self.walls,tmp)
end
function GrissSystem:addBullet(b,coll)
local bx,by = b.x,b.y
local vx,vy = b.lvx,b.lvy
for i = 1,3 do
table.insert(self.plates,BrokenPlate:new(i,bx,by,vx,vy,self.scene))
end
end
function GrissSystem:update(dt)
-- PLATES
for i = #self.plates,1,-1 do
local v = self.plates[i]
v:update(dt)
local dx,dy = v.body:getPosition()
local lvl = self.scene.level
if dx > lvl.width-SquareSize or dx < 0+SquareSize then
v.body:destroy()
table.remove(self.plates,i)
elseif dy > lvl.height - SquareSize or dy < 0+SquareSize then
v.body:destroy()
table.remove(self.plates,i)
end
end
while #self.plates > 500 do
table.remove(self.plates,1)
end
-- WALLS
end
function GrissSystem:draw()
for k,v in ipairs(self.floor) do
love.graphics.draw(floorgriss, v.q, v.x, v.y, v.o, 1, 1, 16, 16)
end
for k,v in ipairs(self.walls) do
love.graphics.draw(wallgriss, v.q, v.x, v.y, v.o, 1, 1, 16, 16)
end
for k,v in ipairs(self.plates) do
v:draw()
end
end
return GrissSystem