Flixel Forums

development => help => Topic started by: Evan Zenker on Mon, Oct 18, 2010

Title: How can I make a bullet array?
Post by: Evan Zenker on Mon, Oct 18, 2010
I was wondering how I could make a bullet array where the game checks to see if any of the bullets are hitting the enemy?
Title: Re: How can I make a bullet array?
Post by: initials on Mon, Oct 18, 2010
FlxInvaders is a great example of this.

http://github.com/AdamAtomic/Flx-Invaders

Basically, it generates a number of bullets, and puts them into a FlxGroup.

If you are looking to check for collisions amongst a group of objects, FlxGroups are definitely worth reading up about.

This is also a great article that includes the use of FlxGroups.
http://flashgamedojo.com/wiki/index.php?title=Memory_Management_(Flixel)
Title: Re: How can I make a bullet array?
Post by: OmegaStorm on Mon, Oct 18, 2010
The easiest way would be to add the bullets to a FlxGroup and the enemies to a FlxGroup and check to see if the two groups collide/overlap.

EDIT: What initials said. XD
Title: Re: How can I make a bullet array?
Post by: initials on Mon, Oct 18, 2010
EDIT: What initials said. XD

I love that this community has two different posts go up essentially at the same time. So many people keen to answer questions.
Title: Re: How can I make a bullet array?
Post by: Evan Zenker on Mon, Oct 18, 2010
It says there "There is currently no text in this page. You can search for this page title in other pages, search the related logs, or edit this page."  ???
Title: Re: How can I make a bullet array?
Post by: Evan Zenker on Mon, Oct 18, 2010
How would I do this?
Title: Re: How can I make a bullet array?
Post by: OmegaStorm on Mon, Oct 18, 2010
http://flashgamedojo.com/wiki/index.php?title=Memory_Management_%28Flixel%29 (http://flashgamedojo.com/wiki/index.php?title=Memory_Management_%28Flixel%29)

Another link on collision between groups: http://flashgamedojo.com/wiki/index.php?title=Collision_%28Flixel%29 (http://flashgamedojo.com/wiki/index.php?title=Collision_%28Flixel%29)
Title: Re: How can I make a bullet array?
Post by: Evan Zenker on Mon, Oct 18, 2010
I can't figure out how to do this!!! please help me  :'(
Title: Re: How can I make a bullet array?
Post by: OmegaStorm on Mon, Oct 18, 2010
Take a look at this tutorial that shows you how to create a basic defender style shoot 'em up. It'll cover creating a player class, enemy class, and bullet class, how to add them to groups and the stage, and collision between them.

http://www.creativeapplications.net/flash/flixel-2-tutorial-flash-tutorials-games/

It helped me out quite a bit when I was getting started. I've expanded upon it a bit by adding different weapons, powerups, and a heads up display in my own 2 part tutorial.

http://www.omegastormproductions.com/uber-flash/flixel-2-tutorial-extended
Title: Re: How can I make a bullet array?
Post by: Bandaro on Tue, Oct 19, 2010
Another option, if for some reason the FlxGroup is no good, is to push each Bullet object you make into and array, then in your update function, do a for loop check against the target.

for(var i:int = bulletArray.length-1;i>=0;i--){
  if(bulletArray.hitTest(player)){
    //result
   }
}

But since you are using Flixel, take advantage of it doing a lot of footwork for you and use the FlxGroup.

Same concept, just add each bullet into the FlxGroup instead of an array when you create the bullets and then do a

FlxU.collide(FlxGroup, Target, Function)

check in the update instead of the for loop.

Long story short, I agree with the FlxGroup, but there are multiple ways to approach this.
Title: Re: How can I make a bullet array?
Post by: Evan Zenker on Thu, Oct 21, 2010
FlxGroup worked beautifully :) My flixel game is almost complete!
Title: Re: How can I make a bullet array?
Post by: initials on Thu, Oct 21, 2010
FlxGroup worked beautifully :) My flixel game is almost complete!
Make sure you post your release in the Games forum.
Or email me directly at initials@initialscommand.com when it's done, I'd love to see it.
Title: Re: How can I make a bullet array?
Post by: Evan Zenker on Thu, Oct 21, 2010
Sure!