Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                #cc
p A post-jam version is available at 
  a(href="https://codepen.io/Mimarik/full/YRLBoJ")
    | https://codepen.io/Mimarik/full/YRLBoJ
  | .
              
            
!

CSS

              
                #cc
  max-width 432px
  margin 0 auto

body
  text-align center
  font-family Montserrat, "Open Sans", Calibri, sans-serif
              
            
!

JS

              
                var w = 432;
var h = 768;
var canvas;
var platforms = [[1, w/6, h*7/8], [1, w/2, h*7/8], [1, w*5/6, h*7/8]];
const cols = [null, "#2ecc71", "#fff", "#9b59b6"];
var platw = 120;
var plath = 30;
var epoch = 0;
var known = [2];
var acc = .2;
var playx = w/2;
var playy = w*3/4;
var playv = 0;
var jumpv = -12;
var speed = 3;
var score = 0;
const ystep = plath*5.8;

function setup() {
  canvas = createCanvas(w,h);
  canvas.parent("cc");
  textFont("Montserrat");
  rectMode(CENTER);
  noStroke();
  textAlign(CENTER, CENTER);
  genp(); genp(); genp();
}

function draw() {
  switch (epoch) {
    case 0:
      background(255);
      playv += acc;
      playy += playv;
      for (let i = 0; i < platforms.length; i += 1) {
        p = platforms[i];
        if (!known.includes(p[0])) {
          epoch = p[0];
        }
        fill(cols[p[0]]);
        rect(p[1], p[2], platw, plath);
        if (Math.abs(p[1]-playx) < (platw+plath)/2 && Math.abs(p[2]-playy) < plath && playv > 0 && p[0] != 2) {
          playy = p[2]-plath;
          jumpv = Math.min(-12, jumpv+.5);
          if (p[0] == 3) {
            jumpv -= 3;
          }
          playv = jumpv;
        }
        if (p[2]-plath/2 > h) {
          platforms.splice(i, 1);
          i--;
          genp();
        }
      }
      if (keyIsPressed) {
        if (keyCode == RIGHT_ARROW) {
          playx += speed;
        }
        if (keyCode == LEFT_ARROW) {
          playx -= speed;
        }
      }
      playx = Math.min(w, Math.max(0, playx));
      let diff = h*7/8-plath/2-jumph()-playy;
      if (diff > 0) {
        playy += diff;
        for (let i in platforms) {
          platforms[i][2] += diff;
        }
        score += diff;
      }
      fill("#2c3e50");
      rect(playx, playy, plath, plath);
      textSize(24);
      /*rect(w/2, h*7/8-plath/2-jumph(), w, 2);
      text(h*7/8-plath/2-jumph(), w/4, h/8);
      text(playy, w*3/4, h/8);*/
      text(Math.floor(score), w/2, h/8);
      if (playy-plath/2 > h) epoch = -1;
      break;
    case 1:
      background(192);
      fill(0);
      textSize(36);
      text("This is a simple\nupwards platformer.\nYour aim is to get\nas high as possible.\nThere is no limit.\nJump on the green\nblocks to get higher.\nControl the game\nusing the arrow keys.\n\nPress any key to\ndismiss this message.\nYou might need to\nfocus the canvas first\nby clicking it.", w/2, h/2);
      known.push(1);
      break;
    case 3:
      background(192);
      fill(0);
      textSize(36);
      text("Purple platforms\nprovide a boost to\njump height for\nthe next six jumps.", w/2, h/2);
      known.push(3);
      break;
    case -1:
      textSize(48);
      text("GAME OVER.\n\nRefresh to retry.", w/2, h/2);
      epoch--;
      break;
  }
}

function jumph() {
  return jumpv*jumpv/acc/2;
}

function genp(type) {
  let p = platforms[platforms.length-1];
  let y = p[2]-ystep;
  if (type == null) {
    type = Math.floor(1+Math.random()*Math.min(score/1000));
  }
  if (type == 2 && p[0] == 2) {
    type--;
  }
  if (type >= cols.length) {
    type = 1;
  }
  p = [type, Math.floor(Math.random()*w), y];
  platforms.push(p);
  console.log(platforms);
}

function keyPressed() {
  epoch = 0;
}
              
            
!
999px

Console