Results 1 to 14 of 14

Thread: Bullets from a sprite?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2002
    Posts
    17

    Unhappy Bullets from a sprite?

    Im making an action game in a 2d environment with 2d characters. The charcter(man), holding a gun, is all one image or sprite. So I use the page flipping method in directdraw to animated him walking. Im having problem as how would I make him shoot a bullet from the tip of the nozzle of the gun. Because the gun keeps moving and is not in the same place everytime. Is there a way to get its x,y coordinate?

  2. #2
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    I'm not sure if it is an easy way to do that. But if you want to do it you could always record wich "picture" is showing and hardcode the X,Y coordinates for the gun and add the left and top coordinates of your man....

  3. #3
    Addicted Member
    Join Date
    Aug 2002
    Location
    Baltimore, MD
    Posts
    230
    Use an array of points that matches the animation frames, similar to what NoteMe posted. Hopefully the gun still points in a direction that makes sense to shot at. If the gun points down in one frame and you let him shoot then, it will look pretty silly if the bullet flies out horizontally.

  4. #4
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Originally posted by Machaira
    Use an array of points that matches the animation frames, similar to what NoteMe posted. Hopefully the gun still points in a direction that makes sense to shot at. If the gun points down in one frame and you let him shoot then, it will look pretty silly if the bullet flies out horizontally.
    ...hehehe...lol....yes...that would look silly...

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Dec 2002
    Posts
    17
    well......thats tideous work but looks like i have no choice..thanks for the advice!

  6. #6
    Fanatic Member alkatran's Avatar
    Join Date
    Apr 2002
    Location
    Canada
    Posts
    860

    hmmm

    Assuming I understand what you mean..

    You want a man to be able to rotate around (360 degrees or just u/d/r/l...)

    Anyways, my suggestion is to have a variable keeping track of his rotation, and to use that angle to move bullet... so:

    VB Code:
    1. sub shoot
    2. BulletDir = AngleOfPerson:BulletX = XofPerson':lalalalalla
    3. 'ok so MAYBE im leaving a bit out...
    4. end sub
    5.  
    6. sub move(Ref X,Ref Y,Ref speed,Ref angle)
    7. 'All the above should be referenced, I'm not sure if it's written correctly.
    8. X = X + Speed * Sin(Angle)
    9. Y = Y + Speed * Cos(Angle)
    10. End sub

    That move code is INCREDIBLY usefull, it lets you move things in all directions, by changing the angle variable (0-360, 361 = 1 duh)
    Don't pay attention to this signature, it's contradictory.

  7. #7
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: hmmm

    Originally posted by alkatran
    Assuming I understand what you mean..

    You want a man to be able to rotate around (360 degrees or just u/d/r/l...)

    Anyways, my suggestion is to have a variable keeping track of his rotation, and to use that angle to move bullet... so:

    VB Code:
    1. sub shoot
    2. BulletDir = AngleOfPerson:BulletX = XofPerson':lalalalalla
    3. 'ok so MAYBE im leaving a bit out...
    4. end sub
    5.  
    6. sub move(Ref X,Ref Y,Ref speed,Ref angle)
    7. 'All the above should be referenced, I'm not sure if it's written correctly.
    8. X = X + Speed * Sin(Angle)
    9. Y = Y + Speed * Cos(Angle)
    10. End sub

    That move code is INCREDIBLY usefull, it lets you move things in all directions, by changing the angle variable (0-360, 361 = 1 duh)

    If that was what you ment..then I think I and Machaira may have miss understodd you...are you rotating 360degrees or is it a one man walking in 2D game (left right)...???

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Dec 2002
    Posts
    17
    MY game is supposed 2d, ie. moving left and right only

  9. #9
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Then I think alkatran missunderstood...and you would have to do it the hard way..

  10. #10
    Fanatic Member alkatran's Avatar
    Join Date
    Apr 2002
    Location
    Canada
    Posts
    860

    Well

    Damn, stupid inferior games!!

    But anyways, make a frame where he shoots, problem solved, always in same spot.
    Don't pay attention to this signature, it's contradictory.

  11. #11
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: Well

    Originally posted by alkatran
    Damn, stupid inferior games!!

    But anyways, make a frame where he shoots, problem solved, always in same spot.
    Thats the best idea I have heard all day....hheheeh....

  12. #12
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    basically I am with alcatran, why would he shoot on every walking frame... I doubt you actually shoot standing on the tips of one foot
    well what I wanted to say is that you might want to check out Statemachines for that
    a good explanation can be found on www.ur.co.nz
    Sanity is a full time job

    Puh das war harter Stoff!

  13. #13
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755

    Re: hmmm

    Originally posted by raoul85
    MY game is supposed 2d, ie. moving left and right only
    Well, that would be 1d....moving in only one direction...

    Originally posted by alkatran
    VB Code:
    1. X = X + Speed * Sin(Angle)
    2. Y = Y + Speed * Cos(Angle)
    shouldnt it be like this?
    VB Code:
    1. X = X + Speed * Sin(Angle * (Pi / 180))
    2. Y = Y + Speed * Cos(Angle * (Pi / 180))
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  14. #14
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    well only if he has his angle stored in degree what wouldn't really help to much
    Sanity is a full time job

    Puh das war harter Stoff!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width