variable problem

Started by
3 comments, last by megaman 21 years, 10 months ago
Hi, I am making a submarine game in Visual Basic 6, and of course the torpedos fire from the back of the ship. That means, the X coordinate of the Torpedo is the same as the X of the Ship in my bitblt code. After its fired, however, when the ship''s X changes to move along the screen, the torpedo moves with it while its moving down. How do I make the X variable constant and independant of the Submarine AFTER it is fired? Thanks, -Jerry
Advertisement
Well, if in your BitBlt code, when you're blitting everything, you set the screen X of the torpedo to whatever variable you're using for the screen X of the submarine, it will most certainly move with the sub. If you're using a separate variable to keep track of the torpedo's X (as you most certainly should), it would appear that in in your loop you're setting the torpedo's X to the submarine's X no matter what the conditions are (for instance, the torpedo having left the sub). What I would have is something like this (although I'd have to see your code to tell you for sure):

if (torpedo fire)
create torpedo
set torpedo position to (submarineX, y)

if (torpedo exists)
set torpedo position to (torpedoX, torpedoY)

You might have something somewhere in your loop which says:
torpedoX = submarineX
and it does it regardless of whether the torpedo was just fired or not.

Oh, and this could be either in your blitting code, in your screen position updating code, or, if you have it, in your virtual position updating code. And you definitely don't want to set the X of the torpedo BitBlt to the X of your submarine ever, unless you know that the torpedo was just fired.

Twilight Dragon
www.freewebz.com/j-world

[edited by - TDragon on June 5, 2002 3:59:47 PM]
{[JohnE, Chief Architect and Senior Programmer, Twilight Dragon Media{[+++{GCC/MinGW}+++{Code::Blocks IDE}+++{wxWidgets Cross-Platform Native UI Framework}+++
only the loop when you hit FIRE, do you set the torpedo''s x = submarine''s x.
Precisely.

Twilight Dragon
www.freewebz.com/j-world
{[JohnE, Chief Architect and Senior Programmer, Twilight Dragon Media{[+++{GCC/MinGW}+++{Code::Blocks IDE}+++{wxWidgets Cross-Platform Native UI Framework}+++
thank you so much it works great!

This topic is closed to new replies.

Advertisement