Page 1 of 1

Visual Basic Timer/Sorta

Posted: Wed Nov 07, 2007 2:27 pm
by Twister
Ok I am currently making a game in Visual Basic 6. Its my first game and i have some fireballs to be shooting at the enemy ships. But, too many fireballs are being shot when i press the spacebar and i need to find a way to limit this. <img src=\'http://www.killanet.net/forum3/public/s ... Debate.gif\' class=\'bbc_emoticon\' alt=\'(debate)\' /> I have this keyarray in an Array timer so it can tell when the key is pressed. I was wondering if anyone knew a way i can limit the amount of shots by hitting the spacebar. <img src=\'http://www.killanet.net/forum3/public/s ... >/blum.gif\' class=\'bbc_emoticon\' alt=\':P\' />

Code: Select all

If KeyArray(32) = True Then 'Spacebar Shoot
				Call MAKE_FIREBALL(0)
		End If
Here's a screenshot to see whats happening.
shipwars.jpg

Visual Basic Timer/Sorta

Posted: Wed Nov 07, 2007 5:34 pm
by Tami
I can't personally help you - because I don't know how to programme - however I found this [url="http://www.vb6.us/"]open source site[/url] which has several game development tutorials for VB6, and there seem to be some tutorials which will help you.

For Example:

Understanding control arrays - This explains the very useful feature of control arrays. Control arrays allow you to create controls at runtime.

Understanding the timer control - The timer control is very useful learn how to use it effectively.

And there is this site, which is all about developing [url="http://www.vbgames.com/"]VB Games[/url]. On the front page, it appears they are also offering a free book which you might find informative:

[quote]Programming Games for Beginners - VB 6.0

Have you ever wanted to create your own game, but found it hard to learn how? This book teaches you the basic skills needed to program Visual Basic Games. The basic concepts and techniques behind creating your own Visual Basic Games can be easily learned by anyone with a little programming know-how. Price: Free![/quote]

They also offer downloadable VB games with source code.

Visual Basic Timer/Sorta

Posted: Thu Nov 08, 2007 1:53 pm
by Twister
Thank you Tami, but I have already used control arrays in this program and I already know how to use it. But, the information you provided was useful about that book so I thank you for that. That piece of code that i posted is in a timer.

Here's the full code for the timer.
[code]Private Sub tmrArray_Timer()
Dim NUM As Integer

'ARROW KEYS
If PLAYER1_EXIST Then
If KeyArray(39) = True Then
SHIP(0).X = SHIP(0).X + 25
End If
If KeyArray(37) = True Then
SHIP(0).X = SHIP(0).X - 25
End If
If KeyArray(38) = True Then
SHIP(0).Y = SHIP(0).Y - 25
End If
If KeyArray(40) = True Then
SHIP(0).Y = SHIP(0).Y + 25
End If
If KeyArray(32) = True Then 'Spacebar Shoot [This bit lets the user use the spacebar to shoot fireballs.]
Call MAKE_FIREBALL(0)
End If
End If
End If[/code]

But the bad thing is, its shooting too many at a time. I cant find a way to limit this.

Visual Basic Timer/Sorta

Posted: Thu Nov 08, 2007 5:23 pm
by Josh
Well, it has to lay within this code:

[code] If KeyArray(32) = True Then 'Spacebar Shoot [This bit lets the user use the spacebar to shoot fireballs.]
Call MAKE_FIREBALL(0)
End If[/code]

What is MAKE_FIREBALL?

Visual Basic Timer/Sorta

Posted: Thu Nov 08, 2007 8:07 pm
by Twister
MAKE_FIREBALL makes the fireball paints the picture and put its into the center of the shipcraft. For the enemy ship and the player 1 & 2 ship. and i know that it has to lay with that specific part of the code but i dont know how to limit the shots... and the (0) identifies which ship its coming from (0) is 1st player (1) is second player and remaining array numbers are for enemy ships. but all i need is for 0 and 1

Visual Basic Timer/Sorta

Posted: Thu Nov 08, 2007 8:10 pm
by Josh
So when you press your space bar it just creates and creates and creates? Are you just wanting one fireball to shoot out when you hit the space bar?

Visual Basic Timer/Sorta

Posted: Thu Nov 08, 2007 8:18 pm
by Twister
yes thats fine with me, at least with some kind of delay ya know as longs as its not extremely repetitive like it is now

Visual Basic Timer/Sorta

Posted: Thu Nov 08, 2007 8:36 pm
by Josh
Well the way I'm looking at the code is...

You have a timer and I'm assuming it's set on a very low interval so the game can update fast. So every time that timer is going through the code it's looking if you're pressing that spacebar and when you press that spacebar it is to make a fireball. I don't have VB6 installed anymore so I can't play around so I'm not sure how to find a solution to this.

I remember a long time ago that I used a KeyDown event on keyboard buttons. On KeyDown I would make it execute something (such as making a fireball shoot).

Let me see if I can find my VB6 installation CD's to play around with it a bit.

Visual Basic Timer/Sorta

Posted: Thu Nov 08, 2007 9:51 pm
by Josh
The only thing that I can come up with would be this:

[code]Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 32 Then
Call MAKE_FIREBALL(0)
End If
End Sub[/code]

However, it will create more fireballs if the space bar is held down...

Visual Basic Timer/Sorta

Posted: Thu Nov 08, 2007 10:11 pm
by Twister
thanks dren... if you hold it down it still does the same thing but u cannot move and press the spacebar down which is a good thing so i guess this can work for now but i want it to limit the amount thats being shot but thanks for that because it can be very useful.