Map masks?

This is a discussion on Map masks? within the Game Programming forums, part of the General Programming Boards category; Hey, I'm working on an ASCII game. You know the ones I'm talking about (with the #'s and the *'s). ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    49

    Unhappy Map masks?

    Hey, I'm working on an ASCII game. You know the ones I'm talking about (with the #'s and the *'s). Anyway, I came across a problem. When ever the player walks over the buildings I have made it basically deletes the building part that the player steps on. I did this in QB, and I used a mask; I was just wondering, how would I put the mask in with C++? Any hints/tips would be greatly appreciated.
    Thanks
    -Kavity
    i'm not stupid, just a little short on brains.
    Kav's game!
    Featuring:
    # - Goodguy mc goodguy
    * - Bad guy mc badguy
    $ - Princess Mc Cess
    @ - Mcdonalds Mc chicken! mmmmmm

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    411
    If you are useing an array for the map, then you would simply write in a if statement to check if the space your moveing to has anything already there.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    49

    Unhappy Hmm :/

    I don't completely understand how to use array's. I've read the tutorial here. And I still don't understand. If you could help out a little it would be Greatfully apreciated. Thanks even if you don't.
    -Kavity
    i'm not stupid, just a little short on brains.
    Kav's game!
    Featuring:
    # - Goodguy mc goodguy
    * - Bad guy mc badguy
    $ - Princess Mc Cess
    @ - Mcdonalds Mc chicken! mmmmmm

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,584
    There are two ways to accomplish what you want to do.

    Masks, by the way, can be implemented the same way in QB as in C++. You must use logical operators and bit masks.

    Option 1 - In memory or in an array
    If you are wanting to preserve the contents of an array or section of memory you do not need to use masks. Before you place your player, ASCII value, or whatever inside the array, save the current value at that location. When you move the player, you can then restore the value which will effectively erase the player and place what was there prior to the player occupying the location.

    Option 2 - On the screen
    If you wish to do this on screen, simply preserve the ASCII character at screen location row,column and place your player ASCII character at location row,column. When the player leaves location row,column simply place your stored value at that location. The background image or character will be preserved.

    Option 3 - Other methods
    There are other ways using buffering and other methods, but text mode is so fast, there is almost no need to create a buffer.
    Using the array as the 'screen' in memory is one way to buffer the output (look at my first explanation). To draw the screen, simply start at 0,0 and place element 0 of the array there. Iterate through the array and place the value at the appropriate place on the screen. Effectively, your array is what the screen will look like.

    Very simplistic explanation of arrays
    While I cannot explain all about arrays and their uses here (there are about a million ways to use them), I can explain a simple one dimensional array.


    For instance:

    Code:
    int MyArray[10];
    This creates an integer array of 11 elements. This is equivalent to the QB statement:

    Code:
    dim MyArray(0 to 10) as integer
    All arrays in C start at 0, while in QBasic they can start at 1 or 0 depending on your OPTION BASE statement. Technically, there is no advantage or disadvantage in regards to whether an array starts at 0 or 1. It's just that in C, all arrays start at 0. However, for most projects you will find that starting at 0 is easier when you start working with offsets into memory, etc.

    To access the array simply specify the array element you want.

    For instance to access the 0th element of MyArray:

    Code:
    int test=MyArray[0];
    or in QB:

    Code:
    dim test as integer
    test=MyArray(0)
    To loop through and print all the elements:

    Code:
    for (int i=0;i<10;i++)
    {
       printf("%d ",MyArray[i]);
    }
    Most of the time in C, you will want to access arrays via pointers, but that definitely cannot be explained in this post as it is a huge topic.

    This prints the array in QB:

    Code:
    for int i=0 to 10 step 1
      print MyArray(i);" ";
    next
    Hope that helps. Since I assumed you knew QB, switching between C and QB may help you understand C a bit better.

    There is much, much, much more. Buy a book on C. Books by Bjarne Strousoup (correct spelling?) and Herbert Schildt are excellent and they also cover C++ in great depth. The Sams series of books are great, but I personally do not feel that you can learn and master C in 24 hours or less. C takes a lifetime to master because it is so powerful and versatile.

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    411
    "For instance:



    code:--------------------------------------------------------------------------------
    int MyArray[10];
    --------------------------------------------------------------------------------


    This creates an integer array of 11 elements. "

    You mean an array of 10 elements right.

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,584
    Yes, I do mean 10 elements.

  7. #7
    Registered User
    Join Date
    Aug 2001
    Posts
    49

    Smile

    Thanks alot man. Aww.. just like qb, that's good to hear :P
    Thanks, and I hope this helps me. Well thanks again, and see you later.
    -Kavity
    i'm not stupid, just a little short on brains.
    Kav's game!
    Featuring:
    # - Goodguy mc goodguy
    * - Bad guy mc badguy
    $ - Princess Mc Cess
    @ - Mcdonalds Mc chicken! mmmmmm

  8. #8
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,584
    Well,....not exactly like QB, C is much more powerful. But, if you get a good grasp on QB it will not be nearly as hard to move to C/C++ and other languages.

  9. #9
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    if you are moving from QB to C/++ [like so many of us have... around the age of 12/14...] i strongly recommend having a book to guide you... if not necessarily "C/++ for QB-ers"... a "C/++ for beginners" nonetheless... the Dummies series is good... oh, and if i may offer more advice... C/++ are only different as one is an extension and slight alteration of the other... do not let it be construed otherwise... notice how most posts in C/++ forums could have been in either...
    hasafraggin shizigishin oppashigger...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Adding a Map to a program
    By Shogun32 in forum C++ Programming
    Replies: 1
    Last Post: 05-04-2009, 09:42 AM
  2. Polynomials and ADT's
    By Emeighty in forum C++ Programming
    Replies: 20
    Last Post: 08-19-2008, 08:32 AM
  3. New editor updates
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-05-2005, 02:26 PM
  4. Creating a map engine.
    By suzakugaiden in forum Game Programming
    Replies: 11
    Last Post: 06-21-2005, 05:06 AM
  5. Searching STL Map Inside STL Map Object :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 11-14-2002, 08:11 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21