This one’s on a time crunch for a class, so I’d really appreciate help fast. Issue is, I’m a beginner trying to execute an idea overly ambitious for me, but now I really need to complete it for class. I’d appreciate any help possible. Thank you!
-
How can I increase the number of yellow coins available?
-
Also, how do I display a pop-up message randomly from a list of predefined messages? (eg. each time you get a coin, it says any one of the 20 messages from a defined list) Or maybe each time you collect a coin a one from a predefined set of pictures pops up for a few seconds?
int[] h = new int[500];
int[] hw = new int[500];
int[] x = new int[500];
int[] v = new int[500];
int[] vw = new int[500];
int[] y = new int[500];
float[] coinx = new float[4];
float[] coiny = new float[coinx.length];
boolean[] ctd = new boolean[coinx.length];
int points = 0;
int px, py;
boolean up = true, down = true, left = true, right = true;
int set = 50;
void setup() {
size(600, 600);
px = width/2-10;
py = height/2-10;
for (int i = 0; i < v.length; i++) {
v[i] = (int)random(width);
vw[i] = (int)random(set);
x[i] = (int)random(60)*50;
h[i] = (int)random(width);
hw[i] = (int)random(set);
y[i] = (int)random(50)*80;
}
for (int i = 0; i < coinx.length; i++) {
coinx[i] = (int)random(width);
coiny[i] = (int)random(height);
ctd[i] = true;
}
}
void draw() {
background(0);
for (int i = 0; i < coinx.length; i++) {
if (ctd[i]) {
stroke(255, 255, 0);
} else {
stroke(0);
}
strokeWeight(7);
point(coinx[i], coiny[i]);
if (ctd[i] && (dist(px, py, coinx[i], coiny[i]) <= 5)) {
ctd[i] = false;
points++;
}
if (coinx[i] < 0) {
coinx[i] = width;
coiny[i] = (int)random(height);
ctd[i] = true;
}
if (coinx[i] > width) {
coinx[i] = 0;
coiny[i] = (int)random(height);
ctd[i] = true;
}
if (coiny[i] < 0) {
coiny[i] = height;
coinx[i] = (int)random(width);
ctd[i] = true;
}
if (coiny[i] > height) {
coiny[i] = 0;
coinx[i] = (int)random(width);
ctd[i] = true;
}
}
for (int i = 0; i < v.length; i++) {
fill(0, 0, 128);
noStroke();
rect(x[i], v[i], 12, vw[i]);
rect(h[i], y[i], hw[i], 15);
if (x[i] + 15 < 4) {
x[i] = width;
v[i] = (int)random(width);
vw[i] = (int)random(set);
}
if (h[i] + hw[i] < 0) {
h[i] = width;
hw[i] = (int)random(set);
y[i] = (int)random(20)*30;
}
if (x[i] > width) {
x[i] = -15;
v[i] = (int)random(width);
vw[i] = (int)random(set);
}
if (h[i] > width) {
hw[i] = (int)random(set);
y[i] = (int)random(20)*30;
h[i] = -hw[i];
}
if (v[i] + vw[i] < 0) {
v[i] = height;
vw[i] = (int)random(set);
x[i] = (int)random(20)*30;
}
if (y[i] + 15 < 0) {
y[i] = height;
h[i] = (int)random(width);
hw[i] = (int)random(set);
}
if (v[i] > height) {
vw[i] = (int)random(set);
x[i] = (int)random(20)*30;
v[i] = -vw[i];
}
if (y[i] > height) {
y[i] = -15;
h[i] = (int)random(width);
hw[i] = (int)random(set);
}
strokeWeight(3.5);
stroke(255);
point(px, py);
for (int e = 0; e < x.length; e++) {
if (((px == h[e]) && (py <= y[e] + 15) && (py >= y[e])) || ((px == x[e]) && (py <= v[e] + vw[e]) && (py >= v[e]))) {
right = false;
}
if (((px == h[e] + hw[e]) && (py <= y[e] + 15) && (py >= y[e])) || ((px == x[e] + 15) && (py <= v[e] + vw[e]) && (py >= v[e]))) {
left = false;
}
if (((py == v[e]) && (px <= x[e] + 15) && (px >= x[e])) || ((py == y[e]) && (py <= h[e] + hw[e]) && (py >= h[e]))) {
down = false;
}
if (((py == v[e] + vw[e]) && (px <= x[e] + 15) && (px >= x[e])) || ((py == y[e] + 15) && (py <= h[e] + hw[e]) && (py >= h[e]))) {
up = false;
}
}
if (keyPressed && (key == CODED)) {
if (up && (keyCode == UP)) {
y[i] += 1;
v[i] += 1;
for (int e = 0; e < coiny.length; e++) {
coiny[e] += 0.002;
}
}
if (down && (keyCode == DOWN)) {
y[i] -= 1;
v[i] -= 1;
for (int e = 0; e < coiny.length; e++) {
coiny[e] -= 0.002;
}
}
if (left && (keyCode == LEFT)) {
x[i] += 1;
h[i] += 1;
for (int e = 0; e < coinx.length; e++) {
coinx[e] += 0.002;
}
}
if (right && (keyCode == RIGHT)) {
x[i] -= 1;
h[i] -= 1;
for (int e = 0; e < coinx.length; e++) {
coinx[e] -= 0.002;
}
}
}
up = true;
down = true;
left = true;
right = true;
}
fill(0);
strokeWeight(2);
stroke(255);
rect(500, 25, 60, 60);
fill(255);
textSize(30);
text(points, 522, 65);
textSize(40);
text("", 30, 65);
}