Skip to content

Commit

Permalink
change border color when players consume
Browse files Browse the repository at this point in the history
  • Loading branch information
cguardia authored and chiruzzimarco committed Nov 8, 2024
1 parent 283d0d3 commit ba9fde2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions dlgr/griduniverse/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,14 @@ def handle_item_consume(self, msg):
for player_to in self.grid.players.values():
player_to.score += player_item.public_good

consumed_msg = {
"type": "item_consumed",
"player_id": player.id,
"player_color": player.color,
"player_item": player_item and player_item.serialize(),
}
self.publish(consumed_msg)

def handle_item_pick_up(self, msg):
player = self.grid.players[msg["player_id"]]
player_item = player.current_item
Expand Down
10 changes: 10 additions & 0 deletions dlgr/griduniverse/static/scripts/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@

pixels.canvas.style.marginLeft = (window.innerWidth * 0.03) / 2 + "px";
pixels.canvas.style.marginTop = (window.innerHeight * 0.04) / 2 + "px";
pixels.canvas.style.border = "5x solid #000000";
document.body.style.transition = "0.3s all";
document.body.style.background = "#ffffff";

Expand Down Expand Up @@ -901,6 +902,14 @@
}
}

function onItemConsumed(msg) {
console.log("Item consumed by player " + msg.player_id + ": " + msg.player_item.id);
pixels.canvas.style.border = "5px solid " + msg.player_color;
setTimeout(() => {
pixels.canvas.style.border = "5px solid #000000"
}, 1500);
}

function onDonationProcessed(msg) {
var recipient_id = msg.recipient_id,
team_idx,
Expand Down Expand Up @@ -1288,6 +1297,7 @@
stop: gameOverHandler(player_id),
wall_built: addWall,
move_rejection: onMoveRejected,
item_consumed: onItemConsumed
},
};
const socket = new socketlib.GUSocket(socketSettings);
Expand Down

0 comments on commit ba9fde2

Please sign in to comment.