Hi there, Right now I am trying to figure out how I can make the ball bounce off the point where
the environment is. I am new to processing so this may be easy but I have asked around and it seems to be
a rather large problem.
Also the if mousePressed to change stage doesn't seem to work properly in the main menu the instructions and exit(); will not activate and if you press start game the ball moves without re-clicking.
Any help would be gratefully taken!
import processing.opengl.*;
PImage bg;
PImage startscreen;
PFont titlefont;
PFont menufont;
boolean start = false;
boolean inside;
int stage;
PVector ballPos, ballVel;
int score = 0;
int multiplier = 0;
int scoreincrement = 100;
int level = 1;
// Maybe change boxes to objects and them call them in to check for intersections?
void setup() {
ballPos = new PVector(275, 187, -30);
ballVel = new PVector(); // no speed
stage = 1;
size(550, 375, OPENGL, P3D);
rectMode(CENTER);
smooth();
titlefont = loadFont("Game-Over-250.vlw");
menufont = loadFont("Harabara-80.vlw");
bg = loadImage("leo.jpg");
startscreen = loadImage("start.jpg");
}
void boxes (int j, int k) {
rect(width/2, height/2, width -j, height-k);
}
void draw() {
if (stage==1) {
mainMenuStage();
}
if (stage==2) {
background(bg);
noStroke();
lights();
textFont(menufont, 18);
fill(0, 255, 255);
text("Score:", 125, 50);
text(score, 185, 50);
text("Level:", 350, 50);
text(level, 410, 50);
noFill();
strokeWeight(0.75);
stroke(50, 205, 50);
quad(195, 137.5, 195, 237.5, 50, 350, 50, 25);
quad(355, 137.5, 355, 237.5, 500, 350, 500, 25);
stroke(50, 180, 205);
boxes( 100, 50); //Outer box
stroke(50, 205, 50);
boxes( 190, 120);
boxes( 252, 170);
boxes( 308, 210);
boxes( 345, 240);
boxes( 375, 262);
stroke(205, 50, 50);
boxes( 390, 275); // Inner Box
stroke(50, 205, 50);
strokeWeight(0.75);
fill(255);
noStroke();
pushMatrix();
translate(ballPos.x, ballPos.y, ballPos.z);
sphere(28);
popMatrix();
noFill();
stroke(50, 50, 205);
strokeWeight(2);
rect(mouseX, mouseY, 125, 80);
// is ball hitting the paddle?
if ((ballPos.x > mouseX-63)
&& (ballPos.x < mouseX +63)
&& (ballPos.y > mouseY - 40)
&& (ballPos.z < mouseY + 40)) {
inside = true;
} else {
inside = false;
}
if (stage==3) {
background(startscreen);
text("Instructions", 200, 300);
text("The objective of the game is to hit the ball with your paddle and get the highest score possible!", 275, 300);