|
-
Apr 27th, 2000, 05:25 AM
#1
Thread Starter
Frenzied Member
I can't figure this out:
Public Sub CheckKeys()
'SHOOTING
If KD(vbKeySpace) = True Then
Shoot
End If
End Sub
Public Sub Shoot()
Shot.y = Shot.y - 1
End Sub
When I hold down the space bar, the bullet goes; but when i lift it, the bullet stops. How do I keep the function going?
-
Apr 27th, 2000, 07:13 AM
#2
Hyperactive Member
Do you have some kind of infinite loop that keeps running and updating everything? When the keyboard button is pressed you can set some variable to true. Your loop can check that variable in each iteration, and if its true, move the bullet along.
"People who think they know everything are a great annoyance to those of us who do."
-
Apr 28th, 2000, 01:22 AM
#3
Fanatic Member
Or you can put replace the shoot thing with a timer and
enable it for shooting and disable it when it hits (if that
is what your game's about).
I know most people hate timers, but if you ask me they're a
mixed blessing.
Adios!
-
Apr 28th, 2000, 04:56 AM
#4
Thread Starter
Frenzied Member
I don't exactly want to use a timer because Im using BitBlt. I used to use timers, yes most of the time they are blessings in disguise.
-
Apr 28th, 2000, 08:08 AM
#5
Hyperactive Member
Steve did you get your tank shooting ok?
Well timers are useful when precise timing isnt important. However, when I was using them to control the main loop of my game it was pretty obvious that it wasnt going to do.
"People who think they know everything are a great annoyance to those of us who do."
-
Apr 28th, 2000, 08:24 AM
#6
Thread Starter
Frenzied Member
Hey noone, I only had a few minutes to check out your code. I checked vb world, and then my family and I set out for Connecticut (USA if you don't live there). On saturday I will be able to play with it some more. I'll tell you how It goes. Thanks!
-
May 5th, 2000, 07:36 PM
#7
transcendental analytic
I have an idea if you need to make multiple bullets to shoot, make a an UDT:
Type tBullet
x as integer
y as integer
speedx as integer
speedy as integer
end type
Dim bullet() as tbullet
And now you can have make it shot 75 bullets/second if you want, and the bullet goes in every direction you want
Use a mainloop in your game in the Sub Main with a doevents so that it can move the bullets if they're fired
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 5th, 2000, 11:13 PM
#8
Hyperactive Member
Kedeman is right about the array of UDT, it's probably the best and easiest way to go.
"People who think they know everything are a great annoyance to those of us who do."
-
May 5th, 2000, 11:39 PM
#9
transcendental analytic
Wait i got a better suggestion:
Make a classmodule instead of udt and make it handle the code for when it hits something or not. Then put a classcollection to add and remove new bullets, in this way you don't need to remove the last UDT in the array, Classcollection handles the referings and you don't need to rearange the udt everytime a bullet hits something before the last bullet
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 6th, 2000, 01:39 AM
#10
Hyperactive Member
I thought about using classes too but was informed that it might be a bit too slow, and becuase VB isnt as OOP as Java or C++ wasnt worth it. What you might want to do is put a boolean variable in your UDT that determines if the bullet is currently active or not, if that variable is false you can just skip over it.
"People who think they know everything are a great annoyance to those of us who do."
-
May 6th, 2000, 02:22 AM
#11
transcendental analytic
You may be right noone, that's if this tank game needs speed. You need to make a sub launched not as frequent as the main loop, to free up the already hit bullets from the UDT array.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 6th, 2000, 02:38 AM
#12
Hyperactive Member
Is there any reason to move them in and out of the array? I jsut always kept them in the array but set the active variable to false.
"People who think they know everything are a great annoyance to those of us who do."
-
May 6th, 2000, 02:54 AM
#13
transcendental analytic
Well you will fill up the memory each time you fire a bullet, so they have to be removed from the udt as soon as a specified amount of bullets have been reached
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 6th, 2000, 06:45 AM
#14
Hyperactive Member
About how much memory would each of those UDT take up?
"People who think they know everything are a great annoyance to those of us who do."
-
May 6th, 2000, 07:36 AM
#15
transcendental analytic
Each UDT will take up as much as the vars inside it will take, go look at the datatype summary in the vb help
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 6th, 2000, 09:47 PM
#16
New Member
The use of a type is most possibly the best way to do it,
but maybe having instead of having .speedx and speedy you could use .angle in degrees since:
x = x + sin(angle / 57)
y = y + cos(angle / 57)
I think that perhaps you'll have to subtract 90 degress
from the angle, but testing will show if you need to do so in order to make certain that 0 is straight up.
The reason you divide in 57 is that you have to convert degress into radians, and 57 usable, although it's very aprox. If you want a closer value you can easily calculate
the value by doing 360 / (2 * pi).
Woopsie, this may be a little off the topic, but it's very usefull for a Shoot'm'up game.
Well, it's a pentium parrot, besides, it's only a decimal.
-
May 7th, 2000, 12:47 AM
#17
transcendental analytic
Just learning how to use radians instead and put the angles in radians instead of degrees save both time and performance, . In this case it's better to put speedx and speedy and make the degree calculations from outside, or we end up with performance problems, if we have to calculate the new position with sin and cos every time.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 7th, 2000, 06:21 AM
#18
Hyperactive Member
I was just asking about taking them out of the array because I'm doing someting similar now and never take things out of the array. At initialization I create the array and put in as many as I'm going to use. Will this cause memory problems?
"People who think they know everything are a great annoyance to those of us who do."
-
May 7th, 2000, 08:47 AM
#19
New Member
Of course, my mistake, wasn't thinking there.
Defining .xspeed and .yspeed as cos/sin values is
much better. And for even more increase of speed it's
wise to create cos and sin tables
Well, it's a pentium parrot, besides, it's only a decimal.
-
May 7th, 2000, 03:59 PM
#20
transcendental analytic
Well I haven't calculated anything but you wont probably notice anything, as this UDT don't take much space but if you don't care for all your variable in you game, you might end up with a Ram eater
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 9th, 2000, 09:03 AM
#21
Addicted Member
Back to the arrays. How do you delete something from an array? I've heard of it but never have I seen it done.
-
May 9th, 2000, 04:05 PM
#22
transcendental analytic
Code:
Redim Preserve array(ubound(array)-1)
This will delete the last item in an array. So if you want to delete an item which is not the last, and the order doesn't matter, you can put the lastitem to the deleted items place and then redim it.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|