Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Why wont my game start??

$
0
0

Hello again! I'm sorry for posting so much, but I want to keep updated with the progress I make. So I have my homescreen working. I have my game here in the code too, but why isn't it playing after the homescreen hits the spacebar and it disappears? Any help is very appreciated.

____________Main Body______________

import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;

Minim minim;
AudioPlayer player;

Logo l;
final int stateGame  = 0;
final int stateHome = 1;
int state = stateHome;
int grid = 20;
int buttonA, buttonB, buttonC, buttonD;
int total = 0;
boolean startover = true;
boolean stopgame=false;
boolean buttonpressed;
boolean capture;
PFont Silom;
PImage Rink;
PImage BH;
PImage SC;
PVector Cup;
float x = 0;
float y = 0;
float xspeed = 1;
float yspeed = 0;
ArrayList<PVector> trail = new ArrayList<PVector>();

void setup()
{
  size(600, 631);
  l = new Logo();
  frameRate(8);
  pickLocation();
  Rink = loadImage("Rink.jpg");
  BH = loadImage("BH.png");
  SC = loadImage("SC.png");
  Silom = loadFont("Silom.vlw");
  background(Rink);

  minim = new Minim( this );

  player = minim.loadFile("CD.mp3");
  player.play();
  player.loop();
}

void draw()
{
  switch (state) {

  case stateHome:
    handleStateHome();
    break;

  case stateGame:
    handleStateGame();
    break;
  }
}
void handleStateGame() {
}
void pickLocation() {
  int across = width/grid;
  int down = height/grid;
  Cup = new PVector(floor(random(across)), floor(random(down)));
  Cup.mult(grid);
}
boolean capture(PVector pos) {
  float d = dist(x, y, pos.x, pos.y);
  if (d < 1) {
    return true;
  } else {
    return false;
  }
}
void show() {
  image(SC, x, y, grid, grid);
}

void dir(float x, float y) {
  xspeed = x;
  yspeed = y;
}

void death() {
  for (int i = 0; i < trail.size(); i++) {
    PVector pos = trail.get(i);
    float d = dist(x, y, pos.x, pos.y);
    if (d < 1) {
      state = stateHome;
      total = 0;
    }
  }
}

void update() {
  x = x + xspeed*grid;
  y = y + yspeed*grid;

  {
    x = constrain(x, 0, width-grid);
    y = constrain(y, 0, height-grid);
  }

  if (l.capture(Cup)) {
    pickLocation();
  }
  l.death();
  l.update();
  l.show();
}

void handleStateHome() {
  background(Rink);
  fill(0);
    if (buttonpressed) {
      fill(255, 255, 255, 0);
    } else {
      textFont(Silom, 20);
      text("Press the arrow keys to move around", 100, 330);
      textFont(Silom, 60);
      text("Catch the cup!", 70, 300);
      textFont( Silom, 20);
      text("Press Space to Begin", 180, 360);
    }
  }




void keyPressed() {

  switch (state) {

  case stateGame:
    keyPressedForStateGame();
    break;

  case stateHome:
    keyPressedForStateHome();
    break;
  }
}
void keyPressedForStateHome() {
  if (keyCode == ' ');
    buttonpressed = true;
}
void keyPressedForStateGame() {
  if (key == CODED)
  {
    if (keyCode == UP) {
      l.dir(0, -1);
    } else if (keyCode == DOWN) {
      l.dir(0, 1);
    } else if (keyCode == RIGHT) {
      l.dir(1, 0);
    } else if (keyCode == LEFT) {
      l.dir(-1, 0);
    }
  }
}

_____________________Logo________________________

 class Logo {
  float x = 0;
  float y = 0;
  float xspeed = 1;
  float yspeed = 0;
  int total = 0;
  ArrayList<PVector> tail = new ArrayList<PVector>();

  Logo() {
  }

  boolean capture(PVector pos) {
    float d = dist(x, y, pos.x, pos.y);
    if (d < 1) {
      total++;
      return true;
    } else {
      return false;
    }
  }
  void show() {
    fill(255);
    for (PVector v : tail) {
      rect(v.x, v.y, grid, grid);
    }
    rect(x, y, grid, grid);
  }

  void dir(float x, float y) {
    xspeed = x;
    yspeed = y;
  }

  void death() {
    for (int i = 0; i < tail.size(); i++) {
      PVector pos = tail.get(i);
      float d = dist(x, y, pos.x, pos.y);
      if (d < 1) {
        state = stateHome;
        total = 0;
      }
    }
  }

  void update() {
    x = x + xspeed*grid;
    y = y + yspeed*grid;

    x = constrain(x, 0, width-grid);
    y = constrain(y, 0, height-grid);
  }
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles