public override void UpdateActions(GameTime gameTime) { float secFraction = gameTime.ElapsedGameTime.Milliseconds / (float)1000.0; Game1 game = Game1.main_instance; // these are not smart bullets... they just go straight. :3 // check whether we've left the player's local area entirely if (Vector3.DistanceSquared(world.Translation, game.protagonist.world.Translation) > 3000.0F * 3000.0F) { active = false; return; } // let's do collision detection against ships here, though // that way there should be no confusion about whether bullets move or do this check first... Vector3 future = world.Translation + (velocity * secFraction); bool removebullet = false; // is the player hit? if (from != game.protagonist && Game1.TestLineSphereIntersection(world.Translation, future, game.protagonist.world.Translation, game.spaceship.Meshes[0].BoundingSphere.Radius)) { IOConsole.instance.WriteLine("player is hit."); game.protagonist.TakeHit(world.Translation, 0); removebullet = true; } // check all the other ships, if any >_< // foreach (ActorModel who in modelManager.models) // same problem as above with foreach() if (!removebullet) { for (int j = 0; j < game.modelManager.models.Count;) { BasicSpaceshipActor who = game.modelManager.models[j] as BasicSpaceshipActor; if (from != who && Game1.TestLineSphereIntersection(world.Translation, future, who.world.Translation, who.model.Meshes[0].BoundingSphere.Radius * 1.1f)) // XXX are we supposed to add BoundingSphere.Center to the translation as an offset? let's assume not. { who.TakeHit(world.Translation, 0); if (!who.active) { game.modelManager.models.RemoveAt(j); // I guess they asploded? } removebullet = true; } ++j; } } // this is getting twisted now :( if (removebullet) { this.active = false; } }
public Bullet(Model m, BasicSpaceshipActor origin) : base(m) { from = origin; }