-
Notifications
You must be signed in to change notification settings - Fork 1
/
game.lua
131 lines (114 loc) · 3.58 KB
/
game.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
local tracking_campagin = '?utm_source=whereispixel&utm_medium=desktop&utm_term=main+menu&utm_campaign=games'
game = {
title = 'Where is Pixel?',
debug = false,
graphics = {
mode = { height = love.graphics.getHeight(), width = love.graphics.getWidth() }
},
fonts = {},
sounds = require('sounds'),
version = require('version'),
name = 'Where is Pixel?',
url = 'http://ananasblau.com/whereispixel' .. tracking_campagin,
paypal_url = 'https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=UJ2S9DN8QHWZJ',
more_games_url = 'http://ananasblau.com/games' .. tracking_campagin,
volume = 1.0,
music_volume = 1.0,
pixel_size = 2, -- 1 is hard, 2 medium and 4 easy
found_pixel_messages = {
'You found Pixel!',
'Oh, there is Pixel :)',
'That was a good hiding spot',
'Not in a hundert years'
},
current_level = 1
}
function game:update(dt)
if game.music_volume and game.music_volume ~= game.last_music_volume then
game.music:setVolume(game.music_volume)
game.last_music_volume = game.music_volume
end
end
function game:createFonts(offset)
local font_file = 'fonts/Orbitron Medium.ttf'
self.fonts = {
lineHeight = (20 + offset) * 1.7,
small = love.graphics.newFont(font_file, 14 + offset),
regular = love.graphics.newFont(font_file, 20 + offset),
large = love.graphics.newFont(font_file, 24 + offset),
very_large = love.graphics.newFont(font_file, 48 + offset)
}
end
function game:setMode(mode)
self.graphics.mode = mode
love.graphics.setMode(mode.width, mode.height, mode.fullscreen or self.graphics.fullscreen)
if self.graphics.mode.height < 600 then
self:createFonts(-2)
else
self:createFonts(0)
end
end
function game:startMenu()
love.mouse.setVisible(true)
game.current_level = 1
game.current_state = StartMenu()
end
function game:start()
game.stopped = false
--love.mouse.setVisible(false)
game.current_state = LevelState(game.current_level)
game.level = game.current_state.level
end
-- pass nil to turn the music off
function game.changeMusic(new_music)
if not game.music then
game:playMusic(new_music)
else
tween(0.5, game, { music_volume = 0.0 }, 'linear', game.playMusic, new_music)
end
end
function game.playMusic(music)
if not music then return end
if game.music then -- just in case
love.audio.stop(game.music)
end
game.music = music
game.music_volume = 0.0
game.music:setVolume(0)
love.audio.play(game.music)
tween(2, game, {music_volume = game.volume})
end
function game:hasNextLevel()
return self.current_level < #Level.levels
end
function game:nextLevel()
if self:hasNextLevel() then
self.current_level = self.current_level + 1
end
game:start()
end
function game.finished(message, progress, pixel)
love.mouse.setVisible(true)
game.stopped = true
game.current_state = Finish(message, progress, game.current_state.view, pixel)
end
function game.foundPixel(pixel)
love.audio.play(game.sounds.fx.found_pixel)
game.finished(game.found_pixel_messages[(game.current_level % #game.found_pixel_messages) + 1], true, pixel)
end
function game.loadImage(image)
return love.graphics.newImage(image)
end
function game:newVersion(version, url)
game.current_state = NewVersion(version, url)
end
function game:showCredits()
game.current_state = State(self, 'Credits', CreditsView())
end
function game.clearScreen(color, x, y, width, height)
if not color then
color = {50,103,200,255}
end
love.graphics.setColor(unpack(color))
love.graphics.rectangle('fill', x or 0, y or 0, width or game.graphics.mode.width, height or game.graphics.mode.height)
end