Exodes
Ensign
- Registriert
- Jan. 2010
- Beiträge
- 170
Hallo
Als Abschlussarbeit muss ich PingPong mit Processing programmieren.
Ich hab mir dabei gedacht, dass ich Player1, Player2 und den Ball als Objekt schreibe.
Nun komm ich allerdings nicht mehr weiter. ich kann meinen 2. player nicht bewegen und ich weis nicht so wirklich, wie ich den ball bei berührung abstoße.
Hier mein bisheriger Code
Ich hoffe ihr könnt mir weiterhelfen 
Als Abschlussarbeit muss ich PingPong mit Processing programmieren.
Ich hab mir dabei gedacht, dass ich Player1, Player2 und den Ball als Objekt schreibe.
Nun komm ich allerdings nicht mehr weiter. ich kann meinen 2. player nicht bewegen und ich weis nicht so wirklich, wie ich den ball bei berührung abstoße.
Hier mein bisheriger Code
Code:
Player1 p1;
Player2 p2;
Ball b;
void setup()
{
size(400,225);
frameRate(50);
smooth();
p1= new Player1(width/4, height/2, #FFFFFF, 3);
p2= new Player2(width/1.38, height/2, #FFFFFF, 3);
b= new Ball(width/2, height/2, #00BFFF, 3);
}
void draw()
{
background(0);
stroke(255);
ellipseMode(CENTER);
fill(0);
ellipse(width/2,height/2,50,50); //mittelkreis
line(width/2,0,width/2,height); //mittellinie
rect(0-1,height/4,width/8,height/2); //linke torlinie
rect(width*0.88,height/4,width+1,height/2); //rechte torlinie
p1.bewegen();
p2.bewegen();
b.bewegen();
}
//----------------------Player1----------------------
class Player1
{
float pos_x;
float pos_y;
float richtung;
float tempo;
color farbe;
Player1(float x, float y, color f, float speed)
{
pos_x = x;
pos_y = y;
farbe = f;
tempo = speed;
}
void bewegen()
{
if (keyPressed)
{
if (key == 'w' || key == 'W') {richtung = 0; pos_y = pos_y - tempo;}
if (key == 'd' || key == 'D') {richtung = 1; pos_x = pos_x + tempo;}
if (key == 's' || key == 'S') {richtung = 2; pos_y = pos_y + tempo;}
if (key == 'a' || key == 'A') {richtung = 3; pos_x = pos_x - tempo;}
}
zeichnen(pos_x,pos_y);
}
void zeichnen(float x, float y)
{
fill(farbe);
rectMode(CORNER);
rect(x,y,5,height/6);
}
}
//----------------------Player2----------------------
class Player2 extends Player1
{
Player2(float x, float y, color f, float speed)
{
super(x,y,f,speed);
}
void bewegen()
{
if (keyPressed)
{
if (keyCode == 'i') {richtung = 0; pos_y = pos_y - tempo;}
if (keyCode == 'l') {richtung = 1; pos_x = pos_x + tempo;}
if (keyCode == 'k') {richtung = 2; pos_y = pos_y + tempo;}
if (keyCode == 'j') {richtung = 3; pos_x = pos_x - tempo;}
}
zeichnen(pos_x,pos_y);
}
}
//----------------------Ball----------------------
class Ball
{
float pos_x;
float pos_y;
color farbe;
float tempo;
float richtung;
Ball(float x, float y, color f, float speed)
{
pos_x=x;
pos_y=y;
farbe=f;
tempo=speed;
}
void bewegen()
{
zeichnen(pos_x, pos_y);
}
void zeichnen(float x, float y)
{
fill(farbe);
ellipse(x,y,10,10);
}
}

Zuletzt bearbeitet von einem Moderator: