Results 1 to 14 of 14
Like Tree1Likes
  • 1 Post By Fubarable

Thread: Pacman Game

  1. #1
    Hollowsoul is offline Member
    Join Date
    Jul 2011
    Posts
    30
    Rep Power
    0

    Default Pacman Game

    I am at the moment trying to make a Pacman game for fun. However im having alot of problems. The main one is that i cant seem to print anything on the window. Heres the source.

    Java Code:
    package Runner;
    import java.awt.Color;
    import java.awt.DisplayMode;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import Charecters.*;
    public class Runner extends JFrame {
    	private boolean GameIsRunning=true;
    	public static void main(String[] args) {
    		JFrame f = new JFrame("Pacman");
    		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		f.setSize(800,1000);
    		f.setResizable(false);
    		f.setVisible(true);
    	}
    	Image pacman;
    	private boolean loaded;
    	Image inky = new ImageIcon("resources\\Inky.png").getImage();
    	Image pinky = new ImageIcon("resources\\Pinky.png").getImage();
    	Image blinky = new ImageIcon("resources\\Blinky.png").getImage();
    	Image clyde = new ImageIcon("resources\\Clyde.png").getImage();
    	public void loadpics() {
    		pacman = new ImageIcon("resources\\PacmanOpenMouth.png").getImage();
    		loaded = true;
    	}
    	public void paint(Graphics backg) {
    		backg.setColor(Color.blue);
    		// top wall x1, y1 x2, y2
    		backg.drawLine(50, 50, 750, 50);
    		backg.drawLine(70, 70, 390, 70);
    		backg.drawLine(410, 70, 730, 70);
    		// top wall down extension
    		backg.drawLine(390, 70, 390, 170);
    		backg.drawLine(390, 170, 410, 170);
    		backg.drawLine(410, 170, 410, 70);
    		// left/top side
    		backg.drawLine(50, 50, 50, 300);
    		backg.drawLine(70, 70, 70, 280);
    		// right/top side
    		backg.drawLine(750, 50, 750, 300);
    		backg.drawLine(730, 70, 730, 280);
    		// left 3/4 box extension
    		backg.drawLine(50, 300, 150, 300);
    		backg.drawLine(70, 280, 170, 280);
    		backg.drawLine(150, 300, 150, 350);
    		backg.drawLine(170, 280, 170, 370);
    		backg.drawLine(150, 350, 50, 350);
    		backg.drawLine(170, 370, 50, 370);
    		backg.drawLine(50, 350, 50, 370);
    		// right 3/4 box extension
    		backg.drawLine(750, 300, 650, 300);
    		backg.drawLine(730, 280, 630, 280);
    		backg.drawLine(650, 300, 650, 350);
    		backg.drawLine(630, 280, 630, 370);
    		backg.drawLine(650, 350, 750, 350);
    		backg.drawLine(630, 370, 750, 370);
    		backg.drawLine(750, 350, 750, 370);
    		// left/bottom 3/4 box extension
    		backg.drawLine(50, 420, 170, 420);
    		backg.drawLine(50, 440, 150, 440);
    		backg.drawLine(170, 420, 170, 510);
    		backg.drawLine(150, 440, 150, 490);
    		backg.drawLine(170, 510, 70, 510);
    		backg.drawLine(150, 490, 50, 490);
    		backg.drawLine(50, 420, 50, 440);
    		// right/bottom 3/4 box extension
    		backg.drawLine(750, 420, 630, 420);
    		backg.drawLine(750, 440, 650, 440); 
    		backg.drawLine(630, 420, 630, 510);
    		backg.drawLine(650, 440, 650, 490);
    		backg.drawLine(630, 510, 730, 510);
    		backg.drawLine(650, 490, 750, 490);
    		backg.drawLine(750, 420, 750, 440);
    		// bottom/left wall (top half)
    		backg.drawLine(50, 490, 50, 800);
    		backg.drawLine(70, 510, 70, 635);
    		// bottom/left wall extension (bottom half)
    		backg.drawLine(70, 635, 100, 635);
    		backg.drawLine(70, 655, 100, 655);
    		backg.drawLine(100, 635, 100, 655);
    		backg.drawLine(70, 655, 70, 780);
    		// bottom/right wall (top half)
    		backg.drawLine(730, 510, 730, 635);
    		backg.drawLine(750, 490, 750, 800);
    		// bottom/right wall extension (bottom half)
    		backg.drawLine(730, 635, 700, 635);
    		backg.drawLine(730, 655, 700, 655);
    		backg.drawLine(700, 635, 700, 655);
    		backg.drawLine(730, 655, 730, 780);
    		// bottom wall
    		backg.drawLine(70, 780, 730, 780);
    		backg.drawLine(50, 800, 750, 800);
    		// top T
    		backg.drawLine(390, 230, 390, 300);
    		backg.drawLine(390, 300, 410, 300);
    		backg.drawLine(410, 300, 410, 230);
    		backg.drawLine(330, 210, 470, 210);
    		backg.drawLine(330, 210, 330, 230);
    		backg.drawLine(470, 210, 470, 230);
    		backg.drawLine(330, 230, 390, 230);
    		backg.drawLine(470, 230, 410, 230);
    		// top/left -
    		backg.drawLine(170, 210, 110, 210);
    		backg.drawLine(170, 230, 110, 230);
    		backg.drawLine(170, 210, 170, 230);
    		backg.drawLine(110, 210, 110, 230);
    		// top/left box
    		backg.drawRect(110, 110, 60, 60);
    	//	backg.drawRect(x, y, width, height)
    		// top/right box
    		backg.drawRect(630, 110, 60, 60);
    		//top/right -
    		backg.drawLine(690, 210, 630, 210);
    		backg.drawLine(690, 230, 630, 230);
    		backg.drawLine(690, 210, 690, 230);
    		backg.drawLine(630, 210, 630, 230);
    		//top/left/right box
    		backg.drawRect(230, 110, 100, 40);
    		//top right/left box
    		backg.drawRect(460, 110, 100, 40);
    		//top/right/t
    		backg.drawLine(552, 230, 552, 368);
    		backg.drawLine(529, 230, 552, 230);
    		backg.drawLine(529, 368, 552, 368);
    		backg.drawLine(460, 289, 529, 289);
    		backg.drawLine(529, 230, 529, 289);
    		backg.drawLine(529, 368, 529, 312);
    		backg.drawLine(529, 312, 460, 312);
    		backg.drawLine(460, 312, 460, 289);
    		//top/left/t
    		backg.drawLine(230, 230, 230, 368);
    		backg.drawLine(230, 230, 253, 230);
    		backg.drawLine(230, 368, 253, 368);
    		backg.drawLine(253, 289, 322, 289);
    		backg.drawLine(253, 230, 253, 289);
    		backg.drawLine(253, 368, 253, 312);
    		backg.drawLine(253, 312, 322, 312);
    		backg.drawLine(322, 312, 322, 289);
    		//Ghost box
    		backg.drawLine(317, 454, 478, 454);
    		backg.drawLine(317, 454, 317, 355);
    		backg.drawLine(478, 454, 478, 355);
    		backg.drawLine(317, 355, 377, 355);
    		backg.drawLine(478, 355, 422, 355);
    		backg.drawLine(468, 365, 422, 365);
    		backg.drawLine(468, 444, 468, 365);
    		backg.drawLine(327, 444, 468, 444);
    		backg.drawLine(327, 444, 327, 365);
    		backg.drawLine(327, 365, 376, 365);
    		backg.drawLine(376, 355, 376, 365);
    		backg.drawLine(422, 355, 422, 365);
    		//bottom left -
    		backg.drawRect(230, 420, 20, 90);
    		//bottom right -
    		backg.drawRect(532, 420, 20, 90);
    		//bottom top t
    		backg.drawLine(317, 494, 478, 494);
    		backg.drawLine(317, 494, 317, 514);
    		backg.drawLine(478, 494, 478, 514);
    		backg.drawLine(317, 514, 378, 514);
    		backg.drawLine(415, 514, 478, 514);
    		backg.drawLine(415, 514, 415, 574);
    		backg.drawLine(378, 514, 378, 574);
    		backg.drawLine(415, 574, 378, 574);
    		
    		//bottom bottom t
    		backg.drawLine(317, 644, 478, 644);
    		backg.drawLine(317, 644, 317, 664);
    		backg.drawLine(478, 644, 478, 664);
    		backg.drawLine(317, 664, 378, 664);
    		backg.drawLine(415, 664, 478, 664);
    		backg.drawLine(415, 664, 415, 724);
    		backg.drawLine(378, 664, 378, 724);
    		backg.drawLine(415, 724, 378, 724);
    		//bottom bottom left -
    		backg.drawRect(225, 552, 90, 20);
    		//bottom bottom right -
    		backg.drawRect(465, 552, 90, 20);
    		//bottom left L thingy lol
    		backg.drawLine(175, 560, 175, 655);
    		backg.drawLine(175, 560, 105, 560);
    		backg.drawLine(105, 560, 105, 580);
    		backg.drawLine(105, 580, 150, 580);
    		backg.drawLine(150, 580, 150, 655);
    		backg.drawLine(150, 655, 175, 655);
    		//bottom right L thingy ^_^
    		backg.drawLine(620, 560, 620, 655);
    		backg.drawLine(620, 560, 690, 560);
    		backg.drawLine(690, 560, 690, 580);
    		backg.drawLine(690, 580, 645, 580);
    		backg.drawLine(645, 580, 645, 655);
    		backg.drawLine(645, 655, 620, 655);
    		//Bottom most left L thingy
    		backg.drawLine(110, 740, 320, 740);
    		backg.drawLine(110, 740, 110, 720);
    		backg.drawLine(320, 740, 320, 720);
    		backg.drawLine(110, 720, 240, 720);
    		backg.drawLine(320, 720, 265, 720);
    		backg.drawLine(265, 720, 265, 610);
    		backg.drawLine(240, 720, 240, 610);
    		backg.drawLine(240, 610, 265, 610);
    		//bottom most right L thingy
    		backg.drawLine(470, 740, 680, 740);
    		backg.drawLine(470, 740, 470, 720);
    		backg.drawLine(680, 740, 680, 720);
    		backg.drawLine(680, 720, 550, 720);
    		backg.drawLine(470, 720, 525, 720);
    		backg.drawLine(525, 720, 525, 610);
    		backg.drawLine(550, 720, 550, 610);
    		backg.drawLine(550, 610, 525, 610);
    		loadpics();
    		if(loaded) {
    			//Pacman Start Point
    			backg.drawImage(pacman, 370, 590, null);
    			repaint();
    			
    		}
    	}
    	
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,755
    Rep Power
    25

    Default

    Do you have a missing package: Charecters?

    You never create a instance of the Runner class.
    Last edited by Norm; 07-16-2011 at 03:31 AM.

  3. #3
    Hollowsoul is offline Member
    Join Date
    Jul 2011
    Posts
    30
    Rep Power
    0

    Default

    Nevermind i fixed it :D

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,755
    Rep Power
    25

    Default

    There is a lot more to fix then the missing GUI.
    How will the movement of the pacman be kept from going across a boundary?
    All your hardcoded drawing of boundaries should be put into an object that can be used to detect collisions when the pacman moves.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    And the numbers representing the boundaries should probably be placed in a data file that the program reads in on start up. This will give you the added flexibility of being able to change the maze without having to change any code.
    Norm likes this.

  6. #6
    Hollowsoul is offline Member
    Join Date
    Jul 2011
    Posts
    30
    Rep Power
    0

    Default

    I changed it a lot now it looks much better. But the text file idea is a good one i will probably do that. However now im having trouble with the KeyListeners. Right now i just want it to exit my program when i hit q. Mainly because it isnt closing properly and leaves a bunch of still running programs that slow my computer down. For some reason they arent working and i cant figure out why. I Can show you the source but um... there is quite a bit lol

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,755
    Rep Power
    25

    Default

    What code are you executing to exit the program?
    System.exit(0) should stop the JVM.
    What are the "bunch of still running programs"?

  8. #8
    Hollowsoul is offline Member
    Join Date
    Jul 2011
    Posts
    30
    Rep Power
    0

    Default

    I just started using System.exit(0); and by still running i mean that the program exits but if you go into the processes there is still a bunch of still running jvms that suck up my ram. I have been just ending the processes till i could figure out the KeyListener problem which should in turn solve the other problem.

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,755
    Rep Power
    25

    Default

    I have no idea where the other jvms are coming from. How many do you create when you start your program?

  10. #10
    Hollowsoul is offline Member
    Join Date
    Jul 2011
    Posts
    30
    Rep Power
    0

    Default

    Just one. But i have to use alt f4 to exit the program because i made the game fullscreen but when i alt f4 it doesnt stop the process aparently...

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,755
    Rep Power
    25

    Default

    there is still a bunch of still running jvms
    Where do these come from?

  12. #12
    Hollowsoul is offline Member
    Join Date
    Jul 2011
    Posts
    30
    Rep Power
    0

    Default

    The game i think. im not running any other code of any code. Im using Eclipse and when i go to run it without ending the process Eclipse says its already running. However i didnt notice this for a while and so it stacked up a bunch of running jvms

  13. #13
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,755
    Rep Power
    25

    Default

    AHHH!!! The IDE is doing things in the background.

  14. #14
    Hollowsoul is offline Member
    Join Date
    Jul 2011
    Posts
    30
    Rep Power
    0

Similar Threads

  1. Making PacMan game, need help!
    By Mondos in forum Java Gaming
    Replies: 14
    Last Post: 06-03-2011, 04:24 PM
  2. pacman 2d array help please
    By Java26 in forum Advanced Java
    Replies: 2
    Last Post: 05-11-2011, 06:55 PM
  3. Huge problem. PacMan game.
    By Bullfrog in forum New To Java
    Replies: 3
    Last Post: 06-01-2010, 03:39 PM
  4. Help implementing Pacman
    By scheng12 in forum New To Java
    Replies: 2
    Last Post: 03-07-2010, 11:26 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
  •