Making a Maze For Pacman (and his monsters)

Hi. Im new to making games. Ive so far gone through a space Invaders tutorial and done an asteroids clone. I now want to improve my knowledge further so am thinking about doing a Pacman game.
However, I currently dont know how to go about making the maze, (which of course, restricts both the player and the monsters from crossing over the walls of this maze.)
Thanks in advance to any one who helps.
Andy

Hi
Ive created a game using tiles. However, My pacman currently doen't always stop properly at the walls. There seems to be two main problems.
a)Each tile is 16 pixels wide. Pacman moves 4 pixels each time. This means that
three quarters of the time, he's not properly in line with the corridor. However,
I think my program only checks whether the pixel at the top left of pacman is in
a tile that is not a wall. This means that pacman often can move half through a wall.
b) Using System.out.println, Ive noticed that when a button is held down (such as the left arrow key), System.out.println is activated once, then there is about half a seconds pause, and only then does System.out.println begin to constantly activate. It seems that during that half second break, the system isn't going through the bit of code that checks whether the tile is a wall or not (meaning he'll walk straight through the tile)
Here is some of my code...
   //When one of the arrow keys is pressed, a boolean is activated
   // and update speed is called
   public void keyPressed(KeyEvent e) {
        switch (e.getKeyCode()) {
          case KeyEvent.VK_UP : up = true; break;
          case KeyEvent.VK_LEFT : left = true; break;
          case KeyEvent.VK_RIGHT : right = true; break;
          case KeyEvent.VK_DOWN : down = true;break;
        updateSpeed();
//Work out the x and y speeds (vx and vy)
//This is done by checking if the tile is a wall.
//The player speed is only maintained if it is not.
private void updateSpeed() {
        vx=0;vy=0;
        if (down){
             if (!Tiles.tileGrid[(y/tileSize)+1][x/tileSize])
                  vy = PLAYER_SPEED;
        if (up){
             if (!Tiles.tileGrid[(y/tileSize)-1][x/tileSize])
                     vy = -PLAYER_SPEED;
        if (left){
              if (!Tiles.tileGrid[y/tileSize][(x/tileSize)-1]){
                   vx = -PLAYER_SPEED;
                   System.out.println("yx" + y + " " +x);
         System.out.println("Grid" + (y/tileSize) + " " + (x/tileSize));}
        if (right){
             if (!Tiles.tileGrid[y/tileSize][(x/tileSize)+1])
                  vx = PLAYER_SPEED;
         System.out.println("yx" + y + " " +x);
         System.out.println("Grid" + (y/tileSize) + " " + (x/tileSize));
      }

Similar Messages

  • PacMan and His Many Friends (Ghosts)

    Well, my friend and I are working very diligently on a Pacman game and had it working perfectly... with just PacMan. We have never really explored or used threads, and have only used buffering sporadically.
    So we decided to use Threads on this project of ours, since we wanted the Ghosts each to move at their own speed, and PacMan at his own, of course. So we wrote up our Ghost class... which reads something like this:
    import java.lang.Thread;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Point;
    import javax.swing.JApplet;
    import java.awt.Image;
    public class Ghost extends Thread{
         //Data Fields
         private Graphics g,G;
         private Image Buffer;
         private JApplet app;
         private int gX,gY,gridSize,speed;
         private char direction;
         private Point destination,homePoint;
         private int state;
         private String strat;
         private Color color;
         private boolean staticRoute,running;
         private Sleeper s;
         Ghost(){}
         Ghost(JApplet app,Graphics G,int x,int y,String s, Color c, int gridSize, int speed){
              this.app=app;
              Buffer = app.createImage(app.getWidth(),app.getHeight());
              Graphics g=Buffer.getGraphics();
              this.G=G;
              gX=x;
              gY=y;
              homePoint = new Point(x,y);
              strat=s;
              color=c;
              this.gridSize=gridSize;
              this.speed=speed;
              this.s = new Sleeper();
              this.g=g;
              running=true;
              calcDestination();
         public int getX(){ return gX; }
         public int getY(){ return gY; }
         public String getStrat(){ return strat; }
         public int getState(){ return state; }
         public Color getColor(){ return color; }
         public void run(){
              while(running){
                   if(destination.equals(new Point(gX,gY)))
                        staticRoute=false;
                   calcDestination();
                   if(direction=='R')
                        PacMan.drawLevel(g,gX-1,gY);
                   else if(direction=='L')
                        PacMan.drawLevel(g,gX+1,gY);
                   draw();
                   s.sleep(speed);
                   G.drawImage(Buffer,0,0,app);
         public void stopRun(){
              running=false;
         public void die(){
              destination = new Point((int)homePoint.getX(),(int)homePoint.getY());
              staticRoute=true;
         public void draw(){
              g.setColor(color);
              g.fillOval(((gX+1)*gridSize-(gridSize*2))+2,((gY+1)*gridSize-(gridSize*2))+2,(gridSize*3)-4,(gridSize*3)-4);
         public void calcDestination(){ //Doesn't work as it will in final version, just makes it go back and forth along the bottom or top... trying to get two ghosts going at once
              if(!staticRoute){
                   if(strat.equals("Test")){
                        if(gX==2 && gY==42){
                             destination = new Point(30,42);
                             direction='R';
                        else{
                             destination = new Point(2,42);
                             direction='L';
                        staticRoute=true;
                   if(strat.equals("Test2")){
                        if(gX==2 && gY==2){
                             destination = new Point(30,2);
                             direction='R';
                        else{
                             destination = new Point(2,2);
                             direction='L';
                        staticRoute=true;
              calcPoint();
         public void calcPoint(){  //Excuse the utter stupidity of this method.  It is merely for testing and will be better implemented later.
              if(gY==(int)destination.getY() && (int)destination.getX()>gX)
                   gX++;
              else
                   gX--;
    }Let me explain part of the development behind this...
    First off we started with just PacMan.java. I wrote it pretty much on my own and made it so it would read a series of numbers from a textfile to generate a level. It also contained the speed and how much pelets were worth, but that's not relevant. It worked fine, all of it.
    Then the next step was having a yellow 'circle' move around in that field in the way we wanted it to. That also worked.
    The third step was implementing the warps, which could be represented and generated from the text field itself. This worked and was implemented quite well. However, we did not use Threads up until now.
    The fourth and current step was the Ghost implementation. This isn't going as planned. We use two Graphics objects in our PacMan class (which extends JApplet) and simply drew everything in one step to the 'invisible' one, then at the end of the paint method, draw it all over to the 'visible' graphics object. That worked fine in the previous steps, as mentioned above. However, we ran into a problem with the different speeds of the Ghosts. We passed in the 'invisible' Graphics object and had the Ghosts draw themselves to that via the run method. That worked fine if the speed was the same, but when it was different it created problems. Another problem was that since we passed in the SAME Graphics object, if one of the two Ghost instances changed the color, then it could affect the color of what was being drawn in the main PacMan class. (Usually during the inital display of the level. We'd have red-colored dots.)
    I know this all sounds very... overwhelming.. and trust me, it is for us too. I'm just not sure how to go about solving this problem. If you look at the code closely, I have two Graphics objects for each Ghost. One is the main one from the app, and the other is the one it draws itself to so it prevents Color conflicts. Then at the end of the 'run' method we try drawing the individual Ghost Graphics object to the bigger one... and it all just jumbles up.
    I guess to cut to the chase, what I'm asking for is advice on how to have multiple Ghost Threads running and drawing constantly without conflicts with color or too much lag. (I noticed when we set all the speeds to the same thing then it worked, but it was very choppy) One guess of mine would be to put PacMan on his own Thread, but my brain is so fried I'm not quite sure where to begin. Any guidance/references would be appriciated.

    Personally I think you've got the wrong approach.
    Instead of creating a Thread for every ghost, you should keep yourself to the one you've got in the PackMan class.
    Tough what you need to do is make the whole game frames based.
    You've got a speed variable that you should use to add/increase the X/Y location each frame, something like:
    Ghost[X].newTick();Where newTick() should be something like:
    public void newTick(); {
         x += speed;
         y += speed;
    }and instead of drawing inside the Ghost class you should draw in the PackMan class, no collision with double usage of the Graphics objects.
    Well, I hope you've got the general idea, post a message if you would like a practical example.
    GL HF

  • Table for STO and his production order in manufacturing plant.

    Hello Experts,
    I would like to know in which table I can find a relation between STO and his related Production Order.
    Thanks in advance.
    Regards
    Mayur
    Edited by: mayur kshirsagar on Dec 19, 2007 1:48 PM

    Dear Mayur,
    For Production order related tables check in
    AFKO              Order Header
    AFPO               Order Item Detail
    AFVC               Order Operations Detail
    AFFL                Order Sequence Details
    AFFH               Order PRT Assignment
    AFBP               Order Batch Print Requests
    AFRU               Order Completion Confirmations
    AFFW              Confirmations -- Goods Movements with Errors
    AFRC               Confirmations -- Incorrect Cost Calculations
    AFRD               Confirmations -- Defaults for Collective Confirmation
    AFRH               Confirmations -- Header Info for Confirmation Pool
    AFRV               Confirmation Pool
    AFWI               Confirmations -- Subsequently Posted Goods Movements
    AUFK     Order master data
    AUFM     Goods Movements for Order
    VBAG                           Sales Document: Release Data by Schedule Line in Sch.Agrmt.
    VBAK                           Sales Document: Header Data                               
    VBAP                           Sales Document: Item Data                                 
    VBBE                           Sales Requirements: Individual Records                    
    VBBS                           Sales Requirement Totals Record                           
    are you meaning stock?
    then check in MARD.
    Regards
    Mangal

  • Editing a current website making it fluid for iphone and ipad

    How do I edit a current website so that is fluid for Iphone and ipad?
    It looks good on the web but i dont know how to edit it so that it changed to the iphone or ipad!
    If anyone can help that would be awesome!
    Thanks
    Chris

    OPTION #1
    Rebuild your fixed width site layout with CSS Media Queries.  One style sheet for mobile, another for tablet and a 3rd one for desktops.
    Introduction to CSS Media Queries
    http://www.adobe.com/devnet/dreamweaver/articles/introducing-media-queries.html
    OPTION #2
    Jump start the process using the Fluid Grid Layouts feature in DW CS6 or CC.  Be sure to build your mobile layout first.
    http://tv.adobe.com/watch/digital-design-cs6/creating-adaptive-designs-using-fluid-grid-la youts-in-dreamweaver-cs6/
    OPTION #3
    Use one of these Responsive Frameworks:
    Foundation Zurb
    http://foundation.zurb.com/templates.php
    Skeleton Boilerplate
    http://www.getskeleton.com/
    Initializr (HTML5 Boilerplate, Responsive or Bootstrap)
    http://www.initializr.com/
    DMX Zone's Bootstrap extension for DW
    http://www.dmxzone.com/go/21759/dmxzone-bootstrap/
    Project Seven's Page Packs (CSS Templates)
    http://www.projectseven.com/products/templates/index.htm
    Nancy O.

  • I have OSX Lion 10.7.5 and iphoto 11 9.2.1 I have spent 3 days making a book for christmas and when I go to buy it I am told I need to update iPhoto.  I went to apps and clicked on the update tab but it showed no results.  HELP!

    I am trying to buy the book I created in Iphoto and it says I need to update iphoto.  I have OSX Lion 10.7.5 and Iphoto 11 9.2.1.  I don't know how to update.  I tried to follow the suggested instruction by going to Mac App, clicking on update tab but nothing was found.  I am not sure what to do.  I have spent three days creating this book for a Christmas present and I am 5 hours from the closest Apple store.  Can anyone help.  I don't mind paying for upgrades if that is what is needed I just don't know what is needed or how to do it. 
    Thanks,
    Linda

    Yep, just install iDVD (plus sounds and jingles) and iWeb if you want it (but note that iWeb apparently won't work if you upgrade to Mountain Lion).
    Then use Software Update to get any late iDVD updates.

  • Marketing Attributes for account and Contact

    Hi,
    I am looking at Marketing Attributes of an Account. They are fine.
    And I am looking at Marketing attributes of an Contact for this account. But these values are different from Account Marketing Attributes.
    They are not same...can you please let me know..when they will bcome same (for Account and his contact).
    And when I create lead(campaign)...will these attributes changes for Account and Contact?
    Please let me know...as I am very new to CRM Marketing.
    Thanks,
    Sandeep

    Hi,
    If the marketing attribute set is created with assignment to bith Accounts and Contacts.. the same would be visible through out.
    If u want different set of attributes for contacts and accounts, define multiple marketing attributes and select the checkbox for availability in either contacts or accounts and not both.

  • My iphone 4S has problem in making and receiving the calls. While making the call , call fails and netwrok disappears. Like wise no voice is heard for incoming calls. This happened after return from the overseas travel.

    My iphone 4S has problem in making and receiving the calls. While making the call , call fails and netwrok disappears. Like wise no voice is heard for incoming calls. This happened after return from the overseas travel.

    Hello SamSax
    Check out the assist page below for troubleshooting call connectivity.
    Calls and connection issues
    http://www.apple.com/support/iphone/assistant/calls/
    Thanks for using Apple Support Communities.
    Regards,
    -Norm G.

  • TS3694 I was making the update for my iphone 4s . then he stops. My phone in this time is in the recovery mode and do not take the firmware to open my phone, please can u help me to recover my phone. My current  ios 6.0.1. plese send me some thing that is

    was making the update for my iphone 4s . then he stops. My phone in this time is in the recovery mode and do not take the firmware to open my phone, please can u help me to recover my phone. My current  ios 6.0.1. plese send me some thing that is useful

    Thanks for that 'sberman' - because my iPhone is backed-up to my work computer (only at this stage) I have had to call our IT Department in Adleaide. (4 times this morning). The last guy managed to get the phone into 'DFU Mode' - no more recovery mode screen - (kind of 'asleep' perhaps) from my understanding of same. I am awaiting a call again from IT so they can get my computer to actually recognise my iPhone on the C Drive. This also happened to  one of my colleagues in Newman (WA). She got so frustrated with the whole process that she bought another phone the next time she was in 'civilisation.' She hasn't had any problems since. (Cross fingers).
    Thanks again, Sandra2474.

  • Why is iMessage taking my incoming emails and then not making them available for my PC to get?  Why can I not send a text msg with photos when iMessage is turned off (but MMS is still on).

    Apple is great!
    Why is iMessage taking my incoming emails and then not making them available for my PC to get?  Why can I not send a text msg with photos when iMessage is turned off (but MMS is still on).
    I compose an iMessage with the destination as my email address and I attach 2 photos I want on my PC.  I send them several times from my iPhone 5C but they never arrive. I look at my ipad later and realize that it's iMessage app is getting ( and swallowing) these emails. I then turn the ipad off.  Still can't get the photos through because iphone is now getting them on it's iMessage.  I turn off the iMessage feature and try to send photos from text msging.  Phone tells me it can't send photos unless iMessage it turned on.  What happened to regular MMS text messaging?  I go and try to send photos as an email attachment and see that there is no option to attach from the stupid email program.  I look up online to learn about the brave new world of apple attachments and send them.
    Why is iMessage taking my incoming emails and then not making them available for my PC to get?
    The email program on my iphone is not configured to remove messages from the server.
    If iMessage is turned off I don't have the issue.
    Why can I not send a text msg with photos when iMessage is turned off (but MMS is still on).

    Did not work. I've selected iMessage to ON and left it. After a few hours I recieved a message "activation unsuccessful. Turn on iMessage to try again". This has been going on for the past 3 days.

  • HT1918 My husband's iPhone4 uses one apple id for purchases and updates, but another is listed in the App Store. How do I reconfigure his phone to only use the apple I'd and password that is used in the the "featured" section of the App Store?

    My husband's iphone4 seems to have 2 apple ids. The one listed in the featured section of the App Store is the correct one. The one that asks to be signed into for purchase and updates is also mine, and the incorrect one. Hence, our devices are linked. How can I remove my apple Id from his phone so that there is no connection between the two?

    I think it may be because he got his phone first and not seeing a future issue, I set his phone up to my already existing apple Id used for my iPod. If I connect his iPhone to our pc, can I create his own apple id account?

  • I have deleted my sons apple id and data from his old phone by accident as i thought i was resetting it for me to use and now he has lost everything on his new phone and his id etc does not work.  Can someone please explain how i am able to retrieve

    Can someone please shed some light on this???
    I thought i was resetting my son's iphone 4 so that I could use it. But I seem to have erased his icloud/apple id and all of his data from his new phone too.  His Apple ID doesnt work and cant be accessed as it now says it is disabled.  I have tried the iforgot.apple.com website without success and have no idea how to rectify.  I have requested a password change to his email address but that is not working either.
    Please help? 

    That sounds confusing.  First off, don't be too worried. There's practically no way to actually delete an Apple ID or it's purchase history.  You should be able to get to it back somehow.  Secondly, that's likely something that you'll need to talk to a real person on the phone for since it likely requires you to explain that you need access on behalf of your son, (who probably just set some security questions or an email address that you didn't know he put in.)  Just call the appropriate AppleCare phone line (800-APL-CARE in the USA, or see the link below for other countries) and tell them you want to talk about an iCloud account security question.
    Phone Support: Contact Apple for support and service - Apple Support

  • My father has itunes account for ipad and my mother for an iphone my father has taken over iphone and needs to link it to his account

    my father has itunes account for ipad and my mother for an iphone my father has taken over iphone and needs to link it to his account

    iTunes will need to be set up on your computer however you can set up a new Apple ID to use for your iPhone. Really all you need to do is Assign a new Apple ID to your iCloud account.
    Follow the link to create a new Apple ID: https://appleid.apple.com/cgi-bin/WebObjects/MyAppleId.woa/
    After you do that, on the device you want to assign a new iCloud account go: Settings > iCloud > Delete Account and then sign in with the new Apple ID.
    NOTE: This does not effect iTunes, all of your devices can continue to use one shared iTunes account under your original Apple ID for downloading apps and backups. This simply gives iCloud a place to sync the individual devices information and will stop iCloud form merging all the information, such as contacts, with all of your devices.

  • I used to use the free version of Adobe Reader to convert my publisher files to pdf files. When I was making a booklet for our hockey team, it said I had to buy it. Now I bought it and it won't convert the files. I am ready to throw this computer out the

    I used to use the free version of Adobe Reader to convert my publisher files to pdf files. When I was making a booklet for our hockey team, it said I had to buy it. Now I bought it and it won't convert the files. I am ready to throw this computer out the window!! Can you tell me what is the problem? No it does not exceed 100 M. either.

    Adobe Reader never converted Publisher files to PDF, for free, never. I suspect you use to have the (paid for) Adobe Acrobat. Sometimes people have Acrobat (more than $300 worth) and install Adobe Reader over the top, losing that valuable software.
    That said, if you subscribed to PDF Pack it should do this conversion. What exactly happens now.

  • I want to use an external microphone for both my iPhone 5S and my MacBook Pro. This is for music and for making recordings outside such as birds. Any suggestions?

    I want to use an external microphone for both my iPhone 5S and my MacBook Pro. This is for music and for making recordings outside such as birds. Any suggestions?

    use a splitter something like this
    http://www.amazon.co.uk/3-5mm-Headphone-Splitter-Cable-iPhone-White/dp/B003W37DS E/ref=pd_sxp_grid_pt_2_1

  • Nobody get back to me on my other question, so I'm going to try again. I am making a PowerPoint for a meeting and I want to take a 3D PDF and have it spin or rotate on a continuous loop. How can I accomplish this?

    Nobody get back to me on my other question, so I'm going to try again. I am making a PowerPoint for a meeting and I want to take a 3D PDF and have it spin or rotate on a continuous loop. How can I accomplish this?

    Please ignore PowerPoint comment, I can make the 3D PDF no problem with my converter plug-in for AutoCAD. Once it is made though you can spin it by hand/mouse in Adobe. but I want a video like scene with the object spinning by itself for modeling purposes?

Maybe you are looking for