Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Library Used: https://github.com/ddf/Minim
- Base Sound Effects From: zapsplat.com, freesound.org - Edited by Christian Leona to Suit the Game
- Individual Components
- (Sound Effects) - Justin Abellera [13044173] & Christian Leona [13044235] <--- search comments using our student number
- */
- ///////////13044173 - Justin Abellera//////////////////
- import ddf.minim.*;
- import ddf.minim.spi.*;
- import ddf.minim.ugens.*;
- Minim minim;
- FilePlayer filePlayer;
- AudioOutput out;
- Sampler collision0, collision1, collision2, goal, border, applause0, applause1, applause2;
- ///////////13044173 - Justin Abellera//////////////////
- String fileName = "sfx/sounds_back2_final.mp3";
- float board_theme = 0; //0 = vanilla / 1 = jungle / 2 = neon
- void setup(){
- size(1280,960);
- background(75,100,255);
- //fill(colourR,colourG,colourB); //custom colours
- fill(255,255,255);
- ///////////13044173 - Justin Abellera//////////////////
- minim = new Minim(this);
- out = minim.getLineOut();
- filePlayer = new FilePlayer( minim.loadFileStream("sfx/sounds_back2_final.mp3") );
- filePlayer.loop();
- filePlayer.patch(out);
- border = new Sampler( "sfx/border.mp3", 1, minim ); //SFX Edited/Provided by Justin Abellera - 13044173 (Source: YouTube)
- border.patch(out);
- goal = new Sampler( "sfx/goal.mp3", 1, minim ); //SFX Edited/Provided by Christian Leona - 13044235 (Source: FreeSound.org)
- goal.patch(out);
- collision0 = new Sampler( "sfx/vanilla_collision.mp3", 1, minim ); //SFX Edited/Provided by Justin Abellera - 13044173 (Source: YouTube)
- collision0.patch(out);
- applause0 = new Sampler( "sfx/vanilla_applause.mp3", 1, minim ); //SFX Edited/Provided by Justin Abellera - 13044173 (Source: YouTube)
- applause0.patch(out);
- }
- //##### INITIALISE VARIABLES #####//
- float width = 1280; //manual declaration to enable usage of width and height here
- float height = 960;
- float ballX = width/2; //Ball is placed in the middle, for now
- float ballY = height/2;
- float friction = 2; //rate for the Ball to slow down over time
- float bounceFriction = 0.8; //multiplier for the Ball to lose speed when hit, 1 for no effect, speed loss increases as this decreases to 0 [can be higher than 1 to gain speed instead] [can split this for both players, potentially]
- float ballRadius = 2; //allows Ball radius to be modified live, potentially
- float ballSpeedX = 0; //placeholder because speed is calculated by coordinates elsewhere
- float ballSpeedY = 0;
- float hitDelay = 0; //prevent multiple micro-collisions with a paddle
- float paddle_X1 = 0; //Paddle coordinate for player One. placeholder x and y, because they are mapped to hands
- float paddle_Y1 = 0;
- //float paddle_X2 = 0; //Paddle coordinate for player Two
- //float paddle_Y2 = 0;
- float paddle_X2 = width-2*(width/10); //placeholder coordinates for player Two
- float paddle_Y2 = height/2;
- int p2direction = 0; //placeholder for paddle movement for player Two
- float prev_X1 = 0; //store the coordinate in the previous frame, to calculate speed
- float prev_Y1 = 0;
- float prev_X2 = 0; //player Two
- float prev_Y2 = 0;
- float prevTick = 0; //placeholder used in the process of storing previous X and Y
- float Xspeed1 = 0; //placeholder variable for speed calculation
- float Yspeed1 = 0;
- float Xspeed2 = 0; //player Two
- float Yspeed2 = 0;
- float paddleSize_1 = 1; //allows the paddle size to be modified live, potentially
- float paddleSize_2 = 1; //allows one specific player's size to be modified, instead of only both
- //float paddlePower_1 = 1; //how fast the Ball bounces off the paddle, potentially [can be used alongside bounceFriction]
- //float paddlePower_2 = 1;
- //boolean punchOne = false; //potential feature, player can press a button to hit harder
- //boolean punchTwo = false;
- float goal_X1 = width/10; //coordinate of goal for player One. allows the goal to move, potentially
- float goal_Y1 = height/2;
- float goal_X2 = 9*(width/10); //coordinate of goal for player Two
- float goal_Y2 = height/2;
- float goalSize_1 = 1; //allows the goal size to be modified live, potentially
- float goalSize_2 = 1;
- //float goal1_Height = 0;
- int goalState = 0; //0 for no goal, 1 for player 1 goal, 2 for player 2 goal, reset to 0 after the timer
- int goalScores_1 = 0; //score tracker for player 1
- int goalScores_2 = 0;
- float goalDelay = 0; //goal score animation timer
- //float modifier_windy = 0; //potential feature
- //boolean noFrictionMode = false;
- //float colourR = random(70,255); //custom colours
- //float colourG = random(70,255);
- //float colourB = random(70,255);
- //variable = int(variable); //convert to integer
- float placeholderAnimationY = 0; //placeholder for goal animation
- void draw(){
- //ambience.trigger();
- frameRate(60);
- background(75,100,200);
- countHitDelay();
- countGoalDelay();
- draw_theme0(); //note: order matters for the Ball to be drawn on top of the background
- draw_paddle_1();
- draw_paddle_2();
- draw_goal_1();
- draw_goal_2();
- draw_ball();
- applyFriction();
- speedCap();
- borderPrevention(); //prevent origin from leaving the border
- debugText(); //debug note: display variable values to check functionality
- p2move(); //debug note: placeholder for player 2 paddle
- paddleSpeed_1();
- paddleSpeed_2();
- checkHitboxes();
- updateBallPosition();
- checkGoals();
- //put this AFTER paddleSpeed_One(), so that prev_X1 is not the same as paddleX_One
- prevCoordinateStorage();
- //debug note: does the order of these methods matter?
- }
- //##### DRAW METHODS #####//
- void draw_paddle_1(){ //draw the paddle for player One
- pushMatrix();
- translate(paddle_X1,paddle_Y1);
- fill(255,0,0); //chosen colour, fixed for now
- //paddle_X1 = map(mouseX, 0, width, 0, width); //the paddle can follow the mouse, mapped to a specific area
- //paddle_Y1 = map(mouseY, 0, height, 0, height);
- paddle_X1 = mouseX; //placeholder updating paddle position
- paddle_Y1 = mouseY;
- ellipse(0,0,20*paddleSize_1,20*paddleSize_1); //the drawn paddle
- fill(255,255,255); //reset colour
- popMatrix();
- }
- void draw_paddle_2(){ //draw the paddle for player Two
- pushMatrix();
- translate(paddle_X2,paddle_Y2);
- fill(200,0,200);
- ellipse(0,0,20*paddleSize_2,20*paddleSize_2);
- fill(255,255,255); //reset colour
- popMatrix();
- }
- void draw_ball(){
- pushMatrix();
- translate(ballX,ballY);
- fill(0,255,0);
- ellipse(0,0,40*ballRadius,40*ballRadius);
- ellipse(-2,-2,4,4); //debug midpoint
- fill(255,255,255); //reset colour
- popMatrix();
- }
- void draw_goal_1(){
- pushMatrix();
- translate(goal_X1,goal_Y1);
- rect(-15*goalSize_1,-60*goalSize_1,30*goalSize_1,120*goalSize_1);
- ellipse(-2,-2,4,4); //debug midpoint
- popMatrix();
- }
- void draw_goal_2(){
- pushMatrix();
- translate(goal_X2,goal_Y2);
- rect(-15*goalSize_2,-60*goalSize_2,30*goalSize_2,120*goalSize_2);
- ellipse(-2,-2,4,4); //debug midpoint
- popMatrix();
- }
- //##### AESTHETIC THEMES #####//
- void draw_theme0(){ //pong theme
- pushMatrix();
- //middle line (20 squares down the middle) ['20' value or rect value can be changed, because the Y values are scaled to height]
- noStroke();
- pushMatrix();
- translate(width/2,height/23);
- pushMatrix();
- for (int i = 0; i < 20; i++) {
- translate(0,height/28);
- rect(-8,-8,16,16); //raw pixel values
- }
- popMatrix();
- popMatrix();
- //goal rings
- pushMatrix(); //player One
- translate(goal_X1+width/128,goal_Y1);
- noFill();
- stroke(255,255,255,127);
- strokeWeight(4);
- arc(0, 0, width/8, width/8, radians(270), radians(450)); //inner ring
- strokeWeight(8);
- arc(0, 0, width/4, width/4, radians(270), radians(450)); //outer ring
- popMatrix();
- pushMatrix(); //player Two
- translate(goal_X2-width/128,goal_Y2);
- noFill(); //redundant line of code
- stroke(255,255,255,127);
- strokeWeight(4);
- arc(0, 0, width/8, width/8, radians(90), radians(270)); //inner ring
- strokeWeight(8);
- arc(0, 0, width/4, width/4, radians(90), radians(270)); //outer ring
- stroke(255,255,255); //reset
- popMatrix();
- //boundary lines
- line(width/10, height/20, width/10*9, height/20); //top line
- line(width/10, height/20*19, width/10*9, height/20*19); //bottom line
- line(width/10, height/20, width/10, height/20*7); //left, up line
- line(width/10, height/20*13, width/10, height/20*19); //left, down line
- line(width/10*9, height/20, width/10*9, height/20*7); //right, up line
- line(width/10*9, height/20*13, width/10*9, height/20*19); //right, down line
- //
- stroke(0,0,0); //reset
- strokeWeight(1);
- fill(0,0,0);
- popMatrix();
- }
- //##### FUNCTIONAL METHODS #####//
- void borderPrevention(){
- //prevent the Ball from leaving the border
- if (ballX > width/10 * 9 -40){ //horizontal speed [moving right]
- ballSpeedX = abs(ballSpeedX) * -1;
- border.trigger(); ///////////13044173 - Justin Abellera//////////////////
- } //force move away from border
- if (ballX < width/10 + 40){ //horizontal speed [moving left]
- ballSpeedX = abs(ballSpeedX);
- border.trigger(); ///////////13044173 - Justin Abellera//////////////////
- }
- if (ballY > height/20 * 19 -40){ //vertical speed [moving down]
- ballSpeedY = abs(ballSpeedY) * -1;
- border.trigger(); ///////////13044173 - Justin Abellera//////////////////
- }
- if (ballY < height/20 + 40){ //vertical speed [moving up]
- ballSpeedY = abs(ballSpeedY);
- border.trigger(); ///////////13044173 - Justin Abellera//////////////////
- }
- }
- void countHitDelay(){
- //if the Ball is hit, it cannot be hit again until some time later
- if (hitDelay > 0 && hitDelay < 17){ //Ball cannot be hit until 15 frames [17 because it starts at 1 and is immediately incremented to 2, probably]
- hitDelay++;
- }
- if (hitDelay > 15){ //reset
- hitDelay = 0;
- } //debug note: can this be improved using >= and <= ??? check frame by frame
- }
- void countGoalDelay(){ //can be merged with countHitDelay() [and every other method that is used on every frame]
- //if a goal has been scored, goal animation plays and the Ball is removed until some time later
- if (goalDelay > 0 && goalDelay < 241){ //goal animation ends after 239 frames
- goalDelay++;
- ballX = width/2; //move the Ball off the screen while the goal animation plays
- ballY = height/2;
- fill(0,255,0); //begin placeholder goal animation
- pushMatrix();
- translate(width/2-24,height/8);
- text("G O A L !",0,placeholderAnimationY);
- //placeholder goal animation
- popMatrix();
- fill(255,255,255);
- placeholderAnimationY = placeholderAnimationY + 3; //placeholder goal animation
- }
- if (goalDelay > 239){ //reset
- goalDelay = 0;
- goalState = 0; //allow goal to be scored again
- ballSpeedX = 0; //reset Ball speed for when it is moved back to the middle
- ballSpeedY = 0;
- ballX = width/2; //move the Ball back to the middle
- ballY = height/2;
- placeholderAnimationY = 0; //placeholder goal animation
- }
- }
- void checkHitboxes(){
- //check if the paddle is overlapping the Ball, by using radial distance
- if (dist(paddle_X1, paddle_Y1, ballX, ballY) < (25*ballRadius)) {
- //check if Ball is not affected by hitDelay
- if (hitDelay == 0){ //this can be problematic if the player reaches over the middle and prevents the other player from hitting the Ball [DEBUG NOTE: prevent player from hitting the Ball while they are over the middle boundary]
- hitDelay = 1;
- if(board_theme == 0) //Vanilla Theme
- {
- collision0.trigger();
- }
- else if(board_theme == 1) //Jungle Theme
- {
- collision1.trigger();
- }
- else if(board_theme == 2) //Neon Theme
- {
- collision2.trigger();
- }
- //if the Ball is moving fast, bounce off the paddle to simulate realistic ricochet/deflection
- if (ballSpeedX >= 10 || ballSpeedX <= -10 || ballSpeedY >= 10 || ballSpeedY <= -10){
- if (ballX > paddle_X1 && ballY < paddle_Y1){ //approximate deflection based on quadrant, top right
- ballSpeedX = abs(ballSpeedX)*bounceFriction; //force move to the right [and also lose some speed]
- ballSpeedY = (abs(ballSpeedY)*-1)*bounceFriction; } //force move up
- if (ballX > paddle_X1 && ballY > paddle_Y1){ //quadrant, bottom right
- ballSpeedX = abs(ballSpeedX)*bounceFriction; //force move right
- ballSpeedY = abs(ballSpeedY)*bounceFriction; } //force move down
- if (ballX < paddle_X1 && ballY > paddle_Y1){ //quadrant, bottom left
- ballSpeedX = (abs(ballSpeedX)*-1)*bounceFriction; //force move left
- ballSpeedY = abs(ballSpeedY)*bounceFriction; } //force move down
- if (ballX < paddle_X1 && ballY < paddle_Y1){ //quadrant, bottom right
- ballSpeedX = (abs(ballSpeedX)*-1)*bounceFriction; //force move left
- ballSpeedY = (abs(ballSpeedY)*-1)*bounceFriction; } //force move up
- }
- //if the Ball is moving VERY fast, bounce away from the paddle regardless of quadrant [due to large differences in pixels distances for each frame, the Ball can skip over the paddle and be placed in the wrong quadrant, resulting in an unexpected ricochet (in most cases, the Ball would be forced in the same direction after teleporting to the opposite side of the paddle)]
- if (ballSpeedX >= 25 || ballSpeedX <= -25 || ballSpeedY >= 25 || ballSpeedY <= -25){ //25 can be changed to scale with ballRadius and paddleSize, to increase the range of speeds that maintain the realistic ricochet
- ballSpeedX = (abs(ballSpeedX)*-1)*bounceFriction; //force flip X direction
- ballSpeedY = (abs(ballSpeedY)*-1)*bounceFriction; //force flip Y direction
- }
- //otherwise if the Ball is slow, it will copy the speed and direction of the paddle instead
- if (ballSpeedX < 10 && ballSpeedX > -10 && ballSpeedY < 10 && ballSpeedY > -10){
- ballSpeedX = Xspeed1;
- ballSpeedY = Yspeed1;
- }
- }
- //hitDelay = 1; //uncomment this if you want the delay to reset UNTIL the paddle is not on the Ball [potential issues if the player tracks the Ball with the paddle]
- }
- //for player Two
- if (dist(paddle_X2, paddle_Y2, ballX, ballY) < (25*ballRadius)) {
- if (hitDelay == 0){
- hitDelay = 1;
- if(board_theme == 0) //Vanilla Theme
- {
- collision0.trigger();
- }
- else if(board_theme == 1) //Jungle Theme
- {
- collision1.trigger();
- }
- else if(board_theme == 2) //Neon Theme
- {
- collision2.trigger();
- }
- //Ball is moving fast
- if (ballSpeedX >= 10 || ballSpeedX <= -10 || ballSpeedY >= 10 || ballSpeedY <= -10){
- if (ballX > paddle_X2 && ballY < paddle_Y2){ //quadrant, top right
- ballSpeedX = abs(ballSpeedX)*bounceFriction; ballSpeedY = (abs(ballSpeedY)*-1)*bounceFriction; }
- if (ballX > paddle_X2 && ballY > paddle_Y2){ //quadrant, bottom right
- ballSpeedX = abs(ballSpeedX)*bounceFriction; ballSpeedY = abs(ballSpeedY)*bounceFriction; }
- if (ballX < paddle_X2 && ballY > paddle_Y2){ //quadrant, bottom left
- ballSpeedX = (abs(ballSpeedX)*-1)*bounceFriction; ballSpeedY = abs(ballSpeedY)*bounceFriction; }
- if (ballX < paddle_X2 && ballY < paddle_Y2){ //quadrant, bottom right
- ballSpeedX = (abs(ballSpeedX)*-1)*bounceFriction; ballSpeedY = (abs(ballSpeedY)*-1)*bounceFriction; } }
- //Ball is moving VERY fast
- if (ballSpeedX >= 25 || ballSpeedX <= -25 || ballSpeedY >= 25 || ballSpeedY <= -25){
- ballSpeedX = (abs(ballSpeedX)*-1)*bounceFriction; ballSpeedY = (abs(ballSpeedY)*-1)*bounceFriction; }
- //Ball is slow
- if (ballSpeedX < 10 && ballSpeedX > -10 && ballSpeedY < 10 && ballSpeedY > -10){
- ballSpeedX = Xspeed2; ballSpeedY = Yspeed2; }
- }
- }
- }
- void checkGoals(){ //check if the Ball is within a goal
- if (goalState == 0){
- if (ballX > goal_X1-(15*goalSize_1)-20*ballRadius && ballX < goal_X1+(15*goalSize_1)+20*ballRadius ){ //Ball is within goal 1
- if (ballY > goal_Y1-(60*goalSize_1)-18*ballRadius && ballY < goal_Y1+(60*goalSize_1)+18*ballRadius ){ //the hitbox is slightly generous around the corners because the Ball is a circle and dist() is not used
- //taken from draw_goal_1(): rect(-15*goalSize_1,-60*goalSize_1,30*goalSize_1,120*goalSize_1)
- goalState = 2; //goal has been scored for player 2
- goalScores_2 = goalScores_2 + 1; //increase score for player 2
- goalDelay = 1; //begin goal animation timer
- goal.trigger();
- if(board_theme == 0) //Vanilla Theme
- {
- applause0.trigger();
- }
- else if(board_theme == 1) //Jungle Theme
- {
- applause1.trigger();
- }
- else if(board_theme == 2) //Neon Theme
- {
- applause2.trigger();
- }
- }
- }
- if (ballX > goal_X2-(15*goalSize_2)-20*ballRadius && ballX < goal_X2+(15*goalSize_2)+20*ballRadius ){ //Ball is within goal 2
- if (ballY > goal_Y2-(60*goalSize_2)-18*ballRadius && ballY < goal_Y2+(60*goalSize_2)+18*ballRadius ){
- goalState = 1; //goal has been scored for player 1
- goalScores_1 = goalScores_1 + 1; //increase score for player 1
- goalDelay = 1; //begin goal animation timer
- goal.trigger();
- if(board_theme == 0) //Vanilla Theme
- {
- applause0.trigger();
- }
- else if(board_theme == 1) //Jungle Theme
- {
- applause1.trigger();
- }
- else if(board_theme == 2) //Neon Theme
- {
- applause2.trigger();
- }
- }
- }
- //debug note: how wide does the goal need to be to prevent a player from camping?
- }
- }
- void applyFriction(){
- //reduce the speed of the Ball while friction is active
- //DEBUG NOTE: the '4' here must be changed if friction is greater than 8 [applyFriction() -> 0.1*friction cannot exceed the range of 8 from 4>x>-4 because the stopping range will be skipped]
- if (ballSpeedX > 4){ //the Ball is moving RIGHT
- //ballspeed.trigger();
- ballSpeedX = ballSpeedX - (0.1*friction); }
- if (ballSpeedX < -4){ //the Ball is moving LEFT
- ballSpeedX = ballSpeedX + (0.1*friction); }
- if (ballSpeedY > 4){ //the Ball is moving DOWN
- //ballspeed.trigger();
- ballSpeedY = ballSpeedY - (0.1*friction); }
- if (ballSpeedY < -4){ //the Ball is moving UP
- ballSpeedY = ballSpeedY + (0.1*friction); }
- }
- void speedCap(){
- if (ballSpeedX > 80){ ballSpeedX = 80; }
- if (ballSpeedX < -80){ ballSpeedX = 80; }
- if (ballSpeedY > 80){ ballSpeedY = 80; }
- if (ballSpeedY < -80){ ballSpeedY = 80; }
- }
- void updateBallPosition(){
- ballX = ballX + ballSpeedX;
- ballY = ballY + ballSpeedY;
- }
- void paddleSpeed_1(){
- //compare coordinates of the paddle to calculate the speed
- Xspeed1 = paddle_X1 - prev_X1; //if moved to the right, speed is positive
- Yspeed1 = paddle_Y1 - prev_Y1; //if moved down, speed is positive
- }
- void paddleSpeed_2(){ //can be merged with paddleSpeed_1()
- //compare coordinates of the paddle to calculate the speed
- Xspeed2 = paddle_X2 - prev_X2; //if moved to the right, speed is positive
- Yspeed2 = paddle_Y2 - prev_Y2; //if moved down, speed is positive
- }
- void prevCoordinateStorage(){ //functions similarly to pmouseX, but can be used for more than just one frame, potentially
- prevTick++;
- if (prevTick > 0){ //delayed by one frame
- prevTick = 0;
- prev_X1 = paddle_X1;
- prev_Y1 = paddle_Y1;
- prev_X2 = paddle_X2;
- prev_Y2 = paddle_Y2;
- }
- }
- void testTheme(){
- if(board_theme == 0) //Vanilla Theme
- {
- collision0 = new Sampler( "sfx/vanilla_collision.mp3", 1, minim ); //SFX Edited/Provided by Justin Abellera - 13044173 (Source: YouTube)
- collision0.patch(out);
- applause0 = new Sampler( "sfx/vanilla_applause.mp3", 1, minim ); //SFX Edited/Provided by Justin Abellera - 13044173 (Source: YouTube)
- applause0.patch(out);
- }
- else if(board_theme == 1) //Jungle Theme
- {
- collision1 = new Sampler( "sfx/jungle_collision.mp3", 1, minim ); //SFX Edited/Provided by Christian Leona - 13044235 (Source: FreeSound.org)
- collision1.patch(out);
- applause1 = new Sampler( "sfx/jungle_applause.mp3", 1, minim ); //SFX Edited/Provided by Christian Leona - 13044235 (Source: FreeSound.org)
- applause1.patch(out);
- }
- else if(board_theme == 2) //Neon Theme
- {
- collision2 = new Sampler( "sfx/neon_collision.mp3", 1, minim ); //SFX Edited/Provided by Justin Abellera - 13044173 (Source: YouTube)
- collision2.patch(out);
- applause2 = new Sampler( "sfx/vanilla_applause.mp3", 1, minim ); //SFX Edited/Provided by Christian Leona - 13044235 (Source: YouTube)
- applause2.patch(out);
- }
- }
- //##### debug methods for testing purposes #####//
- void debugText(){
- pushMatrix();
- fill(0,255,0);
- text(Xspeed1+" Xspeed1",20,20);
- text(Yspeed1+" Yspeed1",20,20+20);
- text(hitDelay+" hitDelay",20,20+40);
- text(paddle_X1+" paddle_X1",20,20+60);
- text(prev_X1+" prev_X1",20,20+80);
- text(ballSpeedX+" ballSpeedX",20,20+100);
- text(ballX+" ballX",20,20+120);
- text("goalState "+goalState,20,20+160);
- text("goalScores_1 "+goalScores_1,20,20+180);
- text("goalScores_2 "+goalScores_2,20,20+200);
- text("theme "+board_theme,20,20+500);
- text(goalDelay+" goalDelay",20,20+240);
- text(Xspeed2+" Xspeed2",1160,20);
- text(Yspeed2+" Yspeed2",1160,40);
- //text(var+" var",20,20+);
- fill(255,255,255);
- popMatrix();
- }
- void mousePressed() { //debug note: teleport the ball to the mouse
- if (mouseButton == LEFT) {
- ballX=mouseX;
- ballY=mouseY;
- board_theme++;
- if (board_theme>4){board_theme=0;};
- testTheme();
- }
- }
- void keyPressed() { //debug note: placeholder for player 2 paddle movement
- if (key == CODED) {
- if (keyCode == UP) {
- p2direction = 4;
- } else if (keyCode == DOWN) {
- p2direction = 2;
- } else if (keyCode == LEFT) {
- p2direction = 3;
- } else if (keyCode == RIGHT) {
- p2direction = 1;
- }
- }
- }
- void keyReleased() { //debug note: placeholder for player 2 paddle movement, stops movement after releasing ANY key
- p2direction = 0;
- }
- void p2move(){ //debug note: placeholder for player 2 paddle movement, forces movement until a different direction is pressed
- if (p2direction != 0){ //this line is redundant
- if (p2direction == 4){
- paddle_Y2 = paddle_Y2 - 6; //up
- } else if (p2direction == 2){
- paddle_Y2 = paddle_Y2 + 6; //down
- } else if (p2direction == 3){
- paddle_X2 = paddle_X2 - 6; //left
- } else if (p2direction == 1){
- paddle_X2 = paddle_X2 + 6; //right
- }
- }
- }
- //debug issue: a paddle can move through the Ball without triggering the hitbox, if the paddle is moving very fast and cannot keep up with the movement within 1 frame (e.g. paddle moves 160 pixels within 1 frame, skipping over the Ball hitbox) [partially solved using speed cap]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement