Thread: Graphics for pacman

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    43

    Red face Graphics for pacman

    Hi !

    I have just started creating (the oft repeated & much harassed) the pacman game. I have created a 2 - D array, calling it map, that would serve to be my logical grid...

    My 2 - D array contains following values :
    0 - Empty, 1 - Wall, 2 - Pill, 3 - Ghost, 4 - Pacman

    I want to create the grid graphically using information from 'map'...sumthng like where there is a '1' plot pixels & so on...Here's what I did (to create the walls or grid) :

    Code:
       for(int i = 0; i < MAX_SZ; i++)
       {
        x = 99;
    
        for(int j = 0; j < MAX_SZ; j++)
        {
         if(map[i][j] == 1)
          putpixel(x, y, BLUE);
    
         x++;
        }
    
        y++;
       }
    where MAX_SZ is 21 (rows or columns of map) & x & y are my starting point - 99

    This code creates a 21 x 21 pixels grid (my animated pacman is bigger than the grid & gobbles it up when it is moved around )

    Can you guys suggest me a better way to do this, as in creating a grid in which each cell is of uniform size (i.e, pixels) ?

    I dont intend to use sprites or any other fancy graphics tool - just the graphics header in turbo c (happen to be targetting the dos enviroment).

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    The idea is probably that your grid may well be 21x21, but each "cell" is more than one pixel large. However large your pacman is -- that's how large everything should be. So if it's a wall, you don't just draw a pixel worth of blue; you make it a box of blue.

    I don't know anything whatsoever about the graphics header in Turbo C, but hopefully there's a way to draw a box.

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    43
    Thanks tabstop ! I understand the notion that you just described...in turbo c we dont have a function like a box but we do have a function called line() that can be used to achieve the same...its just that I have been unable to tweak my simple for loop to do that using line function...

  4. #4
    Registered User
    Join Date
    Nov 2009
    Posts
    43
    I resolved my problem by doing this :

    Code:
       for(int i = 0; i < MAX_SZ; i++)
       {
        x = 49;
    
        for(int j = 0; j < MAX_SZ; j++)
        {
         if(map[i][j] == 1)
         {
          //putpixel(x, y, BLUE);
          line(x, y, x + 15, y);
          line(x + 15, y, x + 15, y + 15);
          line(x + 15, y + 15, x, y + 15);
          line(x, y, x, y + 15);
         }
    
         x += 15;
        }
    
        y += 15;
       }
    The idea is probably that your grid may well be 21x21, but each "cell" is more than one pixel large. However large your pacman is -- that's how large everything should be. So if it's a wall, you don't just draw a pixel worth of blue; you make it a box of blue.
    That & an expresso really drove the point home

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. graphics.h link error
    By aristotle1 in forum C Programming
    Replies: 4
    Last Post: 02-25-2010, 10:11 AM
  2. Turtle Graphics, how does it work?
    By freddyvorhees in forum C++ Programming
    Replies: 15
    Last Post: 08-28-2009, 09:57 AM
  3. Graphics Programming :: Approach and Books
    By kuphryn in forum Windows Programming
    Replies: 4
    Last Post: 05-11-2004, 08:33 PM
  4. egavga.bgi problem
    By sunil21 in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 09-22-2003, 05:06 PM
  5. Graphics Devices and Cprintf clash
    By etnies in forum C Programming
    Replies: 6
    Last Post: 05-09-2002, 11:14 AM