void draw() { background(255); drawMaze(); drawPlayer(); drawTarget(); drawBox(box1X, box1Y, boxColors[2]); // Draw Box with yellow drawBox(box2X, box2Y, boxColors[2]); // Draw Box with yellow drawBox(box3X, box3Y, boxColors[3]); // Draw Box with pink drawBox(box4X, box4Y, boxColors[3]); // Draw Box with pink drawBox(box5X, box5Y, boxColors[1]); // Draw Box with blue drawBox(box6X, box6Y, boxColors[1]); // Draw Box with blue drawBox(box7X, box7Y, boxColors[0]); // Draw Box with red drawBox(box8X, box8Y, boxColors[0]); // Draw Box with red drawBox(box9X, box9Y, boxColors[4]); // Draw Box with red drawBox(box10X, box10Y, boxColors[4]); // Draw Box with red if (playerX == targetX && playerY == targetY) { fill(0); textSize(80); textAlign(CENTER, CENTER); text("You Win!", width / 2, height / 2); // win message } // Check if the player reaches Box 1 if (playerX == box1X && playerY == box1Y) { playerX = box2X; // Respawn the player at Box 2 X position playerY = box2Y; // Respawn the player at Box 2 Y position reachedBox1 = true; } if (playerX == box4X && playerY == box4Y) { playerX = box3X; // Respawn the player at Box 3 X position playerY = box3Y; // Respawn the player at Box 3 Y position reachedBox1 = true; } if (playerX == box7X && playerY == box7Y) { playerX = box8X; // Respawn the player at Box 8 X position playerY = box8Y; // Respawn the player at Box 8Y position reachedBox1 = true; } if (playerX == box6X && playerY == box6Y) { playerX = box5X; // Respawn the player at Box 5 X position playerY = box5Y; // Respawn the player at Box 5 Y position reachedBox1 = true; } if (playerX == box9X && playerY == box9Y) { playerX = box10X; // Respawn the player at Box 5 X position playerY = box10Y; // Respawn the player at Box 5 Y position reachedBox1 = true; } } void drawMaze() { for (int i = 0; i < maze.length; i++) { for (int j = 0; j < maze[i].length; j++) { if (maze[i][j] == 1) { fill(100); rect(j * tileSize, i * tileSize, tileSize, tileSize); } } } } void drawPlayer() { fill(playerColor); ellipse(playerX, playerY, tileSize * 0.8, tileSize * 0.8); } void drawTarget() { fill(0, 255, 0); rect(targetX - tileSize / 2, targetY - tileSize / 2, tileSize, tileSize); } void drawBox(int x, int y, color boxColor) { fill(boxColor); // Use the color rect(x - tileSize / 2, y - tileSize / 2, tileSize, tileSize); }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter