xxxxxxxxxx
89
let players = [];
let counter = 0;
let laser;
function populate() {
for (let i = 0; i < 30; i++) {
// players.push(new RPS("🤖"), new RPS("👾"), new RPS("🦄"));
players.push(new RPS("🗿"), new RPS("🗞"), new RPS("✂️"));
}
}
function setup() {
laser = loadSound('assets/laser.mp3');
createCanvas(200, 600);
populate();
}
class RPS {
constructor(name) {
this.name = name;
this.posX = 0;
this.posY = 0;
this.xoff = random(0, 100);
this.yoff = random(0, 100);
}
move() {
this.xoff = this.xoff + random(0.0001, 0.001);
let nX = noise(this.xoff) * width;
this.posX = nX;
this.yoff = this.yoff + random(0.0001, 0.001);
let nY = noise(this.yoff) * height;
this.posY = nY;
}
show() {
text(`${this.name}`, this.posX, this.posY);
}
change(other) {
let d = dist(this.posX, this.posY, other.posX, other.posY);
if (d < 10) {
if (this.name == "🤖" && other.name === "🦄") {
other.name = "🤖";
}
if (this.name == "🦄" && other.name === "👾") {
other.name = "🦄";
}
if (this.name == "👾" && other.name === "🤖") {
other.name = "👾";
}
}
}
dalek() {
stroke(5, 255, 255);
strokeWeight(3);
if (players.length < 2) {
textSize(50);
text(players[0].name, width / 2 - 25, height / 2 - 25);
noLoop();
} else {
if (counter > 60) {
const randomPosition = Math.floor(random(0, players.length));
const randomPlayer = players[randomPosition];
laser.play();
line(width/2, 0, randomPlayer.posX, randomPlayer.posY);
players.splice(randomPosition, 1);
counter = 0;
}
}
}
}
function draw() {
textSize(10);
background(79, 213, 227);
for (let emoji of players) {
emoji.show();
emoji.move();
for (let other of players) {
emoji.change(other);
}
emoji.dalek();
}
counter++;
}