xxxxxxxxxx
69
let shared;
let players;
let me;
function preload() {
partyConnect(
"wss://deepstream-server-1.herokuapp.com",
"salil_olivier_party",
"main"
);
shared = partyLoadShared("shared");
players = partyLoadParticipantShareds();
me = partyLoadMyShared();
}
function setup() {
createCanvas(400, 400);
noStroke();
shared.history = shared.history || [];
}
function mousePressed() {
// write shared dataa
const x = mouseX;
const y = mouseY;
const newHistory = Array.isArray(shared.history) ? [shared.history] : [];
newHistory.push({ x: x, y: y });
shared.history = newHistory;
}
function keyPressed() {
if (key === "r" || key === "R") {
shared.history = [];
}
}
function mouseMoved(){
me.x = mouseX;
me.y = mouseY;
}
function draw() {
background("#ffcccc");
noFill();
stroke("#000066");
if (Array.isArray(shared.history)) {
beginShape();
for (let i = 0; i < shared.history.length; i++) {
const p = shared.history[i];
vertex(p.x, p.y);
}
endShape();
}
noStroke();
fill("#000066");
text("Hit 'R' to clear screen", 4, 14);
for (const p of players) {
if( p.x && p.y ){
circle( p.x, p.y, 10 )
}
}
}