-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.lua
185 lines (136 loc) · 2.81 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
local mc = require('lib/middleclass')
Gamestate = require('lib/gamestate')
suit = require('lib/SUIT')
require('assets')
require('cloud')
require('cookie')
require('scrollcanvas')
require('world')
require('menu')
require('win')
require('credits')
C = { --table for constants
g = 9.81*2,
pixelpermeter = 64,
W = love.graphics.getWidth(),
H = love.graphics.getHeight(),
}
--DEBUG = require("mobdebug").start() -- start debugger for live-coding
--DEBUG.on()
--DEBUG.off()
-- gamestate stuff
menu = {}
game = {}
win = {}
credits = {}
sound = true
function menu:enter()
if sound then
music:play()
end
end
function menu:update()
update_menu()
end
function menu:draw()
draw_menu()
end
function menu:keypressed(key, code)
suit.keypressed(key)
if key == 'return' then
Gamestate.switch(game)
end
end
function game:enter()
if sound then
music:setVolume(0.4)
music:rewind()
music:play()
end
love.physics.setMeter(C.pixelpermeter)
world = love.physics.newWorld(0, C.g*love.physics.getMeter(), true)
world:setCallbacks(beginContact, endContact, preSolve, postSolve)
borderL()
borderR()
borderU()
--Test wolken --
scrollcanvas = SC:new()
place_clouds()
-- CookieSpieler --
cookieA = Cookie:new(C.W/2+350, 400, "cookie1", Cookie1)
cookieB = Cookie:new(C.W/2-350, 400, "cookie2", Cookie2)
end
function game:update(dt)
world:update(dt)
--Ton aus mit M
if love.keyboard.isDown("m") then
sound = false
love.audio.pause()
end
--Ton an mit L
if love.keyboard.isDown("l") then
sound = true
music:setVolume(0.4)
music:rewind()
music:play()
end
-- Bewegungen --
-- cookie A
if love.keyboard.isDown("left") then
cookieA:linksGehen()
end
if love.keyboard.isDown("right") then
cookieA:rechtsGehen()
end
if love.keyboard.isDown("up") then
if cookieA.contact then
cookieA:springen()
end
end
-- cookie B
if love.keyboard.isDown("a") then
cookieB:linksGehen()
end
if love.keyboard.isDown("d") then
cookieB:rechtsGehen()
end
if love.keyboard.isDown("w") then
if cookieB.contact then
cookieB:springen()
end
end
scrollcanvas:update(dt)
end
function game:draw()
scrollcanvas:draw()
love.graphics.draw(background, 0, 0)
for k,v in pairs(clouds) do
v:draw()
end
cookieA:draw()
cookieB:draw()
love.graphics.draw(milch, 0, 550)
end
function love.load()
load_assets()
love.graphics.setBackgroundColor(177, 215, 231)
Gamestate.registerEvents()
Gamestate.switch(menu)
end
function win:update()
update_win()
end
function win:draw()
draw_win()
end
function credits:update()
update_credits()
end
function credits:draw()
draw_credits()
end
function love.update(dt)
end
function love.draw()
suit.draw()
end