Thread: Creating Bullet Patterns

  1. #1
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788

    Creating Bullet Patterns

    What would the best solution be for creating patterns for bullets fired in a shoot 'em up game?

    Should I hard code values into arrays?

    The kind of patterns I want to create are for bosses like in the games Strikers 1945, Aero Fighters etc.

  2. #2
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    Load the values from a file. Do not, do not, hard code them.
    Away.

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Well those bullet patterns are created by scripts. Think of several different basic bullet movements like move, circle, speed up, etc. Make functions that operate on the bullets in this manner. Then in your boss script you can do this.


    MOVE bullet1 TO x,y
    CIRCLE bullet1 player


    In this fashion you could easily create some complex bullet moves and boss moves. Of course you will have to write a small script interpreter but this should not be too hard.

  4. #4
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    I've been toying with this equation for a bullet pattern.

    It involves a very short period sign wave : /\/\/\/\/\/\/\/\/.
    It involves an increasing amplitude of the sign wave over period of time of continuous fire.


    Basicly you move the bullets pitch up and down (after every shot from the first [the first should be dead on]) based on the length of time since the player pressed fire, and your sign wave. The amplitude of your sign wave should increase every few frames of continous fire. The left and right yaw of the bullets is controlled via a simler sign wave, that doesnt change. It too has a short periods. You just create random values of time periods. This should create a nice jerky - apparantly random variation of bullet patterns.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  5. #5
    Registered User
    Join Date
    Oct 2003
    Posts
    4
    You could use a "cone of fire" idea. Basically you make a cone, and the bullet will travel and a random spot through the cone. This is more for a first person shoot (half-life uses this) but you could make it work for other styles of games.

  6. #6
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    I think I'm gonna use BulletML. I've downloaded a parser, but the thing is I don't know how to use it 'cos the readme file is in Japanese, so I was wandering if there's anyone who can translate the for me? (It's not that much)

    Here's a link to the file:
    http://user.ecc.u-tokyo.ac.jp/~s3155...tml/README.txt

  7. #7
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    Possibly, but my japanese is bad so it would take a long time. If I run out of things to do this weekend I will.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  8. #8
    Visionary Philosopher Sayeh's Avatar
    Join Date
    Aug 2002
    Posts
    212
    Has anybody thought of precalculating an xyz coord table based on rand() and sin() and cos() for the coordinates at program startup? This would generate a conical pattern. Simply increase the randomness the further you go in the table. How many holes do you need? Do 30. then whenever you need bullet holes, you can start at the beginning of the table and go through it until the user lets go of the "trigger".

    Since shot randomness is based on grade of ammunition and primarily thermal effects of the barrel warming up and the length of the barrel, a cooler barrel is more accurate, while a hot barrel might generate more "flyers".
    It is not the spoon that bends, it is you who bends around the spoon.

  9. #9
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    length of the barrel,
    one also cannot forget how good the rifling of the barrel is, how clean it is, and the different gas exhaust systems help determine the trajectory of a round, as well as the person stance(which include how he is holding and operating the firearm). one could theoretically make a huge C++ library based on nothing except firearms.

    EDIT:
    or one could simply include as part of the guns struct all these different parameters.

  10. #10
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    And all of this is much too complex simply to emulate shots being fired at an object which will happen millions of times in a game. You could emulate a good bullet with a simplified model and w/o all the extremely slow and cumbersome physics equations. Who cares what gravity really is - just increase the y component of the bullet and each object in the game by a pre-set amount and call it gravity. No one will ever know the diff.

    Bullet drop is so minimal over short distances that most games don't even bother. Spray pattern is a very good idea though and could produce some very quick shotgun-like patterns on your walls.

    Code:
    for (int i=0;i<MAXPATTERN;i++)
    {
      int radius=random(MAXRADIUS);
      int angle=random(360);  //or rand() % 360 if no random()
      shotgun(i).x=cos(angle*PI/180)*radius;
      shotgun(i).y=sin(angle*PI/180)*radius;
    }
    You could create a bitmap mask out of this pattern and then blit it to the texture or combine it with the texture or you could draw the pattern in real time and alpha blend or do some other blending function with the wall texture.

    then in the game:
    Code:
    for (int i=0;i<MAXPATTERN;i++)
    {
      bx=WhereBulletHitWall.x;
      by=WhereBulletHitWall.y;
      int sprayx=(double)bx+shotgun(i).x;
      int sprayy=(double)by+shotgun(i).y;
      int texturex=(int)sprayx % texturemaxx;
      int texturey=(int)sprayy % texturemaxy;
      AlphaBlend
       (TextureWeHit,BulletHoleColor,AlphaCoef,texturex,texturey);
    }
    Data types are prob conflicting but you get the idea.

    To make the pattern fade after time simply decrease the AlphaCoef to 0 and the BulletHole will not be visible. Then when the bullet pattern has faded - de-activate it so you don't continually update an old pattern.

    Sheesh, all of this has got me thinking. I like it.....yes, yes I do. Off to the drawing board.
    Last edited by VirtualAce; 10-30-2003 at 03:35 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. Cprog tutorial: Design Patterns
    By maes in forum C++ Programming
    Replies: 7
    Last Post: 10-11-2004, 01:41 AM
  3. Creating Patterns
    By incognito in forum Game Programming
    Replies: 5
    Last Post: 03-16-2003, 09:02 AM
  4. pic movement
    By pode in forum Game Programming
    Replies: 31
    Last Post: 08-21-2002, 09:30 PM
  5. Allegro help-o
    By Vicious in forum Game Programming
    Replies: 109
    Last Post: 06-11-2002, 08:38 PM