PDA

Click to See Complete Forum and Search --> : projectiles


timmy
Dec 8th, 2001, 01:31 AM
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

NOMADMAN
Dec 8th, 2001, 01:16 PM
What I do is set up an array of bullets, usually give them there own type

i.e.

Type Bullet
X as long
Y as long
FIRED as boolean
End Type


something to that affect. After that I just track the bullets with a sort little function. like...

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


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


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

timmy
Dec 9th, 2001, 04:36 AM
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

Bazza81
Dec 9th, 2001, 05:21 AM
My space invaders game I made a while ago, have a look, hope it helps :)

Jotaf98
Dec 9th, 2001, 12:07 PM
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 :)

NOMADMAN
Dec 9th, 2001, 12:09 PM
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...

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

Jotaf98
Dec 9th, 2001, 12:24 PM
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:



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

timmy
Dec 10th, 2001, 07:52 AM
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...


'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

Zaei
Dec 10th, 2001, 03:19 PM
You have to create a variable of type character first. What you are trying to do is sort of like doing:

Integer = 10


It just doesnt work. Instead, do:

Dim x as character
x.name = "Hello"


Z.

timmy
Dec 11th, 2001, 05:55 AM
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

Sastraxi
Dec 11th, 2001, 07:32 AM
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.

NOMADMAN
Dec 11th, 2001, 11:53 AM
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


Type Player
NAME as string
end type


That is probably your invalid qualifier
See if that helps!

NOMAD

Jotaf98
Dec 12th, 2001, 08:41 AM
Ok, I'm gonna try to explain it to you the best I can:

When you do this:



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:



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? :)

timmy
Dec 13th, 2001, 05:58 AM
hey thanks heaps jotaf
that clears it up :D

Jotaf98
Dec 13th, 2001, 02:29 PM
You're welcome ;)