Archived

This topic is now archived and is closed to further replies.

variable problem

This topic is 5669 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
only the loop when you hit FIRE, do you set the torpedo''s x = submarine''s x.

Share this post


Link to post
Share on other sites