Results 1 to 15 of 15

Thread: projectiles

  1. #1

    Thread Starter
    Junior Member timmy's Avatar
    Join Date
    Nov 2001
    Location
    qld aus
    Posts
    23

    Arrow projectiles

    hey,
    i was just wondering what would be the best way to make projectiles project from an pic drawn with BitBlt. like space invaders type shoting. any help would be HEAP appreciated, code would be good.

    thanks

  2. #2
    NOMADMAN
    Guest
    What I do is set up an array of bullets, usually give them there own type

    i.e.
    VB Code:
    1. Type Bullet
    2.      X as long
    3.      Y as long
    4.      FIRED as boolean
    5. End Type
    something to that affect. After that I just track the bullets with a sort little function. like...
    VB Code:
    1. For i = 0 to numBullets
    2.      If Bullet(i).FIRED = true then Bullet(i).Y = Bullet(i).Y - 100 'minus goes UP
    3.      If Bullet(i).Y < = -50 then Bullet(i).FIRED = False
    4. Next i

    This moves the bullet and resets the shot when it reaches the top, a bit more similar code to make it stop if it hit something like a space invader. Then you need to know which bullet to fire next, meaning which is ready next. I use a little for statment for this...

    VB Code:
    1. NextBullet = -1
    2. For i = 0 to numBullets
    3.      If Bullet(i).FIRED = false then NextBullet = i
    4. Next i

    Then when you detect the player fires (spacebar press) then just do something like this...

    VB Code:
    1. If (whatever) = vbSpaceKey  AND NextBullet <> -1 then
    2.      With Bullet(NextBullet)    
    3.           .FIRED = true
    4.           .X = player.x + (player.width / 2) 'shoots out the middle
    5.           .Y = player.y
    6.      End With
    7. End If

    The NextBullet <> - 1 is a safty so that if there are no bullets that are ready it retains the value of -1 from the for statment. And won't shoot.
    Hope that helps, if you need me to ******** any of this I'll be checking back.

    NOMAD

  3. #3

    Thread Starter
    Junior Member timmy's Avatar
    Join Date
    Nov 2001
    Location
    qld aus
    Posts
    23
    hey thanks, yea that helps heaps
    just one thing im not sure on though is that type statement? i mean i understand it i guess from looking at it, but when i actually tried it, it doesnt seem to work

    it keeps saying 'invalid qualifier'

    just not sure on how to use that type statement...

    thanks neway

  4. #4
    Addicted Member Bazza81's Avatar
    Join Date
    Apr 2001
    Location
    Nottingham, UK
    Posts
    203

    Here, hope this helps

    My space invaders game I made a while ago, have a look, hope it helps
    Attached Files Attached Files
    Who needs rhetorical questions anyway?


    Bazza NET - The place you want to be!

  5. #5
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Hum, the type declaration should be before ANY other sub/function, and if it's in a form, you'll have to add "Private" before the first line
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  6. #6
    NOMADMAN
    Guest
    I couldn't make mine say invalid qualifier but I forgot to mention, you should put your api and type declarations in a module, for reasons I can explain but don't think it would help much. After you make a type its a type just like an integer or a boolean or anything else. You declare things as follows...
    VB Code:
    1. Dim SHOTS(4) as Bullet

    Also its possible to do it without the type statement. Just make a BulletX array of longs, BulletY array of longs, and a BulletFIRED array of booleans. You'd need to change the code from the above. But worst come to worst this is essentially the same thing, just a little messier.

    But try putting the type in a module. If that doesn't solve it post some code braket it in [ vbcode] and [/vbcode ] so its easy to read. (Minus the spaces before and after the ['s)

    Sorry for the confusion

    NOMAD

  7. #7
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    When you make a type it's basically like an object, the vars you define are kinda like properties

    For example, this would define an enemy ship:

    VB Code:
    1. Private Type tEnemyShip
    2.     X As Long
    3.     Y As Long
    4.     Health As Long
    5. End Type

    Of course you can add more stuff like the ship type, ammunition, shields, etc. It's a good way to keep your game organized without using slow classes
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  8. #8

    Thread Starter
    Junior Member timmy's Avatar
    Join Date
    Nov 2001
    Location
    qld aus
    Posts
    23
    hey thanks people for all the advice though its still not working

    something is up, heres the exact situation...

    i have a module in which id like to declare a type thing which i can use throughout my whole program like a global variable.

    this is the sort of thing ive been trying...

    VB Code:
    1. 'in a module
    2. Public Type character
    3.   name as string
    4. End Type
    5.  
    6.  
    7. 'in the program somewhere
    8. character.name = mynamegoeshere.Text
    9. 'or whatever

    i have no idea why its not working
    anyway thanks people

  9. #9
    Zaei
    Guest
    You have to create a variable of type character first. What you are trying to do is sort of like doing:
    Code:
    Integer = 10
    It just doesnt work. Instead, do:
    Code:
    Dim x as character
    x.name = "Hello"
    Z.

  10. #10

    Thread Starter
    Junior Member timmy's Avatar
    Join Date
    Nov 2001
    Location
    qld aus
    Posts
    23
    i dont totally understand that zaei but thats ok
    ive got some more questions i thought i may as well just post here though..

    i was wondering, ive been hearing in a few other posts a bout tiles, and i was wondering if anyone has some example projects or something using them, like the use of maps and scrolling for games and stuff...that would be cool

    one more thing that isnt that important but hey if you feel like it you can answer, i was wondering how you get multiple peices of information in one line of a listbox, you know in Kazaa and stuff like that with the dl screen for example...is that possible in vb???

    anyway thanks people

  11. #11
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    When you make a type it's like a listbox; you don't just say listbox.locked = true, etc.

    What you do is drag the control on and name it. You do the same with the types, like Zaei showed.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  12. #12
    NOMADMAN
    Guest
    I believe that character is taken by the system, just like integer and long so you can't make a type of character. You mean character like player huh? Try

    VB Code:
    1. Type Player
    2.      NAME as string
    3. end type

    That is probably your invalid qualifier
    See if that helps!

    NOMAD

  13. #13
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Ok, I'm gonna try to explain it to you the best I can:

    When you do this:

    VB Code:
    1. Public Type tPlayer
    2.   Name As String
    3.   Health As Long
    4. End Type

    You're not creating a variable. That's just a type; you can use that for a lot of variables, like this:

    VB Code:
    1. Dim Player1 As tPlayer
    2. Dim Player2 As tPlayer
    3. Dim Player3 As tPlayer
    4. Dim Player4 As tPlayer
    5.  
    6. Player1.Name = "Jotaf"
    7. Player1.Health = 100
    8. Player2.Name = "Timmy"
    9. Player2.Health = 50
    10.  
    11. '...

    Got it?
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  14. #14

    Thread Starter
    Junior Member timmy's Avatar
    Join Date
    Nov 2001
    Location
    qld aus
    Posts
    23
    hey thanks heaps jotaf
    that clears it up

  15. #15
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    You're welcome
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

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