array and class problem
in
Programming Questions
•
1 year ago
I have been trying to script this now for a couple of hours and starting to get more and more confused what I am doing.
I´m trying to use a button to add players with there own score.
when you press the button the next players should bee added under the udder.
This is the class
I´m trying to use a button to add players with there own score.
when you press the button the next players should bee added under the udder.
- import controlP5.*;
ControlP5 controlP5;
PFont font;
int X = 100;
int Y = 65;
Car[] car;
int p;
int carNR=0;
void setup(){
size(400, 400);
smooth();
frameRate(30);
controlP5 = new ControlP5(this);
controlP5.addButton("AddPlayer",0,20,50,60,20);
font = createFont("Helvetica-24", 12, true);
textFont(font, 12);
background(0);
car = new Car[100];
int[]ps = new int[p];
}
void draw()
{
background(0);
for (int i = 0; i<carNR; i++ ){
car[carNR].player();
}
}
public void AddPlayer() {
if (carNR<14){
car[carNR] = new Car(X, Y, width, height);
carNR++;
Y+=20;
}
This is the class
- class Car{
int x, y, w, h;
car(int x, int y, int w, int h){
this.x = x;
this.y = y;
this.w = w;
this.h = h;
}
void player()
{
fill(255);
textAlign(LEFT);
textFont(font, 15);
text("Player:"+carNR+" "+ps+" P", x, y);
}
}
1