i got one small question. i want a timer to start and count in my program after a start it. i got an opening screen and if i press enter it goes to the main screen and i want the timer to start then instead of the beginning of the program. i made an small example of what is in my code. maybe you guys can help me.
i got a problem. i need a game sort of qual to snake. and i have my triangle and moving. but i use that in the draw.
so i need the balls to be in the void draw too. but if i give them a random they keep moving. if i declare it globally outside the voids. it starts with one position and thats good. but i want to go over the ball with the triangle and then it needs to dissappear and appear somewhere random on the screen. and let that dissappear again if I go over it with the triangle.
it also needs to fit in little squares of 40. so the triangle fits perfectly over the balls.
I already tried something but that didnt work out.
hope you guys can help me out.
here is my try:
int ballPos = round(random(0,amountOfSquares-1)) * SquareSize
I got a moving Triangle in my program and i also have a few screens you have to go trough by pressing enter.
Now i only want the triangle to be controllable in the last screen. but for it to move it needs to be checked constantly and that is where void draw is for. but if i put it in draw it wont show the other screens. is there a way to do it without draw?
I'm pretty new to Processing and for my program that I am making I want to move a triangle with the directional arrows on the keyboard.I found a way to do it but the code is very long and it gots bugs because the triangle gets really weird shapes when i keep moving.
This is my code for the moving triangle:
boolean up = true;
boolean down = false;
boolean right = false;
boolean left = false;
int X1 = 200;
int Y1 = 200;
int X2 = 220;
int Y2 = 160;
int X3 = 240;
int Y3 = 200;
void setup() {
background(0);
size(400, 400);
}
void draw() {
background(0);
drawTriangle();
}
void drawTriangle() {
fill(#FFFFFF);
triangle(X1, Y1, X2, Y2, X3, Y3);
if ( X1 == 1) {
X1 = 0;
}
}
void keyPressed() {
if (keyCode == UP && up == true) {
Y1= Y1 - 40;
Y2 = Y2 - 40;
Y3 = Y3 - 40;
}
if (keyCode == UP && down == true) {
Y2 = Y2 - 40;
Y1 = Y1 + 40;
Y3 = Y3 + 40;
up = true;
down = false;
}
if (keyCode == UP && right == true) {
Y1 = Y1 + 40;
X2 = X2 - 20;
Y2 = Y2 - 20;
X3 = X3 + 40;
up = true;
right = false;
}
if (keyCode == UP && left == true) {
X1 = X1 - 40;
X2 = X2 + 20;
Y2 = Y2 - 20;
Y3 = Y3 + 40;
left = false;
up = true;
}
if (keyCode == DOWN && down == true) {
Y1= Y1 + 40;
Y2 = Y2 + 40;
Y3 = Y3 + 40;
}
if (keyCode == DOWN && up == true) {
Y2 = Y2 + 40;
Y1 = Y1 - 40;
Y3 = Y3 - 40;
down = true;
up = false;
}
if (keyCode == DOWN && right == true) {
X1 = X1 + 40;
X2 = X2 - 20;
Y2 = Y2 + 20;
Y3 = Y3 - 40;
down = true;
right = false;
}
if (keyCode == DOWN && left == true) {
Y1 = Y1 - 40;
Y2 = Y2 + 20;
X2 = X2 + 20;
X3 = X3 - 40;
left = false;
down = true;
}
if (keyCode == RIGHT && right == true) {
X1 = X1 + 40;
X2 = X2 + 40;
X3 = X3 + 40;
}
if (keyCode == RIGHT && up == true) {
Y1 = Y1 - 40;
X2 = X2 + 20;
Y2 = Y2 + 20;
X3 = X3 - 40;
up = false;
right = true;
}
if (keyCode == RIGHT && left == true) {
X1 = X1 - 40;
X2 = X2 + 40;
X3 = X3 - 40;
left = false;
right = true;
}
if (keyCode == RIGHT && down == true) {
Y1 = Y1 + 40;
Y2 = Y2 - 20;
X2 = X2 + 20;
X3 = X3 - 40;
down = false;
right = true;
}
if (keyCode == LEFT && left == true) {
X1 = X1 - 40;
X2 = X2 - 40;
X3 = X3 - 40;
}
if (keyCode == LEFT && up == true) {
X1 = X1 + 40;
X2 = X2 - 20;
Y2 = Y2 + 20;
Y3 = Y3 - 40;
left = true;
up = false;
}
if (keyCode == LEFT && down == true) {
Y1 = Y1 + 40;
Y2 = Y2 - 20;
X2 = X2 - 20;
X3 = X3 + 40;
left = true;
down = false;
}
if (keyCode == LEFT && right == true) {
X1 = X1 + 40;
X2 = X2 - 40;
X3 = X3 + 40;
left = true;
right = false;
}
}
I hope that you guys can help me because i really want to finish this program.