forked from zero-to-mastery/ZTM-Quest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
138 lines (119 loc) · 5.05 KB
/
main.js
File metadata and controls
138 lines (119 loc) · 5.05 KB
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
import { k, time } from './kplayCtx';
import { getGameState, setGameState } from './utils/gameState';
import { updateEnergyUI } from './utils/energyUpdate';
import { updateCoinsUI } from './utils/coinsUpdate';
import { start } from './scenes/start';
import './scenes/gameOver';
import './styles/global.css';
import { city } from './scenes/city';
import { arcade } from './scenes/arcade';
import { forest } from './scenes/forest';
import { forestJunction } from './scenes/forest_junction';
import { campusHouse1 } from './scenes/campus_house_1';
import { bootstrap } from './scenes/bootstrap';
import { bootstrap as miniGameBootstrap } from './scenes/fishing_minigame/scene/bootstrap';
import { fishing } from './scenes/fishing_minigame/scene/fishing';
import { gameStartScreen } from './scenes/gameMachine/startSceen';
import { loseScreen } from './scenes/gameMachine/lose';
import { classroom } from './scenes/classroom';
import { seaside } from './scenes/seaside';
import { downtown } from './scenes/downtown';
import { realtor } from './scenes/realtor';
import { extendedCampus } from './scenes/extended_campus';
import { orangeHouse } from './scenes/orange_house';
import { redHouse } from './scenes/red_house';
import { companyInterior } from './scenes/company_interior';
import { loadingScreen } from './scenes/loadingScreen';
import { mainMenuScene } from './scenes/mainMenuScene';
import { setupPauseMenu } from './utils/pauseMenu';
import { setupMenuModals } from './utils/menuModals';
import { Backpack } from './backpack';
k.scene('loadingScreen', () => loadingScreen(k));
k.scene('start', (enter_tag) => bootstrap(start, { enter_tag }));
k.scene('city', (enter_tag) => bootstrap(city, { enter_tag }));
k.scene('arcade', (enter_tag) => bootstrap(arcade, { enter_tag }));
k.scene('forest', (enter_tag) => bootstrap(forest, { enter_tag }));
k.scene('forest_junction', (enter_tag) =>
bootstrap(forestJunction, { enter_tag })
);
k.scene('campus_house_1', (enter_tag) =>
bootstrap(campusHouse1, { enter_tag })
);
k.scene('classroom', (enter_tag) => bootstrap(classroom, { enter_tag }));
k.scene('seaside', (enter_tag) => bootstrap(seaside, { enter_tag }));
k.scene('downtown', (enter_tag) => bootstrap(downtown, { enter_tag }));
k.scene('fishing', (enter_tag) => miniGameBootstrap(fishing, { enter_tag }));
k.scene('extended_campus', (enter_tag) =>
bootstrap(extendedCampus, { enter_tag })
);
k.scene('orange_house', (enter_tag) => bootstrap(orangeHouse, { enter_tag }));
k.scene('red_house', (enter_tag) => bootstrap(redHouse, { enter_tag }));
k.scene('realtor', (enter_tag) => bootstrap(realtor, { enter_tag }));
k.scene('company_interior', (enter_tag) =>
bootstrap(companyInterior, { enter_tag })
);
// Game Machine Scenes
k.scene('startScreen', gameStartScreen);
k.scene('lose', loseScreen);
// Initialize menu modals (settings, achievements, stats, credits)
setupMenuModals();
// Load saved game state from localStorage (if available)
// Wait for assets to load, THEN show main menu
// In main.js
k.onLoad(() => {
setupPauseMenu();
mainMenuScene();
});
// To test different maps instead of going through each and every scene to get to yours,
// Import the scene, name the scene, and then name the spawn point as an additional tag
// k.go('insert_scene_name_here', 'insert_spawn_point_here');
/*
Spawn Points
Start - spawn_left, spawn_right
City - spawn_left, spawn_top, spawn_arcade, spawn_right, spawn_office_left, spawn_office_right
Arcade - player (No need to add a tag)
Forest Junction - spawn_bottom, spawn_top, spawn_right
Forest - spawn_bottom, spawn_topright, spawn_topleft
Campus House - player (No need to add a tag)
*/
updateEnergyUI(getGameState().player.energy);
updateCoinsUI();
setInterval(() => {
const gameState = getGameState(); // This should be inside setInterval so that gameState variable is updated at every interval.
if (gameState.player.energy) {
gameState.player.energy -= 1;
setGameState(gameState);
updateEnergyUI(gameState.player.energy);
} else if (Math.floor(k.time()) % 3 == 0) {
// This ensures log appears atmost 2 times per minute.
k.debug.log('I need some energy.');
}
}, 10000);
const clock = document.getElementById('clock');
setInterval(() => {
displayTime();
if (!time.paused) {
time.addMinutes(k.dt());
if (Math.ceil(time.seconds) % 60 === 0) {
time.seconds = 0;
time.addHours(1);
}
if (time.minutes % 24 === 0) {
time.minutes = 0;
}
}
}, 10);
function displayTime() {
const minutes = Math.ceil(time.minutes);
const seconds = Math.ceil(time.seconds);
clock.innerHTML = `${minutes < 10 ? `0${minutes}` : `${minutes % 24}`}:${seconds < 10 ? `0${seconds % 60}` : `${seconds % 60}`}`;
}
const creditsButton = document.getElementById('credits-button');
if (creditsButton) {
creditsButton.addEventListener('click', () => {
const leftPanel = document.getElementById('left-panel');
leftPanel.classList.toggle('show-misc-menu');
k.go('gameOver');
});
}
Backpack.init();