-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
142 lines (124 loc) · 3.59 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
require 'classes/ball'
require 'classes/goal'
require 'lib/util'
objects = {}
bg = love.graphics.newImage("res/field.png");
teams = {}
numTeams=0
width = 1000
height = 560
printme = ''
debugPoints = {}
function love.load()
love.physics.setMeter(10)
world = love.physics.newWorld(0, 0, true)
objects.ball = ball:new(world, width / 2, height / 2)
objects.goals = {}
loadTeam("coda")
loadTeam("mike")
love.graphics.setMode(width, height, false, true, 0)
end
function love.keypressed(key)
if key == "q" then
love.event.push("quit")
elseif key == "right" then
objects.ball:kick(90, 75)
elseif key == "left" then
objects.ball:kick(270, 75)
elseif key == "up" then
objects.ball:kick(0, 75)
elseif key == "down" then
objects.ball:kick(180, 75)
end
end
function love.update(dt)
--printme = love.timer.getTime()
world:update(dt)
objects.ball:update(dt)
for k, team in pairs(teams) do
team.goal:update(dt)
for k, player in ipairs(team) do
player:update()
player:govern()
end
end
end
function love.draw()
--draw dat field
love.graphics.setColor(255,255,255,128)
love.graphics.draw(bg)
objects.ball:draw()
for k, team in ipairs(teams) do
team.goal:draw()
for k, player in ipairs(team) do
player:draw()
end
end
love.graphics.setColor(255,255,255,255)
love.graphics.print(printme, 100, 100)
for i, points in ipairs(debugPoints) do
love.graphics.setColor(
points.R and points.R or 255,
points.G and points.G or 255,
points.B and points.B or 255,
255
)
love.graphics.line(points.X-5, points.Y, points.X+5, points.Y)
love.graphics.line(points.X, points.Y-5, points.X, points.Y+5)
debugPoints[i] = nil
end
end
function loadTeam(team)
if numTeams == 2 then return end
numTeams = numTeams + 1
-- load player classes
teams[team] = {}
teams[team].name = team
teamDir = "teams/"..team
files = love.filesystem.enumerate(teamDir)
for k, file in ipairs(files) do
assert(loadstring('require "'..teamDir.."/"..string.sub(file,1,-5)..'"'))()
end
for i=1,2 do
y = math.random(height)
x = (numTeams == 1) and math.random(width / 2) + width / 2 or math.random(width / 2)
z = teams[team]
teams[team][i] = assert(loadstring("return "..team..i..":new(z, x, y)")())
end
-- goal things
if numTeams == 1 then
x, y, r = 960, 280, 180
else
x, y, r = 40, 280, 0
end
teams[team].goal = goal:new(world, x, y, r, objects.ball, numTeams, teams[team][1].color, teams)
-- set up references
teams[team].number = numTeams
teams[numTeams] = teams[team]
if (numTeams == 2) then
teams[1].otherTeam = teams[2]
teams[2].otherTeam = teams[1]
end
end
function resetPlayers()
for k, team in ipairs(teams) do
for k, player in ipairs(team) do
y = math.random(height)
x = (player.team.number == 1) and math.random(width / 2) + width / 2 or math.random(width / 2)
player.body:setPosition(x, y)
player.body:setLinearVelocity(0,0)
if(player.reset) then player:reset() end
end
end
objects.ball.body:setPosition(width / 2, height / 2)
objects.ball.body:setLinearVelocity(0,0)
end
function debug(pX, pY, cR, cG, cB)
table.insert(debugPoints, {
["X"] = pX,
["Y"] = pY,
["R"] = cR,
["G"] = cG,
["B"] = cB
})
end