I made a maze game where you have to reach the goal without touching a wall.
Here is the code for this game
void setup() { size(600, 400); background(40, 130, 0); fill(50, 100, 0); noStroke(); ellipseMode(CENTER); map(); } void draw() { drawline(); dontGoOver(); goal(); reset(); } void map() { // make a map textSize(13); text("START", 10, 30); text("HERE", 10, 50); rect(60, 0, 20, 340, 5); rect(130, 50, 20, 350, 5); rect(190, 0, 20, 360, 5); rect(240, 60, 20, 340, 5); rect(280, 0, 20, 380, 5); rect(310, 80, 20, 320, 5); rect(310, 80, 100, 20, 5); rect(390, 0, 20, 100, 5); fill(150, 30, 160); rectMode(CENTER); rect(350, 40, 40, 40); } void drawline() { // when mousepressed, draw a line stroke(255); if (mousePressed) { line(pmouseX, pmouseY, mouseX, mouseY); } } void dontGoOver() { //show "again" when they cross over if(mousePressed) { if(mouseX > 60 && mouseX < 80){ if(mouseY >0 && mouseY < 340){ background(255); textSize(32); text("AGAIN", 250, 100); fill(0, 102, 153); text("AGAIN", 250, 200); fill(0, 102, 153, 51); text("AGAIN", 250, 300); } } } if(mousePressed) { if(mouseX > 130 && mouseX < 150){ if(mouseY >50 && mouseY < 400){ background(255); textSize(32); text("AGAIN", 250, 100); fill(0, 102, 153); text("AGAIN", 250, 200); fill(0, 102, 153, 51); text("AGAIN", 250, 300); } } } if(mousePressed) { if(mouseX > 190 && mouseX < 210){ if(mouseY >0 && mouseY < 360){ background(255); textSize(32); text("AGAIN", 250, 100); fill(0, 102, 153); text("AGAIN", 250, 200); fill(0, 102, 153, 51); text("AGAIN", 250, 300); } } } if(mousePressed) { if(mouseX > 240 && mouseX < 210){ if(mouseY > 60 && mouseY < 400){ background(255); textSize(32); text("AGAIN", 250, 100); fill(0, 102, 153); text("AGAIN", 250, 200); fill(0, 102, 153, 51); text("AGAIN", 250, 300); } } } if(mousePressed) { if(mouseX > 280 && mouseX < 300){ if(mouseY > 0 && mouseY < 380){ background(255); textSize(32); text("AGAIN", 250, 100); fill(0, 102, 153); text("AGAIN", 250, 200); fill(0, 102, 153, 51); text("AGAIN", 250, 300); } } } if(mousePressed) { if(mouseX > 310 && mouseX < 330){ if(mouseY > 80 && mouseY < 400){ background(255); textSize(32); text("AGAIN", 250, 100); fill(0, 102, 153); text("AGAIN", 250, 200); fill(0, 102, 153, 51); text("AGAIN", 250, 300); } } } if(mousePressed) { if(mouseX > 310 && mouseX < 550){ if(mouseY > 80 && mouseY < 100){ background(255); textSize(32); text("AGAIN", 250, 100); fill(0, 102, 153); text("AGAIN", 250, 200); fill(0, 102, 153, 51); text("AGAIN", 250, 300); } } } if(mousePressed) { if(mouseX > 500 && mouseX < 550){ if(mouseY > 80 && mouseY < 350){ background(255); textSize(32); text("AGAIN", 250, 100); fill(0, 102, 153); text("AGAIN", 250, 200); fill(0, 102, 153, 51); text("AGAIN", 250, 300); } } } if(mousePressed) { if(mouseX > 390 && mouseX < 550){ if(mouseY > 320 && mouseY < 350){ background(255); textSize(32); text("AGAIN", 250, 100); fill(0, 102, 153); text("AGAIN", 250, 200); fill(0, 102, 153, 51); text("AGAIN", 250, 300); } } } if(mousePressed) { if(mouseX > 390 && mouseX < 410){ if(mouseY > 150 && mouseY < 350){ background(255); textSize(32); text("AGAIN", 250, 100); fill(0, 102, 153); text("AGAIN", 250, 200); fill(0, 102, 153, 51); text("AGAIN", 250, 300); } } } if(mousePressed) { if(mouseX > 330 && mouseX < 370){ if(mouseY > 20 && mouseY < 60){ background(255); textSize(20); text("You thought this was the goal? Not quite, bro.", 70, 100); fill(0, 102, 153); text("You thought this was the goal? Not quite, bro.", 70, 200); fill(0, 102, 153, 51); text("You thought this was the goal? Not quite, bro.", 70, 300); } } } } void goal() { // when the player reaches to the goal, show "GOOD JOB" if(mousePressed) { if(mouseX > 420 && mouseX < 490){ if(mouseY > 250 && mouseY < 350){ background(0, 255, 0); textSize(32); text("GOOD JOB", 200, 100); fill(0, 102, 153); text("GOOD JOB", 200, 200); fill(0, 102, 153, 51); text("GOOD JOB", 200, 300); } } } } void reset(){ // click spacebar to restart if(keyPressed) { rectMode(CORNER); background(40, 130, 0); fill(50, 100, 0); noStroke(); ellipseMode(CENTER); map(); } }
The problem with this coding is, it doesn’t restrict the player to start from the left top so basically he can cheat. I guess I can do something like: if mouse pressed at left top, start the game, else, game over. i tried to do that but i couldn’t make the code that works so it’s left as it is.
I wanted also to make it look more appealing, but i couldn’t. I guess there is a limit in how good looking you can make with just colours. I have to either use more colors or use some textures (like bricks or metal).