Game Level Issues!

edited June 2015 in Questions about Code

Hi, I'm very new to programming and I need to create a game for my uni assignment. And the due date is on the 16th of June! The code is written by Ben KtBYTE. I'm experiencing problem with creating a new level (the game is similar to flappy bird) and to move to the next level the player have to pass about 10 pillars. The next level will be more difficult by increasing the pillars'movement'. Thanks in advance!

import ddf.minim.*; import ddf.minim.analysis.*;

Minim minim; AudioPlayer song;

//load images from web// PImage backgroundImg =loadImage("http://i.imgur.com/5I3ZhOZ.png"); PImage dogImg =loadImage("http://www.pixeljoint.com/files/icons/flycorgi.gif"); PImage pillarImg =loadImage("http://i.imgur.com/4SUsUuc.png"); PImage startImg=loadImage("https://i.imgur.com/InWqdRD.png"); int gamestate = 1;//start game from startscreen// int score = 0;//to record the score// int highScore = 0;//keep track of high scores// int x = -200, y, vd = 0; //position and velocity of the dog// int px[] = new int[2];//pillar x position, integer is set to 2 because there's only two pillars in the game// int py[] = new int[2];//pillar y position, integer is set to 2 because there's only two pillars in the game// int level;

void setup() { size(600, 800);//size of the background/ canvas// fill(0);//text colour is set to black// textSize(30); //size of text is set to 40// textAlign(CENTER);

minim = new Minim(this); song = minim.loadFile("music.wav", 1024); song.loop(); }

void draw() { //runs 60 times a second// if (gamestate == 0) { imageMode(CORNER);//image position is set to corner// image(backgroundImg, x, 0);//this is the first background and is set to the right side of the canvas// image(backgroundImg, x+backgroundImg.width, 0);//background is set to the left side of the first background image// x -= 3;//background is set to move// vd = 1;//setting the gravity of the dog// y += vd;//velocity of the dog falling// if (x == -1800) x = 0;//wraps the screen around according to the width of the background image// for (int i = 0; i < 2; i++) { imageMode(CENTER);//pillars position to center// image(pillarImg, px[i], py[i] - (pillarImg.height/2+100));//position both the pillars up and down and shift them by a 100 to create space in between the pillars// image(pillarImg, px[i], py[i] + (pillarImg.height/2+100));//position both the pillars up and down and shift them by a 100 to create space in between the pillars// if (px[i] < 0) {//if the pillar have passed left this is to wrap it around// py[i] = (int)random(200, height-200); px[i] = width;//x position is set to right side of the screen// } if (px[i] == width/2) highScore = max(++score, highScore);//everytime the x position passed the pillar the score increase by 1// if (y>height||y<0||(abs(width/2-px[i])<25 && abs(y-py[i])>100)) gamestate=0;//if dog touch the pillar or goes of the screen, the player loses// //also the distance between the dog and the pillar is small and the distance on the y-axis is small// px[i] -= 3;//pillars is set to move// } image(dogImg, width/2, y); text(""+score, width/2, 600);//text of the score// text("Level 1", width/2, 650);//text of the level// } else if (gamestate==1) { imageMode(CENTER);//startscreen is set to center// image(startImg, width/2, height/2); text("High Score: "+highScore, width/2, 600);//high score can be seen when the game is reset// text("Press ENTER to start ", width/2, 550);//using ENTER key to start// } if (gamestate == 0) { if (score >= 5) { for (int i = 0; i < 2; i++) { imageMode(CENTER);//pillars position to center// image(pillarImg, px[i], py[i] - (pillarImg.height/2+100));//position both the pillars up and down and shift them by a 100 to create space in between the pillars// image(pillarImg, px[i], py[i] + (pillarImg.height/2+100));//position both the pillars up and down and shift them by a 100 to create space in between the pillars// if (px[i] < 0) {//if the pillar have passed left this is to wrap it around// py[i] = (int)random(200, height-200); px[i] = width;//x position is set to right side of the screen// } if (px[i] == width/2) highScore = max(++score, highScore);//everytime the x position passed the pillar the score increase by 1// if (y>height||y<0||(abs(width/2-px[i])<25 && abs(y-py[i])>100)) gamestate=0;//if dog touch the pillar or goes of the screen, the player loses// //also the distance between the dog and the pillar is small and the distance on the y-axis is small// px[i] -= 4;//pillars is set to move// }

}
}

}

void keyPressed() { if (keyCode == UP) { y -= 80;//allows the dog to 'skip' when mouse is clicked// } if (keyCode == DOWN) { y += 80;//allows the dog to 'skip' when mouse is clicked// }

if (gamestate==1) {//if is at the start screen// px[0] = 600;//making sure the pillars do not overlap// py[0] = y = height/2;//making sure the pillars do not overlap// px[1] = 900;//making sure the pillars do not overlap// py[1] = 600;//making sure the pillars do not overlap// x = gamestate = 0; score = 0;//the dog starts at x=0// }

} void mousePressed() { if (gamestate==0) { } if (gamestate==1) { px [0] = 600; py [0] = y = height/2; px [1] = 900; py [1] = 600; x = gamestate = 0; score = 0; }

}

Tagged:

Answers

  • import ddf.minim.*; import ddf.minim.analysis.*;

    Minim minim; AudioPlayer song;

    //load images from web// PImage backgroundImg =loadImage("http://i.imgur.com/5I3ZhOZ.png"); PImage dogImg =loadImage("http://www.pixeljoint.com/files/icons/flycorgi.gif"); PImage pillarImg =loadImage("http://i.imgur.com/4SUsUuc.png"); PImage startImg=loadImage("https://i.imgur.com/InWqdRD.png"); int gamestate = 1;//start game from startscreen// int score = 0;//to record the score// int highScore = 0;//keep track of high scores// int x = -200, y, vd = 0; //position and velocity of the dog// int px[] = new int[2];//pillar x position, integer is set to 2 because there's only two pillars in the game// int py[] = new int[2];//pillar y position, integer is set to 2 because there's only two pillars in the game// int level;

    void setup() {
      size(600, 800);//size of the background/ canvas//
      fill(0);//text colour is set to black//
      textSize(30); //size of text is set to 40// 
      textAlign(CENTER);
    
      minim = new Minim(this);
      song = minim.loadFile("music.wav", 1024);
      song.loop();
    }
    void draw() { //runs 60 times a second//
      if (gamestate == 0) {
        imageMode(CORNER);//image position is set to corner//
        image(backgroundImg, x, 0);//this is the first background and is set to the right side of the canvas//
        image(backgroundImg, x+backgroundImg.width, 0);//background is set to the left side of the first background image//
        x -= 3;//background is set to move//
        vd = 1;//setting the gravity of the dog//
        y += vd;//velocity of the dog falling//
        if (x == -1800) x = 0;//wraps the screen around according to the width of the background image//
        for (int i = 0; i < 2; i++) {
          imageMode(CENTER);//pillars position to center//
          image(pillarImg, px[i], py[i] - (pillarImg.height/2+100));//position both the pillars up and down and shift them by a 100 to create space in between the pillars//
          image(pillarImg, px[i], py[i] + (pillarImg.height/2+100));//position both the pillars up and down and shift them by a 100 to create space in between the pillars//
          if (px[i] < 0) {//if the pillar have passed left this is to wrap it around//
            py[i] = (int)random(200, height-200);
            px[i] = width;//x position is set to right side of the screen//
          }
          if (px[i] == width/2) highScore = max(++score, highScore);//everytime the x position passed the pillar the score increase by 1//
          if (y>height||y<0||(abs(width/2-px[i])<25 && abs(y-py[i])>100)) gamestate=0;//if dog touch the pillar or goes of the screen, the player loses//
          //also the distance between the dog and the pillar is small and the distance on the y-axis is small//
          px[i] -= 3;//pillars is set to move//
        }
        image(dogImg, width/2, y);
        text(""+score, width/2, 600);//text of the score//
        text("Level 1", width/2, 650);//text of the level//
      } else if (gamestate==1) {
        imageMode(CENTER);//startscreen is set to center//
        image(startImg, width/2, height/2);
        text("High Score: "+highScore, width/2, 600);//high score can be seen when the game is reset//
        text("Press ENTER to start ", width/2, 550);//using ENTER key to start//
      }
      if (gamestate == 0) {
        if (score >= 5) {
          for (int i = 0; i < 2; i++) {
            imageMode(CENTER);//pillars position to center//
            image(pillarImg, px[i], py[i] - (pillarImg.height/2+100));//position both the pillars up and down and shift them by a 100 to create space in between the pillars//
            image(pillarImg, px[i], py[i] + (pillarImg.height/2+100));//position both the pillars up and down and shift them by a 100 to create space in between the pillars//
            if (px[i] < 0) {//if the pillar have passed left this is to wrap it around//
              py[i] = (int)random(200, height-200);
              px[i] = width;//x position is set to right side of the screen//
            }
            if (px[i] == width/2) highScore = max(++score, highScore);//everytime the x position passed the pillar the score increase by 1//
            if (y>height||y<0||(abs(width/2-px[i])<25 && abs(y-py[i])>100)) gamestate=0;//if dog touch the pillar or goes of the screen, the player loses//
            //also the distance between the dog and the pillar is small and the distance on the y-axis is small//
            px[i] -= 4;//pillars is set to move//
          }
        }
      }
    }
    void keyPressed() {
      if (keyCode == UP) {
        y -= 80;//allows the dog to 'skip' when mouse is clicked//
      }
      if (keyCode == DOWN) {
        y += 80;//allows the dog to 'skip' when mouse is clicked//
      }
    
      if (gamestate==1) {//if is at the start screen//
        px[0] = 600;//making sure the pillars do not overlap//
        py[0] = y = height/2;//making sure the pillars do not overlap//
        px[1] = 900;//making sure the pillars do not overlap//
        py[1] = 600;//making sure the pillars do not overlap//
        x = gamestate = 0;
        score = 0;//the dog starts at x=0//
      }
    }
    void mousePressed() {
      if (gamestate==0) {
      }
      if (gamestate==1) {
        px [0] = 600;
        py [0] = y = height/2;
        px [1] = 900;
        py [1] = 600;
        x = gamestate = 0;
        score = 0;
      }
    }
    
    
  • edited June 2015

    The code is written by Ben KtBYTE.

    you are handing in a code by somebody else combined with our code for the level management....?

    This is an interesting university....

    ;-)

  • yea i did wrote the code is written by Ben KtByte

Sign In or Register to comment.