working on a pacman game need help
I'm working on a pacman game and I'm having some problems .
first of all when the enemy is passing the pacman nothing happens while it is supposed to less the lives of the pacman and sometimes it less the lives of the pacman but the enemy hasn't pass the pacman .
the second problem is this that in the easy mode the enemy should understand if the pacman is near it in four around places it works first that I just add it for one way but when I add it for all four possible ways it is not doing it .
in the medium mode the enemy should search the five next places in each possible way ( I mean right , left , up and down ) to see if the pacman is at those places follow it but it cannot do it .
OK . Let's take a look at my code :
this is the part that I'm trying to reduce from the lives of the pacman :
Code:
if ( (en1.x == x && en1.y == y) || (en2.x == x && en2.y == y) || (en3.x == x && en3.y == y)) {
lives--;
x = 15 ;
y = 10 ;
System.out.println("you die");
if ( lives == 0){
new GameOver() ;
}
}
this the part that for the second problem :
Code:
public class MidiumEnemy extends Thread{
int x ;
int y ;
int dir ;
Random r = new Random() ;
MidiumPanel p ;
public MidiumEnemy (int x , int y ,MidiumPanel p) {
this.x = x ;
this.y = y ;
this.p = p ;
dir = 3 ;
}
public void run () {
while (true) {
if (dir == 3) {
if (p.map[y-1][x] != 1 && p.enemy[y-1][x] == false) {
for (int i = 1 ; i < 6 ; i++) {
if (p.pacman[y][x-i] == true) {
if (x == 0) x = 19 ;
dir = 1 ;
}
else if (p.pacman[y][x+i] == true) {
if (x == 19) x = 0 ;
dir = 2 ;
}
else if (p.pacman[y+1][x] == true) {
if (y == 19) y = 0 ;
dir = 4 ;
// if (y == 19) y = 0 ;
}
else break ;
}//end of for
p.enemy[y][x] = false ;
y--;
p.enemy[y][x] = true ;
if (y == 0) y = 19 ;
}//end of if (p.map)
else dir = Math.abs(r.nextInt())%4+1;
}// end of if dir ==3
if (dir == 4) {
if (p.map[y+1][x] != 1 && p.enemy[y+1][x] == false) {
for (int i = 1 ; i < 6 ; i++) {
if (p.pacman[y][x-i] == true) {
if (x == 0) x = 19 ;
dir = 1 ;
}
else if (p.pacman[y][x+1] == true) {
if (x == 19) x = 0 ;
dir = 2 ;
}
else if (p.pacman[y-1][x] == true) {
if (y == 0) y = 19 ;
dir = 3 ;
}
else break ;
}// end of for
p.enemy[y][x] = false ;
y++;
p.enemy[y][x] = true ;
if (y == 19) y = 0 ;
}// end of if p.map
else dir = Math.abs(r.nextInt())%4+1;
}// end of if dir == 4
if (dir == 1) {
if (p.map[y][x-1] != 1 && p.enemy[y][x-1] == false) {
for (int i = 1 ; i < 6 ; i++) {
if (p.pacman[y][x+i] == true) {
if (x == 19) x = 0 ;
dir = 2 ;
}
else if (p.pacman[y-i][x] == true) {
if (y == 0) y = 19 ;
dir = 3 ;
}
else if (p.pacman[y+i][x] == true) {
if (y == 19) y = 0 ;
dir = 4 ;
}
else break ;
}//end of for
p.enemy[y][x] = false ;
x--;
p.enemy[y][x] = true ;
if (x == 0) x = 19 ;
}// end of if p.map
else dir = Math.abs(r.nextInt())%4+1;
}//end of if dir ==1
if (dir == 2) {
if (p.map[y][x + 1] != 1 && p.enemy[y][x+1] == false) {
for ( int i = 1 ; i < 6 ; i++) {
if (p.pacman[y][x-i] == true) {
if (x == 0) x = 19 ;
dir = 1 ;
}
else if (p.pacman[y-i][x] == true) {
if (y == 0) y = 19 ;
dir = 3 ;
}
else if (p.pacman[y+i][x] == true) {
if (y == 19) y = 0 ;
dir = 4 ;
}
else break ;
}//end of for
p.enemy[y][x] = false ;
x++;
p.enemy[y][x] = true ;
if (x == 19) x = 0 ;
}//end of if p.map
else dir = Math.abs(r.nextInt())%4+1;
}// end of if dir ==2
try {
sleep(150) ;
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}// end of while
}// end of run
}
I really need help . If anyone needed to know more about it just tell me .
Re: working on a pacman game need help
Could you tell me what en1, 2 and 3 are? For example, is it a Rectangle,etc.?
Re: working on a pacman game need help
Quote:
Originally Posted by
waker3210
Could you tell me what en1, 2 and 3 are? For example, is it a Rectangle,etc.?
thank you for your help but it solved anyway they are objects from another class named Enemy