create-okona-game 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/index.js +1 -1
- package/package.json +2 -2
- package/template/game.js +15 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
npm create okona-game my-party-game
|
|
5
5
|
```
|
|
6
6
|
|
|
7
|
-
Scaffolds a phone-controlled
|
|
7
|
+
Scaffolds a phone-controlled HTML5 game for [Okona](https://okonaonline.com): a lobby built to the [Okona game standards](https://okonaonline.com/developers/docs.html#standards) (a controller joins by pressing A, any joined player starts, the game freezes while the Okona menu is open, no join code: Okona shows it), six seats with names and colours pushed to each phone, the frame loop, and a `game.js` with `start` / `update` / `draw` hooks holding a small sample (a coin-grab race) to replace with your game.
|
|
8
8
|
|
|
9
9
|
Open `index.html` in a browser and the keyboard is P1 — no build step, no `package.json`. Ship it with the [`okona` CLI](https://www.npmjs.com/package/okona-cli) (`npx okona-cli`, Node 18.17+): push to your sandbox first to try it with real phones, then submit it to the Okona catalog; once it's approved, players join in the Okona app with a phone or a gamepad.
|
|
10
10
|
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-okona-game",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Scaffold a phone-controlled
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Scaffold a phone-controlled HTML5 game for Okona: lobby, join code, six seats, and a game.js to make yours.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://okonaonline.com/developers/docs.html#html5",
|
|
7
7
|
"bugs": {
|
package/template/game.js
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
// select/l3/r3/up/down/left/right, pad.justPressed('a') (start + home are
|
|
9
9
|
// Okona's: they never reach the game), player.joined (pressed A: a player),
|
|
10
10
|
// pad.triggers.lt/rt (0..1), pad.parked (controller away — seat held).
|
|
11
|
+
// Saves: Okona.save.get/set keep data for the player's account, on any screen
|
|
12
|
+
// (the sample keeps its best round); read it after Okona.ready.
|
|
11
13
|
var Game = {
|
|
12
14
|
title: '{{NAME}}',
|
|
13
15
|
subtitle: 'Grab the coins. Most coins after 45 seconds wins.',
|
|
@@ -26,6 +28,7 @@ var Game = {
|
|
|
26
28
|
onResume: function (player, pad) {},
|
|
27
29
|
|
|
28
30
|
start: function (players, pads) {
|
|
31
|
+
this.best = Okona.save.get('best', 0); // the best round on this account, kept by Okona
|
|
29
32
|
this.coins = [];
|
|
30
33
|
for (var i = 0; i < 10; i++) this.spawnCoin();
|
|
31
34
|
players.forEach(function (p) { p.x = 300 + p.index * 260; p.y = 540; p.vx = 0; p.vy = 0; });
|
|
@@ -55,7 +58,16 @@ var Game = {
|
|
|
55
58
|
}
|
|
56
59
|
}
|
|
57
60
|
}
|
|
58
|
-
|
|
61
|
+
var over = elapsed >= this.ROUND_SECONDS;
|
|
62
|
+
if (over) this.keepBest(players);
|
|
63
|
+
return over;
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
// A new best round goes in the save (it plays on fine if the save is unavailable).
|
|
67
|
+
keepBest: function (players) {
|
|
68
|
+
var top = 0;
|
|
69
|
+
players.forEach(function (p) { if (p.joined && p.score > top) top = p.score; });
|
|
70
|
+
if (top > this.best) { this.best = top; Okona.save.set('best', top); Okona.save.flush(); }
|
|
59
71
|
},
|
|
60
72
|
|
|
61
73
|
draw: function (ctx, players, pads, W, H) {
|
|
@@ -80,5 +92,7 @@ var Game = {
|
|
|
80
92
|
// HUD: big type — it is read from across the room
|
|
81
93
|
ctx.fillStyle = '#E8A525'; ctx.textAlign = 'left'; ctx.font = 'bold 40px system-ui, sans-serif';
|
|
82
94
|
ctx.fillText(this.title, 70, 100);
|
|
95
|
+
ctx.fillStyle = '#A0B4C8'; ctx.textAlign = 'right';
|
|
96
|
+
ctx.fillText('Best ' + this.best, W - 70, 100);
|
|
83
97
|
}
|
|
84
98
|
};
|