This repository has been archived by the owner on Feb 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.lua
executable file
·159 lines (126 loc) · 3.88 KB
/
main.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
require 'input'
require 'player'
require 'obstacle'
require 'fruit'
require 'inner_wall'
require 'outer_wall'
require 'time'
require 'presets'
require 'fruit_placer'
require 'scoreboard'
require 'popup'
require 'background_image'
require 'background_sound'
require 'TEsound' -- Using an external Library for managing sound
love.animation = require 'vendor/anim8'
entities = {}
fruits = {}
local player1 = Player:new(love, {x = 10, y = 10})
local player2 = Player:new(love, {
x = GAME_WIDTH - 200,
y = GAME_HEIGHT - GAME_INFO_OFFSET_Y - 200,
playerNumber = 2,
keys = {
up = "w",
down = "s",
left = "a",
right = "d"
},
graphics = {
source = "assets/images/nyancat-sprites-playerO.png",
facing = "right"
},
sound = {
moving = {
source = "assets/sounds/move2.wav"
}
}
})
local wall_1 = InnerWall:new(love, {x = 200, y = 200}, 1)
local wall_2 = InnerWall:new(love, {x = 200, y = 400}, 2)
local wall_3 = InnerWall:new(love, {x = 200, y = 600}, 3)
local backgroundImage = BackgroundImage:new(love)
local backgroundSound = BackgroundSound:new(love)
-- Outer Walls render all 4 render
local outerWalls = OuterWall:createWalls(love)
function love.load()
time = Time:new(GAME_TIME_LIMIT_SECONDS)
time:start(os.time());
table.insert(entities, player1)
table.insert(entities, player2)
table.insert(entities, obstacle)
table.insert(entities, wall_1)
table.insert(entities, wall_2)
table.insert(entities, wall_3)
for i = 1, #outerWalls do
table.insert(entities, outerWalls[i])
end
fruitPlacer = FruitPlacer:new(love, entities)
fruitPlacer:place(10)
love.input.bind('up', 'up')
love.input.bind('left', 'left')
love.input.bind('right', 'right')
love.input.bind('down', 'down')
love.input.bind('w', 'w')
love.input.bind('a', 'a')
love.input.bind('d', 'd')
love.input.bind('s', 's')
-- backgroundSound:play()
TEsound.playLooping("assets/sounds/on-cloud.wav", "music")
end
function love.update(dt)
time:tick(os.time())
TEsound.cleanup()
if (time.finished) then
thread = love.thread.getThread("die_thread")
if thread then
if thread:get('ready') then
love.event.push('quit')
end
else
thread = love.thread.newThread("die_thread", "die.lua")
thread:start()
end
else
for _, entity in pairs(entities) do
entity:update(dt)
for _, other in pairs(entities) do
if other ~= entity then
if entity:collidingWith(other) then
if other.type == 'Fruit' then
entity:collide(other)
other:collide(entity, fruitPlacer)
elseif entity.type == 'Fruit' then
entity:collide(other, fruitPlacer)
other:collide(entity)
else
entity:collide(other)
-- other:collide(entity)
end
end
end
end
end
end
end
function love.draw()
backgroundImage:fillBackground()
for _, e in pairs(entities) do
e:draw()
end
time:draw()
player1.scoreboard:draw()
player2.scoreboard:draw()
if time:game_over() then
local popup
if player1.scoreboard.score > player2.scoreboard.score then
popup = Popup:new("Game Over! Player 1 Wins!!")
elseif player2.scoreboard.score > player1.scoreboard.score then
popup = Popup:new("Game Over! Player O Wins!!")
else
popup = Popup:new("Game Over! It's a tie!!")
end
popup:draw()
end
backgroundImage:drawBottomFence()
end