Skip to main content
gamedev.net
🔒 Locked

variable problem

Started by megaman 3 replies 200+ views
Original Post
megaman
megaman
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
TDragon
TDragon
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]
megaman
megaman
thank you so much it works great!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.