-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgame.lua
137 lines (111 loc) · 3.08 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
132
133
134
135
136
137
local class = require ( 'lib/middleclass' )
local Stateful = require ( 'lib/stateful' )
local Game = class('Game'):include(Stateful)
-- includes
flux = require "lib.flux"
cron = require 'lib.cron'
Menu = require 'lib.menu'
require ('lib/TEsound')
--debug music
TEsound.sound=true
TEsound.music=true
-- global Ressources
_menu_ = { image = {}, texture = {}, sound = {} }
_ingame_ = { image = {}, texture = {}, sound = {} }
local fps_ = 0
--local paused_ = false
local screenwidth, screenheight = 1280,720
--------------------------------------------------------------------------------
-- don't change this, put your code into the baseXXX functions !!!!
-- Also include "default safe" methods for the callbacks
-- This way we don't have to define "mousepressed" on the states that don't need it
--------------------------------------------------------------------------------
function Game:update(dt)
end
function Game:draw()
end
function Game:keypressed(key,unicode)
end
function Game:keyreleased(key,unicode)
end
function Game:mousepressed(x, y, button)
end
function Game:mousereleased(x, y, button)
end
function Game:focus()
end
function Game:quit()
end
--------------------------------------------------------------------------------
-- main functions
--------------------------------------------------------------------------------
function Game:initialize()
local success = love.window.setMode( screenwidth, screenheight )
love.graphics.setDefaultFilter( 'nearest', 'nearest' )
-- menu ressources
self:gotoState('Loading', 'MainMenu', require( 'subclass/menuressources' ), _menu_ )
end
function Game:baseUpdate(dt)
fps_ = love.timer.getFPS()
-- update music/sound
TEsound.cleanup()
cron.update(dt)
flux.update(dt)
-- call standard
self:update(dt)
end
function Game:baseDraw()
-- draw game
self:draw()
end
-- by default, exit when pressing 'escape'
function Game:baseKeypressed(key, code)
print( 'Game:baseKeypressed', key )
-- if key == 'escape' then
-- self:exit()
-- end
-- call standard
self:keypressed(key,unicode)
end
function Game:baseKeyreleased(key, code)
-- call standard
self:keyreleased(key,unicode)
end
function Game:baseMousepressed(x,y,button)
-- call standard
self:mousepressed(x, y, button)
end
function Game:baseMousereleased(x,y,button)
-- call standard
self:mousereleased(x, y, button)
end
function Game:baseFocus(f)
-- call standard
self:focus()
end
function Game:baseQuit()
-- call standard
self:quit()
end
--------------------------------------------------------------------------------
-- Include the methods available in all states here
--------------------------------------------------------------------------------
-- Screen Options
function Game:GetScreenwidth()
return screenwidth
end
function Game:GetScreenheight()
return screenheight
end
-- prints output in the console
-- If you are on windows you will need to activate it first, see
-- https://love2d.org/wiki/Config_Files
-- for details (you have to set t.console to true)
function Game:log(...)
print(...)
end
function Game:exit()
self:log("Goodbye!")
love.event.push('quit')
end
return Game