It's ok to have "die" as a method because bullets don't die often. But
"update" should be called only once and then loop through the bullets,
not the other way round (looping through the bullets and calling
"update" on each). Same with "checkEvents" and "move".
I'm not entirely sure how you intend me to do this Mark..
I have a Bullet class, and an array of instances of this class. I want to keep whatever is related to positioning and moving bullets *in this array* to the best of my abilities. As for hit detection and such, that's a separate task altogether, what i'm primarily concerned with now is moving programmatic points along vectors. updateBullets() must call every screen update, because it is what makes sure all bullet transformations happen in one operation, ie BEFORE hit detection. Bullet.update(); must call for every bullet looped through during updateBullets(), because it is what actually moves the bullets according to their event arrays. Every single bullet can do any number of things every update, from acceleration to aiming for the player to exploding and emitting more bullets.

So if i'm reading you right, you're saying this:

public function update(time:Number){
       age+=time;
       for(var i = events.length;i--;){
           if(age>=events[i].triggerTime){
               switch(e.eventType){
               case 1:
               //random vector add
               vector.x += -4+random(8);
               vector.y += -4+random(8);
               break;
               case 2:
               //aim for mouse
               break;
               case 3:
               //change velocity
               break;
               case 4:
               //change direction
               break;
               }
               events.splice(i,1);
               var angle = Math.atan2(vector.y,vector.x);
               angle = angle*180/Math.PI;
               clip._rotation = angle;
           }
       }
       if(age>=lifeSpan){
           die();
       }else{
           position.x=position.x+vector.x*time;
           position.y=position.y+vector.y*time;
           clip._x = position.x;
           clip._y = position.y;
       }
   }

Is better than:
public function update(time:Number){
       age+=time;
       checkEvents();
       if(age>=lifeSpan){
           die();
       }else{
           move(time);
       }
   }
private function checkEvents(){
       for(var i = events.length;i--;){
           if(age>=events[i].triggerTime){
               handleEvent(events[i]);
               events.splice(i,1);
           }
       }
   }
private function handleEvent(e:BulletEvent){
       trace("event is type "+e.eventType);
       switch(e.eventType){
           case 1:
           //random vector add
           vector.x += -4+random(8);
           vector.y += -4+random(8);
           break;
           case 2:
           //aim for mouse
           aimForMouse();
           break;
           case 3:
           //change velocity
           break;
           case 4:
           //change direction
           break;
       }
       updateClipRotation();
   }
   private function updateClipRotation(){
       var angle = Math.atan2(vector.y,vector.x);
       angle = angle*180/Math.PI;
       clip._rotation = angle;
   }

etc?

This feels like going back to procedural programming again and it makes me wonder why the hell i even bother making a Bullet class in the first place if the amount of functionality i can give a class has to be supplied in raving great lumps like this or little to none at all.
Also, when you
create them, you can give them a deathDate property you test "time"
against.
I already do that, mailing you everything i have right now off-list :)

- Andreas
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to