DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2006
    Posts
    3

    Help figuring out pacman barrier collision detect

    Im making a pacman game, and im trying to figure out how to draw the barriers and make sure pacman cant cross the walls. How do i approach this? Thank you muchly.

    im obviously no pro, so go easy on me :P

  2. #2
    Join Date
    Sep 2006
    Posts
    3
    anyone? please?

  3. #3
    Join Date
    Mar 2004
    Posts
    635
    Store your map as a 2D grid.

    0 = clear
    1 = dot
    2 = wall

    Decide the size of each wall segment, say 10x10. So every 10 units you'd have a new wall segment or square from the grid.

    - player_controls
    - store old pacman position
    - update new pacman position variables
    - check where in grid new pacman position is. If its a wall, change position variables to old pacman position.
    - draw pacman

    So if pacman is at 152,36 in world coordinates, to find that in grid coordinates, divide by the dimensions of a grid square (10x10).

    Code:
    int gx = 152/10  //15
    int gy = 36/10    //3
    
    if (map[gx][gy] == 2) //pacman hit a wall
    {
        pacX = oldX
        pacY = oldY
    }
    else if ( == 1) //pacman ate a dot
    {
        map[][] = 0
        score++;
    }

  4. #4
    Join Date
    Sep 2006
    Posts
    3
    wow thank you so much, i would never have thought of that!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links