-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
139 lines (113 loc) · 3.25 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
-- main.lua
-- Project Nanquim
-- Created by RPG Programming Team
-- Copyright © 2016 Rio PUC Games. All rights reserved.
io.stdout:setvbuf("no")
require "utils"
local dir = love.filesystem.getSourceBaseDirectory() .. '/Ink/'
love.filesystem.setRequirePath("?.lua;?/init.lua;" .. dir .. "?.lua;")
local RPG_Logo = require "RPG_Full_Logo/RPG_Logo"
local game = require "src/game"
local menu = require "Menu/menu"
local level_selector = require "Menu/Level Selector/level_selector"
local scene
--[[
- Engine check for avaible Joysticks in PC and add them to a table
- Our game is a Single Player game, so we only use the first Joystick in the list
]]
local joystickList = love.joystick.getJoysticks()
joystick1 = joystickList[1]
function love.load()
love.mouse.setVisible(false)
local font = love.graphics.setNewFont("Assets/TimeMachino.ttf", 100)
--love.keyboard.setKeyRepeat( true )
RPG_Logo.load(1.5,1.5,1.5,function ()
change_scene("menu")
end)
scenes = { logo = RPG_Logo, game = game, menu = menu, level_selector = level_selector }
change_scene("logo")
end
--[[
change_scene
-This function the the current "scene". When it changes all the functions in main changes and use now the current scene to load,update,draw,...
Parameters:
-new : a string with the name of the new scene, this new scene must also be inside a table, normally called "scenes"
Inside :
-Change the scene based on the string in the parameter and calls that scene start function
]]
function change_scene(new,num)
if num ~= 0 then
local numero = num
end
scene = new
scenes[scene].start(num)
end
function love.update(dt)
scenes[scene].update(dt)
end
function love.keypressed(key)
if scenes[scene].keypressed then
scenes[scene].keypressed(key)
end
end
--[[
-Check the buttons pressed on the Gamepad and transform them in keyboard keys
]]
function love.gamepadpressed( joystick, button )
if button == "dpright" then
love.keypressed("right")
end
if button == "dpleft" then
love.keypressed("left")
end
end
function love.gamepadreleased(joystick, button)
if button == "dpright" then
love.keyreleased("right")
end
if button == "dpleft" then
love.keyreleased("left")
end
end
function love.joystickpressed(joystick, button)
if button == 1 then
love.keypressed("up")
end
if button == 3 then
love.keypressed("d")
end
if button == 8 then
love.keypressed("return")
end
end
function love.joystickreleased(joystick, button)
if button == 1 then
love.keyreleased("up")
end
if button == 3 then
love.keyreleased("d")
end
end
function love.keyreleased(key)
if scenes[scene].keyreleased then
scenes[scene].keyreleased(key)
end
end
function love.mousepressed(x, y, button, istouch)
if scenes[scene].mousepressed then
scenes[scene].mousepressed(x, y, button, istouch)
end
end
function love.mousereleased(x, y, button, istouch)
if scenes[scene].mousereleased then
scenes[scene].mousereleased(x, y, button, istouch)
end
end
function love.mousemoved(x, y, dx, dy )
if scenes[scene].mousemoved then
scenes[scene].mousemoved(x, y, dx, dy)
end
end
function love.draw()
scenes[scene].draw()
end