We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi,
I was working on a simple platformer game. The simple idea is that there are three arrays. Those arrays contain the obstacles.
One array for the x cord, one for the y cord, and one for the radius of the obstacle.
What i have working so far is the player to be able to go to the obstacles, and it will automatically move up. the issue is it is not moving down.
The way it checks is it has a for loop. the for loop runs through the array and detects if the x and y cord of the player overlap with the obstacle. the problem is when it is hitting one obstacle, that obstacle is telling it to go up but the other one is telling it to go down, so in the end nothing really happens. Heres the code.
//Start
int ex = 20;
int ey = 480;
int ew = 20;
int[] xo = {
400,
200
};
int[] yo = {
490,
490
};
int[] ro = {
50,
50
};
//Define Obstacles
//Program
void setup() {
size(750, 500);//--------------------------
}
void draw() {
background(200, 200, 200);
fill(0, 0, 255);
ellipse(ex, ey, 20, 20);
for (int i = 0; i < xo.length; i++) {
fill(255, 255, 255);
ellipse(xo[i], yo[i], ro[i], ro[i]);
if (dist(ex, ey, xo[i], yo[i]) < ro[i]-ew/2) {
println("up");
ey--;
}
}
}
void keyPressed() {
if (keyCode == UP) {
ey-= 15;
}
if (keyCode == LEFT) {
ex-= 5;
}
if (keyCode == RIGHT) {
ex+= 5;
}
}
//end
If anybody could help out that would be great. thanks!
edit: I fixed it.
Answers
http://forum.Processing.org/two/discussion/8045/how-to-format-code-and-text
Thanks!
Oh, I fixed it.
http://studio.ProcessingTogether.com/sp/pad/export/ro.9LZizxKsIAY4F