|
-
Dec 8th, 2001, 02:31 AM
#1
Thread Starter
Junior Member
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
-
Dec 8th, 2001, 02:16 PM
#2
What I do is set up an array of bullets, usually give them there own type
i.e.
VB Code:
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...
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
-
Dec 9th, 2001, 05:36 AM
#3
Thread Starter
Junior Member
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
-
Dec 9th, 2001, 06:21 AM
#4
Addicted Member
-
Dec 9th, 2001, 01:07 PM
#5
Frenzied Member
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
-
Dec 9th, 2001, 01:09 PM
#6
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...
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
-
Dec 9th, 2001, 01:24 PM
#7
Frenzied Member
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
-
Dec 10th, 2001, 08:52 AM
#8
Thread Starter
Junior Member
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:
'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
-
Dec 10th, 2001, 04:19 PM
#9
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:
Dim x as character
x.name = "Hello"
Z.
-
Dec 11th, 2001, 06:55 AM
#10
Thread Starter
Junior Member
-
Dec 11th, 2001, 08:32 AM
#11
Good Ol' Platypus
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)
-
Dec 11th, 2001, 12:53 PM
#12
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
-
Dec 12th, 2001, 09:41 AM
#13
Frenzied Member
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?
-
Dec 13th, 2001, 06:58 AM
#14
Thread Starter
Junior Member
hey thanks heaps jotaf
that clears it up
-
Dec 13th, 2001, 03:29 PM
#15
Frenzied Member
You're welcome
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
|