Results 1 to 7 of 7

Thread: Help

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Posts
    225
    Hiyas,

    I've progressed very far with my game - I can now move soldiers all over my map (which scrolls), and the path finder works perfectly. I'm up to the stage of weapons fire.

    How can I move weapons fire from one X,Y point to another X,Y point? (whatever direction, doesn't matter) I want to do it so it moves pixel by pixel, although very quickly.

    I was using a loop using the X/Y distance formula, but that used the SQR function, so it was very very slow... =/

    I had the idea of maybe using a gradient (Rise/Run), although I'm not sure how to implement it. I've tried to do it, but it failed rather dismally. =(

    Can anyone give me some insight? I'd love to get the weapons code written, so then I can start blasting the terrain! *grin* All I need is the basic movement code - I can write the collision detection, BitBlt graphics code, offset info., etc. myself.

    Btw, with Loops, if you have a Loop running constantly, does that actually freeze the program, or can you still do stuff while it's doing the loop?

    Thanks.

    -Git

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    i suppose you don't need ballistic projectiles :)

    unless you move the bullets very fast, it will freeze your app, vb doesn't support multithreading
    No 3d effects in your game? The bullet doesn't go in Z axis?
    Just plain move from x1,y2 to x2,y2?
    Any vectors implemented in your game? (could be easier to work with. faster performance with the calculations...)
    of course, it looks much more cool if you have many bullets and explosions at the same time so i recommend you make up an array for a bullet UDT and youll get more fireworks in your game.
    How about the game engine? A game loop that blits the screen with api or directX?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Posts
    225
    The game is turn-based, so it doesn't matter if it freezes it.

    I'm just using BitBlt for graphics, not experienced enough for DX (yet).

    It's just a simple game, doesn't use height, only X/Y. =)

    -Git

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Posts
    225
    Btw, Vectors.......?

    I take it that means from one X/Y point to another?

    -Git

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    ok vectors are what you need
    That means a velocity in a direction and when specifying it in (X,Y) and the best and fastest way to do calculations with artimetically moving objects.
    So what you do is calculate the vector when the you initiate the projectile:
    a) by angle and velocity
    Vector.Y = sin(angle)*velocity
    Vector.X = sin(angle)*velocity
    b) by two coordinates and velocity
    angle=atn((y0-y1)/(x0-x1))+((y-y0)>0)*3.1415
    Note, all angles are in radians

    Then to move the projectile you do
    Coordinate.X=Coordinate.X+Vector.X
    Coordinate.Y=Coordinate.Y+Vector.Y
    and it will hit the spot




    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6
    Member
    Join Date
    Aug 2000
    Location
    USA
    Posts
    32

    No need for trig ...

    Trigonometric functions execute slowly and are often simply a pain to work with. There is a much easier way of obtaining a vector of a given length in the direction of another vector--the unit vector.

    If you divide the x, y, and z (if you have z) components of a vector by the length of the vector you will get a vector in the same direction but with a length of one.

    So, to get the x and y lengths of the vector (which I will call xv and yv), given the starting and ending x and y coords and the velocity of the projectile:

    xd = x1 - x2 'xd is the horizontal distance
    yd = y1 - y2 'yd is the vertical distance
    dist = Sqr (xd * xd + yd * yd) 'Sqr is slow, but you only call it once here...
    xv = (xd * velocity) / dist
    yv = (yd * velocity) / dist


    Then you can move the projectile just as kedaman said. =)

    -Koralt

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Youre correct Koralt, i was thinking about that angle all the time. Squareroot is also slow but in any case Atn or Sqr is only needed to calculate the initial vector, and won't affect any performance at all, thats the whole idea with using vectors
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

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