A 3D game.

I have searched the internet looking for a 3D game created in processing. All I have found are lame games. Has anyone created or found a game that I can try out. If its a non-lame game, I may decide to make a gameplay video for it on youtube (with giving credit to the creator obviously). Thanks

Comments

  • // 3D pong
    // still lot of room for improvement.
    // ESC is off in the menu, use q instead.
    //
    
    // images 
    PImage bg;
    PImage startscreen;
    // fonts 
    PFont titlefont;
    PFont menufont;
    // game logic (during game)
    boolean start;
    boolean gameOver;
    boolean autoPlay=false;
    boolean inside; // inside paddle 
    // stage / state:
    // We give the stages proper names 
    // so everything is better readable. 
    final int stageMenu=1; // constants
    final int stageGame=2;
    final int stageInstructions=3;
    int stage; // current stage 
    // 
    PVector boxSize; // containing box / game field 
    PVector ballPos; // ball
    PVector ballVel;
    PVector paddlePos = new PVector(); // paddle
    //
    int score = 0;
    int multiplier = 0;
    int scoreincrement = 100;
    int level = 1;
    
    // ------------------------------------------------------------------------
    void setup() {
      // (only once)
      size(550, 375, P3D);
      titlefont = createFont("Game-Over-250.vlw", 14);
      menufont = createFont("Harabara-80.vlw", 14);
      bg = loadImage("leo.jpg");
      startscreen = loadImage("start.jpg");
      stage = 1;
      sphereDetail(10);
      // containing box / game field  
      boxSize = new PVector();  // size
      boxSize.x = 480;  // size
      boxSize.y = 320;   // size
      boxSize.z = 750-30; // size 
      // init game
      reset();
      textMode(SHAPE); 
      println ("setup() is done.");
    }
    
    void reset() {
      // reset ball (multiple times)
      ballPos = new PVector(275, 187, -31);
      ballVel = new PVector(); // no speed
      // reset game logic 
      start = false; 
      gameOver=false;
      rectMode(CENTER);
      smooth();
      textSize(22);
    }
    
    // ------------------------------------------------------------------------
    
    void draw() {
      //
      switch (stage) {
      case stageMenu:
        // menu
        functionForStageMenu();
        break;
      case stageGame:
        // Game
        functionForStageGame();
        break;
      case stageInstructions:
        // Instructions
        functionForStageInstructions ();
        break;
      default:
        println ("Big error 219 ####; stage being "
          + stage);
        exit();
        break;
      } // switch
      //
    } // func
    // -------------------------------------
    void functionForStageMenu()
    { // menu
      fill(255, 0, 0);
      //noFill();
      // background(startscreen);
      background(0);
      textFont(titlefont, 60);
      textAlign(CENTER);
      text("3D Pong", 275, 100);
      textFont(menufont, 30);
      text(" X Start Game", 275, 200);
      text("  X Instructions", 275, 250);
      text("X Quit Game", 275, 300);
    }
    // ---------------------------------------
    void functionForStageInstructions () {
      // instructions 
      //background(startscreen);
      background(0);
      textSize(17);  
      textFont(titlefont, 60);
      textFont(menufont, 30);
      text("Instructions", width/2, 100);
      textFont(menufont, 20);
      text("The objective of the game is to\n"+
        "hit the ball with your paddle and get\n"+
        "the highest score possible!\n"+
        "Hit ESC to go from Game back to Menu.\n"+
        "Hit q in the menu to quit.\n"+
        "To restart when it's \"Game Over\" click mouse twice.", 275, 150);
    }
    // ------------------------------------
    void functionForStageGame() {
      // Game
      //background(bg);
      background(0);
    
      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);
      noStroke();
      //
      // ball
      pushMatrix();
      fill(255, 0, 0);
      translate(ballPos.x, ballPos.y, ballPos.z);
      sphere(28);  // ball 
      popMatrix();
      // 
      // box (game field) 
      pushMatrix();
      stroke (255, 266, 2);
      noFill();
      translate(width/2, height/2, -boxSize.z/2); // pos 
      box( boxSize.x, boxSize.y, boxSize.z);  // size 
      popMatrix();
      //
      // paddle 
      pushMatrix();
      noFill();
      stroke(50, 50, 205);
      strokeWeight(2);
      // rect(mouseX, mouseY, 125, 80);
      noFill();
      //
      // get paddle pos
      if (autoPlay) {
        //if (ballPos.z>-200) {
        paddlePos.x=ballPos.x; 
        paddlePos.y=ballPos.y;
        //}
      } else 
      {
        paddlePos.x=mouseX;
        paddlePos.y=mouseY;
      }
      translate(paddlePos.x, paddlePos.y, -31); // pos 
      box( 125, 80, 2 );      // size
      strokeWeight(1); 
      popMatrix();
      //
      // 
      // is ball hitting the paddle?
      if ((ballPos.x > paddlePos.x-63)
        && (ballPos.x < paddlePos.x +63)
        && (ballPos.y > paddlePos.y - 40)
        && (ballPos.y < paddlePos.y + 40)) {  
        inside = true;
      } else {
        inside = false;
      }
      //
      // println(ballPos.z);
      ///////////////////////
      if (start) {
        if (!gameOver) {
          // actual movement 
          ballPos.x += ballVel.x;
          ballPos.y += ballVel.y;
          ballPos.z += ballVel.z;
          // 
          // Ball bouncing off and returning.
          // x
          if ( ballPos.x < width/2-boxSize.x/2)
          {
            // bounce off left side
            ballVel.x = abs(ballVel.x);
          } else if ( ballPos.x > width/2+boxSize.x/2)
          {
            // bounce off right side
            ballVel.x = -1 * abs(ballVel.x);
          }
          // y 
          if ( ballPos.y <  height/2-boxSize.y/2)
          {
            // bounce off left side
            ballVel.y = abs(ballVel.y);
          } else if ( ballPos.y > height/2+boxSize.y/2)
          {
            // bounce off right side
            ballVel.y = -1 * abs(ballVel.y);
          } 
          // z
          if (ballPos.z <= -750) {
            // the back of the box; later: did enemy hit the ball?
            ballVel.z = abs(ballVel.z);
          } else if (ballPos.z >= -30 && inside) {
            // we hit the ball
            ballVel.z = -1 * abs(ballVel.z) * 1.01;
            // a small random: 
            ballVel.x +=random(-1, 1);  // changed to +=
            ballVel.y +=random(-1, 1);  // changed to += 
            int scoreup = scoreincrement + multiplier;
            score += scoreup;
            multiplier += 10;
          } else if (ballPos.z >= -30 && !inside) {
            ballPos.z = -30;
            // switch to a game-over stage here
            gameOver=true;
          }
        }
      } // if 
      // 
      if (gameOver) {
        ballPos.z = -30;
        textFont(titlefont, 77);
        fill(255, 0, 0);
        hint(DISABLE_DEPTH_TEST);
        resetMatrix();
        camera();
        noLights();
        text("GAME OVER", 275, 200);
        hint(ENABLE_DEPTH_TEST);
      }
    } // func
    // -------------------------------------
    void mouseClicked() {
      // what happens when mouse is clicked=
      // That is also depending on the stage: 
      switch (stage) {
      case stageMenu:
        analyzeMouseInMenu();
        break;
      case stageGame:
        if (!start) {
          // start level now 
          start = true;
          ballVel.z = random(-4.9, -6.9);
          ballVel.x = random(4, 5);
          ballVel.y = random(4, 5.5);
        } // if
        else if (gameOver) {
          // stay in the game but reset it
          reset();
          start=false;
          // OR go back to menu (not as cool)
          // stage = 1;
        } // else if 
        else { // ?????????????
          //      if  (ballVel.z == 0) {
          //        ballVel.z = -14;
          //      }
        }
        break;
      case stageInstructions:
        // back to menu
        stage = stageMenu;
        break;
      default:
        // error
        println ("Big error 734 +++++++++++++++++++++++++++++");
        exit();
        break;
      } // switch
      //
    } // func
    //
    void analyzeMouseInMenu() {
      ////////////////////////
      //
      if ( mouseX > 18
        && mouseX < 185 + 180 +300
        && mouseY > 170
        && mouseY < 170 + 30)
      {
        stage = stageGame;
      } else if ( mouseX > 18
        && mouseX < 185 + 230 +333
        && mouseY > 170 + 50
        && mouseY < 170 + 50+50
        ) {
        stage = stageInstructions;
      } else if ( mouseX > 18
        && mouseX < 185 + 280 +333
        && mouseY > 170 + 80
        && mouseY < height
        ) {
        println ("Quit.");
        exit();
      }
    }
    //
    void keyPressed() {
      switch (stage) {
      case stageMenu:
        // menu
        //
        // ESC key is killed  
        if (key==ESC) {
          // kill ESC
          key=0;
        } else if (key=='q') {
          // quit
          exit();
        } else {
          // do nothing
        }
        break;
      case stageGame:
        // Game
        // ESC key brings us back 
        if (key=='a') {
          autoPlay=!autoPlay;
        } else if (key==ESC) {
          // back to menu
          key=0;
          stage = stageMenu;
        }
        break;
      case stageInstructions:
        // Instructions
        // any key brings us back 
        // kill ESC 
        if (key==ESC) {
          key=0;
        }
        stage = stageMenu;
        break;
      default:
        println ("Big error 293 #######################; stage being "
          + stage);
        exit();
        break;
      } // switch
      //
    }
    // ------------------------------------------------------------------------
    //void boxes (int j, int k) {
    //  rect(width/2, height/2, width -j, height-k);
    //}
    
    // 
    
Sign In or Register to comment.