Shooting the bullet object out of the gun object at the enemny object. Kablooey!

Nomosoft

  • Posts: 122
I have a behavior called "Gun," which accepts a few parameters, including an actor type to use as ammunition. Every X seconds, the gun spawns an ammunition actor and sends it on its way. Great, except that I want multiple guns on my Player actor, and I don't want to do something silly like make ten copies of my gun behavior and call them Gun1 through Gun10.

So, I thought it would be good to have the gun store a list of all the types of ammo that it can fire, and each frame it checks each piece of ammo to find out whether that piece of ammo should be fired (checks the time since the last piece of that type was fired, checks whether a target is in range, etc.) Imagine the Gun behavior having a list with Bullet, Laser Beam, Missile, Grenade, etc.

I want to build all of the relevant information (delay between firings, time last fired, range, etc) into the actor. That way, the gun simply checks each actor type in its list, gets the information from the actor, then either spawns or doesn't spawn the ammo actor. I do _not_ want to have to hard-code each possible kind of ammo into the Gun behavior, I want to simple have every ammo actor share a behavior, such as "Ammo Stats" that the gun can read. That way, I can simply create a new ammo actor type, fill in the necessary information, and add it to the Gun's list, and the Gun itself does not need to be modified for each new piece of ammo I add.

Still with me? OK, here's the problem: the only way for me to do this seems to be if I create an actor of every type from the ammo list and have them exist somewhere in the scene at all times. Otherwise, I can't read from the "Ammo Stats" behavior because, if there is no actor, there is no behavior. Is there any way to do what I've described without having a bunch of invisible ammunition actors hiding in every scene?

rob1221

  • *
  • Posts: 9472
I'm thinking you can use a game attribute list (or multiple lists) that stores the values for each bullet actor.

Nomosoft

  • Posts: 122
I'm thinking you can use a game attribute list (or multiple lists) that stores the values for each bullet actor.

Tell me if this makes any sense (I am not an AS3 programmer and don't really know where the performance bottlenecks are):

I create a scene behavior which, on loading, iterates through all the ammo actors, creates one of each type, and stores the relevant information from each type in an associative array, thus:
[Ammo actor type]_[attribute] = Value;

So,
Bullet_speed = 40
Bullet_damage = 1
Bullet_firedelay = 100
Bullet_lastfired = 293847
Missile_speed = 25
Missile_damage = 4
Missile_firedelay = 400
Missile_lastfired = 293606

Then, I simply access the associative array for each ammo type in my gun's list. Is this a reasonable way to go about this?


rob1221

  • *
  • Posts: 9472
I don't see any problems with doing that, and if you kill the actors after sending the information to the list then that will help performance a little bit.