Hi everyone!
I am working on a visual novel game project and I wanted to add a mini game(flappy birds) as a seperate challenge to enter the next chapter to the story. I am struggling with adding the game code that my teammate send me to my main code since they are 2 seperate classes.
We also wanted to change the some details for example setting a maximum score of 10 points and if that is reached the story is going to continue in the next chapter. I’ve tried to integrate the flappy birds code and the ideas into my main code a couple of times but i cant get it to work the way we imagined it. If you have any idea what i could change please let me know!
(we called flappy birds aquabounce since the game is supposed to be ocean themed also the rest of my chapters arent written yet)
Here is my main code:
Game game;
void setup()
{
size(1280, 720);
game = new Game();
}
void draw()
{
game.update();
}
/*void mousePressed()
{
game.mousePressed();
}
*/
void keyPressed()
{
game.keyPressed();
}
my game code:
class Game
{
//Einzelne Szenen
PImage qualle;
PImage meer;
boolean message1 = false;
boolean message2 = false;
boolean message3 = false;
boolean message4 = false;
boolean message5 = false;
boolean message6 = false;
boolean message7 = false;
boolean message8 = false;
boolean message9 = false;
boolean message10 = false;
private int gameState = 0;
private int messageCount=0;
//buttons
int rectX=1020, rectY=650;
int circleX=1100, circleY=50;
int rectSize=70;
int circleSize=70;
int currentColor;
color rectColor=color(165,137,193),circleColor=color(165,137,193);
color rectHighlight=color(221,212,232), circleHighlight=color(221,212,232);
boolean backHover = false;
boolean skipHover = false;
boolean homeHover = false;
//Sprechblasen
String nameL;
String nameR;
String messageL;
String messageR;
int index = 0;
int xL=200;
int yL=500;
int bubblewidthL=650;
int bubbleheightL=150;
int xR=1080;
int yR=500;
int bubblewidthR=-650;
int bubbleheightR=150;
Game()
{
qualle = loadImage("Qualle.png");
meer = loadImage("OffenesMeer.png");
for(int i = 0;i<3;i++){
p[i]=new pillar(i);
}
}
public void update()
{
background(#8BBCE5);
switch(this.gameState)
{
case 0:
this.startScreen();
break;
case 1:
this.gameLoop();
break;
case 2:
this.chapter1();
break;
case 3:
this.aquabounce();
break;
case 4:
this.chapter2();
break;
case 5:
this.quiz();
break;
case 6:
this.chapter3();
break;
case 7:
this.endScreen();
break;
}
}
private void startScreen()
{
stroke(0);
textAlign(CENTER);
textSize(15);
fill(255);
text(“Willkommen bei Jellyfish!”, width/2, height/2);
text(“Spiel starten mit ‘s’”, width/2, height/2+30);
}
//Die BUTTONS//
private void homeButton(){
update(mouseX, mouseY);
if(homeHover){
cursor(HAND);
fill(circleHighlight);
} else {
fill(circleColor);
cursor(ARROW);
}
ellipse(circleX,circleY,circleSize,circleSize);
textSize(20);
fill(0);
text(“Home”,circleX,circleY+3);
if(mousePressed&& mouseoverHome(circleX, circleY, circleSize)==true){
setup();
}
}
private void backButton(){
update(mouseX, mouseY);
if (backHover) {
cursor(HAND);
fill(rectHighlight);
} else {
cursor(ARROW);
fill(rectColor);
}
rect(rectX,rectY,rectSize,rectSize-30);
textSize(25);
fill(0);
text(“Back”,rectX+30,rectY+27);
if(mousePressed&& mouseoverBack(rectX,rectY,rectSize,rectSize)==true){
messageCount–;
index=0;
}
}
private void skipButton(){
update(mouseX, mouseY);
if (skipHover) {
fill(rectHighlight);
cursor(HAND);
} else {
cursor(ARROW);
fill(rectColor);
}
rect(rectX+100,rectY,rectSize,rectSize-30);
textSize(25);
fill(0);
text(“Skip”,rectX+130,rectY+27);
if(mousePressed&& mouseoverSkip(rectX,rectY,rectSize,rectSize)==true){
messageCount=+2;
index=0;
}
}
//Die TEXTBUBBLES//
private void textbubbleLeft(String nameL, String messageL, int xL, int yL, int bubblewidthL, int bubbleheightL)
{
noStroke();
fill(255);
rectMode(CORNER);
rect(xL,yL, bubblewidthL, bubbleheightL);
stroke(0);
fill(0);
textSize(20);
text(nameL,xL +30, yL+30);
textSize(15);
if(mousePressed){
index=messageL.length();
}else
{
text(messageL.substring(0,min(index,messageL.length())), xL + 200, yL + 60);
}
if (frameCount % 5 == 0) {
index = min(index+1, messageL.length());
}
}
private void textbubbleRight(String nameR, String messageR, int xR, int yR, int bubblewidthR, int bubbleheightR)
{
noStroke();
fill(255);
rectMode(CORNER);
rect(xR, yR, bubblewidthR, bubbleheightR);
stroke(0);
fill(0);
textSize(20);
text(nameR, xR-600,yR+30);
textSize(15);
if(mousePressed){
index=messageR.length();
}else
{
text(messageR.substring(0,min(index,messageR.length())), xR -400, yR + 50);
}
if (frameCount % 5 == 0) {
index = min(index+1, messageR.length());
}
}
//CHAPTERS//
private void chapter1()
{
background(meer);
if(messageCount==0){
image(qualle,30,350,250,250);
textbubbleLeft(“Jamz”,“Hi Frieda! Was schwimmt?”,xL,yL,bubblewidthL,bubbleheightL);
homeButton();
backButton();
skipButton();
}
else if(messageCount==1){
fill(255);
ellipse(1180,400,50,50);
textbubbleRight(“Frieda”,“Oh ja…Du glaubst nicht, was hier passiert ist…”,xR, yR, bubblewidthR, bubbleheightR);
homeButton();
backButton();
skipButton();
}
else if(messageCount==2){
image(qualle,30,350,250,250);
textbubbleLeft(“Jamz”,“Hmmm…Hau raus!Was liegt dir auf dem Herzen?”,xL,yL,bubblewidthL,bubbleheightL);
homeButton();
backButton();
skipButton();
}
else if(messageCount==3){
fill(255);
ellipse(1180,400,50,50);
textbubbleRight("Frieda","Irgendein Raudi randaliert bei Tonys Haus!",xR, yR, bubblewidthR, bubbleheightR);
homeButton();
backButton();
skipButton();
}
else if(messageCount==4){
fill(255);
ellipse(1180,400,50,50);
textbubbleRight("Frieda","Komm schnell! Wir brauchen deine Hilfe!!",xR, yR, bubblewidthR, bubbleheightR);
}
else if(messageCount==5){
image(qualle,30,350,250,250);
textbubbleLeft(“Jamz”,“Alles klar! Ich mache mich auf den Weg!”,xL,yL,bubblewidthL,bubbleheightL);
homeButton();
backButton();
skipButton();
}
else if(messageCount==6){
fill(255);
ellipse(1180,400,50,50);
textbubbleRight(“Frieda”,“Astrein! Bis denne Antenne!”,xR, yR, bubblewidthR, bubbleheightR);
homeButton();
backButton();
skipButton();
}
else if(messageCount==7){
stroke(255);
textAlign(CENTER);
textSize(25);
fill(255);
text(“Nächstes Kapitel mit ‘s’”, width/2, height/2-50);
}
}
//AQUABOUNCE//
private void aquabounce()
{
background(0);
if(end){
b.move();
}
b.drawBird();
if(end){
b.drag();
}
b.checkCollisions();
for(int i = 0;i<3;i++){
p[i].drawPillar();
p[i].checkPosition();
}
fill(0);
stroke(255);
textSize(32);
if(end){
rect(20,20,100,50);
fill(255);
text(score,30,58);
}else{
rect(150,100,200,50);
rect(150,200,200,50);
fill(255);
if(intro){
text(“Flappy Code”,155,140);
text(“Click to Play”,155,240);
}else{
text(“game over”,170,140);
text(“score”,180,240);
text(score,280,240);
}
}
if(endEnd==true){
background(0,255,255);
textAlign(CENTER);
textSize(20);
text("Congratulations!!!", width/2, height/2);
}
if(mousePressed){
b.jump();
intro=false;
if(end==false){
reset();
}
}
if(keyPressed){
b.jump();
intro=false;
if(end==false){
reset();
}
}
}
private void chapter2()
{
background(meer);
if(messageCount==0){
fill(255);
ellipse(120,530,50,50);
textbubbleLeft(“Jelly”,“kennt man sich”,xL,yL,bubblewidthL,bubbleheightL);
}
}
private void quiz()
{
background(255);
}
private void chapter3()
{
background(0);
}
private void endScreen()
{
stroke(255);
textAlign(CENTER);
textSize(15);
text(“GAME OVER!”, width/2, height/2);
text(“Spiel neustarten mit ‘r’”, width/2, height/2+30);
}
private void gameLoop()
{
}
//BUTTONS MOUSE INTERAKTION//
void update(int x, int y) {
if ( mouseoverHome(circleX, circleY, circleSize) ) {
homeHover = true;
backHover = false;
skipHover = false;
} else if ( mouseoverBack(rectX, rectY, rectSize, rectSize) ) {
backHover = true;
skipHover = false;
homeHover = false;
} else if ( mouseoverSkip(rectX+100,rectY,rectSize,rectSize-30) ) {
backHover = false;
skipHover = true;
homeHover = false;
} else {
homeHover = backHover =skipHover= false;
}
}
boolean mouseoverHome(int x, int y, int diameter){
float distance = dist(x, y, mouseX, mouseY);
if (distance < diameter / 2) {
return true;
} else {
return false;
}
}
boolean mouseoverBack(int x, int y, int width, int height){
if (mouseX >= x && mouseX <= x+width &&
mouseY >= y && mouseY <= y+height) {
return true;
} else {
return false;
}
}
boolean mouseoverSkip(int x, int y, int width, int height){
if (mouseX >= x && mouseX <= x+width &&
mouseY >= y && mouseY <= y+height) {
return true;
} else {
return false;
}
}
//KEY CONTROLLS//
public void keyPressed()
{
if (key == ‘s’)
{
this.gameState++;
messageCount=0;
}
if(key==CODED&&keyCode==RIGHT)
{
this.messageCount++;
index=0;
}
if(key==CODED&&keyCode==LEFT)
{
this.messageCount--;
index=0;
}
if (key == 'r' && this.gameState == 7)
{
setup ();
// messageCount++;
}
}
}
and the flappy birds code:
PImage qualle;
bird b = new bird();
pillar p = new pillar[3];
boolean end=false;
boolean endEnd = false;
boolean intro=true;
int score=0;
class bird{
float xPos,yPos,ySpeed;
bird(){
xPos = 250;
yPos = 400;
}
void drawBird(){
stroke(255);
noFill();
strokeWeight(2);
ellipse(xPos,yPos,20,20);
}
void jump(){
ySpeed=-10;
}
void drag(){
ySpeed+=0.4;
}
void move(){
yPos+=ySpeed;
for(int i = 0;i<3;i++){
p[i].xPos-=3;
}
}
void checkCollisions(){
if(yPos>800){
end=false;
}
for(int i = 0;i<3;i++){
if((xPos<p[i].xPos+10&&xPos>p[i].xPos-10)&&(yPos<p[i].opening-100||yPos>p[i].opening+100)){
end=false;
}
}
}
}
class pillar{
float xPos, opening;
boolean cashed = false;
pillar(int i){
xPos = 100+(i*200);
opening = random(600)+100;
}
void drawPillar(){
line(xPos,0,xPos,opening-100);
line(xPos,opening+100,xPos,800);
}
void checkPosition(){
if(xPos<0){
xPos+=(200*3);
opening = random(600)+100;
cashed=false;
}
if(xPos<250&&cashed==false){
cashed=true;
score++;
}
}
}
void reset(){
end=true;
score=0;
b.yPos=400;
for(int i = 0;i<3;i++){
p[i].xPos+=550;
p[i].cashed = false;
}
}
void endEnd(){
if (score >= 2) {
endEnd = true;
}
}
with kind regards,
madita