Creating bullets

Blitz3D Forums/Blitz3D Beginners Area/Creating bullets

Kairu(Posted 2009) [#1]
I am very new to using blitz3d and can not figure out at all how to program a player to shoot. im still on 2d games. any help would be great. : )


GfK(Posted 2009) [#2]
Pseudocode:
Bullet = CreateCube()

Repeat
  MoveEntity Bullet,0,0,1
Until Bullet Hits Something



Ross C(Posted 2009) [#3]
It's a broad question really. The differences between 2d shooting and 3d shooting depend on what game it's used on.

For instance, a sniper rifle. You wouldn't really want to produce a visible bullet for this, because of the speed it will travel. Your best bet would be a linepick, for an instant hit.

But, a tank, shooting a shell, you'd want to produce a bullet mesh, or sprite of some kind. The code behind it is pretty simple. As Gfk says, move the bullet till it hits something, or it moves too far away. If you have a 3d gun, you'd want to parent a pivot to the gun, to give each bullet a start position.

If your just starting out on 3d stuff, try some really simple stuff, like moving the camera about with the keys. It will get you used to the entity system and the commands needed.


AJ00200(Posted 2009) [#4]
make an array
Dim bullets(100)
for i=0 to 100
    bullets(i)=createCilinder()
    hiteentity(bullets(i))
Next



while not keydown(1)
   <MOVE BULLET CODE>
   if <DETECT COLLISION CODE>
       <HIDE HIT BULLET CODE>    end if 
wend



System4 Studios(Posted 2009) [#5]
A lil correction to AJ's code

it's not
hiteentity(bullets(i))


It's

HideEntity(bullets(i)



Kairu(Posted 2009) [#6]
thank you guys. i keep trying to understand the arrays and all the books i read are not really giving me much application to games. I dont really know what they do except the basic data creation.


Warner(Posted 2009) [#7]
Well, games are programs, too. You can use arrays to store level data in a 2d tile engine. You could store highscores in it. There are all sorts of usage for arrays in games.


RGF(Posted 2009) [#8]
Think of arrays as Excel tables. The first row always contains a number, the index. The second row contains data, that can be a Int number, a text string, a floating point number...

You can read the data stored in second row by selecting a number from the first column.

When you start programming, you don't see the point. But arrays are very important.

Think of Arkanoid game

You have 35 bricks in screen
Let's say each of them is a different bitmap

Instead of writing 35 times "brick1image=createimage(32,32,1)" to create 35 different images, you would :

first, declare array "mybricks", with 35 index numbers in the first row of excel table

dim mybricks(34)

then fill the second row of the table, with images of bricks

for i=0 to 34
mybricks(i)=createimage(32,32,1)
next

whenever you want to draw the image numbered 18 you would use:

draw mybricks(17),x,y


Nate the Great(Posted 2009) [#9]
well I almost never used arrays in b3d... but theyare kinda like little slots you can put numbers in and take them back out later

   23  __  42 __   80     
|____|  |____|  |____|...etc
   1       2      3


so there is my visualization :)

the numbers on top are things you stored in the array and the numbers at the bottom are the numbers you put in the parenthesis to return the number above it.


Ross C(Posted 2009) [#10]
I agree with putting the bullets in a type collection. If you use arrays, you have to keep track of dead bullets, and possibly even shift the array contents around. For my waypoint editor, i use array (wish i hadn't for some aspects). And when a waypoint is deleted, it is marked as being deleted.

Then, when i need to create a new waypoint, i call a function which loops through all the array slots and finds the first empty one.


RGF(Posted 2009) [#11]
I agree. When you need to modify data while the program is running, you should use TYPES.
Arkanoid example was only thought for loading or creating brick's images when the program is loading its resources.


Nate the Great(Posted 2009) [#12]
ross c, I have learned a useful way to avoid this and still get the speed of arrays... unless you need them in a certain order that is which I dont need for a physics engine

you make an array and put new objects in it as well as keeping track of how many you add, then when one is deleted, simply move the last array object to the 'hole' you have created for efficiency or shift the entire thing (should be really fast still)


Ross C(Posted 2009) [#13]
That's not a bad idea man, if only one gets deleted, but i can see what you mean. Never thought to do that, thanks :) I like using field names though, rather than numbers. I know you can assign CONST to the array slot names, to help you, but, i still prefer type names.

Thanks for the tip though!