Help with final please! Maze game.
in
Programming Questions
•
10 months ago
Hey guys, I'm in my first programming/coding class and I'm having a little bit of trouble with my final project and am wondering if anyone could help.
For the project I have created a maze game. This game is made of three mazes, each images I have made in photoshop, once you get to the end of the first maze, you go to the next and so on.
For the character to remain constrained in the maze I am coding it based on the color of the pixels, it'll only move in the white areas. The first map works perfectly, but when I get to the next map the character is not constrained anymore, it'll float right over the lines of the map. Can anyone help with this?
For the character to remain constrained in the maze I am coding it based on the color of the pixels, it'll only move in the white areas. The first map works perfectly, but when I get to the next map the character is not constrained anymore, it'll float right over the lines of the map. Can anyone help with this?
Again, I'm pretty new at this, so I would appreciate input! Thank you!
- int page = 1;
- PImage map1;
- PImage map2;
- PImage map3;
- PImage last;
- PImage trainer;
- import ddf.minim.*;
- Minim minim;
- AudioPlayer song;
- int x = 20; //map 1
- int y = 20;
- int xm2 = 20; //map 2
- int ym2 = 20;
- int xm3 = 20; //map 3
- int ym3 = 20;
- int trainerwidth = 20;
- int trainerheight = 20;
- void setup() {
- size(500,700);
- trainer = loadImage("pokemontrainer.jpg");
- map1 = loadImage("map1.jpg");
- map2 = loadImage("map2.jpg");
- map3 = loadImage("map3.jpg");
- last = loadImage("last.jpg");
- minim = new Minim(this);
- song = minim.loadFile("pokemon8bit.mp3");
- song.play();
- }
- void draw() {
- smooth();
- background(255);
- if (page == 1) {
- image(map1, 0, 0);
- // make trainer
- image(trainer, x, y, trainerwidth, trainerheight);
- }
- if (page == 2) {
- image(map2, 0, 0);
- // make trainer
- image(trainer, xm2, ym2, trainerwidth-5, trainerheight-5);
- }
- if (page == 3) {
- image(map3, 0, 0);
- // make trainer
- image(trainer, xm3, ym3, trainerwidth-5, trainerheight-5);
- }
- if (page == 4) {
- image(last, 0, 0);
- }
- if (page == 1) {
- if ((x > 420) && (x < 505) && (y > 640) && (y < 700)) {
- page = 2;
- }
- }
- if (page == 2) {
- if ((xm2 > 0) && (xm2 < 80) && (ym2 > 640) && (ym2 < 700)) {
- page = 3;
- }
- }
- if (page == 3) {
- if ((xm3 > 440) && (xm3 < 505) && (ym3 > 640) && (ym3 < 700)) {
- page = 4;
- }
- }
- if (page == 4) {
- if (mousePressed == true) {
- page = 1;
- x = 15;
- y = 15;
- }
- }
- if (page == 1) {
- if(keyPressed){
- if(key=='a'){
- int loc = x-1 + y*map1.width;
- float redpix = red(map1.pixels[loc]);
- if(redpix > 200) {
- x--;
- }
- }
- else if(key=='d'){
- int loc = x+trainerwidth+1+y*map1.width;
- float redpix = red(map1.pixels[loc]);
- if(redpix > 200) {
- x++;
- }
- }
- else if(key=='w'){
- int loc = x + (y-1)*map1.width;
- float redpix = red(map1.pixels[loc]);
- if(redpix > 200) {
- y--;
- }
- }
- else if(key=='s'){
- int loc = x +(trainerheight+1+y)*map1.width;
- float redpix = red(map1.pixels[loc]);
- if(redpix > 200) {
- y++;
- }
- }
- }
- }
- if (page == 2) {
- if(keyPressed){
- if(key=='a'){
- int loc = x-1 + y*map2.width;
- float redpix = red(map1.pixels[loc]);
- if(redpix > 200) {
- xm2--;
- }
- }
- else if(key=='d'){
- int loc = x+trainerwidth+1+y*map1.width;
- float redpix = red(map1.pixels[loc]);
- if(redpix > 200) {
- xm2++;
- }
- }
- else if(key=='w'){
- int loc = x + (y-1)*map2.width;
- float redpix = red(map2.pixels[loc]);
- if(redpix > 200) {
- ym2--;
- }
- }
- else if(key=='s'){
- int loc = x +(trainerheight+1+y)*map2.width;
- float redpix = red(map2.pixels[loc]);
- if(redpix > 200) {
- ym2++;
- }
- }
- }
- }
- if (page == 3) {
- if(keyPressed){
- if(key=='a'){
- int loc = x-1 + y*map3.width;
- float redpix = red(map3.pixels[loc]);
- if(redpix > 200) {
- xm3--;
- }
- }
- else if(key=='d'){
- int loc = x+trainerwidth+1 + y*map3.width;
- float redpix = red(map3.pixels[loc]);
- if(redpix > 200) {
- xm3++;
- }
- }
- else if(key=='w'){
- int loc = x + (y-1)*map3.width;
- float redpix = red(map3.pixels[loc]);
- if(redpix > 200) {
- ym3--;
- }
- }
- else if(key=='s'){
- int loc = x +(trainerheight+1+y)*map3.width;
- float redpix = red(map3.pixels[loc]);
- if(redpix > 200) {
- ym3++;
- }
- }
- }
- }
- }
- void stop() {
- song.close();
- minim.stop();
- super.stop();
- }
1