Another game of mine...

This is a discussion on Another game of mine... within the Game Programming forums, part of the General Programming Boards category; I am working on another game, and have mostly completed, but I need help on the collision (sorta) detection. When ...

  1. #1
    Satan valar_king's Avatar
    Join Date
    Aug 2001
    Posts
    288

    Question Another game of mine...

    I am working on another game, and have mostly completed, but I need help on the collision (sorta) detection. When the guy swings his sword, I want the program to know if he hits the monster. I've gotten the upwards swing one mostly in (it still messes up, try swinging it to the right of the monster, but nowhere near him), and I'm try to put in the downwards swing one, but so far, it hasn't worked.


    Screenshots:
    Screen 1
    Screen 2


    Thanks,
    Valar_King

    (The zip attached has all of the .bmps, .cpps, and for those trusting folks out there, a .exe. But you can compile it if you have allegro and the Visual C++.)[FONT=arial][FONT=arial][FONT=arial]
    -Save the whales. Collect the whole set.

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    375
    Where's the zip? I'm probably being stupid, but I can't figure out how it is attached..
    Allegro precompiled Installer for Dev-C++, MSVC, and Borland: http://galileo.spaceports.com/~springs/

  3. #3
    Satan valar_king's Avatar
    Join Date
    Aug 2001
    Posts
    288

    Angry

    Hmm, seems the attachment didn't work. Try this:
    http://personal.bellsouth.net/~markhand/game.zip

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    375
    Alright, a couple comments.

    First, the following lines are repeditive in what they do:
    BITMAP *guy = create_bitmap(90, 90)
    guy = load_bmp("cdown.bmp", default_palette);

    The load_bmp function will allocate the memory for the *guy BITMAP, so ya only need to call it.

    Then, at the end of the proggy, don't forget to deallocate it with the destroy_bitmap() function. allegro_exit() may do this for you, but destroying the bitmap is the #1 way to ensure you don't cause a memory leak.

    Now then, the collision detection:
    if ((ex - sx) < 90 && (sy - ey) < 90 && (ey - sy) < 90) ...

    This is a tad confusing, but if I understand correctly, you are trying to say, if the enemy x is within 90 pixels of the sword x and the enemy y is also within 90 pixels of the sword y, then a collision has occured. Here would be the way I would do this:
    if(ex > (sx - 45) && ex < (sx + 45) && ey > (sy - 45) && ey < (sy + 45) ...

    This makes a nice neat box of collision detection, and you aren't worried about negative values and such.

    Hope that helps. (Kind of a late reply, so you may have figured that out already.)

    -Justin

    P.S. Looking good so far. You'll have the next best RPG/Action Adventure going in no time at all. (If you are having a problem with flickering and are running 2K, see this post on some of the quirks of DirectX in full screen.)
    Last edited by Justin W; 12-30-2001 at 06:50 PM.
    Allegro precompiled Installer for Dev-C++, MSVC, and Borland: http://galileo.spaceports.com/~springs/

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    129
    Just a quick question related to that BITMAP thing. How about functions that return a BITMAP - ie. how to destroy those ones?

    Code:
    BITMAP foo();
    
    void bar
    {
        blit(foo(), screen, 0, 0, 0, 0, x, y);
    }
    kooma - t.h@iki.fi

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    375
    So foo() creates a bitmap and then returns a pointer to it, right? Probably, allegro_exit() will clear that up, but if you want to be sure, you'd better have a pointer waiting in bar() to pick it up.


    Code:
    BITMAP foo();
    
    void bar
    {
        BITMAP *Temp=foo();
        blit(Temp, screen, 0, 0, 0, 0, x, y);
        destroy_bitmap(Temp);
    }
    Allegro precompiled Installer for Dev-C++, MSVC, and Borland: http://galileo.spaceports.com/~springs/

  7. #7
    Registered User
    Join Date
    Aug 2001
    Posts
    129
    Code:
    >    BITMAP *Temp=foo();
    >    blit(Temp, screen, 0, 0, 0, 0, x, y);
    But both of them still go to blit as `source':
    void blit(BITMAP *source, BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height);

    And when it's the same BITMAP all day long it's actually just wasting time to create that `Temp' (!!! since when was that written with capital first letter :-), won't you say?

    Anyway, perhaps it ultimately better - for the sake of a readable source and memory handling - not to return those bitmaps....
    kooma - t.h@iki.fi

  8. #8
    Registered User
    Join Date
    Oct 2001
    Posts
    375
    It probably doesn't hurt to do it the way you were, so maybe the motto "if it ain't broke, don't fix it" applies here. Try your way, and if you run into any memory leaks, you'll know how to fix 'em.
    Allegro precompiled Installer for Dev-C++, MSVC, and Borland: http://galileo.spaceports.com/~springs/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Open-source Game Project
    By Glorfindel in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 03-24-2009, 02:12 AM
  2. 20q game problems
    By Nexus-ZERO in forum C Programming
    Replies: 24
    Last Post: 12-17-2008, 05:48 PM
  3. Need book to program game into multiplayer...
    By edomingox in forum Game Programming
    Replies: 3
    Last Post: 10-02-2008, 10:26 AM
  4. Try my game
    By LuckY in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 09-15-2004, 12:58 PM
  5. HELP!wanting to make full screen game windowed
    By rented in forum Game Programming
    Replies: 3
    Last Post: 06-11-2004, 05:19 AM

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