We are about to switch to a new forum software. Until then we have removed the registration on this forum.
/* Use your Mouse to play*/
int ScreenX=440;
int ScreenY=800;
int FrameRate=10;
int[] SquareX=new int[4];
int[] SquareY=new int[4];
int MaxTime=20;
boolean Mouse;
boolean Start;
boolean End;
int Timer;
int Score;
void setup(){
size(ScreenX,ScreenY);
frameRate(FrameRate);
Mouse=false;
Start=false;
End=false;
Timer=0;
Score=0;
for(int A=0;A<4;A++){
SquareX[A]=int(random(0,4));
SquareY[A]=A;
}
}
void draw(){
background(255);
if(Start==true&Timer<MaxTime*FrameRate){
Timer=Timer+1;
}
else if(Timer>=MaxTime){
Start=false;
End=true;
}
for(int B=0;B<4;B++){
fill(0,100);
rect(ScreenX/4*B,ScreenY-ScreenY/5,ScreenX/4,ScreenY/5);
fill(#FFF04B,100);
rect(ScreenX/4*round(SquareX[B]),ScreenY/5*SquareY[B],ScreenX/4,ScreenY/5);
if(B<3){
line(ScreenX/4*(B+1),0,ScreenX/4*(B+1),ScreenY-ScreenY/5);
line(0,ScreenY/5*(B+1),ScreenX,ScreenY/5*(B+1));
}
if(Mouse==true&End==false){
if(mouseX>ScreenX/4*round(SquareX[3])&mouseX<ScreenX/4*(round(SquareX[3])+1)&mouseY>ScreenY-ScreenY/5&mouseY<ScreenY){
Score++;
SquareX[3]=SquareX[2];
SquareX[2]=SquareX[1];
SquareX[1]=SquareX[0];
SquareX[0]=int(random(0,4));
Start=true;
}
Mouse=false;
}
}
if(End==true){
fill(0,255,0,100);
rect(0,0,ScreenX,ScreenY);
fill(0);
textSize((ScreenX*ScreenY)/10000);
textAlign(CENTER,CENTER);
text("End",ScreenX/2,ScreenY/4*1);
text("SCORE:"+round(Score),ScreenX/2,ScreenY/4*2);
text("PLAY AGAIN PRESS SPACE",ScreenX/2,ScreenY/4*3);
if(keyPressed){
if(key==' '){
setup();
}
}
}
}
void mousePressed(){
if(mouseButton==LEFT){
Mouse=true;
}
}
Comments
I want to know your best score :p Mine is 68
Some notes on the code:
ScreenX
orScreenY
? Better callsize(640, 800);
then use the built-in variableswidth
andheight
, instead.Yeah sorry for the capital letters I always program like that, its hard to change an habit.
Hi, i´m doodeling around with your PianoTiles sketch, but i can´t wrap my head around this one thing. Instead of using the mouse (line51,52 in your code), i want to use the keys 1,2,3,4 on my keyboard(or even better midi). could you help me with that?
@TheLacasse2:
this
if(Mouse==true&End==false){
is the same
if(Mouse & !End){
Another note: avoid calling setup() yourself. Better have an setVariables() (for example) function that initialize them to the values in setup(), to call in setup() and in your reset condition.
And to use keyboard instead of mouse, just look at the variables and functions starting with key in the Reference page.
what is the goal ?
How do I play?
Do I always need to click in grey rectangle at the bottom in the column with stone # 3?
Thank you!
-@Chrisir-:
The goal of my game is to beat your best score and yes you have to click in the grey rectangle at the bottom :)
Nice :D
thank you!
using the ScreenX and ScreenY how could the randomly generated tiles be textured with an image
nvm I replaced the rectangle objects with images from the PImage. I was confused, but the dimensions of images change outside of the program. I only needed to place a x,y coordinate
I see
Well done.