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 19, 2024
1 parent 111df31 commit fdb7652
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 66 deletions.
1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@
<div class="menu-bar"></div>
</div>


<div id="header" class="top">ZTM Quest</div>
<div id="left-panel" class="left">
<div class="control-btns d-mobile-hide">
Expand Down
12 changes: 6 additions & 6 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ setInterval(() => {
}
}, 10000);

const creditsButton = document.getElementById("credits-button")
const creditsButton = document.getElementById('credits-button');

if(creditsButton){
creditsButton.addEventListener("click",()=>{
k.go('gameOver')
})
}
if (creditsButton) {
creditsButton.addEventListener('click', () => {
k.go('gameOver');
});
}
4 changes: 0 additions & 4 deletions src/scenes/arcade.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,5 @@ export async function arcade() {
k.go('gameOver');
});



return [map, spawnpoint, gameObjects, interactions, sounds];

}

1 change: 0 additions & 1 deletion src/scenes/city.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ export async function city() {

return [map, spawnpoint, gameObjects, interactions, sounds];
}

70 changes: 37 additions & 33 deletions src/scenes/gameOver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { k } from '../kplayCtx';
import { getAssets, getContributors, getCamScale } from '../utils';

k.scene('gameOver', async () => {

// helper functions from utils files
const contributors = await getContributors();
const assets = await getAssets();
Expand All @@ -23,43 +22,41 @@ Thank you for playing!
const camScale = getCamScale(k);

// Load the background sprite
k.loadSprite("backgroundImage", "/exports/maps/academic_building.png");
k.loadSprite('backgroundImage', '/exports/maps/academic_building.png');


// logic here is to have the text above everything else, tehn the overlay and then the backgrodun, shoudl work if i go my way

const background = k.add([
k.sprite("backgroundImage", { width: k.width(), height: k.height() }),
k.sprite('backgroundImage', { width: k.width(), height: k.height() }),
k.pos(0, 0),
k.opacity(0.2),
k.scale(1),
k.z(60),
k.fixed()
k.fixed(),
]);


const overlay = k.add([
k.rect(k.width(), k.height()),
k.pos(0, 0),
k.color(0, 0, 0), // 40% transparent black
k.z(50),
k.fixed()
k.color(0, 0, 0), // 40% transparent black
k.z(50),
k.fixed(),
]);

// Add the credit text
const center = k.vec2((k.canvas.width / 2), k.canvas.height / 2);
const center = k.vec2(k.canvas.width / 2, k.canvas.height / 2);
const text = k.add([
k.text(creditText, {
size: 15 / camScale,
width: k.width() * 0.9 / camScale,
width: (k.width() * 0.9) / camScale,
lineSpacing: 15 / camScale,
align: "center"
align: 'center',
}),
k.pos(k.width() / 2, k.height()),
k.anchor("top"),
k.anchor('top'),
k.color(255, 255, 255),
k.z(101),
k.scale(camScale)
k.scale(camScale),
]);

const crossButton = k.add([
Expand All @@ -72,37 +69,44 @@ Thank you for playing!
]);

const exitText = k.add([
k.text("Exit", { size: 26 / camScale }),
k.text('Exit', { size: 26 / camScale }),
k.color(255, 255, 255),
k.anchor("topright"),
k.anchor('topright'),
k.z(102),
k.scale(camScale)
k.scale(camScale),
]);


const updateLayout = () => {
const center = k.vec2(k.canvas.width / 2, k.canvas.height / 2);

const center = k.vec2((k.canvas.width / 2), k.canvas.height / 2);

// for updating the background
background.width = k.width();
background.height = k.height();
background.scaleTo(k.width() / background.width, k.height() / background.height);
background.scaleTo(
k.width() / background.width,
k.height() / background.height
);

// for updating the overlay width
overlay.width = k.width();
overlay.height = k.height();

// for the text
text.pos = center;
text.pos.x = k.width() / 2; // Ensure text remains horizontally centered
text.width = k.width() * 0.9 / camScale
text.pos.x = k.width() / 2; // Ensure text remains horizontally centered
text.width = (k.width() * 0.9) / camScale;

// for the cross button and the text in it
const buttonWidth = crossButton.width;
const padding = 10;
crossButton.pos = k.vec2(k.width() - buttonWidth * 0.8 - padding, padding);
exitText.pos = k.vec2(k.width() - buttonWidth * 0.8 - padding, padding + 5);
crossButton.pos = k.vec2(
k.width() - buttonWidth * 0.8 - padding,
padding
);
exitText.pos = k.vec2(
k.width() - buttonWidth * 0.8 - padding,
padding + 5
);
};

updateLayout();
Expand All @@ -125,16 +129,16 @@ Thank you for playing!
const scrollSpeed = 60 * camScale;
const creditsDuration = 25;
let elapsedTime = 0;

k.onUpdate(() => {
elapsedTime += k.dt();

if (elapsedTime < creditsDuration) {
scrollPosition += scrollSpeed * k.dt();
text.pos.y = startPositionAnchor - scrollPosition;
} else {
k.wait(2, () => {
k.go("start");
k.go('start');
});
}
});
Expand All @@ -149,13 +153,13 @@ Thank you for playing!
crossButton.color = k.rgb(255, 0, 0);
exitText.color = k.rgb(255, 255, 255);
});

crossButton.onClick(() => {
k.go("start");
k.go('start');
});

// key bindings, again for added functionality
k.onKeyPress("x", () => {
k.go("start");
// key bindings, again for added functionality
k.onKeyPress('x', () => {
k.go('start');
});
});
8 changes: 0 additions & 8 deletions src/scenes/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import gameObjects from '../gameObjects/map_start';
import interactions from '../interactions/map_start';
import sounds from '../sounds/map_start';




export async function start() {
const objectConfig = {
static: [
Expand All @@ -25,14 +22,9 @@ export async function start() {
k.vec2(0, 11)
);




k.onKeyPress('o', () => {
k.go('gameOver');
});


return [map, spawnpoint, gameObjects, interactions, sounds];
}

34 changes: 21 additions & 13 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,18 +227,26 @@ export const showCanvasFrame = () => {
gameWindow.classList.remove('full-screen');
};

export async function getAssets(){
const fileSHA = await fetch("https://api.github.com/repos/zero-to-mastery/ZTM-Quest/contents/asset_credits.md")
const data = await fileSHA.json()
const fileContents = atob(data.content)
return fileContents.split("\n").filter(content=>content.trim()!=='').join("\n")
export async function getAssets() {
const fileSHA = await fetch(
'https://api.github.com/repos/zero-to-mastery/ZTM-Quest/contents/asset_credits.md'
);
const data = await fileSHA.json();
const fileContents = atob(data.content);
return fileContents
.split('\n')
.filter((content) => content.trim() !== '')
.join('\n');
}

export async function getContributors(){
const contributors = await fetch("https://api.github.com/repos/zero-to-mastery/ZTM-Quest/contributors")
const data = await contributors.json()
return data.map((person)=>{
return person.login
}).join("\n")

}
export async function getContributors() {
const contributors = await fetch(
'https://api.github.com/repos/zero-to-mastery/ZTM-Quest/contributors'
);
const data = await contributors.json();
return data
.map((person) => {
return person.login;
})
.join('\n');
}

0 comments on commit fdb7652

Please sign in to comment.