living.picture
YaBB Newbies
Offline
Posts: 12
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; } } } }