Page 1 of 2 12 LastLast
Results 1 to 20 of 27

Thread: Help with game

  1. #1
    TGH
    TGH is offline Member
    Join Date
    Nov 2009
    Posts
    32
    Rep Power
    0

    Default Help with game

    Hello,

    I'm making a pacman program and i'm stuck.

    I have to make a public boolean, i only dont know what i have to give to this class.
    Under is my code...

    Java Code:
    package pacman;
    
    import javax.swing.*;
    import java.util.*;
    import java.awt.*;
    
    public class Maze 
    {
    	int [ ][ ] raster;
    	int score;
    	final int WALL = -1; //MUUR == WALL
    	final int EMPTY = 0; //EMPTY==LEEG
    	final int PILL = 1; // PILL == PIL
    	int BONUS;
    	int i, j; //helpintegers
    	Random generator;
    	
    	public Maze()
    	{
    		raster = new int [16][11];
    		fillMaze();
    	}
    	
    	public void fillMaze()
    	{
    		Random generator = new Random();
    		raster[0][0] = MUUR;
    		raster[1][0] = MUUR;
    		raster[2][0] = MUUR;
    		raster[3][0] = MUUR;
    		raster[4][0] = MUUR;
    		raster[5][0] = MUUR;
    		raster[6][0] = MUUR;
    		raster[7][0] = MUUR;
    		raster[8][0] = PIL;
    		raster[9][0] = MUUR;
    		raster[10][0] = MUUR;
    		raster[11][0] = MUUR;
    		raster[12][0] = MUUR;
    		raster[13][0] = MUUR;
    		raster[14][0] = MUUR;
    		raster[15][0] = MUUR;
    		raster[0][1] = MUUR;
    		raster[1][1] = MUUR;
    		raster[2][1] = PIL;
    		raster[3][1] = PIL;
    		raster[4][1] = PIL;
    		raster[5][1] = PIL;
    		raster[6][1] = PIL;
    		raster[7][1] = PIL;
    		raster[8][1] = LEEG;
    		raster[9][1] = PIL;
    		raster[10][1] = PIL;
    		raster[11][1] = PIL;
    		raster[12][1] = PIL;
    		raster[13][1] = LEEG;
    		raster[14][1] = PIL;
    		raster[15][1] = MUUR;
    		raster[0][2] = MUUR;
    		raster[1][2] = PIL;
    		raster[2][2] = PIL;
    		raster[3][2] = MUUR;
    		raster[4][2] = MUUR;
    		raster[5][2] = MUUR;
    		raster[6][2] = PIL;
    		raster[7][2] = MUUR;
    		raster[8][2] = PIL;
    		raster[9][2] = LEEG;
    		raster[10][2] = MUUR;
    		raster[11][2] = PIL;
    		raster[12][2] = MUUR;
    		raster[13][2] = PIL;
    		raster[14][2] = LEEG;
    		raster[15][2] = MUUR;
    		raster[0][3] = MUUR;
    		raster[1][3] = LEEG;
    		raster[2][3] = PIL;
    		raster[3][3] = MUUR;
    		raster[4][3] = BONUS = generator.nextInt(15) + 2;
    		raster[5][3] = MUUR;
    		raster[6][3] = LEEG;
    		raster[7][3] = PIL;
    		raster[8][3] = PIL;
    		raster[9][3] = LEEG;
    		raster[10][3] = MUUR;
    		raster[11][3] = BONUS = generator.nextInt(15) + 2;
    		raster[12][3] = MUUR;
    		raster[13][3] = LEEG;
    		raster[14][3] = PIL;
    		raster[15][3] = MUUR;
    		raster[0][4] = MUUR;
    		raster[1][4] = PIL;
    		raster[2][4] = PIL;
    		raster[3][4] = MUUR;
    		raster[4][4] = LEEG;
    		raster[5][4] = MUUR;
    		raster[6][4]= PIL;
    		raster[7][4] = MUUR;
    		raster[8][4] = MUUR;
    		raster[9] [4]= PIL;
    		raster[10] [4]= MUUR;
    		raster[11][4] = MUUR;
    		raster[12][4] = MUUR;
    		raster[13][4] = PIL;
    		raster[14][4] = MUUR;
    		raster[15][4] = MUUR;
    		raster[0][5] = PIL;
    		raster[1][5] = PIL;
    		raster[2] [5]= LEEG;
    		raster[3][5] = LEEG;
    		raster[4][5] = PIL;
    		raster[5][5] = LEEG;
    		raster[6][5] = LEEG;
    		raster[7][5] = BONUS = generator.nextInt(15) + 2;
    		raster[8][5] = MUUR;
    		raster[9] [5]= PIL;
    		raster[10][5] = LEEG;
    		raster[11][5] = PIL;
    		raster[12][5] = LEEG;
    		raster[13] [5]= LEEG;
    		raster[14][5] = PIL;
    		raster[15][5] = PIL;
    		raster[0][6] = MUUR;
    		raster[1][6] = PIL;
    		raster[2][6] = PIL;
    		raster[3][6] = MUUR;
    		raster[4][6] = LEEG;
    		raster[5][6] = MUUR;
    		raster[6][6] = PIL;
    		raster[7][6] = MUUR;
    		raster[8][6] = MUUR;
    		raster[9][6] = LEEG;
    		raster[10][6] = MUUR;
    		raster[11][6]= MUUR;
    		raster[12][6]= MUUR;
    		raster[13][6] = PIL;
    		raster[14][6] = LEEG;
    		raster[15][6] = MUUR;
    		raster[0][7] = MUUR;
    		raster[1][7] = PIL;
    		raster[2][7] = MUUR;
    		raster[3][7] = MUUR;
    		raster[4][7] = BONUS = generator.nextInt(15) + 2;
    		raster[5][7] = MUUR;
    		raster[6][7] = PIL;
    		raster[7][7] = LEEG;
    		raster[8][7] = PIL;
    		raster[9][7] = PIL;
    		raster[10][7] = MUUR;
    		raster[11][7] = BONUS = generator.nextInt(15) + 4;
    		raster[12][7] = MUUR;
    		raster[13][7] = PIL;
    		raster[14][7] = MUUR;
    		raster[15][7] = MUUR;
    		raster[0][8] = MUUR;
    		raster[1][8] = PIL;
    		raster[2][8] = PIL;
    		raster[3][8] = MUUR;
    		raster[4][8] = MUUR;
    		raster[5][8] = MUUR;
    		raster[6][8] = LEEG;
    		raster[7][8] = MUUR;
    		raster[8][8] = LEEG;
    		raster[9][8] = PIL;
    		raster[10][8] = MUUR;
    		raster[11][8] = LEEG;
    		raster[12][8] = MUUR;
    		raster[13][8] = LEEG;
    		raster[14][8] = PIL;
    		raster[15][8] = MUUR;
    		raster[0][9] = MUUR;
    		raster[1][9] = PIL;
    		raster[2][9] = PIL;
    		raster[3][9] = PIL;
    		raster[4][9] = PIL;
    		raster[5][9] = PIL;
    		raster[6][9] = PIL;
    		raster[7][9] = PIL;
    		raster[8][9] = PIL;
    		raster[9][9] = LEEG;
    		raster[10][9] = PIL;
    		raster[11][9] = PIL;
    		raster[12][9] = PIL;
    		raster[13][9] = PIL;
    		raster[14][9] = PIL;
    		raster[15][9] = MUUR;	
    		raster[0][10] = MUUR;
    		raster[1][10] = MUUR;
    		raster[2][10] = MUUR;
    		raster[3][10] = MUUR;
    		raster[4][10] = MUUR;
    		raster[5][10] = MUUR;
    		raster[6][10] = MUUR;
    		raster[7][10] = MUUR;
    		raster[8][10] = PIL;
    		raster[9][10] = MUUR;
    		raster[10][10] = MUUR;
    		raster[11][10] = MUUR;
    		raster[12][10] = MUUR;
    		raster[13][10] = MUUR;
    		raster[14][10] = MUUR;
    		raster[15] [10]= MUUR;
    	}
    	
    	public boolean isAccesible(int x, int y , int howbig)
    	{
    		//Absolutely NO idea what to come here
    	}
    	
    	public void eatBonus(int x, int y, int howbig)
    	{
    		//NO idea what to come here
    	}
    	
    	public void Draw(Graphics g)
    	{
    		for(i = 0; i < 16; i++)
    			for(j = 0; j < 11; j++)
    			{
    				if(raster[i][j] == MUUR)
    				{
    					g.setColor(Color.DARK_GRAY);
    					g.fillRect(i * 50, j * 50, 50, 50);
    				}
    				
    				if(raster[i][j] == LEEG)
    				{
    					g.setColor(Color.LIGHT_GRAY);
    					g.fillRect(i * 50, j * 50, 50, 50);
    					g.setColor(Color.BLACK);//Het lijntje eromheen
    					g.drawRect(i * 50, j * 50, 50, 50);
    				}
    				
    				if(raster[i][j] == PIL)
    				{
    					g.setColor(Color.LIGHT_GRAY);
    					g.fillRect(i * 50, j * 50, 50, 50);
    					g.setColor(Color.WHITE);
    					g.fillOval((i * 50) + 18, (j* 50) + 18, 20, 20);
    					g.setColor(Color.BLACK);//Het lijntje eromheen
    					g.drawRect(i * 50, j * 50, 50, 50);
    				}
    				
    				if(raster[i][j] == BONUS)
    				{
    					g.setColor(Color.LIGHT_GRAY);
    					g.fillRect(i * 50, j * 50, 50, 50);
    					g.drawString(Integer.toString(BONUS), i*50, j*50);
    					g.setColor(Color.BLACK);//Het lijntje eromheen
    					g.drawRect(i * 50, j * 50, 50, 50);
    				}
    			}
    		
    		
    	}
    	
    	
    
    }
    Help?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,368
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by TGH View Post
    Java Code:
    	public boolean isAccesible(int x, int y , int howbig)
    	{
    		//Absolutely NO idea what to come here
    	}
    	
    	public void eatBonus(int x, int y, int howbig)
    	{
    		//NO idea what to come here
    	}
    Help?
    My guess is that you can't walk through a wall (MUUR) so your method can look something like this:

    Java Code:
    boolean isAccessible(int x, int y) {
       return raster[x][y] != MUUR;
    }
    I don't know what that third parameter was all about so I left it out. Your eatBonus( ... ) method should look similar.

    kind regards,

    Jos

  3. #3
    TGH
    TGH is offline Member
    Join Date
    Nov 2009
    Posts
    32
    Rep Power
    0

    Default

    The third parameter was the size.
    I actually dont think it has to be in this code, so I think I will left it out.
    Thank you very much and maybe you will soon see another question if I dont get it right;.

  4. #4
    TGH
    TGH is offline Member
    Join Date
    Nov 2009
    Posts
    32
    Rep Power
    0

    Default

    It doesn't work, I get a NullPointException.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,368
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by TGH View Post
    It doesn't work, I get a NullPointException.
    Which line? NullPointerExceptions are easy to find: System.out.println( ... ) your variables near the line where you receive the exception (the JVM told you where it all happened); work your way back in the code until you find the incorrect line(s).

    kind regards,

    Jos

  6. #6
    TGH
    TGH is offline Member
    Join Date
    Nov 2009
    Posts
    32
    Rep Power
    0

    Default

    Well Eclipse easily says where the error is found.

    The error comes in the Pacman Class. This is the class where the pacman is drawn.

    Java Code:
    package pacman;
    
    import java.awt.*;
    
    public class Pacman extends Poppetje
    {
    	Doolhof doolhof;
    
    	public Pacman(int x, int y, int grootte, boolean hap)
    	{
    		this.x = x;
    		this.y = y;
    		this.grootte = grootte;
    		this.hap = hap;
    
    		if (doolhof.isToegankelijk( x, y ))
    				{
    					doolhof.eetBonus( x, y );
    				}
    	}
    
    	public void tekenPacman(Graphics g)
    	{
    		if(this.hap == true)
    		{
    			g.setColor(Color.YELLOW);
    			g.fillOval(x, y, grootte, grootte);
    			g.setColor(Color.BLACK);
    			g.fillOval(x + (grootte/2) + (grootte/10), y + (grootte/4), grootte/6, grootte/6 );
    		}
    		else
    		{
    			g.setColor(Color.YELLOW);
    			g.fillArc(x, y, grootte, grootte, -135, 290);
    			g.setColor(Color.BLACK);
    			g.fillOval(x + (grootte/2) + (grootte/10), y + (grootte/4), grootte/6, grootte/6 );
    		}
    	}
    
    }
    The error comes with this line:

    Java Code:
    if (doolhof.isToegankelijk( x, y )) <------
    				{
    					doolhof.eetBonus( x, y );
    				}
    What am I doing wrong?

    The other error message comes from the Panel where everything is drawn:

    Java Code:
    public PacmanPaneel()
    	{
    		addMouseWheelListener(this);
    		doolhof = new Doolhof();
    		pacman = new Pacman(450, 100, 50, hap);
    		spookje1 = new Spookje(200, 300, Color.GREEN);
    		spookje2 = new Spookje(50, 110, Color.MAGENTA);
    		spookje3 = new Spookje(400, 50, Color.BLUE);
    		spookje4 = new Spookje(150, 50, Color.RED);
    		Timer autoHap = new Timer(150, this);
    		autoHap.start();
    Error: "pacman = new Pacman(450, 100, 50, hap);"

    I have totally no idea what am I doing wrong...

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,368
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by TGH View Post
    The error comes in the Pacman Class. This is the class where the pacman is drawn.

    Java Code:
    public class Pacman extends Poppetje
    {
    	Doolhof doolhof;
    
    	public Pacman(int x, int y, int grootte, boolean hap)
    	{
    		this.x = x;
    		this.y = y;
    		this.grootte = grootte;
    		this.hap = hap;
    
    		if (doolhof.isToegankelijk( x, y ))
    				{
    					doolhof.eetBonus( x, y );
    				}
    	}
    I have totally no idea what am I doing wrong...
    Think about it: what do you think the value of 'doolhof' is at that line? You didn't initialize it to some sensible value yet so it is null.

    kind regards,

    Jos

  8. #8
    TGH
    TGH is offline Member
    Join Date
    Nov 2009
    Posts
    32
    Rep Power
    0

    Default

    Sorry,

    I dont know what you mean by that...

    Do I have to give the 'doolhof' some kind of value?

    I think that doolhof automatically gets a value, right?

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,368
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by TGH View Post
    Sorry,

    I dont know what you mean by that...
    Do I have to give the 'doolhof' some kind of value?
    I think that doolhof automatically gets a value, right?
    Nothing happens 'automatically'; if you don't assign it a sensible value nothing will and it'll have a value of null, just like any other variable.

    kind regards,

    Jos

  10. #10
    TGH
    TGH is offline Member
    Join Date
    Nov 2009
    Posts
    32
    Rep Power
    0

    Default

    Well, ok, I get that,

    But how do I give the maze the value that is has to?

  11. #11
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,368
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by TGH View Post
    Well, ok, I get that,

    But how do I give the maze the value that is has to?
    Maybe you can pass it in as a parameter to the constructor; something like this:

    Java Code:
    public class Pacman extends Poppetje {
       private Doolhof doolhof; // has value null here
       public PacMan( ... , Doolhof doolhof) {
          this.doolhof= doolhof; // assign your member variable
          ...
       }
       ...
    }
    kind regards,

    Jos

  12. #12
    TGH
    TGH is offline Member
    Join Date
    Nov 2009
    Posts
    32
    Rep Power
    0

    Default

    Well,

    I'm very glad you helped me, but i'm stuck, more then before.
    I really dont have a clue in what I am doing, because there isn't any progress (Seems!) so I'm givin up hope.
    I' did your things, but Im now at the same point as before.
    He walks trough walls and there seems nothing changed.

    Maybe I can make a .jar file from the point that I am now, and you could take a (better) look...

  13. #13
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,368
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by TGH View Post
    Well,

    I'm very glad you helped me, but i'm stuck, more then before.
    I really dont have a clue in what I am doing, because there isn't any progress (Seems!) so I'm givin up hope.
    I' did your things, but Im now at the same point as before.
    He walks trough walls and there seems nothing changed.

    Maybe I can make a .jar file from the point that I am now, and you could take a (better) look...
    Don't post your entire .jar because I won't look at it. If your pacman walks through a wall maybe your 'isAccessible( ... )' method is incorrect? System.out.println( ... ) can be very convenient if you're interested in certain variable values here and there ...

    kind regards,

    Jos

  14. #14
    TGH
    TGH is offline Member
    Join Date
    Nov 2009
    Posts
    32
    Rep Power
    0

    Default

    I understand,

    But, the boolean only returns true or false, I gave the isAccesible the right line, because when x and y are in these certain values, it is false when it isn't as the wall

    Java Code:
     public boolean isAccesible(x, y)
    {
    return raster [x/50][y/50] != MUUR;
    }
    I'm stuck... :(

  15. #15
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,368
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by TGH View Post
    I'm stuck... :(
    Post your code again because you must've changed substantial parts. Also describe what is going wrong (incorrect behaviour, exceptions etc.)

    kind regards,

    Jos

  16. #16
    TGH
    TGH is offline Member
    Join Date
    Nov 2009
    Posts
    32
    Rep Power
    0

    Default

    Ok, what do you want to see,

    The most crucial part, that pacman and ghost cant walk through walls is not going well.

    I post some of my classes,
    I dont get a exception, it just doesnt work...

    Java Code:
    package pacman;
    
    import javax.swing.*;
    import java.util.*;
    import java.awt.*;
    
    public class Doolhof 
    {
    	int [ ][ ] raster;
    	int score;
    	final int MUUR = -1;
    	final int LEEG = 0;
    	final int PIL = 1;
    	int BONUS;
    	int i, j; //hulpintegers
    	Random generator;
    	
    	public Doolhof()
    	{
    		raster = new int [16][11];
    		//vul het raster met de juiste ints
    		vulDoolhof();
    	}
    	
    	public void vulDoolhof()
    	{
    		Random generator = new Random();
    		raster[0][0] = MUUR;
    		raster[1][0] = MUUR;
    		raster[2][0] = MUUR;
    		raster[3][0] = MUUR;
    		raster[4][0] = MUUR;
    		raster[5][0] = MUUR;
    		raster[6][0] = MUUR;
    		raster[7][0] = MUUR;
    		raster[8][0] = PIL;
    		raster[9][0] = MUUR;
    		raster[10][0] = MUUR;
    		raster[11][0] = MUUR;
    		raster[12][0] = MUUR;
    		raster[13][0] = MUUR;
    		raster[14][0] = MUUR;
    		raster[15][0] = MUUR;
    		raster[0][1] = MUUR;
    		raster[1][1] = MUUR;
    		raster[2][1] = PIL;
    		raster[3][1] = PIL;
    		raster[4][1] = PIL;
    		raster[5][1] = PIL;
    		raster[6][1] = PIL;
    		raster[7][1] = PIL;
    		raster[8][1] = LEEG;
    		raster[9][1] = PIL;
    		raster[10][1] = PIL;
    		raster[11][1] = PIL;
    		raster[12][1] = PIL;
    		raster[13][1] = LEEG;
    		raster[14][1] = PIL;
    		raster[15][1] = MUUR;
    		raster[0][2] = MUUR;
    		raster[1][2] = PIL;
    		raster[2][2] = PIL;
    		raster[3][2] = MUUR;
    		raster[4][2] = MUUR;
    		raster[5][2] = MUUR;
    		raster[6][2] = PIL;
    		raster[7][2] = MUUR;
    		raster[8][2] = PIL;
    		raster[9][2] = LEEG;
    		raster[10][2] = MUUR;
    		raster[11][2] = PIL;
    		raster[12][2] = MUUR;
    		raster[13][2] = PIL;
    		raster[14][2] = LEEG;
    		raster[15][2] = MUUR;
    		raster[0][3] = MUUR;
    		raster[1][3] = LEEG;
    		raster[2][3] = PIL;
    		raster[3][3] = MUUR;
    		raster[4][3] = BONUS = generator.nextInt(15) + 2;
    		raster[5][3] = MUUR;
    		raster[6][3] = LEEG;
    		raster[7][3] = PIL;
    		raster[8][3] = PIL;
    		raster[9][3] = LEEG;
    		raster[10][3] = MUUR;
    		raster[11][3] = BONUS = generator.nextInt(15) + 2;
    		raster[12][3] = MUUR;
    		raster[13][3] = LEEG;
    		raster[14][3] = PIL;
    		raster[15][3] = MUUR;
    		raster[0][4] = MUUR;
    		raster[1][4] = PIL;
    		raster[2][4] = PIL;
    		raster[3][4] = MUUR;
    		raster[4][4] = LEEG;
    		raster[5][4] = MUUR;
    		raster[6][4]= PIL;
    		raster[7][4] = MUUR;
    		raster[8][4] = MUUR;
    		raster[9] [4]= PIL;
    		raster[10] [4]= MUUR;
    		raster[11][4] = MUUR;
    		raster[12][4] = MUUR;
    		raster[13][4] = PIL;
    		raster[14][4] = MUUR;
    		raster[15][4] = MUUR;
    		raster[0][5] = PIL;
    		raster[1][5] = PIL;
    		raster[2] [5]= LEEG;
    		raster[3][5] = LEEG;
    		raster[4][5] = PIL;
    		raster[5][5] = LEEG;
    		raster[6][5] = LEEG;
    		raster[7][5] = BONUS = generator.nextInt(15) + 2;
    		raster[8][5] = MUUR;
    		raster[9] [5]= PIL;
    		raster[10][5] = LEEG;
    		raster[11][5] = PIL;
    		raster[12][5] = LEEG;
    		raster[13] [5]= LEEG;
    		raster[14][5] = PIL;
    		raster[15][5] = PIL;
    		raster[0][6] = MUUR;
    		raster[1][6] = PIL;
    		raster[2][6] = PIL;
    		raster[3][6] = MUUR;
    		raster[4][6] = LEEG;
    		raster[5][6] = MUUR;
    		raster[6][6] = PIL;
    		raster[7][6] = MUUR;
    		raster[8][6] = MUUR;
    		raster[9][6] = LEEG;
    		raster[10][6] = MUUR;
    		raster[11][6]= MUUR;
    		raster[12][6]= MUUR;
    		raster[13][6] = PIL;
    		raster[14][6] = LEEG;
    		raster[15][6] = MUUR;
    		raster[0][7] = MUUR;
    		raster[1][7] = PIL;
    		raster[2][7] = MUUR;
    		raster[3][7] = MUUR;
    		raster[4][7] = BONUS = generator.nextInt(15) + 2;
    		raster[5][7] = MUUR;
    		raster[6][7] = PIL;
    		raster[7][7] = LEEG;
    		raster[8][7] = PIL;
    		raster[9][7] = PIL;
    		raster[10][7] = MUUR;
    		raster[11][7] = BONUS = generator.nextInt(15) + 4;
    		raster[12][7] = MUUR;
    		raster[13][7] = PIL;
    		raster[14][7] = MUUR;
    		raster[15][7] = MUUR;
    		raster[0][8] = MUUR;
    		raster[1][8] = PIL;
    		raster[2][8] = PIL;
    		raster[3][8] = MUUR;
    		raster[4][8] = MUUR;
    		raster[5][8] = MUUR;
    		raster[6][8] = LEEG;
    		raster[7][8] = MUUR;
    		raster[8][8] = LEEG;
    		raster[9][8] = PIL;
    		raster[10][8] = MUUR;
    		raster[11][8] = LEEG;
    		raster[12][8] = MUUR;
    		raster[13][8] = LEEG;
    		raster[14][8] = PIL;
    		raster[15][8] = MUUR;
    		raster[0][9] = MUUR;
    		raster[1][9] = PIL;
    		raster[2][9] = PIL;
    		raster[3][9] = PIL;
    		raster[4][9] = PIL;
    		raster[5][9] = PIL;
    		raster[6][9] = PIL;
    		raster[7][9] = PIL;
    		raster[8][9] = PIL;
    		raster[9][9] = LEEG;
    		raster[10][9] = PIL;
    		raster[11][9] = PIL;
    		raster[12][9] = PIL;
    		raster[13][9] = PIL;
    		raster[14][9] = PIL;
    		raster[15][9] = MUUR;	
    		raster[0][10] = MUUR;
    		raster[1][10] = MUUR;
    		raster[2][10] = MUUR;
    		raster[3][10] = MUUR;
    		raster[4][10] = MUUR;
    		raster[5][10] = MUUR;
    		raster[6][10] = MUUR;
    		raster[7][10] = MUUR;
    		raster[8][10] = PIL;
    		raster[9][10] = MUUR;
    		raster[10][10] = MUUR;
    		raster[11][10] = MUUR;
    		raster[12][10] = MUUR;
    		raster[13][10] = MUUR;
    		raster[14][10] = MUUR;
    		raster[15][10]= MUUR;
    	}
    	
    	public boolean isToegankelijk(int x, int y, int grootte)
    	{
    		return raster [x/50][y/50] != MUUR;		
    	}
    	
    	public void eetBonus(int x, int y, int grootte)
    	{
    		
    	}
    	
    	public void Teken(Graphics g)
    	{
    		for(i = 0; i < 16; i++)
    			for(j = 0; j < 11; j++)
    			{
    				if(raster[i][j] == MUUR)
    				{
    					g.setColor(Color.DARK_GRAY);
    					g.fillRect(i * 50, j * 50, 50, 50);
    				}
    				
    				if(raster[i][j] == LEEG)
    				{
    					g.setColor(Color.LIGHT_GRAY);
    					g.fillRect(i * 50, j * 50, 50, 50);
    					g.setColor(Color.BLACK);//Het lijntje eromheen
    					g.drawRect(i * 50, j * 50, 50, 50);
    				}
    				
    				if(raster[i][j] == PIL)
    				{
    					g.setColor(Color.LIGHT_GRAY);
    					g.fillRect(i * 50, j * 50, 50, 50);
    					g.setColor(Color.WHITE);
    					g.fillOval((i * 50) + 18, (j* 50) + 18, 20, 20);
    					g.setColor(Color.BLACK);//Het lijntje eromheen
    					g.drawRect(i * 50, j * 50, 50, 50);
    				}
    				
    				if(raster[i][j] == BONUS)
    				{
    					g.setColor(Color.LIGHT_GRAY);
    					g.fillRect(i * 50, j * 50, 50, 50);
    					g.setColor(Color.green);
    					g.drawString(Integer.toString(BONUS), i*50, j*50);
    					g.setColor(Color.BLACK);//Het lijntje eromheen
    					g.drawRect(i * 50, j * 50, 50, 50);
    				}
    			}
    		
    		
    	}
    	
    	
    
    }
    Java Code:
    package pacman;
    
    import java.awt.*;
    
    public class Pacman extends Poppetje
    {
    	Doolhof doolhof;
    	Poppetje poppetje;
    	
    	public Pacman(int x, int y, int grootte, boolean hap, Doolhof doolhof)
    	{
    		this.x = x;
    		this.y = y;
    		this.grootte = grootte;
    		this.hap = hap;
    		this.doolhof = doolhof;
    		if (doolhof.isToegankelijk( x, y, grootte ))
    		{
    			doolhof.eetBonus( x, y, grootte );
    		}
    		
    	}
    
    	public void tekenPacman(Graphics g)
    	{
    		if(this.hap == true)
    		{
    			g.setColor(Color.YELLOW);
    			g.fillOval(x, y, grootte, grootte);
    			g.setColor(Color.BLACK);
    			g.fillOval(x + (grootte/2) + (grootte/10), y + (grootte/4), grootte/6, grootte/6 );
    		}
    		else
    		{
    			g.setColor(Color.YELLOW);
    			g.fillArc(x, y, grootte, grootte, -135, 290);
    			g.setColor(Color.BLACK);
    			g.fillOval(x + (grootte/2) + (grootte/10), y + (grootte/4), grootte/6, grootte/6 );
    		}
    	}
    
    }
    Java Code:
    package pacman;
    
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    
    public class PacmanPaneel extends JPanel implements ActionListener, MouseWheelListener
    {
    	Spookje spookje1, spookje2, spookje3, spookje4;
    	private Pacman pacman;
    	private boolean hap;
    	Timer autohap;
    	Timer spookbeweging;
    	Poppetje poppetje;
    	Doolhof doolhof;
    
    	public PacmanPaneel()
    	{
    		addMouseWheelListener(this);
    		doolhof = new Doolhof();
    		pacman = new Pacman(450, 100, 50, hap, doolhof);
    		spookje1 = new Spookje(200, 300, Color.GREEN);
    		spookje2 = new Spookje(50, 110, Color.MAGENTA);
    		spookje3 = new Spookje(400, 50, Color.BLUE);
    		spookje4 = new Spookje(150, 50, Color.RED);
    		Timer autoHap = new Timer(150, this);
    		autoHap.start();
    	}
    Are some more classes, those aren't relevant I think...

  17. #17
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,368
    Blog Entries
    7
    Rep Power
    20

    Default

    In your 'isToegankelijk' method you are dividing your coordinates by 50; print the results as well as the value of the 'raster' and see what happens.

    kind regards,

    Jos

  18. #18
    TGH
    TGH is offline Member
    Join Date
    Nov 2009
    Posts
    32
    Rep Power
    0

    Default

    I did System.out.println(doolhof.isToegankelijk(x,y,groo tte)) it says, true...

    EDIT;

    I now set the
    Java Code:
    if (doolhof.isToegankelijk(doolhof.getX(), doolhof.getY(), doolhof.getSize() ))
    		{
    			//doolhof.eetBonus( x, y, grootte );
    		}
    in the actionperformed...

    I just think that my isToegankelijk inst right, I only doenst know where to start with that method...
    Last edited by TGH; 01-08-2010 at 06:18 PM.

  19. #19
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,368
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by TGH View Post
    I did System.out.println(doolhof.isToegankelijk(x,y,groo tte)) it says, true...

    EDIT;

    I now set the
    Java Code:
    if (doolhof.isToegankelijk(doolhof.getX(), doolhof.getY(), doolhof.getSize() ))
    		{
    			//doolhof.eetBonus( x, y, grootte );
    		}
    in the actionperformed...

    I just think that my isToegankelijk inst right, I only doenst know where to start with that method...
    Sure it prints 'true'; print that x/50 and y/50 values in the body of that method so you can see where your pacman actually is. Reread my previous reply.

    kind regards,

    Jos

  20. #20
    TGH
    TGH is offline Member
    Join Date
    Nov 2009
    Posts
    32
    Rep Power
    0

    Default

    I actually gave my pacman already the coordinates where to start...

    Java Code:
    pacman = new Pacman(450, 100, 50, hap, doolhof)
    The reason I /50 is because the blocks are 50 big, each one, also the pacman self...

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 2
    Last Post: 08-05-2010, 04:49 AM
  2. Help! Game.
    By MIA6 in forum New To Java
    Replies: 4
    Last Post: 11-08-2009, 12:22 AM
  3. Help with my game!
    By Manikyr in forum New To Java
    Replies: 6
    Last Post: 06-06-2009, 11:09 AM
  4. 2D strategy game or 2D war game
    By led1433 in forum Java 2D
    Replies: 5
    Last Post: 02-10-2009, 06:00 AM
  5. game
    By amith in forum AWT / Swing
    Replies: 0
    Last Post: 05-19-2008, 05:16 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
  •