We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Simple Maze Game, need help
Page Index Toggle Pages: 1
Simple Maze Game, need help (Read 996 times)
Simple Maze Game, need help
Jan 15th, 2010, 1:56am
 
Hey,
i am working on a mini game for my processing class..
I use a collision map and i have already drawn the map and added a little light spot arround my player, so that you can only see a little part of the maze.
now i am thinking of integrating a key which you get somewhere in the labyrinth and a door which you can only pass if you first pass the key..
but i am very new to processing.. so maybe some can help me ?

furthermore an enemy moving threw the maze would be great, but i think this is very difficult and the key thing would be more important Smiley
thank you
Re: Simple Maze Game, need help
Reply #1 - Jan 15th, 2010, 3:00am
 
A key and a door is simple enough. Just make the door into a wall that is solid only when you have the key. If you like you can get really fancy and make it so the door turns invisible (that is, it isn't even drawn!) when you pick the key up.

As for an enemy moving about the maze, would you want one that hunts down the player ruthlessly, or wanders about aimlessly? Both should be easy to add.

We can make suggestions about what you can do all day long, but the best way for us to help you is by letting us see your code. Post a function or two (or three) (or all of it) so we can really see what's going on.
Re: Simple Maze Game, need help
Reply #2 - Jan 16th, 2010, 2:17am
 
Ok,
so Labyrinth.gif is the maze, level.gif is the same picture.
schirm is a black screen with an ellipse in the middle threw that you can see.
the get key, make wall invisible option would be great and the aimless moving enemy

int x;
int y;
int s;
int half_size;
int speed;

PImage level;
PImage schirm;


boolean[][] collisionMap;

void setup() {
 
 size(1200, 800);
 background(0);
 rectMode(CENTER);
   schirm = loadImage ("schirm.png");

 x = 50;
 y = 750;

 s = 10;
 half_size = s / 2;
 speed = 12;
 

 level = loadImage("level.gif");
 PImage colMapImage = loadImage("collisionMap.gif");
 collisionMap = new boolean[colMapImage.width][colMapImage.height];
 
 color black = color(0);
 color white = color(255);
 

 for (int i = 0; i < colMapImage.width; i++) {
   for (int j = 0; j < colMapImage.height; j++) {
     
     color c = colMapImage.get(i, j);
     if (c == black) {
       collisionMap[i][j] = false;
     }

     else if (c == white) {
       collisionMap[i][j] = true;
     }
     else {
       println("Whoops! We shouldn't have colors other than black and white in our collision map!");
     }

   }
 }
}

void draw() {
 background(0);
 image(level, 0, 0);
 
 fill(255, 0, 0);
 noStroke();
 rect(x, y, 10, 10);
 image(schirm, x-2400, y-1600);
}

void keyPressed() {

 boolean up_left = false;
 boolean up_right = false;
 boolean down_right = false;
 boolean down_left = false;

 if (keyCode == LEFT) {
   if (x >= half_size + speed)
   {

     up_left = collisionMap[x - speed - half_size][y - half_size];
     up_right = collisionMap[x - speed + half_size][y - half_size];
     down_right = collisionMap[x - speed + half_size][y + half_size];
     down_left = collisionMap[x - speed - half_size][y + half_size];
     

     if (up_left && up_right && down_right && down_left) {

       x -= speed;
     }
   }
 }
 

 if (keyCode == RIGHT) {
   if (x <= width - half_size - speed)
   {
     up_left = collisionMap[x + speed - half_size][y - half_size];
     up_right = collisionMap[x + speed + half_size][y - half_size];
     down_right = collisionMap[x + speed + half_size][y + half_size];
     down_left = collisionMap[x + speed - half_size][y + half_size];

     if (up_left && up_right && down_right && down_left) {
       x += speed;
     }
   }
 }

 if (keyCode == UP) {
   if (y >= half_size + speed)
   {
     up_left = collisionMap[x - half_size][y - speed - half_size];
     up_right = collisionMap[x + half_size][y - speed - half_size];
     down_right = collisionMap[x + half_size][y - speed + half_size];
     down_left = collisionMap[x - half_size][y - speed + half_size];

     if (up_left && up_right && down_right && down_left) {
       y -= speed;
     }
   }
 }

 if (keyCode == DOWN) {
   if (y <= height - half_size - speed)
   {
     up_left = collisionMap[x - half_size][y + speed - half_size];
     up_right = collisionMap[x + half_size][y + speed - half_size];
     down_right = collisionMap[x + half_size][y + speed + half_size];
     down_left = collisionMap[x - half_size][y + speed + half_size];

     if (up_left && up_right && down_right && down_left) {
       y += speed;
     }
   }
 }
}





Page Index Toggle Pages: 1