0 Members and 2 Guests are viewing this topic.
public class Player { //declares field variables for position, velocity, //and the number corresponding to the players color private int x; private int y; private int vel_x; private int vel_y; private int colorNum; //declares field variables so the object knows if it //has won and if the game is over private boolean won; private boolean gameOver; //declares field variables that store the initial //position and velocity of the player private int init_x; private int init_y; private int init_velx; private int init_vely; //declares integer constants that correspond to colors final private int RED = 0; final private int GREEN = 1; final private int BLUE = 2; final private int YELLOW = 3; Player(int start_x, int start_y, int start_velx, int start_vely, int start_color) { //constructor for player; //stores parameters to field variables x = start_x; y = start_y; vel_x = start_velx; vel_y = start_vely; colorNum = start_color; //initializes the boolean variables to be initially false won = false; gameOver = false; //stores initial position and velocity init_x = start_x; init_y= start_y; init_velx = start_velx; init_vely = start_vely; } void display() { //displays player on screen //sets fill color according to the designated player color if(colorNum == 0) fill(255,0,0); else if(colorNum == 1) fill(0,255,0); else if(colorNum == 2) fill(0,0,255); else fill(0,255,255); //draws player as a small circle ellipseMode(CORNER); ellipse(x,y,5,5); } void updatePos() { //updates the position of the player according to the current velocity x += vel_x; y += vel_y; //moves the player to the opposite side of the screen if it hits an edge if(x < 0) { x = (w_width-grid_size); } else if(x >= w_width) { x =0; } if(y < 0) { y = (w_height-grid_size); } else if(y >= w_height) { y = 0; } } void resetPos() //resets boolean variables, player position, { //and velocity to initial values won = false; gameOver = false; x = init_x; y = init_y; vel_x = init_velx; vel_y = init_vely; } void changeDir(int new_velx, int new_vely) { //method that changes the direction of movement of the player vel_x = new_velx; vel_y = new_vely; } int updateX() { //returns the current x position return x; } int updateY() { //returns the current y position return y; } int updateVelx() { //returns the current x velocity return vel_x; } int updateVely() { //returns the current y velocity return vel_y; } void endGame() { //sets the velocity to 0 at the end of the game vel_x=0; vel_y=0; } void won() { //records if the player has won won = true; } boolean getWon() { //returns if the player has won return won; } void gameOver() { //records if the round has ended gameOver = true; } boolean getGameOver() { //returns if the player recognizes the end of the round return gameOver; }}
final int w_width = 600; //declares window dimensions as constantsfinal int w_height = 400;final int grid_size = 5; //declares the size of the grid squaresint[][] grid; // declares array for the gridcolor[] hit; // declares array for the grid square colorsPlayer player1; //declares playersPlayer player2;Player player3;Player player4;boolean startGame = false; //declares boolean var that tells if the game has startedboolean gameEnded = false; //declares boolean var that tells if the round has endedboolean endOne = false;boolean endTwo = false;boolean endThree = false;boolean endFour = false;boolean playOne = true;boolean playTwo = false;boolean playThree = false;boolean playFour = false;void setup() { size(w_width, w_height); //sets the window dimensions grid = new int[w_height/grid_size][w_width/grid_size]; //initializes the //grid array, making //as many values as //squares that will fit //in the window for (int r = 0; r < grid.length; r++) //sets all of the values of the array //to 0, making each square in the grid //initially black { for (int c = 0; c < grid[r].length; c++) { grid[r][c] = 0; } } hit = new color[5]; //initializes the color array and gives them three //values for black, blue, and red hit[0] = color(0, 0, 0); hit[1] = color(0, 0, 255); hit[2] = color(255, 0, 0); hit[3] = color(0, 255, 0); hit[4] = color(255, 255, 0); player1 = new Player((0+50), (w_height-50), 5, 0, 2); //initializes the players player2 = new Player((w_width-50), (0+50), -5, 0, 0); player3 = new Player((w_width-50), (w_height-50), -5, 0, 3); player4 = new Player ((0+50), (0+50), 5, 0, 4);}void draw() { drawGrid(); //draws the grid lines if (gameEnded == false) //prevents the color of the grid squares from being //changed while the round is over to make it easier //to tell who the winner is updateGrid(); for (int r = 0; r < grid.length; r++) //draws the grid sqaures { for (int c = 0; c < grid[r].length; c++) { fill(hit[grid[r][c]]); //colors the square rect(c * grid_size, r * grid_size, grid_size, grid_size); } } if (startGame == false) { //welcome message, telling object of the game //and player controls stroke(255, 255, 255); rect((w_width/12), (w_height/8), (w_width-100), (w_height-100)); PFont fontA = loadFont("OCRAExtended-48.vlw"); textFont(fontA, 20); fill(255, 255, 255); text("Welcome to Trawn!", (w_width/12)+50, (w_height/8)+60); text("Select Number of Players (Press 1-4)", (w_width/12)+50, (w_height/8)+80); text("Player 1 Controls are the Arrows", (w_width/12)+50, (w_height/8)+120); text("Player 2 Controls are WASD", (w_width/12)+50, (w_height/8)+140); text("Player 3 Controls are YGHJ", (w_width/12)+50, (w_height/8)+160); text("Player 4 Controls are 8456 (NumPad)", (w_width/12)+50, (w_height/8)+180); text("The Player that Collides with", (w_width/12)+50, (w_height/8)+220); text("the Light Path Loses.", (w_width/12)+50, (w_height/8)+240); text("Press Spacebar to Play! Good Luck!", (w_width/12)+50, (w_height/8)+260); if (keyPressed && (key == '2')) { playTwo = true; } if (keyPressed && (key == '3')) { playThree = true; } if (keyPressed && (key == '4')) { playFour = true; } if (keyPressed && (key == ' ')) //when Y is pressed, the game //begins startGame = true; } else if (startGame == true) { //begins game player1.display(); //displays players if (playTwo == true) { player2.display(); } if (playThree == true) { player2.display(); player3.display(); } if (playFour == true) { player2.display(); player3.display(); player4.display(); } player1.updatePos(); //updates position of players if (playTwo == true || playThree == true || playFour == true) { player2.updatePos(); } if (playThree == true || playFour == true) { player3.updatePos(); } if (playFour == true) { ; player4.updatePos(); } hitCheck(player1); //checks to see if a player has hit the light trail if (playTwo == true || playThree == true || playFour == true) { hitCheck(player2); } if (playThree == true || playFour == true) { hitCheck(player3); } if (playFour == true) { hitCheck(player4); } }}void updateGrid() { //checks player position to color the grid square //corresponding to each player's position in the color //of the player for (int r = 0; r < grid.length; r++) { for (int c = 0; c < grid[r].length; c++) { if ((player1.updateX()/grid_size == c) && (player1.updateY()/grid_size == r)) grid[r][c] = 1; } } if (playTwo == true || playThree == true || playFour == true) { for (int r = 0; r < grid.length; r++) { for (int c = 0; c < grid[r].length; c++) { if ((player2.updateX()/grid_size == c) && (player2.updateY()/grid_size == r)) grid[r][c] = 2; } } } if (playThree == true || playFour == true) { for (int r = 0; r < grid.length; r++) { for (int c = 0; c < grid[r].length; c++) { if ((player3.updateX()/grid_size == c) && (player3.updateY()/grid_size == r)) grid[r][c] = 3; } } } if (playFour == true) { for (int r = 0; r < grid.length; r++) { for (int c = 0; c < grid[r].length; c++) { if ((player4.updateX()/grid_size == c) && (player4.updateY()/grid_size == r)) grid[r][c] = 4; } } }}void drawGrid() //draws the grid lines{ background(0); //sets the background as black stroke(50, 50, 50); //colors the grid lines gray for (int i = 0; i < w_width; i += grid_size) //draws lines { line(i, 0, i, w_height); line(0, i, w_width, i); }}void hitCheck(Player P) //checks to see if a player has hit a light trail{ int borderCheck_x=P.updateX(); //instantiates two variables that will go int borderCheck_y=P.updateY(); //into the check, set at default to be the //current player position if (P.updateY()<0) //checks to see if the players position is outside of the //dimensions of the window, and sets the borderCheck //to be on the edge so that there is no array error //since the array only corresponds to positions inside //the dimensions of the window borderCheck_y=0; else if (P.updateY()>w_height) borderCheck_y=w_height-grid_size; else if (P.updateX()<0) borderCheck_x=0; else if (P.updateX()>w_width) borderCheck_x=w_width-grid_size; if (grid[(borderCheck_y)/grid_size][(borderCheck_x)/grid_size]!=0) { //checks the grid square corresponding the players current position to //see if it is already colored (meaning there is a light trail there) P.endGame(); //stops all players if (P == player1) { //Prevents Player from moving after hit endOne = true; } if (P == player2) { endTwo = true; } if (P == player3) { endThree = true; } if (P == player4) { endFour = true; } if (playFour == true) { if ( (endOne == false && endTwo == true && endThree == true && endFour == true) || (endOne == true && endTwo == false && endThree == true && endFour == true) || (endOne == true && endTwo == true && endThree == false && endFour == true) || (endOne == true && endTwo == true && endThree == true && endFour == false)|| (endOne == true && endTwo == true && endThree == true && endFour == true)) { gameEnded = true; } } else if ( playThree == true) { if ( (endOne == false && endTwo == true && endThree == true) || (endOne == true && endTwo == false && endThree == true) || (endOne == true && endTwo == true && endThree == false) || (endOne == true && endTwo == true && endThree == true)) { gameEnded = true; } } else if (playTwo == true) { if ( (endOne == false && endTwo == true) || (endOne == true && endTwo == false) || (endOne == true && endTwo == true)) { gameEnded = true; } } else if (playOne == true) { if (endOne == true) { gameEnded = true; } } else { gameEnded = false; } P.gameOver(); //tells a losing player that the game has ended } else if (gameEnded == true) { P.endGame(); P.won(); //the player that has not hit a light trail is told that it is //the winner. if both players lose simultaneously, there is a tie P.gameOver(); //tells a winning player that the game has ended } if ((playFour == true) && (gameEnded == true)&&((player1.getGameOver()==true) && (player2.getGameOver()==true) && (player3.getGameOver()==true) && (player4.getGameOver()==true))) { //when the game is over, and when both players have been told the game is over //(in order to keep the judging of the winner before the text reports the winner) endText(); //displays the winner and ending message } else if ((playThree == true) && (player1.getGameOver() == true) && (player2.getGameOver()==true) && (player3.getGameOver()==true)) { endText(); } else if ((playTwo == true) && (player1.getGameOver() == true) && (player2.getGameOver()==true)) { endText(); } else if ((gameEnded == true) && (player1.getGameOver() == true)) { endText(); }}void endText() { //displays the winner and ending message PFont fontA = loadFont("OCRAExtended-48.vlw"); //imports font textFont(fontA, 20); //sets font and font size fill(255, 255, 255); //makes font white //reports winner in the form of an on-screen message if (playFour == true) { if (endOne == false && endTwo == true && endThree == true && endFour == true) text("Player 1 Wins!", 10, 30); else if (endOne == true && endTwo == false && endThree == true && endFour == true) text("Player 2 Wins!", 10, 30); else if (endOne == true && endTwo == true && endThree == false && endFour == true) text("Player 3 Wins!", 10, 30); else if (endOne == true && endTwo == true && endThree == true && endFour == false) text("Player 4 Wins!", 10, 30); else text("It's a tie!", 10, 30); } else if (playThree == true) { if (endOne == false && endTwo == true && endThree == true) text("Player 1 Wins!", 10, 30); else if (endOne == true && endTwo == false && endThree == true) text("Player 2 Wins!", 10, 30); else if (endOne == true && endTwo == true && endThree == false) text("Player 3 Wins!", 10, 30); else text("It's a tie!", 10, 30); } else if (playTwo == true) { if (endOne == false && endTwo == true) text("Player 1 Wins!", 10, 30); else if (endOne == true && endTwo == false) text("Player 2 Wins!", 10, 30); else text("It's a tie!", 10, 30); } else { text("Game Over", 10, 30); } text("Play Again? (Press the Spacebar)", 10, 50); //prompts user if he/she wishes to play again //to press Y if (keyPressed && (key == '1')) { playOne = true; playTwo = false; playThree = false; playFour = false; } if (keyPressed && (key == '2')) { playOne = false; playTwo = true; playThree = false; playFour = false; } if (keyPressed && (key == '3')) { playOne = false; playTwo = false; playThree = true; playFour = false; } if (keyPressed && (key == '4')) { playOne = false; playTwo = false; playThree = false; playFour = true; } if (keyPressed && (key == ' ')) { player1.resetPos(); //resets player positions if (playTwo == true || playThree == true || playFour == true) player2.resetPos(); if (playThree == true || playFour == true) player3.resetPos(); if (playFour == true) player4.resetPos(); endOne = false; endTwo = false; endThree = false; endFour = false; for (int r = 0; r < grid.length; r++) //resets the colors of the grid squares { for (int c = 0; c < grid[r].length; c++) { grid[r][c] = 0; } } gameEnded = false; //starts the game up again }}void keyPressed() { //player controls; //checks to see if a button has been pressed, and changes the direction of //movement on the corresponding player. Prevents a player from moving //opposite the current direction of travel if (gameEnded == false) { //will not work if round has ended if (endOne == false) { if ((key == CODED)&&((keyCode == UP) && (player1.updateVely() <= 0))) player1.changeDir(0, -5); else if ((key == CODED)&&((keyCode == DOWN) && (player1.updateVely() >=0))) player1.changeDir(0, 5); else if ((key == CODED)&&((keyCode == LEFT) && (player1.updateVelx() <= 0))) player1.changeDir(-5, 0); else if ((key == CODED)&&((keyCode == RIGHT) && (player1.updateVelx() >= 0))) player1.changeDir(5, 0); } if (endTwo == false) { if ((key == 'w' || key == 'W') && (player2.updateVely() <= 0)) player2.changeDir(0, -5); else if ((key == 's' || key == 'S') && (player2.updateVely() >= 0)) player2.changeDir(0, 5); else if ((key == 'a' || key == 'A') && (player2.updateVelx() <= 0)) player2.changeDir(-5, 0); else if ((key == 'd' || key == 'D') && (player2.updateVelx() >= 0)) player2.changeDir(5, 0); } if (endThree == false) { if ((key == 'y' || key == 'Y') && (player3.updateVely() <= 0)) player3.changeDir(0, -5); else if ((key == 'h' || key == 'H') && (player3.updateVely() >= 0)) player3.changeDir(0, 5); else if ((key == 'g' || key == 'G') && (player3.updateVelx() <= 0)) player3.changeDir(-5, 0); else if ((key == 'j' || key == 'J') && (player3.updateVelx() >= 0)) player3.changeDir(5, 0); } if (endFour == false) { if ((key == '8') && (player4.updateVely() <= 0)) player4.changeDir(0, -5); else if ((key == '5') && (player4.updateVely() >= 0)) player4.changeDir(0, 5); else if ((key == '4') && (player4.updateVelx() <= 0)) player4.changeDir(-5, 0); else if ((key == '6') && (player4.updateVelx() >= 0)) player4.changeDir(5, 0); } }}
Will have to check it out, sounds nice.
Post CountA Novel by Inject OH 4
Conjoint Gaming"You thought a Human Centipede was bad, wait till you get a load of us."
Bears, beer and bitches. That's everyone's motto.
First of all, books were all but dead until tablets rejuvenated the industry
Cortez I'm actually on black tar heroin fyi
Only been in it once didn't really pay attention to the staff, I think their was an eatable thong... but that may have been a totally different store, ANYWAYS... lol.
The plunger could simply be out of view, the pants + it's location behind the toilet may hide it... Or it's a fraud and we need to take down the system with out golden axes while destroying the rest of the demon-spawn so that we may live in a utopia.
That is really cool, especially being a fan on TronNice work - I'm sure that was a good grade