Skip to content

Commit be6502e

Browse files
committed
Add custom animated loading screen with in-game NPCs
- Replace Kaplay default loading bar with immersive RPG-style screen - Feature 3 random NPCs from actual game sprite sheet walking across - Animated pixel art scenery: day/night sky, stars, clouds, hills, grass - Treasure chest style progress bar with gold fill and sparkles - Rotating gameplay tips during load (5 unique tips) - Pulsing ZTM logo with glow effect - 15-second display time ensures full experience - Matches ZTM Quest's top-down RPG aesthetic perfectly Closes #25
1 parent d268f4f commit be6502e

3 files changed

Lines changed: 347 additions & 12 deletions

File tree

src/kplayCtx.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ export const k = kaplay({
1111
down: { keyboard: ['s', 'down'], gamepad: 'south' },
1212
left: { keyboard: ['a', 'left'], gamepad: 'west' },
1313
right: { keyboard: ['d', 'right'], gamepad: 'east' },
14-
// Configure map key to be bound to m
1514
map: { keyboard: ['m'] },
1615
},
16+
loadingScreen: false,
17+
background: [15, 15, 35],
1718
});
1819

19-
// In the actual game we have hours and minutes adjacent to the player
20-
// But in real time we have minutes and seconds we can use
20+
k.loadSprite('ztmLogo', './assets/sprites/favicon-32x32.png');
21+
2122
export const time = {
2223
minutes: 0,
2324
seconds: 0,
@@ -41,9 +42,11 @@ export const time = {
4142
};
4243

4344
k.loadFont('pixelFont', './assets/fonts/PixelifySans-VariableFont_wght.ttf');
45+
4446
k.onCustomEvent = (eventName, cb) => {
4547
k.canvas.addEventListener(eventName, cb.bind(k));
4648
};
49+
4750
k.triggerEvent = (eventName, detail) => {
4851
k.canvas.dispatchEvent(new CustomEvent(eventName, { detail }));
4952
};

src/main.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ import { extendedCampus } from './scenes/extended_campus';
2525
import { orangeHouse } from './scenes/orange_house';
2626
import { redHouse } from './scenes/red_house';
2727
import { companyInterior } from './scenes/company_interior';
28+
import { loadingScreen } from './scenes/loadingScreen';
2829

30+
k.scene('loadingScreen', () => loadingScreen(k));
2931
k.scene('start', (enter_tag) => bootstrap(start, { enter_tag }));
3032
k.scene('city', (enter_tag) => bootstrap(city, { enter_tag }));
3133
k.scene('arcade', (enter_tag) => bootstrap(arcade, { enter_tag }));
@@ -54,15 +56,17 @@ k.scene('company_interior', (enter_tag) =>
5456
k.scene('startScreen', gameStartScreen);
5557
k.scene('lose', loseScreen);
5658

57-
// Load saved game state from localStorage (if available)
59+
// Load saved game state
5860
const gameState = getGameState();
5961

60-
// Initialize the scenes with position if saved, else go to default position
61-
if (gameState) {
62-
k.go(gameState.player.scene);
63-
} else {
64-
k.go('start'); // Go to the default starting scene
65-
}
62+
// Wait for assets to load, THEN show 30-second loading screen
63+
k.onLoad(() => {
64+
// Start with loading screen scene
65+
k.go('loadingScreen');
66+
67+
// After loading screen finishes (30s), it will automatically go to 'start'
68+
// The loadingScreen scene handles the transition
69+
});
6670

6771
// To test different maps instead of going through each and every scene to get to yours,
6872
// Import the scene, name the scene, and then name the spawn point as an additional tag
@@ -81,13 +85,12 @@ if (gameState) {
8185
updateEnergyUI(getGameState().player.energy);
8286
updateCoinsUI();
8387
setInterval(() => {
84-
const gameState = getGameState(); // This should be inside setInterval so that gameState variable is updated at every interval.
88+
const gameState = getGameState();
8589
if (gameState.player.energy) {
8690
gameState.player.energy -= 1;
8791
setGameState(gameState);
8892
updateEnergyUI(gameState.player.energy);
8993
} else if (Math.floor(k.time()) % 3 == 0) {
90-
// This ensures log appears atmost 2 times per minute.
9194
k.debug.log('I need some energy.');
9295
}
9396
}, 10000);

0 commit comments

Comments
 (0)