• If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Illumination

Page history last edited by Surya Pasupuleti 9 years, 4 months ago

The following is code written in Processing. It only requires 3 fonts which can be downloaded from the program by default to play.

 

A screenshot of a game in progress is attached:

 

 

 

/****************************

Illumination by Surya Pasupuleti

Last edited on 11/14/14

 

This is a game entirely done in black

and white and exploring the concept

of failure. 

*****************************/

 

int x = 525;

int y = 550;

int i = 0;

PFont f;

PFont g;

PFont h;

char lastPress; 

 

void setup() {

  size (660, 660);

  background (0);

  frameRate(8);

  strokeWeight(10);

  f = loadFont("Arial-BoldMT-48.vlw");

  g = loadFont("SegoeUI-Italic-36.vlw");

  h = loadFont("IrisUPCBoldItalic-48.vlw");

  textFont(f, 48);

  text("Start", 530, 570);

  text("Goal", 270, 38);

  textFont(g, 24);

  rect (0, 590, 660, 600);

  fill (0);

  text("Use WASD or arrow keys to move", 100, 640);

  stroke (255, 90);

}

 

//void draw() {

  //if (keyPressed) {

 

//}

 

void draw() {

  if (keyPressed) {

    if ((key == 'w' || keyCode == UP) && y > 0) { //movin' on up

      line (x, y, x, y - 25);

      y -= 25;

      lastPress = 'w';

      //print ("y = ");

      //println(y);

    }

    if ((key == 's'|| keyCode == DOWN) && y < 610) { //goin' down

      line (x, y, x, y + 25);

      y += 25;

      lastPress = 's';

      //print ("y = ");

      //println(y);

    }

    if ((key == 'd' || keyCode == RIGHT) && x < 610) { //boogie to the right

      line (x, y, x + 25, y);

      x += 25;

      lastPress = 'd';

      //print ("x = ");

      //println(x);

    }

    if ((key == 'a' || keyCode == LEFT) && x > 0) { //shimmy to the left

      line (x, y, x - 25, y);

      x -= 25;

      lastPress = 'a';

      //print ("x = ");

      //println(x);

    }

    wallCollision();

   if (wallCollision() == true) {

      wallMessage();

      //noLoop();

      //keyPressed();

  }

  Goal();

  print ("x = ");

  println(x);

  print ("y = ");

  println(y);

  }

 

}

 

void draw(char keyInput) {

    if (lastPress == 'w') {

      line (x, y, x, y + 25);

      y += 25;

    }

    else if (lastPress == 's') {

      line (x, y, x, y - 25);

      y -= 25;

    }

    else if (lastPress == 'd') {

      line (x, y, x - 25, y);

      x -= 25;

    }

    else if (lastPress == 'a') {

      line (x, y, x + 25, y);

      x += 25;

    }

    else if (lastPress == ' ') {

      //text("No need to take two steps back", 50, 640);

    }

}

 

boolean wallCollision() {

  // horizontal walls ((> top bound && < bottom bound) && (< left bound || > right bound))

  // vertical walls (roof && ((< left bound || > right bound))

  if (y == 575) {

    fill (255);

    rect (0, 590, 660, 600);

    fill (0);

    text("There's nothing for you there. Press SPACE", 50, 640); 

    noLoop();

    return false;

  }

  if ((y > 450 && y <= 550) && (x < 300 || x > 500)) return true; //horizontal wall

  if (y == 450 && (x > 350 || x < 300)) return true; //vertical wall

  if ((y > 350 && y < 450) && (x < 300 || x > 550)) return true; //h

  if (y == 350 && (x < 500 || x > 550)) return true; //v

  if ((y > 300 && y < 350) && (x < 150 || x > 550)) return true; //h

  if (y == 300 && (x < 150 || x > 200)) return true; //v

  if ((y > 150 && y < 300) && (x < 150 || x > 450)) return true; //h

  if (y == 150 && (x < 400 || x > 450)) return true; //v

  if ((y > 100 && y < 150) && (x < 200 || x > 450)) return true; //h

  if (y == 100 && (x < 200 || x > 250)) return true; //v

  if (y == 0) {

    fill (255);

    rect (0, 590, 660, 600);

    fill (0);

    text("Come back, the goal is behind you!", 100, 640); 

    return false;

  }

  return false;

}

 

 

void keyPressed() {

  if (key == ' ') {

    fill (255);

    rect (0, 590, 660, 600);

    fill (0);

        loop();

    draw(lastPress);

    lastPress = ' ';

  }

}

 

void wallMessage() {

      fill (255);

      rect (0, 590, 660, 600);

      fill (0);

      //text("You have hit a wall, press SPACE to start over", 40, 640);

      text("You have hit a wall, press SPACE to step back", 40, 640);

      noLoop();

 

boolean Goal() {

  if (y < 50 && x >= 270 && x <= 370) {

        /*  

      background(255);

      fill (0);

      textFont(h, 40);

      text("The road to success is winding and unknowable;", 60, 290);

      text("you may traverse it only if you do not fear failure.", 50, 390);

      */

      noLoop();

 

      noStroke();

      rect(270, 0, 110, 40);

      rect(530, 520, 110, 55);

      rect (0, 590, 660, 600);

 

      return true;

 

  }

  else return false;

}

 

//leave a space when a wall is encountered from multiple directions

 

 

Comments (0)

You don't have permission to comment on this page.