Hey there! I am busy with a schoolproject, but I can’t figure out how to configure the scoreboard.
There is a grid with yellow rects. These are points and there is a purple rect that is the player. Don’t mind the red rectangles at this moment. I want to have a working code so when the purple rect goes over the yellow rect the point wil be +1 and the yellow rect wil dissapear and spawn onto another random place of the grid.
Can someone please help me!!?
Thank you in advance!
This is my code so far:
int breedteGrid = 60;
int lengteGrid = 40;
int heleGrid = breedteGrid*lengteGrid;
int huidig=0;
int duikerX = 0;
int duikerY = 150;
int duikerH = 21;
int duikerB = 31;
int itemsr = 80;
int itemsb = 50;
int speelveld;
int score = 0;
int[][] grid = new int[breedteGrid][lengteGrid];
final float stopKnopX = 1350;
final float stopKnopY = 55;
final float stopKnopW = 120;
final float stopKnopH = 50;
IntList seq = new IntList(heleGrid);
IntList seqb = new IntList(heleGrid);
IntList seqr = new IntList(heleGrid);
boolean stopKnopDrukken;
void preset() {
for (int i = 0; i<heleGrid; i++)
seq.append(i);
seq.shuffle();
for (int i = 0; i<heleGrid; i++);
}
void presetb() {
for (int i = 0; i < heleGrid; i++)
seqb.append(i);
seqb.shuffle();
for (int i = heleGrid-1; i >= itemsb; i--) {
}
seqb.sort();
}
void presetr() {
for (int i = 0; i < heleGrid; i++)
seqr.append(i);
for (int i = heleGrid-1; i >= 0; i--)
if ( seqb.hasValue(i) ) {
}
seqr.shuffle();
seqr.sort();
}
void reset() {
for (int i = 0; i < breedteGrid; i++) {
for (int j = 0; j < lengteGrid; j++) {
grid[i][j] = 0;
}
}
}
void setitem(int rec, int value1) {
for (int i = 0; i < breedteGrid; i++)
for (int j = 0; j < lengteGrid; j++)
if ( seq.get(j+i*lengteGrid) == rec )
grid[i][j] = value1;
}
void setitems(int item, int value1) {
for ( int i = 0; i < item; i++ )
setitem(i, value1);
}
void checkitem() {
for (int i = 0; i < breedteGrid; i++)
for (int j = 0; j < lengteGrid; j++)
if ( grid[i][j] == 1) {
}
}
void draw_grid() {
int x0 = 0, y0 = 150, w = 31, h = 21, off = 1;
for (int i = 0; i < breedteGrid; i++)
for (int j = 0; j < lengteGrid; j++) {
fill(255);
if ( grid[i][j] == 1 )
fill(#FFD700);
else if ( grid[i][j] == 2 )
fill(#FF0000);
rect(x0+i*(w+off), y0+j*(h+off),
w, h);
}
}
void keyPressed() {
if (key == CODED) {
if (keyCode == UP) {
duikerY -= duikerH+1;
} else if (keyCode == DOWN) {
duikerY += duikerH+1;
} else if (keyCode == LEFT) {
duikerX -= duikerB+1;
} else if (keyCode == RIGHT) {
duikerX += duikerB+1;
}
}
// Gezorgd dat de duiker altijd binnen de grid blijft.
if (duikerX > width-32) duikerX = 0;
if (duikerX < 0) duikerX = width-32;
if (duikerY >height-60) duikerY = 150;
if (duikerY < 150) duikerY = height-72;
}
// -------------------------------------------------------------------
void setup() {
size(1920, 1080);
reset();
preset();
setitems(itemsr, 1);
setitems(itemsb, 2);
checkitem();
}
void draw() {
background(0);
draw_grid();
fill(#000FFF);
rect(duikerX, duikerY, duikerB, duikerH);
fill(#1E90FF);
rect(0, 0, 1920, 149);
rect(0, 1030, 1920, 30);
fill(#000000);
textSize(66);
textAlign(CENTER);
text("Diving For Treasure", width/2, 75);
fill(#FFFFFF);
rect(1670,55,220,70);
fill(0);
textSize(40);
textAlign(CENTER);
text("Score:", 1730, 45);
stroke(#000000);
fill(#FFFFFF);
rect(stopKnopX,stopKnopY,stopKnopW,stopKnopH);
fill(0);
textSize(40);
textAlign(CENTER);
text("Stop", 1410, 95);
fill(0);
textSize(40);
textAlign(CENTER);
text("Levens:", 125, 45);
text("" + score , 1720, 105);
}