// Laser's methods // Fires a laser if the laser rate of 'flier' allows it, if 'flier' is a Boss, he fires twice more protected void FireLaser(GameTime gameTime, ref TimeSpan prev, TimeSpan rate, IFlier flier) { // if we CAN fire a laser, we fire it if (gameTime.TotalGameTime - prev > rate) { prev = gameTime.TotalGameTime; AddLaser(flier,0f); // see below the process of spawning a laser // Bosses are badasses and shoot three shots, at an angle if (flier is BossEnemy) { AddLaser(flier, 3f); AddLaser(flier, -3f); } } }
// Handles the spawn of the laser and adding it to the active lasers lists protected void AddLaser(IFlier flier, float shotDirection) { // declaration of locals variables Texture2D loc_texture; Vector2 loc_flierPosition; Vector2 loc_laserPostion; Laser laser; // we set the laser position to the position of the flier loc_flierPosition = flier.GetPosition(); loc_laserPostion = loc_flierPosition; // each flier has it's offset to make the laser come out of the gun Vector2 loc_laserFlier = flier.GetGunOffset(); loc_laserPostion += loc_laserFlier; // we adjust the laser position with the offset // we spawn the laser, standard laser for the player // boss-specific is handled in the FireLaser(), a bit of player tracking for the enemies if ((flier is Player)) { loc_texture = t2d_laserTexture; laser = new Laser(); } else if ((flier is BossEnemy)) { loc_texture = t2d_enemyLaserTexture; laser = new EnemyLaser(shotDirection); } else if ((flier is Enemy)) { loc_texture = t2d_enemyLaserTexture; // Enemies track the player's position and adjust aim very slightly float a = 0f; if (player.v2_playerPosition.Y < loc_flierPosition.Y) { a = -2f; } else if (player.v2_playerPosition.Y > loc_flierPosition.Y) { a = 2f; } laser = new EnemyLaser(a); } else { // DEFAULT because C# knows what is good better than us :-) loc_texture = t2d_laserTexture; laser = new Laser(); } Animation laserAnimation = new Animation(); // initlize the laser animation laserAnimation.Initialize(loc_texture, loc_flierPosition, 46, 16, 1, 30, Color.White, 1f, true); // init the laser laser.Initialize(laserAnimation, loc_laserPostion); // add the laser to the proper list if(laser is EnemyLaser) { list_enemiesLasers.Add(laser); } else { list_lasers.Add(laser); } }