cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              #cc
  max-width 1536px
  margin 0 auto
            
          
!
            
              var w = 1536;
var h = 864;
var canvas;
var epoch = 0;
var curse = "";
var curses = ["f***", "c***", "d***", "s***", "h***", "b***", "r***"];
var purses = [[0, 0], [0, 0]];
var gend;
var genp = 4000;
var cols = [];
var score = 0;

function setup() {
  canvas = createCanvas(w,h);
  canvas.parent("cc");
  textFont("Montserrat");
  cols = [color(128, 64, 32), color(32, 64, 128), color(32, 128, 32), color(64, 64, 64)];
  shuf(curses);
  console.log(purses[0]);
}

function draw() {
  background(255);
  switch (epoch) {
    case 0:
      textAlign(CENTER, CENTER);
      textSize(216);
      text("CURSES", w/2, h/4);
      text("PURSES", w/2, h*3/4);
      textSize(144);
      text("versus", w/2, h/2);
      break;
    case 1:
      textAlign(CENTER, CENTER);
      textSize(48);
      rectMode(CENTER);
      text("You have decided to go on a little pickpocketing adventure. And, man, is it tedious! You can't resist some cursing. After all, it looks like it's even useful. You have seven curse words available: f***, c***, d***, h***, b***, r*** and s***. Each of these corresponds to either one of the three shapes or one of the four colours of the purses in the game. After pressing any key to continue, you can type in a curse to pick appropriate purses. The mapping of curses to purse traits is randomized every game. You lose when there are too many purses to keep track of.", w/2, h/2, w, h);
      break;
    case 2:
      textAlign(CENTER, CENTER);
      textSize(72);
      text(curse, w/2, h/4);
      //console.log("drawing epoch 2");
      if (millis() > gend+genp) {
        if (purses.length > 12) {
          epoch = 3;
        } else {
          pgen();
          gend += genp;
        }
      }
      for (let p in purses) {
        //console.log("drawing purse "+p+purses[p][0]+purses[p][1]+w*(p+1)/(purses.length+1));
        push();
        translate(w*(int(p)+1)/(purses.length+1), h/2);
        rectMode(CENTER);
        ellipseMode(CENTER);
        noStroke();
        fill(cols[purses[p][0]]);
        switch(purses[p][1]) {
          case 4:
            ellipse(0, 0, 120, 120);
            break;
          case 5:
            rect(0, 0, 100, 100, 20);
            break;
          case 6:
            rect(0, 0, 120, 80, 20);
            break;
        }
        pop();
      }
      text(score, w/2, h*3/4);
      break;
    case 3:
      textAlign(CENTER, CENTER);
      textSize(144);
      text("Game Over", w/2, h/2);
      text(score, w/2, h*3/4);
  }
}

function keyTyped() {
  console.log(epoch, key, curse);
  switch (epoch) {
    case 0:
      epoch = 1;
      break;
    case 1:
      epoch = 2;
      pgen();
      purses.shift();
      purses.shift();
      gend = millis();
      break;
    case 2:
      curse += key;
      if (curse.length > 3) {
        if (curses.includes(curse)) {
          console.log(curse);
          let i = curses.indexOf(curse);
          for (let p in purses) {
            if (purses[p].includes(i)) {
              purses.splice(p, 1);
              p -= 1;
              score += 1;
            }
          }
        }
        curse = "";
      }
  }
}

function pgen() {
  let npurse = [Math.floor(Math.random()*4), Math.floor(Math.random()*3+4)]
  console.log("new purse: ", npurse);
  purses.push(npurse);
  genp *= 0.9;
  console.log("purses now: ", purses);
}

function shuf(a) {
    for (let i = a.length - 1; i > 0; i--) {
        const j = Math.floor(Math.random() * (i + 1));
        [a[i], a[j]] = [a[j], a[i]];
    }
    return a;
}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console