Skip to content

Commit

Permalink
implement bomb powerup
Browse files Browse the repository at this point in the history
  • Loading branch information
zeucapua committed Jan 10, 2024
1 parent 55da4b9 commit 3f05dc1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
10 changes: 10 additions & 0 deletions party/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ export default class Server implements Party.Server {

else if (this.party_state === "running") {
switch (type) {
// uses bomb powerup
case "bomb": {
const data = JSON.stringify({
type: "bombed",
values: { activator: sender.id }
});

this.party.broadcast(data);
break;
}

// when a player is finished
case "finished": {
Expand Down
31 changes: 31 additions & 0 deletions src/routes/[party]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
(user_string.length / target_string.length) * 100
: 0
);
let bomb_charge = $state(0);
let rocket_charge = $state(0);
let finished : {id: string, result: number}[] = $state([]);
// ending
Expand Down Expand Up @@ -100,6 +102,17 @@
socket.send(data);
}
}
// running
function activateBomb() {
if (socket) {
const data = JSON.stringify({
type: "bomb",
});
socket.send(data);
}
}
// lobby + ending
function toggleReady() {
Expand Down Expand Up @@ -128,6 +141,12 @@
conn_id = data.values.conn_id;
break;
}
case "bombed": {
if (conn_id !== data.values.activator) {
user_string = user_string.length < 10 ? "" : user_string.substring(0, user_string.length - 10);
}
break;
}
case "mirror": {
players = data.values.players;
game_state = data.values.party_state;
Expand Down Expand Up @@ -181,6 +200,18 @@
<input autofocus class="bg-transparent border-b border-white" type="text" bind:value={user_string} disabled={progress === 100}/>
<progress class="bg-transparent border border-white" value={progress} max={100} />

<div class="w-full flex justify-center">
<button
onclick={activateBomb}
class="w-full max-w-24 border-4 border-white rounded-full p-4 disabled:border-dashed disabled:bg-neutral-700"
>
<img
src="/entertainment-events-hobbies-bomb-1.svg"
alt="Entertainment Events Hobbies Bomb 1 by StreamlineHQ"
/>
</button>
</div>

<div class="flex justify-evenly">
{#each players as player, i (player.conn_id)}
{#if finished.find((fin) => fin.id === player.conn_id)}
Expand Down

0 comments on commit 3f05dc1

Please sign in to comment.