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 :D
Printable View
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 :D
What I do is set up an array of bullets, usually give them there own type
i.e.
something to that affect. After that I just track the bullets with a sort little function. like...VB Code:
Type Bullet X as long Y as long FIRED as boolean End Type
VB Code:
For i = 0 to numBullets If Bullet(i).FIRED = true then Bullet(i).Y = Bullet(i).Y - 100 'minus goes UP If Bullet(i).Y < = -50 then Bullet(i).FIRED = False 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:
NextBullet = -1 For i = 0 to numBullets If Bullet(i).FIRED = false then NextBullet = i Next i
Then when you detect the player fires (spacebar press) then just do something like this...
VB Code:
If (whatever) = vbSpaceKey AND NextBullet <> -1 then With Bullet(NextBullet) .FIRED = true .X = player.x + (player.width / 2) 'shoots out the middle .Y = player.y End With 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
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 :confused:
it keeps saying 'invalid qualifier'
just not sure on how to use that type statement...
thanks neway
:D
My space invaders game I made a while ago, have a look, hope it helps :)
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 :)
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:
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
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:
Private Type tEnemyShip X As Long Y As Long Health As Long 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 :p
hey thanks people for all the advice though its still not working :confused:
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:
'in a module Public Type character name as string End Type 'in the program somewhere character.name = mynamegoeshere.Text 'or whatever
i have no idea why its not working
anyway thanks people
:D
You have to create a variable of type character first. What you are trying to do is sort of like doing:
It just doesnt work. Instead, do:Code:Integer = 10
Z.Code:Dim x as character
x.name = "Hello"
i dont totally understand that zaei but thats ok
ive got some more questions i thought i may as well just post here though.. :D
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 :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
:D
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.
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:
Type Player NAME as string end type
That is probably your invalid qualifier
See if that helps!
NOMAD
Ok, I'm gonna try to explain it to you the best I can:
When you do this:
VB Code:
Public Type tPlayer Name As String Health As Long 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:
Dim Player1 As tPlayer Dim Player2 As tPlayer Dim Player3 As tPlayer Dim Player4 As tPlayer Player1.Name = "Jotaf" Player1.Health = 100 Player2.Name = "Timmy" Player2.Health = 50 '...
Got it? :)
hey thanks heaps jotaf
that clears it up :D
You're welcome ;)