xxxxxxxxxx
Player ball;
Input inputSystem;
float trippymode = prompt('Weird but fun mode y/n');
ArrayList<Platform> platforms = new ArrayList<Platform>();
int spawnCounter = 0;
float progression = 20;
float score = 0, goal = 120;
float combo = 1;
float deathCounter = 0;
String gameMode; //MAIN_MENU, PLAY, GAME_OVER
float randomSeed, randomSeed2;
void setup () {
size(800, 800, P3D);
background(50);
randomSeed = random(0, 10);
randomSeed2 = random(0, 10);
ball = new Player();
inputSystem = new Input();
stroke(0, 255, 0);
platforms.add(new Platform(0, 1500, 1000, 8000));
platforms.get(0).createdAnimTimer = 16;
gameMode = "MAIN_MENU";
loadSplash("superbounce");
}
void draw () {
if (!programLoaded) {
int splashLoadCode = splashLoad();
if (splashLoadCode == 0) loadingSquares();
if (splashLoadCode != 2) return;
}
if (keyPressed && (key == 'r' || key == 'R')) {
restart();
}
switch(gameMode) {
case "MAIN_MENU":
mainMenu();
break;
case "GAME":
game();
break;
case "GAME_OVER":
gameOver();
break;
}
}
void keyPressed () {
inputSystem.Log(key);
}
void keyReleased () {
inputSystem.Unlog(key);
}
void mainMenu () {
gameMode = "GAME";
}
void game () {
lights();
colorMode(HSB);
background((50 + (score * 5)) % 255, 255, 100);
colorMode(RGB);
camera(ball.pos.x + map(ball.pos.x, -100, 100,13, -13), ball.pos.y-400, ball.pos.z-800, ball.pos.x, ball.pos.y - map(ball.pos.y, 0, 200, 0, 50), ball.pos.z, 0, 1, 0);
screenshakeEffect();
ball.render();
ball.checkIfDied(platforms);
ball.physics();
for (int i = 0; i < platforms.size(); i++) {
if (millis() > 2000) platforms.get(i).update(progression);
platforms.get(i).render();
if (platforms.get(i).pos.z < -5000) {
platforms.remove(i);
i--;
}
}
spawnCounter ++;
progression += 0.02;
if (spawnCounter > 15) {
spawnCounter = 0;
platforms.add(new Platform(random(-1500, 1500), 6000, random(1000, 2000), random(1000, 2000)));
}
// region
pushMatrix();
translate(0, 30, 0);
noFill();
stroke(0, 255, 0);
box(3000, 5, 5000);
popMatrix();
//lava
if(trippymode == "y"){
pushMatrix();
translate(0, 120, 0);
colorMode(HSB);
colorMode(RGB);
texture(lava); // Apply the lava texture to the box.
noStroke();
box(3000, 1, 5000);
}
else{
pushMatrix();
translate(0, 120, 0);
colorMode(HSB);
colorMode(RGB);
fill(255,0,0);
//noStroke();
stroke(255, 0, 0);
box(3000, 1, 5000);
popMatrix();
}
popMatrix();
//constraining ball to region
float lastBallX = ball.pos.x, lastBallZ = ball.pos.z;
ball.pos.x = constrain(ball.pos.x, -1500, 1500);
ball.pos.z = constrain(ball.pos.z, -2500, 2500);
if (ball.pos.x != lastBallX)
ball.vel.x = 0;
if (ball.pos.z != lastBallZ)
ball.vel.z = 0;
if (inputSystem.right())
ball.roll(-1, 0);
if (inputSystem.left())
ball.roll(1, 0);
if (inputSystem.up())
ball.roll(0, 1);
if (inputSystem.down())
ball.roll(0, -1);
if (inputSystem.space())
ball.jump();
else
combo = 1;
// Ball death checking
if (ball.died) {
deathCounter += 0.1;
if (deathCounter > 15) {
gameMode = "GAME_OVER";
}
}
pushMatrix();
textSize(30);
fill(255);
translate(ball.pos.x - 70, ball.pos.y + 30, ball.pos.z);
rotateY(PI);
if (score >= goal) {
goal = score;
fill(255, 215, 0);
}
text("Score: " + (int)score + "/" + (int)goal, 0, 0);
textSize(70);
if (combo > 1)
text("x" + nf(combo, 0, 2), 70, 110);
popMatrix();
colorMode(HSB);
for (float x = -6000; x < 6000; x += 2000) {
for (float y = -2000; y < 2000; y += 2000) {
float seedA = abs((x / 321) + (y / 456) + randomSeed + (millis() / 250)) % 10; //number between 0 - 10
float seedB = abs((x / 279) + (y / 641) + randomSeed2 + (millis() / 400)) % 10; //number between 0 - 10
if (seedA > 10/2) seedA = 10-seedA;
if (seedB > 10/2) seedB = 10-seedB;
pushMatrix();
translate(x, y, 8000 - (seedB * 200));
rotateX(seedB * 0.3 * combo);
stroke((((seedA / 10) * 255) + (score * 2)) % 255, 255, 255);
noFill();
box(seedA * 700);
fill((((seedA / 10) * 255) + (score * 2)) % 255, 255, 255);
noStroke();
box(seedA * 600);
popMatrix();
}
}
colorMode(RGB);
}
void gameOver () {
textSize(70);
if (score >= goal) {
fill(255, 215, 0);
} else {
fill(255);
}
textAlign(CENTER);
text((score >= goal ? "+++ You have won! +++" : "GAME OVER") + "\n" + "Score: " + (int)score + "\n" + "Press r to restart", width/2, height/2);
}
void restart () {
platforms.clear();
ball = new Player();
platforms.add(new Platform(0, 1500, 1000, 8000));
platforms.get(0).createdAnimTimer = 1;
spawnCounter = 0;
progression = 20;
score = 0;
combo = 1;
deathCounter = 0;
textAlign(LEFT);
gameMode = "GAME";
}
void screenshakeEffect () {
if (ball.shakeLevel > 0) {
float ballShakeHeight = 20;
translate(random(-ball.shakeLevel * ballShakeHeight, ball.shakeLevel * ballShakeHeight),
random(-ball.shakeLevel * ballShakeHeight, ball.shakeLevel * ballShakeHeight),
0);
ball.shakeLevel -= 0.1;
} else {
ball.shakeLevel = 0;
}
}