Pusheen – Too Busy Eating Edition

Pusheen - 3

Pusheen has to save the princess!

But oh no, why is all this food here? As one of our favorite internet cats, pusheen’s pretty notorious for eating everything…and avoiding adventures.

This is a tribute to not only Pusheen but also: a much-loved unicorn game, the classic Mario “The princess is in another castle!” level endings, and of course, food.

Things to update:

– Copy on the level/title screens so it’s clear what the objective of the game is. Add a video before the game, maybe?

– Level 4 is supposed to be a boss battle, with the flame in the middle and the skulls floating around. Since “eating” the skulls shouldn’t really be an option, I would add a collision function, so that every time Pusheen collides with the skulls, you have to start over from level 1.

– A timer class exists, but isn’t used: add that in levels 1-3 where the player has to eat everything in under x amount of time.

– Like Nicole and Dan mentioned, there is a great chance to incorporate inheritance for the food items.

Notes:

Although the game isn’t quite finished, and I solved the problem with the levels not appearing whilst in class, I’m happy the game (which would be the first I’ve made) works. I’m very glad I got to use and understand arraylists for the food objects eaten in the levels, and states for the actual levels. Many, many thanks to Pauline for helping me understand arraylists and for screaming with me when we got the boxes to disappear for the first time. (And also to everyone who pours their heart and code into processing tutorials.)

Download the game & all of the related files.

Code below:

FOR THE GAME:

//Pusheen objects:
Pusheen pusheen;

//Timer:
Timer timer;

//Box Arrays:
ArrayList<Box> box_list; //level 1
ArrayList<Box> box_list2; //level 2
ArrayList<Box> box_list3; //level 3
ArrayList<Box> box_list4; //level 4

//importing minim and serial libraries
import ddf.minim.*;
import processing.serial.*;

//for to play music
Minim minim; 
AudioPlayer player; 

//Background images:
PImage bg1;
PImage bg2;
PImage bg3;
PImage bg4;
PImage bg5;
PImage bg6;
//PImage bg7;
int y;

//Play button:
int playButtonWidth, playButtonHeight;
int playButtonX, playButtonY;

//Levels: 
final int START = 1;
final int LEVEL1 = 2;
final int LEVEL2 = 3;
final int LEVEL3 = 4; 
final int LEVEL4 = 5;
final int WIN = 6;
final int GAME_OVER = 7; 
int state = START; //initial value 

void setup () {
  size(880, 680);
  //load background images:
  bg1 = loadImage("level1bg.png");
  bg2 = loadImage("level2bg.png");
  bg3 = loadImage("level3bg.png");
  bg4 = loadImage("level4bg.png");
  bg5 = loadImage("castlebg.png");
  bg6 = loadImage("startbg.png");
  // bg7 = loadImage("bg7.png");

  minim = new Minim (this);
  player = minim.loadFile ("Always.mp3");
  //Because this is obviously THAT unicorn song.
  //player = minim.loadFile ("Outro.mp3");
  //This is a different song
  player.play ( );

  //array for box, change number of i for levels 
  //from box constructor

  //array for level 1 - img = muffin
  box_list = new ArrayList<Box>();
  for (int i=0; i<31; i++) {
    box_list.add (new Box (random (0, width), random (0, height), random(1, 4), random(1, 4), "muffin.png"));
  }

  //array for level 2 - img = hamburger
  box_list2 = new ArrayList<Box>();
  for (int i=0; i<41; i++) {
    box_list2.add (new Box (random (0, width), random (0, height), random(1, 4), random(1, 4), "hamburger.png"));
  }

  //array for level 3 - img = donut/candy/hotodg ??
  box_list3 = new ArrayList<Box>();
  for (int i=0; i<51; i++) {
    box_list3.add (new Box (random (0, width), random (0, height), random(1, 4), random(1, 4), "donut.png"));
  }

  //array for level 4 - img = skulls (boss-ish level)
  box_list4 = new ArrayList<Box>();
  for (int i=0; i<10; i++) {
    box_list4.add (new Box (random (0, width), random (0, height), random(1, 4), random(1, 4), "skull.png"));
  }

  //things from Pusheen constructor
  pusheen = new Pusheen(400, 200, "unipic.png");

  //play button:
  playButtonWidth = width / 5;
  playButtonHeight = height / 8;
  playButtonX = width / 2;
  playButtonY = 4 * height / 5;
}

void draw () {
  //background(255);
  noCursor();

  //Magic pusheen adventure time! 
  pusheen.unicorn_Draw();
  pusheen.unicorn_Move();

  switch (state)
  {
  case START: 
    showWelcomeScreen();
    pusheen.unicorn_Draw();
    pusheen.unicorn_Move();
    break;
  case LEVEL1:
    background(bg1);
    pusheen.unicorn_Draw();
    pusheen.unicorn_Move();
    for (int i=0; i<box_list.size()-1; i++) {
      box_list.get(i).drawBox();
      box_list.get(i).moveBox();

      if (box_list.get(i).checkBoundaries()); 
      {
        box_list.get(i).bounce_box();
        box_list.get(i).drawBox();
        box_list.get(i).moveBox();
      }

      if (pusheen.check_Collision(box_list.get(i)))
      {
        box_list.remove(i);
      }

      /* else if (box_list.size()==1);
       {
       //println("WHAT HAVE YOU DONE WITH THE COOKIES");
       }
       */
    }//end of FOR (in Level1)
    break;

  case LEVEL2:
    background(bg2);
    pusheen.unicorn_Draw();
    pusheen.unicorn_Move();
    for (int i=0; i<box_list2.size()-1; i++) {
      box_list2.get(i).drawBox();
      box_list2.get(i).moveBox();

      if (box_list2.get(i).checkBoundaries()); 
      {
        box_list2.get(i).bounce_box();
        box_list2.get(i).drawBox();
        box_list2.get(i).moveBox();
      }

      if (pusheen.check_Collision(box_list2.get(i)))
      {
        box_list2.remove(i);
      }
    }//end of FOR (in Level2)
    break;

  case LEVEL3:
    background(bg3);
    pusheen.unicorn_Draw();
    pusheen.unicorn_Move();
    for (int i=0; i<box_list3.size()-1; i++) {
      box_list3.get(i).drawBox();
      box_list3.get(i).moveBox();

      if (box_list3.get(i).checkBoundaries()); 
      {
        box_list3.get(i).bounce_box();
        box_list3.get(i).drawBox();
        box_list3.get(i).moveBox();
      }

      if (pusheen.check_Collision(box_list3.get(i)))
      {
        box_list3.remove(i);
      }
    }//end of FOR (in Level3)
    break;

  case LEVEL4:
    background(bg4);
    pusheen.unicorn_Draw();
    pusheen.unicorn_Move();
    for (int i=0; i<box_list4.size()-1; i++) {
      box_list4.get(i).drawBox();
      box_list4.get(i).moveBox();

      if (box_list4.get(i).checkBoundaries()); 
      {
        box_list4.get(i).bounce_box();
        box_list4.get(i).drawBox();
        box_list4.get(i).moveBox();
      }

      if (pusheen.check_Collision(box_list4.get(i)))
      {
        box_list4.remove(i);
      }
    }//end of FOR (in Level4)
    break;

  case GAME_OVER:
    showGameOverScreen();
    break;
  }//ends state

  //CHANGING LEVELS!!!!: 
  if (state == LEVEL1);
  {
    if (box_list.size() == 1) {
      println("Box array empty, going to level 2");
      println(box_list.size());
      state = LEVEL2;
      //return;
    }
  }

  if (state == LEVEL2);
  {
    if (box_list2.size() == 1) {
      println("MEOW");
      println(box_list2.size());
      state = LEVEL3;
      //return;
    }
  }

  if (state == LEVEL3);
  {
    if (box_list3.size() == 1) {
      println("level 3");
      println(box_list3.size());
      state = LEVEL4;
      // return;
    }
  }

  if (state == LEVEL4);
  {
    if (box_list4.size() == 1) {
      println("level 4");
      println(box_list4.size());
      state = GAME_OVER;
      return;
    }
  }

} //END OF DRAW  

void showGameOverScreen()
{
  background(bg5);
  pusheen.unicorn_Draw();
  pusheen.unicorn_Move();

  String s = "Look's like there's a castle...but you've been too busy eating all the food! The princess is gone...";
  fill(50);
  textSize(20);
  fill(#6C5B7B);
  text(s, width/2, 500, 500, 500);
}

void showWelcomeScreen()
{
  background(bg6);

  showTitle();

  // Play button
  fill(#79BD9A);
  stroke(#3B8686);
  rectMode(CENTER);
  rect(playButtonX, playButtonY, playButtonWidth, playButtonHeight);
  fill(#A8DBA8);
  textSize(32);
  text("PLAY", width /2, 4 * height/5);

  // Instructions
  textSize(24);
  fill(#0B486B);
  text("Will he ever get there???", width/2, height/2 + 50);
}

void showTitle()
{
  // Title
  textAlign(CENTER, CENTER);
  textSize(48);
  fill(#6C5B7B);
  text("Pusheen Saves the Princess!", width/2, height/2);
}

//Boolean & mousePressed to check for player interaction with play button. Starts game. 
boolean isMouseOverPlayButton()
{
  // Half-wdith
  int hw = playButtonWidth / 2;
  // Half-height
  int hh = playButtonHeight / 2;
  // Returns true if mouse position is within the bounds of the button
  return mouseX >= playButtonX - hw && mouseX <= playButtonX + hw &&
    mouseY >= playButtonY - hh && mouseY <= playButtonY + hh;
}

void mousePressed()
{
  // Check if we are at the stat screen, and if the click is within the button bounds
  if (state == START && isMouseOverPlayButton())
  {
    // Now, we can start!
    state = LEVEL1;
    return;
  }
}

BOX CLASS: (What I called the food items)

class Box {

  //box position:
  float x;
  float y;

  int w = 20;
  int h = 20;

  //CHANGING image of items (item, skull, etc)
  // Each item is 40x40 px
  PImage item;

  //Getter functions
  float get_x() {
    return x;
  } //getter function for x position 
  float get_y() {
    return y;
  } //get y position
  int get_w() {
    return w;
  } //get width (of box)
  int get_h() {
    return h;
  } //get height

  //box velocity/speed:
  float x_velocity;
  float y_velocity;  

  //Constructor: 
  Box(float _x, float _y, float _x_velocity, float _y_velocity, String filename) {
    x = _x;
    y = _y; 
    x_velocity = _x_velocity;
    y_velocity = _y_velocity;
    item = loadImage(filename);
  }

  void drawBox() {
    // rect(x, y, w, h);
    image(item, x, y);
  }

  void moveBox() {
    x += x_velocity; 
    y += y_velocity;

    //  this.drawBox();
  }

  //checks to see if boxes go off the screen
  boolean checkBoundaries() {
    boolean out_of_bounds = false;
    //Out of screen (horizontal)
    if (x>(width+(1.5* w))|| x < (0 - (1.5*w))) {
      out_of_bounds = true;
    }

    //Out of screen (vertical)
    if (y>(height+(1.5*h)) || y < (0 - (1.5*h))) {
      out_of_bounds = true;
    }
    return out_of_bounds;
  }

  void bounce_box() {
    //makes box array bounce

    //left side of screen
    if (x<=0) {
      x_velocity*=-1;
    }

    //right side of screen
    if (x+50>=width) {
      x_velocity*=-1;
    }

    //top side of screen
    if (y<=0) {
      y_velocity*=-1;
    }

    //right side of screen
    if (y+50>=height) {
      y_velocity*=-1;
    }
  }
  //End of Box Class
}

PUSHEEN CLASS:

class Pusheen {

  //Pusheen image:
  int x; 
  int y;

  int w = 162; //width
  int h = 148; //height

  PImage unicorn;

  //Constructor:
  Pusheen(int _x, int _y, String filename) {
    x = _x; 
    y = _y; 
    unicorn = loadImage(filename);
  }

  void unicorn_Draw() {
    image(unicorn, x, y);
  }

  void unicorn_Move() {
    x = mouseX-(w/2);
    y = mouseY-(h/2);
  }

  //collision function goes here, 
  boolean check_Collision(Box temporary) {
    boolean signal = false;
    float temp_x = temporary.get_x();
    float temp_y = temporary.get_y();
    int temp_box_height = temporary.get_h();
    int temp_box_width = temporary.get_w();

    if (x < (temp_x + temp_box_width) && (x+w) > (temp_x ))    
      if (y < (temp_y + temp_box_height) && (y+h) > (temp_y )) {
        signal = true;
      }
      else {
        signal = false;
      }

    return signal;
  }  

  //end of pusheen class
}

 

 

Leave a Reply