Could use some help with game

so i have been using processing for a combined time of around 24 hours of actual work time and I feel like I could use some help this project is a class assignment so my goal is to get both of the players bound to each part of their game and for some reason I can also not move both players at the same time Ill just show my code and then if anyone could help me I would love if you also explain what you did.

Player Player1;
Player Player2;
float x = 300;
float y = 200;
float xspeed = 1;
float yspeed = 3.3;
float PlayerSpeed =10;
float x0 = 200;// falling ball
float y0 = 0;//^
float y0_speed=5;//^
int score=0;

void setup() {
  size(600, 400);
  background(55);
  Player1 = new Player(color(255), 137, 369, 2);
  Player2 = new Player(color(255), 452, 369, 2);
}
void draw() {
  println (mouseX +"," + mouseY);
  background(55);
  noStroke();
  fill(255);
  rect(300, 1, 0.1, 800);

 if (y0 > height+15)  //15 is the radius of the ball
  {
    y0 = -15; //Move it back to just above the screen
    x0 = random(width); //start in randmon spot
    y0_speed = random(3, 7); //Pick a new random speed
  }

  //Move the ball
  y0 += y0_speed; //Increase the balls y value 

  //Ball
  fill(255, 255, 255);
  ellipse(x0, y0, 30, 30);

  Player1.display();
  Player2.display();
}

class Player { // Trying out classes xD
  color c;
  float xPlayer;
  float yPlayer;
  float pspeed;

  Player(color tempC, float xpos, float ypos, float padspeed) {
    c = tempC;
    xPlayer = xpos;
    yPlayer = ypos;
    pspeed = padspeed;
  }

  void display() {
    stroke(0);
    fill(c);
    rect(xPlayer, yPlayer, 40, 5);
  }
}

void keyPressed() {// Moving 
  if (key == 'a') { 
    Player1.xPlayer -= PlayerSpeed;
  }
  if (key == 'd') { 
    Player1.xPlayer += PlayerSpeed;
  }
  if (keyCode == LEFT) { 
    Player2.xPlayer -= PlayerSpeed;
  }
  if (keyCode == RIGHT) { 
    Player2.xPlayer += PlayerSpeed;
  }
}
**__
Tagged:

Answers

Sign In or Register to comment.