Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 23 of 23

Thread: Making a pacman game having some problems with drawing

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Making a pacman game having some problems with drawing

    So im using a simple grid[][] ={
    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};

    And im going to be using the 1's as walls and the 0's as dots or open space. Yeah the maze will change and appear different then what it is there. Im just wondering how do i make draw in the walls and the dots?

    I tried with this code :
    public void lagLabyrint(){
    		int x,y;
     
    		for (x=0; x<15; x+=blokkStr)
    		{
    			for (y=0; y<15; y+=blokkStr)
    			{
    				{
    					if(brett[x][y]==0)
    					{
    						g.drawOval(x, y, getWidth(), getHeight());
    						g.setColor(dotFarge);
    						//tegn dots
    					}
    					else if(brett[x][y]==1)
    					{
    						g.drawRect(x, y, getWidth(), getHeight());
    						g.setColor(veggFarge);
    						//tegn vegger
    					}
     
     
     
     
    				}
    			}
    		}
    	}

    and lagLabyrint means makeLabyrinth or drawLabyrinth*

    then i smashed it into my paint method
    public void paint(Graphics g)
    	{
    		super.paint(g);
     
    		Graphics2D g2d = (Graphics2D) g;
     
    		g2d.setColor(Color.black);
     
    		lagLabyrint();
     
    		g.dispose();
    	}

    But all i get now is a pump message displaying somehing is wrong and it cant draw it at all i just get lots of errors after i filled in the color statement above for dots and walls.

    And yeah i have declared everything for it.

    Thanks in advance

    Edit: I found the MAIN PROBLEM, which is the drawing of the rectangle ... thats when im getting the stack overflow null pointer exception, and thats when my program crashes, i guess there is nothing wrong with all the variables as they work for the dots though they arent drawn onto the board. Anyway I really hope you guys can help me out with this one.

    Thanks again!
    Last edited by Matta; June 1st, 2011 at 06:21 AM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,668
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: Making a pacman game having some problems with drawing

    i just get lots of errors
    can you copy and paste the full text of the error messages here?
    They contain information about what was wrong which is needed to fix the problem.

    One problem I see, you need to pass a reference to the graphics object to the drawer:
    lagLabyrint(g);

  3. #3
    Junior Member
    Join Date
    Jun 2011
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Making a pacman game having some problems with drawing

    This is the whole wall of text of the problem, so you suggest that i just add the g statement inside of it? I have created a graphics g; inside the board class or the board that contains the array list.



    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    	at Spillbrett.lagLabyrint(Spillbrett.java:85)
    	at Spillbrett.paint(Spillbrett.java:120)
    	at javax.swing.JComponent.paintChildren(Unknown Source)
    	at javax.swing.JComponent.paint(Unknown Source)
    	at javax.swing.JComponent.paintChildren(Unknown Source)
    	at javax.swing.JComponent.paint(Unknown Source)
    	at javax.swing.JLayeredPane.paint(Unknown Source)
    	at javax.swing.JComponent.paintChildren(Unknown Source)
    	at javax.swing.JComponent.paintToOffscreen(Unknown Source)
    	at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
    	at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
    	at javax.swing.RepaintManager.paint(Unknown Source)
    	at javax.swing.JComponent.paint(Unknown Source)
    	at java.awt.GraphicsCallback$PaintCallback.run(Unknown Source)
    	at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)
    	at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
    	at java.awt.Container.paint(Unknown Source)
    	at java.awt.Window.paint(Unknown Source)
    	at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
    	at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
    	at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
    	at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
    	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    	at java.awt.EventQueue.access$000(Unknown Source)
    	at java.awt.EventQueue$1.run(Unknown Source)
    	at java.awt.EventQueue$1.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    	at Spillbrett.lagLabyrint(Spillbrett.java:85)
    	at Spillbrett.paint(Spillbrett.java:120)
    	at javax.swing.JComponent.paintChildren(Unknown Source)
    	at javax.swing.JComponent.paint(Unknown Source)
    	at javax.swing.JComponent.paintChildren(Unknown Source)
    	at javax.swing.JComponent.paint(Unknown Source)
    	at javax.swing.JLayeredPane.paint(Unknown Source)
    	at javax.swing.JComponent.paintChildren(Unknown Source)
    	at javax.swing.JComponent.paintToOffscreen(Unknown Source)
    	at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
    	at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
    	at javax.swing.RepaintManager.paint(Unknown Source)
    	at javax.swing.JComponent.paint(Unknown Source)
    	at java.awt.GraphicsCallback$PaintCallback.run(Unknown Source)
    	at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)
    	at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
    	at java.awt.Container.paint(Unknown Source)
    	at java.awt.Window.paint(Unknown Source)
    	at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
    	at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
    	at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
    	at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
    	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    	at java.awt.EventQueue.access$000(Unknown Source)
    	at java.awt.EventQueue$1.run(Unknown Source)
    	at java.awt.EventQueue$1.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,668
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: Making a pacman game having some problems with drawing

    at Spillbrett.lagLabyrint(Spillbrett.java:85)
    What variable is null at line 85 in Spillbrett.java?
    Backtrack in your code to see why the variable does NOT have a value.

    I have created a graphics g
    You should use the one passed to the paint method.

  5. #5
    Junior Member
    Join Date
    Jun 2011
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Making a pacman game having some problems with drawing

    Double Posting here but thanks man i got it working once i used ur statement how silly of me to not come up with that, well another problem appears i now only get a small square in the middle of the screen did i do something wrong in the code then? Because its all working and launching no error message so you can look away from my early post.

    But im using a Dimension d; to make the boards or screensize maybe i should remove it and just use the array as the screensize? or something ?

    Screen: {
    {b,b,b,b,b,b,b,b,b,b,b,b,b},
    {b,b,b,b,b,b,b,b,b,b,b,b,b},
    {b,b,b,b,w,w,w,w,w,b,b,b},
    {b,b,b,b,w,b,b,b,b,w,b,b,b},
    {b,b,b,b,w,b,b,b,b,w,b,b,b},
    {b,b,b,b,w,w,w,w,w,w,b,b,b},
    {b,b,b,b,b,b,b,b,b,b,b,b,b},
    {b,b,b,b,b,b,b,b,b,b,b,b,b},}

    looks like tht but in a larger scale with dimension 600,500 and a smaller white frame
    Last edited by Matta; June 1st, 2011 at 07:28 AM.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,668
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: Making a pacman game having some problems with drawing

    i now only get a small square in the middle of the screen
    Is that what your method draws?
    Try debugging your code by adding println statements to show the values of the variables used to control where the drawing takes place.

    Hard to say what the problem is without seeing the code. Make a small program to demonstrate your problem, don't post a lot of code.

  7. #7
    Junior Member
    Join Date
    Jun 2011
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Making a pacman game having some problems with drawing

    well the problem lies within the code i allready posted it seems, i use this 2D-arraylist which described and i want it to draw lines at the number 1 numbers so i get a line all around the game if not possible thats okei ill just make the screen outer lines so that its not possible to move beyond em. I want the number 1 to draw lines which makes squares or just drawRect(); One of either so i get some sort of map/maze for the pacman to move about. That way its easier to make colission detection without having alot of objects instead you got one variable to add the colission to.

    My method now draws a small screen in the middle of the program(which is a black screen); and its just a small square in the middle of it. Thats not what i want it to be i want the grid to fill the whole screen ofcourse. So that i can map out where i want the walls etc etc. but as of now it seems my grid does not apply to the whole screen or atleast thats what im getting at.. ill write some quick code her

    public class View extends JFrame{
    public View{
     
    add(new Spillbrett();
    this.setSize(int,int); // with numbers ofc
    this.setLocationRelativeTo(null);
    this.setTitle(Pacman.Beta);
    this.setResizeable(false);
    this.setVisible(true);
     
     
    }
    }
     
    public class Spillbrett implements JPanel
     
    Ghost ghost; //outer class in its own window(describing movement and creation)
    Pacman pacman; // oute class in its own window(describing movement and creation)
    int blocksize = 20;
     
    int [][] board = {
    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
     
    public void makeBoard(Graphics2D g){
    int x,y;
     
    		for (x=0; x<16; x+=blokkStr)
    		{
    			for (y=0; y<brett.length; y+=blokkStr)
    			{
    				{
    					if(brett[x][y]==1)
    					{
    						g2d.drawLine(x+16*blokkStr,y+16*blokkStr,blokkStr, blokkStr);
    						g2d.setColor(veggFarge);
    						//tegn vegger
    					}
    }
    }
     
    	public void paint(Graphics g)
    	{
    		super.paint(g);
     
    		Graphics2D g2d = (Graphics2D) g;
     
    		lagLabyrint(g2d);
     
    		g.dispose();
    	}
    }

    this is a small part of the code

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,668
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: Making a pacman game having some problems with drawing

    You need to post code that will compile and execute. That helps seeing what the problem is.

    The code you posted has several syntax errors in it.
    Last edited by Norm; June 1st, 2011 at 10:08 AM.

  9. #9
    Junior Member
    Join Date
    Jun 2011
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Making a pacman game having some problems with drawing

    Okei here we go then

    this will be somewhat big but, thanks alot in advance norm ur helping out alot !

    import javax.swing.JFrame;
     
     
    public class View extends JFrame {
     
    	public View(){
     
    		add(new Board());
    		this.setSize(500,500);
    		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    		this.setLocationRelativeTo(null);
    		this.setResizable(false);
    		this.setVisible(true);
     
    	}
     
    	public static void main (String[] arg0){
    		new View();
    	}
    }

    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
     
    import javax.swing.JPanel;
     
     
    public class Board extends JPanel {
     
    	Pacman pacman;
    	Ghost ghost;
     
    	int blockSize = 24;
    	Color wallColor = Color.blue;
     
     
    	int	[][] board ={
    			{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,},
    			{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    			{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    			{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    			{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    			{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    			{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    			{1,0,0,0,0,0,1,1,0,1,1,0,0,0,0,0,1},
    			{1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1},
    			{1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,1},
    			{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    			{1,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,1},
    			{1,0,0,1,1,1,0,0,0,0,0,1,1,1,0,0,1},
    			{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    			{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    			{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
     
    	public Board() {
     
    		setBackground(Color.BLACK);
    		//addKeylistener(keyListener);
     
    	}
     
    	public void makeMaze(Graphics g){
     
    		int x,y;
     
    		for (x=0; x<16; x+=blockSize)
    		{
    			for (y=0; y<board.length; y+=blockSize)
    			{
    				{
    					if(board[x][y]==1)
    					{
    						g.drawRect(x+16*blockSize,y+16*blockSize,blockSize, blockSize);
    						g.setColor(wallColor);
    						//draw the walls as lines first (maybe rects not sure yet)
    					}
     
     
     
     
    				}
    			}
    		}
    	}
    	public void playGame(){
    		//if (dead){
    			//pacman.death();(pacman is dead display how he died i.e by hitting ghosts!) intersection
    		//}else {
    			//pacman.MovePacman(); (Moves pacman around with the directions of the board);
    			//pacman.DrawPacman(); (draws pacman as a drawOval(10,10,10,10)) in the pacman class
    			//ghost.MoveGhost(); (move the ghosts in random directions)
    			//checkMaze(); (checks wether dots are eaten or not)
    		//}
    	}
    	public void paint(Graphics g)
    	{
    		super.paint(g);
     
    		Graphics2D g2d = (Graphics2D) g;
     
    		makeMaze(g2d);
     
    		g.dispose();
    	}
    }
    public class Ghost {
     
    }
    public class Pacman {
     
    }

    okei there it is easy and simple

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,668
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: Making a pacman game having some problems with drawing

    I don't see any comments in the code so I don't know what its supposed to do.

    The contents of the window is all black.

  11. #11
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    471
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Making a pacman game having some problems with drawing

    That makeMaze nested loop is screwy from the start - you're looping while x is less than 16, but you increment x each time by blockSize which is 24... guess how many times that's going to loop?

    I suggest you get some graph paper and a pencil, and figure out your maze drawing algorithm by hand. Once you understand it and it's working, then translate it into code.

    Hint: increment x and y by 1 each time, don't use blockSize in the loop control. Oh, and it will probably work better if the board is square (height == width). Oh, and you're drawing it sideways - you need:

    if (board[y][x] == 1) {.
    Last edited by dlorde; June 1st, 2011 at 01:14 PM.

  12. #12
    Junior Member
    Join Date
    Jun 2011
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Making a pacman game having some problems with drawing

    Quote Originally Posted by dlorde View Post
    That makeMaze nested loop is screwy from the start - you're looping while x is less than 16, but you increment x each time by blockSize which is 24... guess how many times that's going to loop?

    I suggest you get some graph paper and a pencil, and figure out your maze drawing algorithm by hand. Once you understand it and it's working, then translate it into code.

    Hint: increment x and y by 1 each time, don't use blockSize in the loop control. Oh, and it will probably work better if the board is square (height == width). Oh, and you're drawing it sideways - you need:

    if (board[y][x] == 1) {.
    Yeah i have allready done so from the start belive me i have tried to get the loop to work tried with the increment 1 and the blockSize, they paint the same image, nothing is changing. And removed all the blockSize things from the other code aswell then i get some slight changes but i belive the main Issue is the "If" method which outprints/draws it wrong or cant get the right numbers from the Board[][]. Doesnt matter if the board/ dimension is square or not, atleast not when you execute it, it seems.

    The drawing is still fucked up, thanks for the help though and the [y][x] instead of [x][y] didnt do much either .. there gotta be me not figuring out how to draw that line/rect correctly as it doesnt fit into where the numbers 1 are placed ...

    Maybe its better to go with the standard method and just draw in all the rects and then place them around on the map i.e set Coordinates for all of them.

  13. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,668
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: Making a pacman game having some problems with drawing

    One problem is that the board is not square. The for loop tests have the wrong end of loop test. I think it should be:
    for (y=0; y<board[x].length; y++)

    You don't say if your code is working or if you are having problems and what they are.

  14. #14
    Junior Member
    Join Date
    Jun 2011
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Making a pacman game having some problems with drawing

    Edit:

    The problem is atleast what i can comprehend from the code is the tileMap board map or 2d array list isnt putting itself inside the JFrame Correctly since it draws a wierd small retangular object where i place the coordinate if i keep it

    if(board[y][x]==1){
    g.drawRect(x,y,blockSize,blockSize);
    g.setColor(wallColor);
    }
    if I use this i will get it where the x and y coordinates is which is 0,0 at that time yes, then it will draw a rectangular unit right there with the apropriate block size it doesnt seem to place it at the 1s i have made in the 2d arraylist.
    Last edited by Matta; June 3rd, 2011 at 07:30 AM.

  15. #15
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,668
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: Making a pacman game having some problems with drawing

    it doesnt draw em up like it should its just a big blue line + a rectangle around it with nothing more in it.
    Can you screen print and post it.
    Here's what I get with my version:
    Attached Images Attached Images

  16. #16
    Junior Member
    Join Date
    Jun 2011
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Making a pacman game having some problems with drawing

    My scrnPrnt doesnt work... -_- on this comp.

    So i used my phone..
    DSC00047.jpgDSC00046.jpg


    Thats what i have ..
    Last edited by Matta; June 3rd, 2011 at 08:16 AM.

  17. #17
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,668
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: Making a pacman game having some problems with drawing

    You need to figure out where the x,y locations are for each square you want to print.
    Take a piece of paper and draw what you want the output to look like. Just the outer border for now.
    Then extract the x,y location of the upper left corner for each square. Then think about how to write a loop that will generate the x,y locations for all the squares across a row and down a column.

    This has already been suggested by dlorde.

    As an exercise, post here the x,y values for the first 4 squares on the top row.

  18. #18
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    471
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Making a pacman game having some problems with drawing

    Quote Originally Posted by Matta View Post
    Yeah i have allready done so from the start belive me i have tried to get the loop to work tried with the increment 1 and the blockSize, they paint the same image, nothing is changing. And removed all the blockSize things from the other code aswell then i get some slight changes but i belive the main Issue is the "If" method which outprints/draws it wrong or cant get the right numbers from the Board[][]. Doesnt matter if the board/ dimension is square or not, atleast not when you execute it, it seems.

    The drawing is still fucked up, thanks for the help though and the [y][x] instead of [x][y] didnt do much either ..
    OK, so maybe I don't know what you actually want to display; because when I made the changes I suggested to the code you posted, I got the image Norm links to above, but the right way up - and it follows the maze array layout exactly.

  19. #19
    Forum VIP
    Join Date
    Oct 2010
    Posts
    275
    My Mood
    Cool
    Thanks
    32
    Thanked 54 Times in 47 Posts
    Blog Entries
    2

    Default Re: Making a pacman game having some problems with drawing

    Ok not sure if you fixed it but this looks a little funky.


    public void paint(Graphics g)
    {
        super.paint(g); // You tell the super class JPanel to paint all the things done to g, but
        Graphics2D g2d = (Graphics2D) g; // then create Graphics 2d from graphics g and
        makeMaze(g2d); // use that to draw.
    }
    Try using
    public void paint(Graphics g)
    {
        Graphics2D g2d = (Graphics2D) g;
        super.paint(g2d);
        makeMaze(g2d);
    }

  20. #20
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,104
    Thanks
    169
    Thanked 780 Times in 726 Posts
    Blog Entries
    5

    Default Re: Making a pacman game having some problems with drawing

    Ok not sure if you fixed it but this looks a little funky.
    What makes you think this looks funky? Looks perfectly legit to me (aside from the fact that the programmer should override paintComponent rather than paint)

  21. #21
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    471
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Making a pacman game having some problems with drawing

    Quote Originally Posted by Tjstretch View Post
    Ok not sure if you fixed it but this looks a little funky.

    <snip code>

    Try using

    <snip code>
    Whut? Your change makes no difference at all - and why should it? it's the same object and the superclass paint method takes a Graphics argument anyhow...

    I'd do it like this (but that's just me):
    public void paint(Graphics g)
    {
        super.paint(g);
        makeMaze((Graphics2D)g);
    }

  22. #22
    Junior Member
    Join Date
    Jun 2011
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Making a pacman game having some problems with drawing

    Thanks guys i fixed it after some searching throug my head so as of now that problem is fixed actually did it a few days ago so i got the same screen output as you got. The problem is if you fit in more into the table( f.eks add a nr 3 for pacman) then ull get some strange results in there the wall behind will turn yellow if you color pacman yellow!

  23. #23
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,668
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: Making a pacman game having some problems with drawing

    the wall behind will turn yellow
    Is that the result of on too many setColor()?
    Or perhaps not enough calls to setColor()?

Similar Threads

  1. I have problems with my 2d car game.
    By Vegetassj in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 25th, 2011, 10:54 AM
  2. Making a Craps game.
    By SOK in forum Object Oriented Programming
    Replies: 1
    Last Post: March 6th, 2010, 07:23 PM
  3. Theory behind 2d Game making?
    By DarrenReeder in forum Java Theory & Questions
    Replies: 3
    Last Post: January 28th, 2010, 01:54 AM
  4. [SOLVED] How to start writing java mobile application?
    By Kok in forum Java ME (Mobile Edition)
    Replies: 15
    Last Post: July 30th, 2009, 01:52 AM
  5. Problem while programming a simple game of Car moving on a road
    By rojroj in forum Java Theory & Questions
    Replies: 3
    Last Post: April 2nd, 2009, 10:24 AM