PDA

Click to See Complete Forum and Search --> : Help


git
Oct 6th, 2000, 01:53 AM
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

kedaman
Oct 6th, 2000, 07:11 AM
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?

git
Oct 6th, 2000, 07:21 AM
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

git
Oct 6th, 2000, 07:23 AM
Btw, Vectors.......?

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

-Git

kedaman
Oct 6th, 2000, 08:41 AM
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 ;)

Koralt
Oct 7th, 2000, 03:02 PM
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

kedaman
Oct 9th, 2000, 05:27 AM
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 :)