-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
121 lines (111 loc) · 3.36 KB
/
main.lua
File metadata and controls
121 lines (111 loc) · 3.36 KB
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
UserInterface = require("game.ui")
Suit = require("game.suit")
Core = require("game.core")
DebugWorldDraw = require("game.libs.debugWorldDraw")
Colors = require("game.libs.colors")
Debug = require("game.libs.debug")
PerformanceMonitor = require("game.libs.performance")
SplitModule = require("game.splitting")
MergeModule = require("game.merging")
RENDER_DEBUG = false
IsPaused = false
HoveringUIElement = false
SplitBalls = false
MergeBalls = false
Screen = {}
World = {
world = love.physics.newWorld(0, 100, true)
}
Balls = {}
Rects = {}
Ball = {
position = {},
color = { 0.2, 1, 0.2, 1 },
radius = 50,
minRadius = 20,
maxRadius = 80,
startVelocity = 100,
interactCooldown = 0,
canInteract = true,
}
local rect = {
position = { X = Screen.centerX, Y = Screen.centerY },
color = { 0.2, 1, 0.2, 1 },
height = 200,
width = 50,
startVelocity = 0,
}
local border = {}
function love.load(dt)
love.window.maximize()
--World initialization
math.randomseed(os.time())
Screen = UserInterface.windowResized()
World.world:setCallbacks(Core.beginContact, Core.endContact, Core.preContact,
Core.postSolve)
border = Core.createBorder(Screen, World)
-- Other stuff
Ball.position = { X = Screen.centerX, Y = Screen.centerY }
Ball = Core.createBall(Screen, World, Ball)
table.insert(Balls, Ball)
end
function love.update(dt)
--Pre checks and updates
if IsPaused then return end
---
Core.processPendingBallSplits()
Core.processPendingBallRemovals()
Core.processPendingBallMerges()
Core.handleInteractCooldown(Balls, dt)
Core.accelerateAllBalls(Balls, dt)
World.world.update(World.world, dt)
HoveringUIElement = false
UserInterface.drawSuit()
end
function love.draw()
UserInterface.drawFrame(Screen, Balls, Rects)
Suit.draw()
if RENDER_DEBUG then
DebugWorldDraw(World.world, ((Screen.X - Screen.minSize) / 2), ((Screen.Y - Screen.minSize) / 2), Screen.minSize,
Screen.minSize)
end
end
function love.resize()
Screen = UserInterface.windowResized()
border.fixture:destroy()
border = Core.createBorder(Screen, World)
end
function love.mousepressed(x, y, button)
if HoveringUIElement then return end
--Create Ball on mouseclick 1
if button == 1 then
local x, y = love.mouse.getPosition()
local newBall = {
position = { X = x, Y = y },
color = { math.random(), math.random(), math.random(), 1 },
radius = math.random(10, 50),
startVelocity = 100,
angle = math.random(0, 360)
}
newBall = Core.createBall(Screen, World, newBall)
table.insert(Balls, newBall)
print("made new ball (" .. #Balls .. ")")
--Create Rect on mouseclick
elseif button == 2 then
local newRect = {
position = {},
color = { math.random(), math.random(), math.random(), 1 },
width = math.random(10, 100),
height = math.random(10, 100),
startVelocity = 0,
}
newRect = Core.createRect(Screen, World, newRect)
newRect.body:setLinearVelocity(rect.startVelocity, rect.startVelocity * math.pi)
table.insert(Rects, newRect)
print("made new rect (" .. #Rects .. ")")
end
end
--Keypressed
function love.keypressed(k)
Debug.keypressed(k, Balls, Rects)
end