Author Topic: How can I make a bullet array?  (Read 2437 times)

Evan Zenker

  • Member
  • **
  • Posts: 12
  • Karma: +0/-0
    • View Profile
How can I make a bullet array?
« 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?

initials

  • Contributor
  • ****
  • Posts: 378
  • Karma: +0/-0
  • Initials
    • View Profile
    • Initials Blog. Code and other things.
Re: How can I make a bullet array?
« Reply #1 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)
Initials: Super Lemonade Factory, Super Lemonade Factory Part Two, Above The Clouds, Revvolvver, Four Chambers of the Human Heart

OmegaStorm

  • Member
  • **
  • Posts: 36
  • Karma: +0/-0
    • View Profile
    • OmegaStorm Productions
Re: How can I make a bullet array?
« Reply #2 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
« Last Edit: Mon, Oct 18, 2010 by OmegaStorm »

initials

  • Contributor
  • ****
  • Posts: 378
  • Karma: +0/-0
  • Initials
    • View Profile
    • Initials Blog. Code and other things.
Re: How can I make a bullet array?
« Reply #3 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.
Initials: Super Lemonade Factory, Super Lemonade Factory Part Two, Above The Clouds, Revvolvver, Four Chambers of the Human Heart

Evan Zenker

  • Member
  • **
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: How can I make a bullet array?
« Reply #4 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."  ???

Evan Zenker

  • Member
  • **
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: How can I make a bullet array?
« Reply #5 on: Mon, Oct 18, 2010 »
How would I do this?

OmegaStorm

  • Member
  • **
  • Posts: 36
  • Karma: +0/-0
    • View Profile
    • OmegaStorm Productions
« Last Edit: Mon, Oct 18, 2010 by OmegaStorm »

Evan Zenker

  • Member
  • **
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: How can I make a bullet array?
« Reply #7 on: Mon, Oct 18, 2010 »
I can't figure out how to do this!!! please help me  :'(

OmegaStorm

  • Member
  • **
  • Posts: 36
  • Karma: +0/-0
    • View Profile
    • OmegaStorm Productions
Re: How can I make a bullet array?
« Reply #8 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

Bandaro

  • Member
  • **
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: How can I make a bullet array?
« Reply #9 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.

Evan Zenker

  • Member
  • **
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: How can I make a bullet array?
« Reply #10 on: Thu, Oct 21, 2010 »
FlxGroup worked beautifully :) My flixel game is almost complete!

initials

  • Contributor
  • ****
  • Posts: 378
  • Karma: +0/-0
  • Initials
    • View Profile
    • Initials Blog. Code and other things.
Re: How can I make a bullet array?
« Reply #11 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.
Initials: Super Lemonade Factory, Super Lemonade Factory Part Two, Above The Clouds, Revvolvver, Four Chambers of the Human Heart

Evan Zenker

  • Member
  • **
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: How can I make a bullet array?
« Reply #12 on: Thu, Oct 21, 2010 »
Sure!