We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi,
I have made a simple game (flappy birds copy) to try and teach myself the basics of processing. I am currently trying to make a start screen, so that when I click start the game starts. I tried using different function names and calling theta different times to make this possible. However, it isn't working. Is this the way it should be done or is there a better way?
every time i press start on the game start screen it goes to the main game section BUT it cuts off once I release the button. Ill copy and paste my code here and you can try play it, you'll see what I mean `int xPos=650; int xDir=3; int yPos=150; int yDir=3; int Score = 0; boolean gameover = false;
void setup() { size(667,375); background(150,170,255);
fill(0); textSize(30); } void draw(){
//Start Screen
background(45);
fill(255,10,10); text("Glen's Game",250,150); fill(235); rect(240,165,200,50); fill(150); text("Start",305,200);
if(mousePressed && (240<mouseX && mouseX<440) && (165<mouseY && mouseY<215) ){ GameStart(); }
}
void GameStart(){
background(150,170,255);
fill(255);
text("Score = "+Score, 500,50);
fill(112,233,165);
ellipse(150,yPos,25,25);
yPos+=4;
fill(255);
rect(xPos,0,50,100);
fill(100);
rect(xPos,275,50,100);
xPos-=3;
}
void GameOver(){
if(((0375))
{
background(45);
fill(255,10,10);
text("GAME OVER",250,150);
fill(200);
text("Try Again",267,200);
}
}
void Scoring(){ if(xPos==152){ Score++ ; } } void MousePressed(){ if(mousePressed){ yPos= yPos - 12; } if(xPos<1){ xPos=650; } }`
Help much appreciated :)
Answers
http://forum.processing.org/two/discussion/8045/how-to-format-code-and-text
http://forum.processing.org/two/discussion/3580/flappy-code
you need a var
boolean startScreen = true;
(bit like gameover) so that you know when to display your start screenwhen the mouse is Pressed set startScreen to
false
and indraw()
when it'strue
show start scren otherwise normal playand in normal play distinguish between gameover and not gameover....
;-)
Hi Chrisir,
so do you mean have void draw calling the different functions like:
Also does the code feature ever work on this forum? it never works for me.
Re-read the instructions. You must not click on C then paste, but you must paste the code, select it, then click on C.
Here is the code I have changed, I got the start screen to work but it keeps crashing when I die or going straight back to start screen rather than the game over screen. Can anyone assist? por favor
"time out occurred while waiting on packet"
keeps appearing...
Ha! That's a good one! Great bug! Very awesome!
Your code is getting stuck in an endless loop.
See, draw() calls StartScreen() which calls GamePlay() which calls GameOver() which calls StartScreen() which callsGamePlay() which calls GameOver() which calls StartScreen() which callsGamePlay() which calls GameOver() which calls StartScreen() which callsGamePlay() which calls GameOver() which calls StartScreen() which callsGamePlay() which calls GameOver() which calls StartScreen() which callsGamePlay() which calls GameOver() which calls StartScreen() which callsGamePlay() which calls GameOver() which calls StartScreen() which callsGamePlay() which calls GameOver() which calls StartScreen() which callsGamePlay() which calls GameOver() which calls StartScreen() which callsGamePlay() which calls GameOver() which calls StartScreen() which callsGamePlay() which calls GameOver() which calls StartScreen() which callsGamePlay() which calls GameOver() which calls StartScreen() which callsGamePlay() which calls GameOver() which calls StartScreen() which callsGamePlay() which calls GameOver() which calls StartScreen() which callsGamePlay() which calls GameOver() which calls StartScreen() which callsGamePlay() which calls GameOver() which calls StartScreen() which calls....
Instead of having conditionals call other functions, you need to have the game go into a different mode, or state, when certain conditions are met. You were almost there with the boolean variables...
Also you're all over the place with MousePressed and mousePressed when really you only need mousePressed().
yes---
btw
since only one of then can be true at a time:
you might as well have one int "state of the program" that can be 0, 1 or 2.
Thus it is clear, that only one state can be active at the time.
You can also give 0, 1 or 2 names and use them.
then you can use
switch(stateOfTheProgram)
indraw()
Hey I'm not really sure what you mean by using the 0,1 and 2's to vary the states of the program. I have made a proper game now and I am having this problem again. I can get the game to play and go to the game over screen but when I press try again it goes back to the main menu.
The problem is when i go to play the game again it just goes starlight to the game over screen and I dunno why :/
any ideas?
Probably the obvious: you set the default variable values before setup. This only ever gets called once.
So create a separate function called resetVariables. Set the variable defaults using this, by calling it at setup and on game over. This will then reset all variables - including
gameover
- to the default starting state...I have tried what you said but it still skips past the playing(); function the second time around and just goes straight to game over :/ I don't understand why it works first time round but not the second??
Where's the updated code? Do
println(gameover)
where appropriate to check it has actually been reset...This is what I done, maybe I haven't followed your instructions correctly but as far as Im aware I have. not sure why it still isn't working. :/
You haven't done I what suggested. You need to reset every variable that appears before setup that will later be changed, including the position of the player and bad guys. Otherwise at start of next game player is already dead = gameover... To avoid duplication declare variables before setup. Set their values using a function. Call this function at setup and at restart...
An online game example which calls createBalloons() in order to restart the game: :D
http://studio.ProcessingTogether.com/sp/pad/export/ro.9V7R1wu55fOiN/latest
Got ya now blindfish! It was because I wasn't resetting the coordinates of the mines meaning when I started again it was detecting a collision straight away taking me to the game over screen! haha