Need help with a puzzle game
in
Programming Questions
•
10 months ago
Hi, I'm
a beginner in processing. I need to create a word puzzle game that when you piece
the letters
together
in the correct position it gives you a feedback(positive).
At the moment, in my case this feedback is drawing a rect, but I have a problem with it.
I modified a puzzle code, that I found on openprocessing,and this is the code:
- PImage images [];
- rettangolo pezzi[];
- int pos_x, pos_y, dragged_box, grid_x,grid_y;
- boolean config_iniziale;
- int state1;
- int state2;
- int state3;
- void setup(){
- images = new PImage [3];
- pezzi = new rettangolo[3];
- for(int i=0; i<3; i++){
- images[i]= loadImage(i+".png");}
- size(1000, 700);
- pos_x =300;
- pos_y = 500;
- config_iniziale = true;
- dragged_box =-1;
- grid_x = 255; grid_y =200;
- }
- class rettangolo {
- int x1,x2,y1,y2;
- int ini_x1,ini_x2,ini_y1,ini_y2;
- rettangolo(int x1,int y1,int x2,int y2){
- this.x1 = ini_x1=x1;
- this.y1 = ini_y1=y1;
- this.x2 = ini_x2=x2;
- this.y2 = ini_y2=y2;
- }
- boolean over(int x,int y){
- return (x>=x1 && x<=x2 && y>=y1 && y<=y2);
- }
- }
- void draw(){
- background(255);
- fill(230);
- noStroke();
- rect(grid_x, grid_y, 500 ,200);
- int x=pos_x,y=pos_y;
- if(config_iniziale){
- config_iniziale = false;
- for(int i=0;i<3;i++){
- pezzi[i] = new rettangolo(int (random(x)), int (random(y)),x+500,y+500);
- if((i+1)%8==0){
- x = pos_x;
- y +=500;
- }
- else
- x +=300;
- }
- }
- for(int i=0; i<3; i++)
- image(images[i%3],pezzi[i].x1,pezzi[i].y1);
- }
- void mouseDragged(){
- for(int i=0; i<3; i++){
- if(dragged_box==i || (dragged_box== -1 && pezzi[i].over(mouseX,mouseY) )){
- dragged_box = i;
- pezzi[i].x1 = mouseX-50 ;
- pezzi[i].y1 = mouseY-50;
- pezzi[i].x2 = mouseX+50;
- pezzi[i].y2 = mouseY+50;
- break;
- }
- }
- }
- void mouseReleased(){
- int minx,miny,maxx,maxy;
- if(dragged_box!=-1){
- minx = 260+170*(dragged_box%3);
- maxx = minx+150;
- miny =230+ 200*(dragged_box/3);
- maxy = miny+150;
- // println(minx+","+maxx+","+miny+","+maxy);
- // println(mouseX+","+mouseY);
- if(mouseX>=minx && mouseX<=maxx &&
- mouseY>=miny && mouseY<=maxy){
- pezzi[dragged_box].x1 = minx;
- pezzi[dragged_box].x2 = maxx;
- pezzi[dragged_box].y1 = miny;
- pezzi[dragged_box].y2 = maxy;
- }
- dragged_box = -1;
- }
- //this is the part of code that I added to have the feedback but he doesn't work,
- //because first of all I don't know how to find each specific x and y position
- //of each piece(image)
- /*
- for(int i=0; i<3; i++){
- if ((255<<pos_x<421) && (200<<pos_y<400)) {
- state1=0;
- }
- if ((421<<pos_x<587) && (200<<pos_y<400)){
- state2=0;
- }
- if ((587<<pos_x<753) && (200<<pos_y<400)){
- state3=0;
- }
- if ((state1==0) &&(state2==0) && (state3==0)) {
- fill(0);
- rect(0,0,300,300);
- }
- }*/
- }
These are the images used in the code:
1