Skip to content

Commit

Permalink
Run Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Oct 11, 2024
1 parent 79889d3 commit db79ea6
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 136 deletions.
20 changes: 16 additions & 4 deletions src/interactions/map_arcade/game_machine_10.interactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ function startCatchTheMoon(k) {
let score = 0;
const moonPositions = [];


k.go('startScreen', { title: 'Catch the moon', gameSceneName: 'catchTheMoon' });
k.go('startScreen', {
title: 'Catch the moon',
gameSceneName: 'catchTheMoon',
});

k.scene('catchTheMoon', () => {
k.loadSprite('moon', './assets/sprites/moon.png');
Expand Down Expand Up @@ -177,15 +179,25 @@ function startCatchTheMoon(k) {
function updateTimer() {
clearTimeout(timer);
timer = setTimeout(() => {
k.go('lose', { title: 'Catch the moon', gameRestartSceneName: 'catchTheMoon', gameExitSceneName: 'arcade', score });
k.go('lose', {
title: 'Catch the moon',
gameRestartSceneName: 'catchTheMoon',
gameExitSceneName: 'arcade',
score,
});
}, timerDuration);
}

addMoons();
updateTimer();

k.onKeyPress('escape', () => {
k.go('lose', { title: 'Catch the moon', gameRestartSceneName: 'catchTheMoon', gameExitSceneName: 'arcade', score });
k.go('lose', {
title: 'Catch the moon',
gameRestartSceneName: 'catchTheMoon',
gameExitSceneName: 'arcade',
score,
});
clearTimeout(timer);
import('../../scenes/arcade').then((_) => {
k.go('arcade');
Expand Down
12 changes: 10 additions & 2 deletions src/interactions/map_arcade/game_machine_12.interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ function startPatternMemoryGame(k) {
if (currentLevel > 0) {
k.go('patternMemory');
} else {
k.go('startScreen', { title: 'Memorize the pattern!', gameSceneName: 'patternMemory' });
k.go('startScreen', {
title: 'Memorize the pattern!',
gameSceneName: 'patternMemory',
});
}
}

Expand Down Expand Up @@ -114,7 +117,12 @@ function startPatternMemoryGame(k) {
}
} else {
isGameActive = false;
k.go('lose', { title: 'Memorize the pattern!', gameRestartSceneName: 'patternMemory', gameExitSceneName: 'arcade', score });
k.go('lose', {
title: 'Memorize the pattern!',
gameRestartSceneName: 'patternMemory',
gameExitSceneName: 'arcade',
score,
});
}
}

Expand Down
15 changes: 12 additions & 3 deletions src/interactions/map_arcade/game_machine_4.interactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,22 @@ export function startBirdGame(k) {

bird.onCollide('pipe', () => {
k.play('game-over-sound');
k.go('lose', { title: 'Flappy Bird', gameRestartSceneName: 'birdGame', gameExitSceneName: 'arcade', score });
k.go('lose', {
title: 'Flappy Bird',
gameRestartSceneName: 'birdGame',
gameExitSceneName: 'arcade',
score,
});
});

k.onUpdate(() => {
if (bird.pos.y > k.height() || bird.pos.y < 0) {
k.go('lose', { title: 'Flappy Bird', gameRestartSceneName: 'birdGame', gameExitSceneName: 'arcade', score });
k.go('lose', {
title: 'Flappy Bird',
gameRestartSceneName: 'birdGame',
gameExitSceneName: 'arcade',
score,
});
}
});

Expand All @@ -175,5 +185,4 @@ export function startBirdGame(k) {
scoreLabel.text = score;
});
});

}
18 changes: 13 additions & 5 deletions src/interactions/map_arcade/game_machine_6.interactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ function startChromeDinoGame(k) {
const SPEED = 480;
const GRAVITY = 1600;


k.go('startScreen', { title: 'Dino game', gameSceneName: 'dinoGame' });

// Set up the game scene
Expand Down Expand Up @@ -144,7 +143,12 @@ function startChromeDinoGame(k) {

//pressing the esc lets player leave game
k.onKeyPress('escape', () => {
k.go('lose', { title: 'Dino game', gameRestartSceneName: 'dinoGame', gameExitSceneName: 'arcade', score });
k.go('lose', {
title: 'Dino game',
gameRestartSceneName: 'dinoGame',
gameExitSceneName: 'arcade',
score,
});
});

//add platform
Expand Down Expand Up @@ -177,7 +181,7 @@ function startChromeDinoGame(k) {
k.body(),
k.move(k.LEFT, SPEED * scaleFactor + score / 10),
k.offscreen({ destroy: true }),
k.scale(scaleFactor * 3, scaleFactor * (randomHeight)), // Scale height randomly
k.scale(scaleFactor * 3, scaleFactor * randomHeight), // Scale height randomly
'tree',
]);
spawnTree();
Expand All @@ -190,7 +194,12 @@ function startChromeDinoGame(k) {
dino.onCollide('tree', () => {
k.addKaboom(dino.pos);
k.shake();
k.go('lose', { title: 'Dino game', gameRestartSceneName: 'dinoGame', gameExitSceneName: 'arcade', score });
k.go('lose', {
title: 'Dino game',
gameRestartSceneName: 'dinoGame',
gameExitSceneName: 'arcade',
score,
});
});

const SPEEDS = {
Expand Down Expand Up @@ -245,7 +254,6 @@ function startChromeDinoGame(k) {
floor.width = k.width();
});
});

}

// Function to set up the parallax background
Expand Down
7 changes: 6 additions & 1 deletion src/interactions/map_arcade/game_machine_8.interactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ export function initGame(k) {
player.onCollide('tree', () => {
k.addKaboom(player.pos);
k.shake();
k.go('lose', { title: 'Robo Runner', gameRestartSceneName: 'roboRunner', gameExitSceneName: 'arcade', score });
k.go('lose', {
title: 'Robo Runner',
gameRestartSceneName: 'roboRunner',
gameExitSceneName: 'arcade',
score,
});
});
k.onResize(() => {
const scaleFactor = k.width() / k.height();
Expand Down
3 changes: 0 additions & 3 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@ k.scene('campus_house_1', (enter_tag) =>
bootstrap(campusHouse1, { enter_tag })
);



// Game Machine Scenes
k.scene('startScreen', gameStartScreen);
k.scene('lose', loseScreen);


k.go('start');

// To test different maps instead of going through each and every scene to get to yours,
Expand Down
151 changes: 84 additions & 67 deletions src/scenes/gameMachine/lose.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,89 @@
import { k } from '../../kplayCtx'
import { k } from '../../kplayCtx';
import { showCanvasFrame } from '../../utils';

export const loseScreen = ({ title, gameRestartSceneName, gameExitSceneName, score }) => {

const center = k.center();

const exitGame = () => {
showCanvasFrame();
k.setGravity(0);
k.go(gameExitSceneName);
}

const restartGame = () => {
k.go(gameRestartSceneName);
}

k.play('game-over-sound');

const gameOverTxt = k.add([
k.text('Game Over', { size: 64, font: 'pixelFont' }),
k.pos(center.x, center.y - 100),
k.anchor('center')
]);

const scoreTxt = k.add([
k.text(`Score: ${score}`, { size: 48, font: 'pixelFont' }),
k.pos(center.x, center.y - 50),
k.scale(1),
k.anchor('center'),
]);

const restartButton = generateButton('Restart', center.x, center.y + 50, [0, 255, 0]);
const exitButton = generateButton('Exit', center.x, center.y + 120, [255, 0, 0]);

exitButton.onClick(exitGame);
restartButton.onClick(restartGame);



k.onKeyPress('escape', exitGame);
k.onKeyPress('space', restartGame);

k.onResize(() => {
export const loseScreen = ({
title,
gameRestartSceneName,
gameExitSceneName,
score,
}) => {
const center = k.center();

gameOverTxt.pos = k.vec2(center.x, center.y - 100);
scoreTxt.pos = k.vec2(center.x, center.y - 50);
restartButton.pos = k.vec2(center.x, center.y + 50);
exitButton.pos = k.vec2(center.x, center.y + 120);
})
const exitGame = () => {
showCanvasFrame();
k.setGravity(0);
k.go(gameExitSceneName);
};

const restartGame = () => {
k.go(gameRestartSceneName);
};

k.play('game-over-sound');

const gameOverTxt = k.add([
k.text('Game Over', { size: 64, font: 'pixelFont' }),
k.pos(center.x, center.y - 100),
k.anchor('center'),
]);

const scoreTxt = k.add([
k.text(`Score: ${score}`, { size: 48, font: 'pixelFont' }),
k.pos(center.x, center.y - 50),
k.scale(1),
k.anchor('center'),
]);

const restartButton = generateButton(
'Restart',
center.x,
center.y + 50,
[0, 255, 0]
);
const exitButton = generateButton(
'Exit',
center.x,
center.y + 120,
[255, 0, 0]
);

exitButton.onClick(exitGame);
restartButton.onClick(restartGame);

k.onKeyPress('escape', exitGame);
k.onKeyPress('space', restartGame);

k.onResize(() => {
const center = k.center();

gameOverTxt.pos = k.vec2(center.x, center.y - 100);
scoreTxt.pos = k.vec2(center.x, center.y - 50);
restartButton.pos = k.vec2(center.x, center.y + 50);
exitButton.pos = k.vec2(center.x, center.y + 120);
});
};

function generateButton(
btnText,
x,
y,
bgColor = [255, 255, 255],
color = [0, 0, 0]
) {
const button = k.add([
k.rect(200, 60),
k.pos(x, y),
k.anchor('center'),
k.color(...bgColor),
k.area(),
'button',
]);

button.add([
k.text(btnText, { size: 24, font: 'pixelFont' }),
k.anchor('center'),
k.color(...color),
]);

return button;
}

function generateButton(btnText, x, y, bgColor = [255, 255, 255], color = [0, 0, 0]) {

const button = k.add([
k.rect(200, 60),
k.pos(x, y),
k.anchor('center'),
k.color(...bgColor),
k.area(),
'button',
]);

button.add([
k.text(btnText, { size: 24, font: 'pixelFont' }),
k.anchor('center'),
k.color(...color),
]);

return button;
}
Loading

0 comments on commit db79ea6

Please sign in to comment.