Skip to content

Commit 25058f8

Browse files
author
Eoin McGrath
committed
tweaks; win screen music & clamp at 60fps
1 parent 19bbb62 commit 25058f8

File tree

13 files changed

+185
-38
lines changed

13 files changed

+185
-38
lines changed

game.zip

351 Bytes
Binary file not shown.

index.html

+4-4
Large diffs are not rendered by default.

public/game.js

+78-16
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
}, false);
132132
window.setTimeout(() => {
133133
resize(base_default.w, base_default.h);
134-
}, 50);
134+
}, 150);
135135

136136
// src/engine/input.js
137137
var Input = class {
@@ -536,8 +536,15 @@
536536
00 01050440
537537
00 00060240
538538
04 01070440`;
539+
g.p8S3 = `000e0000070600000000000070601106000000130600000007060000000706000000090600a06009060050600706000000000000706011060000001306000000070600000007060000000c0600e0600c0600a060
540+
010e00001a76200000000001a76200000000001a7621f76221762000000000021762000000000021762227621a76200000000001a76200000000001a7621f7621d76200000000001d76200000000001d7621b762
541+
010e00000c043000003f2150000024615000003f215000000c043000003f2150000024615282003f215000000c043000003f2150000024615000003f215000000c043000003f2150000024615000003f21532200
542+
000e00001a76200000000001a76200000000001a7621f762217620000000000217620000000000217622276224762000000000024762000000000024762227622176200000000002176200000000001d7621b762`;
543+
g.p8M3 = `00 00010240
544+
04 00030240`;
539545
document.querySelector("#c").style.cursor = "none";
540546
g.voice = loadSound("t");
547+
g.letsgo = loadSound("letsgo");
541548
console.log(`%c ${g.data.title} V:${version} (${window.BUILD || "DEV"})`, "background: #222; color: #bada55");
542549
}
543550
function mkTail(g, len = 4) {
@@ -627,6 +634,7 @@
627634
this.data = o;
628635
this.dt = 0;
629636
this.fps = 60;
637+
this.msPerFrame = 1e3 / this.fps;
630638
this.frameStep = 1 / this.fps;
631639
this.frameCurr = 0;
632640
this.framePrev = helpers_default.timeStamp();
@@ -670,6 +678,7 @@
670678
Setup(this);
671679
this.track1 = new p8_default(this.p8S, this.p8M);
672680
this.track2 = new p8_default(this.p8S2, this.p8M2);
681+
this.track3 = new p8_default(this.p8S3, this.p8M3);
673682
this.favIcon(this.draw.resize(this.imgs.gecko, 8));
674683
document.querySelector("#l").style.display = "none";
675684
this.c.style.display = "block";
@@ -716,11 +725,17 @@
716725
loop() {
717726
this.frameCurr = helpers_default.timeStamp();
718727
this.dt = this.dt + Math.min(1, (this.frameCurr - this.framePrev) / 1e3);
728+
const delta = this.frameCurr - this.framePrev;
729+
if (delta < this.msPerFrame) {
730+
return;
731+
} else {
732+
}
719733
if (!this.pause) {
720734
this.update(this.frameStep);
721735
this.render();
722736
}
723-
this.framePrev = this.frameCurr;
737+
const excessTime = delta % this.msPerFrame;
738+
this.framePrev = delta - excessTime;
724739
if (this.input.freshKeys.KeyS) {
725740
this.screenshot();
726741
}
@@ -773,7 +788,7 @@
773788
}
774789
runEvents(step) {
775790
this.events.forEach((e, i) => {
776-
e.t -= step * 100;
791+
e.t -= 1;
777792
if (e.t < 0) {
778793
e.cb.call(this);
779794
this.events.splice(i, 1);
@@ -939,7 +954,7 @@
939954
}
940955
render() {
941956
const g = this.g;
942-
g.draw.clear(5);
957+
g.draw.clear(16);
943958
g.draw.img(g.imgs.bg2, 0, this.bgPos - this.g.h);
944959
g.draw.img(g.imgs.bg2, 0, this.bgPos);
945960
g.draw.img(this.shadow, 20, 125);
@@ -987,33 +1002,34 @@
9871002
this.f = g.H.mkFont(g, 5, 4);
9881003
this.f2 = g.H.mkFont(g, 2, 1);
9891004
this.p1 = g.spawn("P1", { p: this });
1005+
const adj = 2;
9901006
g.addText(g.mobile ? "MOVE WITH FINGER" : "MOVE WITH MOUSE", 50);
9911007
g.sfx("piano");
9921008
g.addEvent({
993-
t: 600,
1009+
t: 700 / adj,
9941010
cb: () => {
9951011
g.sfx("piano");
9961012
g.addText("KILL BADDIES", 1);
9971013
g.spawn("Cactus", { p: this });
9981014
}
9991015
});
10001016
g.addEvent({
1001-
t: 1200,
1017+
t: 1200 / adj,
10021018
cb: () => {
10031019
g.sfx("piano");
10041020
g.addText("COLLECT POWERUPS", 1);
10051021
g.spawn("Powerup", { p: this, x: g.w / 2, y: 0 });
10061022
}
10071023
});
10081024
g.addEvent({
1009-
t: 1700,
1025+
t: 1700 / adj,
10101026
cb: () => {
1011-
g.sfx("piano");
1027+
g.letsgo.play();
10121028
g.addText("LETS GO!", 1);
10131029
}
10141030
});
10151031
g.addEvent({
1016-
t: 1900,
1032+
t: 1900 / adj,
10171033
cb: () => {
10181034
g.changeScene("Play");
10191035
}
@@ -1248,9 +1264,9 @@
12481264
spawn() {
12491265
if (this.gameOver || this.boss)
12501266
return;
1251-
let level = ~~(this.dist / 500);
1252-
level = level > 20 ? 20 : level;
1253-
const nextSpawn = this.g.H.rnd(80, 120) - level;
1267+
let level = ~~(this.dist / 700);
1268+
level = level > 10 ? 10 : level;
1269+
const nextSpawn = this.g.H.rnd(50, 100) - level;
12541270
this.g.addEvent({
12551271
t: nextSpawn,
12561272
cb: () => {
@@ -1318,15 +1334,35 @@
13181334
this.bgPos = 0;
13191335
this.f = g.H.mkFont(g, 6, 2);
13201336
this._f = g.H.mkFont(g, 6, 0);
1321-
this.d = this.g.draw.resize(this.g.imgs["donut"], 8);
1337+
this.donuts = [];
1338+
for (let i = 1; i < 9; i += 1) {
1339+
this.donuts.push(this.g.draw.resize(this.g.imgs["donut"], i));
1340+
}
1341+
console.log(this.donuts);
1342+
this.d = this.donuts[7];
13221343
g.addText("THE END", 100, false, g.h - 50, 1);
1344+
g.addEvent({
1345+
t: 20,
1346+
cb: () => {
1347+
this.g.audio = this.g.track3.music(0);
1348+
}
1349+
});
1350+
for (let i = 0; i < 15; i += 1) {
1351+
g.addEvent({
1352+
t: i * 30,
1353+
cb: () => {
1354+
this.g.ents.push(new Treat(this.g, { donuts: this.donuts }));
1355+
}
1356+
});
1357+
}
13231358
}
13241359
update(dt) {
13251360
this.g.ents.forEach((e) => {
13261361
e.update(dt);
13271362
});
13281363
if (this.g.input.freshKeys.Escape && !this.escape) {
13291364
this.escape = true;
1365+
this.g.audio.stop();
13301366
this.g.changeScene("Title");
13311367
}
13321368
}
@@ -1335,14 +1371,40 @@
13351371
g.draw.clear(16);
13361372
g.draw.img(g.imgs.bg2, 0, this.bgPos - this.g.h);
13371373
g.draw.img(g.imgs.bg2, 0, this.bgPos);
1374+
g.ents.forEach((e) => {
1375+
e.render();
1376+
});
13381377
if (this.g.fader > 0) {
13391378
this.g.draw.text("YOU ROCK", this._f, false, 26);
13401379
this.g.draw.text("YOU ROCK", this.f, false, 20);
13411380
}
13421381
this.g.draw.img(this.d, 105, 200);
1343-
g.ents.forEach((e) => {
1344-
e.render();
1345-
});
1382+
}
1383+
};
1384+
var Treat = class {
1385+
constructor(g, o) {
1386+
this.g = g;
1387+
this.donuts = o.donuts;
1388+
this.vy = 0;
1389+
this.reset();
1390+
}
1391+
reset() {
1392+
this.scale = this.g.H.rnd(1, 1);
1393+
this.i = this.donuts[this.scale];
1394+
this.w = this.i.width;
1395+
this.h = this.i.height;
1396+
this.vy = this.scale;
1397+
this.x = this.g.H.rnd(this.w, this.g.w - this.w);
1398+
this.y = this.g.H.rnd(10, 60) * -1;
1399+
}
1400+
render() {
1401+
this.g.draw.img(this.i, this.x, this.y);
1402+
}
1403+
update() {
1404+
this.y += this.vy;
1405+
if (this.y > this.g.h + this.h) {
1406+
this.reset();
1407+
}
13461408
}
13471409
};
13481410

public/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
position: absolute;
2222
top: 15vh;
2323
height: 30vw;
24-
width: 70vw; background: #000;
24+
width: 70vw; background: #000;
2525
padding-left: 1rem;
2626
color: #fff;
2727
}
@@ -90,7 +90,7 @@
9090
</head>
9191
<body>
9292
<div id="l"><h1 id="h">loading...</h1></div>
93-
<canvas id="c" width="320" height="480"></canvas>
93+
<canvas id="c" width="170" height="480"></canvas>
9494
<script src="./game.js"></script>
9595
</body>
9696
</html>

public/letsgo.mp3

7.04 KB
Binary file not shown.

scripts/zip.js

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ const DEST_FOLDER = "build";
1111
const MAX_SIZE = 1024 * 13;
1212
const DIR = `${__dirname}/../${DEST_FOLDER}`;
1313

14+
const analytics = '<script defer src="https://cloud.umami.is/script.js" data-website-id="6a7a59ee-cea7-4517-8aac-1aa3347fb5da"></script>';
15+
16+
1417
const src = {
1518
html: fs.readFileSync("public/index.html", "UTF8"),
1619
js: fs.readFileSync("public/game.js", "UTF8"),
@@ -46,6 +49,8 @@ const init = (src) => {
4649
html = html.replace('<script src="game.js"></script>', "");
4750
html = html.replace("</body>", `<script>BUILD='${commit}';${min}</script></body`);
4851

52+
html = html.replace("</head>", `${analytics}</head>`);
53+
4954
let result = fs.writeFileSync(`${DIR}/index.html`, html, "utf8");
5055

5156
zip.file("index.html", fs.readFileSync("build/index.html"));

src/engine/game.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default class Game {
3131
this.data = o;
3232
this.dt = 0;
3333
this.fps = 60;
34+
this.msPerFrame = 1000 / this.fps;
3435
this.frameStep = 1 / this.fps;
3536
this.frameCurr = 0;
3637
this.framePrev = H.timeStamp();
@@ -86,6 +87,8 @@ export default class Game {
8687

8788
this.track1 = new P8(this.p8S, this.p8M);
8889
this.track2 = new P8(this.p8S2, this.p8M2);
90+
this.track3 = new P8(this.p8S3, this.p8M3);
91+
8992
this.favIcon(this.draw.resize(this.imgs.gecko, 8));
9093
document.querySelector('#l').style.display = 'none';
9194
this.c.style.display = "block";
@@ -137,13 +140,23 @@ export default class Game {
137140
// this.stats.begin();
138141
this.frameCurr = H.timeStamp();
139142
this.dt = this.dt + Math.min(1, (this.frameCurr - this.framePrev) / 1000);
143+
const delta = this.frameCurr - this.framePrev;
144+
145+
if (delta < this.msPerFrame) {
146+
// console.log('TOO FAST!');
147+
return;
148+
} else {
149+
// console.log(delta, this.msPerFrame, 'NO SKIP')
150+
}
140151

141152
if (!this.pause) {
142153
this.update(this.frameStep);
143154
this.render();
144155
}
145156

146-
this.framePrev = this.frameCurr;
157+
// this.framePrev = this.frameCurr;
158+
const excessTime = delta % this.msPerFrame
159+
this.framePrev = delta - excessTime
147160

148161
if (this.input.freshKeys.KeyS) {
149162
this.screenshot();
@@ -204,7 +217,8 @@ export default class Game {
204217

205218
runEvents(step) {
206219
this.events.forEach((e, i) => {
207-
e.t -= step * 100;
220+
// e.t -= step * 100;
221+
e.t -= 1;
208222
if (e.t < 0) {
209223
e.cb.call(this);
210224
this.events.splice(i, 1);

src/engine/resize.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ export default resize;
3434

3535
window.setTimeout(() => {
3636
resize(data.w, data.h);
37-
}, 50);
37+
}, 150);
3838

src/game/scenes/play.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ export default class Play {
168168

169169
spawn() {
170170
if (this.gameOver || this.boss) return;
171-
let level = ~~(this.dist / 500);
172-
level = (level > 20) ? 20 : level
173-
const nextSpawn = this.g.H.rnd(80,120) - level;
171+
let level = ~~(this.dist / 700);
172+
level = (level > 10) ? 10 : level
173+
const nextSpawn = this.g.H.rnd(50,100) - level;
174174
this.g.addEvent({
175175
t: nextSpawn,
176176
cb:() => {

src/game/scenes/title.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default class Title {
7070

7171
render() {
7272
const g = this.g;
73-
g.draw.clear(5);
73+
g.draw.clear(16);
7474
g.draw.img(g.imgs.bg2, 0, this.bgPos - this.g.h);
7575
g.draw.img(g.imgs.bg2, 0, this.bgPos);
7676
g.draw.img(this.shadow, 20, 125);

src/game/scenes/tut.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,35 @@ export default class Tut {
1212
this.f2 = g.H.mkFont(g, 2, 1);
1313
this.p1 = g.spawn('P1', {p: this});
1414

15+
const adj = 2;
16+
1517
g.addText(g.mobile ? 'MOVE WITH FINGER' : 'MOVE WITH MOUSE', 50);
1618
g.sfx('piano');
1719
g.addEvent({
18-
t: 600,
20+
t: 700 / adj,
1921
cb: () => {
2022
g.sfx('piano');
2123
g.addText('KILL BADDIES', 1);
2224
g.spawn('Cactus', {p: this});
2325
}
2426
})
2527
g.addEvent({
26-
t: 1200,
28+
t: 1200 / adj,
2729
cb: () => {
2830
g.sfx('piano');
2931
g.addText('COLLECT POWERUPS', 1);
3032
g.spawn('Powerup', {p: this, x: g.w/2, y: 0});
3133
}
3234
})
3335
g.addEvent({
34-
t: 1700,
36+
t: 1700 / adj,
3537
cb: () => {
36-
g.sfx('piano');
38+
g.letsgo.play();
3739
g.addText('LETS GO!', 1);
3840
}
3941
})
4042
g.addEvent({
41-
t: 1900,
43+
t: 1900 / adj,
4244
cb: () => {
4345
g.changeScene('Play');
4446
}

0 commit comments

Comments
 (0)