Results 1 to 3 of 3
  1. #1
    paris72 is offline Member
    Join Date
    Apr 2012
    Posts
    6
    Rep Power
    0

    Default 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 :
    Java 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 :
    Java 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 .

  2. #2
    waker3210 is offline Member
    Join Date
    Jan 2012
    Posts
    18
    Rep Power
    0

    Default 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.?

  3. #3
    paris72 is offline Member
    Join Date
    Apr 2012
    Posts
    6
    Rep Power
    0

    Default Re: working on a pacman game need help

    Quote Originally Posted by waker3210 View Post
    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

Similar Threads

  1. Replies: 3
    Last Post: 05-09-2012, 10:35 AM
  2. Pacman Game
    By Hollowsoul in forum Java 2D
    Replies: 13
    Last Post: 07-17-2011, 12:31 AM
  3. Making PacMan game, need help!
    By Mondos in forum Java Gaming
    Replies: 14
    Last Post: 06-03-2011, 04:24 PM
  4. Huge problem. PacMan game.
    By Bullfrog in forum New To Java
    Replies: 3
    Last Post: 06-01-2010, 03:39 PM
  5. need help with pacman game!!
    By Newbie_Javaer in forum New To Java
    Replies: 2
    Last Post: 10-22-2009, 03:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •