Results 1 to 22 of 22

Thread: Can't get my tank to shoot right

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    Angry

    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?


  2. #2
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    292
    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."

  3. #3
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516

    Wink

    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!
    Courgettes.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    Red face

    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.

  5. #5
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    292
    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."

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    Cool

    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!

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  8. #8
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    292
    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."

  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  10. #10
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    292
    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."

  11. #11
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  12. #12
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    292
    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."

  13. #13
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  14. #14
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    292
    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."

  15. #15
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  16. #16
    New Member
    Join Date
    May 2000
    Posts
    14
    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.

  17. #17
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  18. #18
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    292
    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."

  19. #19
    New Member
    Join Date
    May 2000
    Posts
    14
    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.

  20. #20
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  21. #21
    Addicted Member drewski's Avatar
    Join Date
    Feb 2000
    Location
    WA
    Posts
    242
    Back to the arrays. How do you delete something from an array? I've heard of it but never have I seen it done.

  22. #22
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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
  •  



Click Here to Expand Forum to Full Width