-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgameScene.lua
91 lines (65 loc) · 2.59 KB
/
gameScene.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
local tiled = require "com.ponywolf.ponytiled"
local physics = require "physics"
local json = require "json"
local gamePanel
local persistence = require "persistence"
local instructions = require "instructions"
local gameState = require "gameState"
local path = require "path"
local fitScreen = require "fitScreen"
physics.start()
-- -----------------------------------------------------------------------------------
-- Declaração das variáveis
-- -----------------------------------------------------------------------------------
local M = { }
local tilesSize = 32
function M:set( miniGame )
local miniGameData
local tileMap
local fileName
local fitTiled
local character
local instructionsTable
if ( miniGame == "map" ) then
fileName = "tiled/newmap.json"
fit = fitScreen.fitMap
elseif ( miniGame == "house" ) then
fileName = "tiled/house.json"
fit = fitScreen.fitDefault
elseif ( miniGame == "school" ) then
fileName = "tiled/school.json"
fit = fitScreen.fitSchool
elseif ( miniGame == "restaurant" ) then
fileName = "tiled/restaurant.json"
fit = fitScreen.fitDefault
end
-- Cria mapa a partir do arquivo JSON exportado pelo tiled
display.setDefault("magTextureFilter", "nearest")
display.setDefault("minTextureFilter", "nearest")
local tiledData = json.decodeFile(system.pathForFile(fileName, system.ResourceDirectory))
tileMap = tiled.new( tiledData, "tiled" )
if ( fit ) then
fit( tileMap )
end
local charName = persistence.loadGameFile().character.name
local charLayer = tileMap:findLayer("character")
for i = 1, charLayer.numChildren do
if ( charLayer[i].myName == persistence.loadGameFile().character.name ) then
character = charLayer[i]
end
end
gameState.new( miniGame, character, onCollision )
miniGameData = gameState:load()
markedPath = path.new( tileMap )
path:setSensors()
instructionsTable = instructions.new( tilesSize, character, markedPath )
if ( ( miniGame == "house" ) and ( ( miniGameData.shownCompletion == true ) or ( ( miniGameData.isGameComplete == false ) and ( ( miniGameData.isComplete == false ) or ( miniGameData.onRepeat == true ) ) ) ) ) then
gamePanel = require "gamePanelTutorial"
else
gamePanel = require "gamePanel"
end
gamePanel.tiled = gamePanel.new( instructions.executeInstructions, miniGameData )
instructions:setGamePanelListeners( gamePanel.stopExecutionListeners, gamePanel.restartExecutionListeners )
return tileMap, character, gamePanel, gameState, path, instructions, instructionsTable, miniGameData
end
return M