Visual Basic Timer/Sorta

Snippets, Projects and Assistance

Moderators: Moderator, Global Moderator

Post Reply
Twister
Newbie
Newbie
Posts: 0
Joined: Sat Jan 22, 2005 8:14 pm

Visual Basic Timer/Sorta

Post 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&#40;32&#41; = True Then 'Spacebar Shoot
				Call MAKE_FIREBALL&#40;0&#41;
		End If
Here's a screenshot to see whats happening.
[attachment=3607]shipwars.jpg[/attachment]
Image
Tami
Administrator
Administrator
Posts: 0
Joined: Sun Apr 25, 2004 1:05 pm

Visual Basic Timer/Sorta

Post by Tami »

I can't personally help you - because I don't know how to programme - however I found this open source site 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 VB Games. On the front page, it appears they are also offering a free book which you might find informative:
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&#33;
They also offer downloadable VB games with source code.
Image

[color=\"#41211C\"]It takes years to build up trust and only seconds to destroy it

[/color]
Twister
Newbie
Newbie
Posts: 0
Joined: Sat Jan 22, 2005 8:14 pm

Visual Basic Timer/Sorta

Post 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: Select all

Private Sub tmrArray_Timer&#40;&#41;
	Dim NUM As Integer
	
	'ARROW KEYS
	If PLAYER1_EXIST Then
		If KeyArray&#40;39&#41; = True Then
			SHIP&#40;0&#41;.X = SHIP&#40;0&#41;.X + 25
		End If
		If KeyArray&#40;37&#41; = True Then
			SHIP&#40;0&#41;.X = SHIP&#40;0&#41;.X - 25
		End If
		If KeyArray&#40;38&#41; = True Then
			SHIP&#40;0&#41;.Y = SHIP&#40;0&#41;.Y - 25
		End If
		If KeyArray&#40;40&#41; = True Then
			SHIP&#40;0&#41;.Y = SHIP&#40;0&#41;.Y + 25
		End If
		If KeyArray&#40;32&#41; = True Then 'Spacebar Shoot &#91;This bit lets the user use the spacebar to shoot fireballs.&#93;
			Call MAKE_FIREBALL&#40;0&#41;
		End If
	End If
End If
But the bad thing is, its shooting too many at a time. I cant find a way to limit this.
Last edited by Twister on Thu Nov 08, 2007 1:54 pm, edited 1 time in total.
Image
Josh
Newbie
Newbie
Posts: 0
Joined: Fri Jun 04, 2004 2:54 pm

Visual Basic Timer/Sorta

Post by Josh »

Well, it has to lay within this code:

Code: Select all

		If KeyArray&#40;32&#41; = True Then 'Spacebar Shoot &#91;This bit lets the user use the spacebar to shoot fireballs.&#93;
			Call MAKE_FIREBALL&#40;0&#41;
		End If
What is MAKE_FIREBALL?
[align=center]

Image

“If you stop learning, you stop living.” ~Tami Quiring

“It's the rare man who understands the value of a single perfect rose.”

[/align]
Twister
Newbie
Newbie
Posts: 0
Joined: Sat Jan 22, 2005 8:14 pm

Visual Basic Timer/Sorta

Post 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
Last edited by Twister on Thu Nov 08, 2007 8:09 pm, edited 1 time in total.
Image
Josh
Newbie
Newbie
Posts: 0
Joined: Fri Jun 04, 2004 2:54 pm

Visual Basic Timer/Sorta

Post 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?
[align=center]

Image

“If you stop learning, you stop living.” ~Tami Quiring

“It's the rare man who understands the value of a single perfect rose.”

[/align]
Twister
Newbie
Newbie
Posts: 0
Joined: Sat Jan 22, 2005 8:14 pm

Visual Basic Timer/Sorta

Post 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
Last edited by Twister on Thu Nov 08, 2007 8:21 pm, edited 1 time in total.
Image
Josh
Newbie
Newbie
Posts: 0
Joined: Fri Jun 04, 2004 2:54 pm

Visual Basic Timer/Sorta

Post 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.
[align=center]

Image

“If you stop learning, you stop living.” ~Tami Quiring

“It's the rare man who understands the value of a single perfect rose.”

[/align]
Josh
Newbie
Newbie
Posts: 0
Joined: Fri Jun 04, 2004 2:54 pm

Visual Basic Timer/Sorta

Post by Josh »

The only thing that I can come up with would be this:

Code: Select all

Private Sub Form_KeyPress&#40;KeyAscii As Integer&#41;
If KeyAscii = 32 Then
	Call MAKE_FIREBALL&#40;0&#41;
End If
End Sub
However, it will create more fireballs if the space bar is held down...
[align=center]

Image

“If you stop learning, you stop living.” ~Tami Quiring

“It's the rare man who understands the value of a single perfect rose.”

[/align]
Twister
Newbie
Newbie
Posts: 0
Joined: Sat Jan 22, 2005 8:14 pm

Visual Basic Timer/Sorta

Post 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.
Image
Post Reply

Return to “Visual Basic”