예제 #1
0
 public static void DropBonus(Panel ActionPanel, Actor sourceActor)
 {
     if (new Random().Next(100) > 80)
     {
         GameWindow.ThisGameWindow.actors[GameWindow.GetFirstOpenIndex(GameWindow.ThisGameWindow.actors)] =
             new Bonus(ActionPanel, sourceActor);
     }
 }
예제 #2
0
        } // end DoesCollide
        private void DropBonusesOnDeath()
        {
            // theory - drop 1/2 the bonuses we have gathered so far.

            int laserBonuses = (int)(laser / 2);
            int healthBonuses = (int)((this.currentMaxHealth - Actor.startHealth) / 2);
            int speedBonuses = (int)((this.speed - Actor.startSpeed) / 2);
            int laserSpeedBonuses = (int)((this.laserSpeed - Actor.startLaserSpeed) / 2);
            int totalBonuses = laserBonuses + healthBonuses + speedBonuses + laserSpeedBonuses;
            int currentBonusIndex = 0;

            for (int i = 0; i < laserBonuses; i++)
            {
                Bonus b = new Bonus(ActionPanel, this, Bonus.BonusCategory.laserPowerBonus);
                // change b's direction

                PositionBonus(b, currentBonusIndex++);

                GameWindow.ThisGameWindow.actors[
                    GameWindow.GetFirstOpenIndex(GameWindow.ThisGameWindow.actors)] = b;
            }

            for (int i = 0; i < healthBonuses; i++)
            {
                Bonus b = new Bonus(ActionPanel, this, Bonus.BonusCategory.healthBonus);
                // change b's direction

                PositionBonus(b, currentBonusIndex++);

                GameWindow.ThisGameWindow.actors[
                    GameWindow.GetFirstOpenIndex(GameWindow.ThisGameWindow.actors)] = b;
            }

            for (int i = 0; i < speedBonuses; i++)
            {
                Bonus b = new Bonus(ActionPanel, this, Bonus.BonusCategory.speedBonus);
                // change b's direction

                PositionBonus(b, currentBonusIndex++);

                GameWindow.ThisGameWindow.actors[
                    GameWindow.GetFirstOpenIndex(GameWindow.ThisGameWindow.actors)] = b;
            }

            for (int i = 0; i < laserSpeedBonuses; i++)
            {
                Bonus b = new Bonus(ActionPanel, this, Bonus.BonusCategory.laserSpeedBonus);
                // change b's direction

                PositionBonus(b, currentBonusIndex++);

                GameWindow.ThisGameWindow.actors[
                    GameWindow.GetFirstOpenIndex(GameWindow.ThisGameWindow.actors)] = b;
            }
        }
예제 #3
0
        } // end drawSelf
        public override void damageMe(int dmg)
        {
            health -= dmg;
            if (health <= 0)
            {
                this.deleteMe = true;

                // explode - 
                Explosion e = new Explosion(ActionPanel, this, Explosion.ExplosionCategory.targetDestroyed);
                GameWindow.ThisGameWindow.actors[
                GameWindow.GetFirstOpenIndex(GameWindow.ThisGameWindow.actors)] = e;
            }
        } // end damageMe
예제 #4
0
        } // end drawSelf
        public override void damageMe(int dmg)
        {
            health -= dmg;
            if (health <= 0)
            {
                // progress level
                GameWindow.ThisGameWindow.isBossPresent = false;
                GameWindow.ThisGameWindow.actors[0].score += lvl * lvl * 10;
                GameWindow.ThisGameWindow.resetLevel();
                this.deleteMe = true;

                // explode - 
                Explosion e = new Explosion(ActionPanel, this, Explosion.ExplosionCategory.PlayerDetroyed);
                GameWindow.ThisGameWindow.actors[
                GameWindow.GetFirstOpenIndex(GameWindow.ThisGameWindow.actors)] = e;

            } // end if dead
        } // end damageMe
예제 #5
0
        } // end constructor
#endregion

#region public methods
        public override void update()
        {
            base.update();
            try
            {
                if (posY > ActionPanel.Height)
                {
                    deleteMe = true;
                }
                else
                {
                    // decide if we want to shoot at the player
                    if (MyRnd.next(1000) >= (998 - this.lvl)) // 0.2% - 0.5% based on lvl.
                    {
                        // shoot
                        Laser shot;
                        this.lvl += 1;
                        if (lvl > 3)
                        {
                            shot = new SeekingLaser(ActionPanel, this);
                        }
                        else
                        {
                            shot = new Laser(ActionPanel, this);
                        }
                        this.lvl -= 1;

                        shot.vY = 10 + this.lvl; // set speed
                        GameWindow.ThisGameWindow.actors[
                            GameWindow.GetFirstOpenIndex(GameWindow.ThisGameWindow.actors)] = shot;

                    }
                } // end not off screen
            }
            catch (ArgumentNullException ane)
            {
                ane.ToString();
            }
            catch (NullReferenceException ne)
            {
                ne.ToString();
            }

        }
예제 #6
0
        public virtual void damageMe(int dmg)
        {
            health -= dmg;

            if (health <= 0)
            {
                // explode - 
                Explosion e = new Explosion(ActionPanel, this, Explosion.ExplosionCategory.PlayerDetroyed);
                GameWindow.ThisGameWindow.actors[
                GameWindow.GetFirstOpenIndex(GameWindow.ThisGameWindow.actors)] = e;
                
                numLives--;

                if (numLives >= 0)
                {
                    // leaving a few upgrades, if appropriate.
                    DropBonusesOnDeath();

                    // reset to a new ship.
                    posX = (ActionPanel.Width - ObjWidth) / 2;
                    posY = ActionPanel.Height - (2 * ObjHeight);
                    vX = 0;
                    vY = 0;
                    speed = startSpeed;
                    laser = 1;
                    laserSpeed = startLaserSpeed;
                    coolDown = startCoolDown;
                    currentMaxHealth = startHealth;
                    health = currentMaxHealth;

                    lastShot = System.DateTime.Now;

                    //FUTURE: set some short time of invincible.

                } // if more lives
                else
                {
                    GameWindow.ThisGameWindow.gameOver = true;
                } // no more lives
            } // end if health below zero (died)
        } // end damageMe
예제 #7
0
        } // end checkWallCollisions
        public override void CheckObjectCollision(Actor[] objects)
        {
            // if laser traveling downward, then it is an enemy laser
            if (vY > 0)
            {
                // if laser hit player AND laser does not belong to player
                if(Actor.DoesCollide(this, objects[0]) 
                    && deleteMe == false
                    && owner != objects[0])
                {
                    // damage player
                    objects[0].damageMe(this.laser);

                    // create small explosion...
                    Explosion e = new Explosion(ActionPanel, this, Explosion.ExplosionCategory.laserHit);
                    GameWindow.ThisGameWindow.actors[
                    GameWindow.GetFirstOpenIndex(GameWindow.ThisGameWindow.actors)] = e;

                    // destroy self
                    this.deleteMe = true;

                } // end if hit player
            } // end if going down (enemy laser)

            else { // it's the players laser
                for (int i = 1; i < objects.Length; i++)
                {
                    if (objects[i] != null &&
                        objects[i] != this &&
                        objects[i].GetType() != typeof(Laser) && // lasers don't counter each other
                        objects[i].GetType() != typeof(SeekingLaser) && // lasers don't counter each other
                        objects[i].GetType() != typeof(Bonus) && // lasers can't kill a bonus
                        objects[i].GetType() != typeof(Explosion) && // lasers go through explosions.
                        objects[i].deleteMe == false)
                    {
                        // check collision, if so, respond.
                        if (Actor.DoesCollide(this, objects[i]))
                        {
                            // player laser damaged target, destroy/hurt target
                            objects[i].damageMe(this.laser);
                            if (objects[i].deleteMe == true)
                            {
                                GameWindow.DropBonus(ActionPanel, objects[i]);
                                objects[0].score += objects[i].laser;
                            }
                            else // if target not destroyed
                            {
                                // create small laser explosion...
                                Explosion e = new Explosion(ActionPanel, this, Explosion.ExplosionCategory.laserHit);
                                
                                // set explosion to match movement of target.
                                e.vX = objects[i].vX;
                                e.vY = objects[i].vY;

                                GameWindow.ThisGameWindow.actors[
                                GameWindow.GetFirstOpenIndex(GameWindow.ThisGameWindow.actors)] = e;
                            }

                            // destory self
                            this.deleteMe = true;
                        } // if collides.
                    } // end if
                } // end for loop
            } // end if going up (player laser)

        } // end checkObjectCollision
예제 #8
0
        } // end constructor
        #endregion

        #region public methods
        public override void update()
        {
            base.update();
            if (this.deleteMe)
            {
                GameWindow.ThisGameWindow.isBossPresent = false;
                return;
            }

                #region Shooting
                // first check if we can shoot yet
                if (lastShot.AddMilliseconds(coolDown).CompareTo(System.DateTime.Now) < 0)
                {
                    // if so, then randomly choose.
                    if (MyRnd.next(100) >= (90 - (this.lvl * 2))) // 10% - 15% based on lvl. (per frame)
                    {
                        // standard shot (x3)
                        int temp = this.lvl;
                        this.lvl = 5;
                        Laser shot = new Laser(ActionPanel, this);
                        Laser shot2 = new Laser(ActionPanel, this);
                        Laser shot3 = new Laser(ActionPanel, this);
                        SeekingLaser shot4 = new SeekingLaser(ActionPanel, this);
                        SeekingLaser shot5 = new SeekingLaser(ActionPanel, this);
                        SeekingLaser shot6 = new SeekingLaser(ActionPanel, this);

                        this.lvl = temp;

                        // level specific shooting capabilities
                        // small spread
                        shot.vY = 5 + this.lvl * 2; // set speed
                        shot2.vY = 5 + this.lvl * 2; // set speed
                        shot3.vY = 5 + this.lvl * 2; // set speed
                        shot4.vY = 5 + this.lvl * 2;
                        shot5.vY = 5 + this.lvl * 2;
                        shot6.vY = 5 + this.lvl * 2;

                        shot2.vX = -3; // set angle
                        shot3.vX = 3; // set angle
                        shot5.vX = -5; // set angle
                        shot6.vX = 5; // set angle

                        // if higher boss, shoot seeking laser instead
                        switch (temp)
                        {
                            case 1:
                                GameWindow.ThisGameWindow.actors[
                                    GameWindow.GetFirstOpenIndex(
                                        GameWindow.ThisGameWindow.actors)] = shot;
                                GameWindow.ThisGameWindow.actors[
                                    GameWindow.GetFirstOpenIndex(
                                        GameWindow.ThisGameWindow.actors)] = shot2;
                                GameWindow.ThisGameWindow.actors[
                                    GameWindow.GetFirstOpenIndex(
                                        GameWindow.ThisGameWindow.actors)] = shot3;
                                break;
                            case 2:
                                GameWindow.ThisGameWindow.actors[
                                    GameWindow.GetFirstOpenIndex(
                                        GameWindow.ThisGameWindow.actors)] = shot2;
                                GameWindow.ThisGameWindow.actors[
                                    GameWindow.GetFirstOpenIndex(
                                        GameWindow.ThisGameWindow.actors)] = shot4;
                                GameWindow.ThisGameWindow.actors[
                                    GameWindow.GetFirstOpenIndex(
                                        GameWindow.ThisGameWindow.actors)] = shot3;
                                break;
                            case 3:
                                GameWindow.ThisGameWindow.actors[
                                    GameWindow.GetFirstOpenIndex(
                                        GameWindow.ThisGameWindow.actors)] = shot5;
                                GameWindow.ThisGameWindow.actors[
                                    GameWindow.GetFirstOpenIndex(
                                        GameWindow.ThisGameWindow.actors)] = shot;
                                GameWindow.ThisGameWindow.actors[
                                    GameWindow.GetFirstOpenIndex(
                                        GameWindow.ThisGameWindow.actors)] = shot6;
                                break;
                            case 4:
                                GameWindow.ThisGameWindow.actors[
                                    GameWindow.GetFirstOpenIndex(
                                        GameWindow.ThisGameWindow.actors)] = shot5;
                                GameWindow.ThisGameWindow.actors[
                                    GameWindow.GetFirstOpenIndex(
                                        GameWindow.ThisGameWindow.actors)] = shot4;
                                GameWindow.ThisGameWindow.actors[
                                    GameWindow.GetFirstOpenIndex(
                                        GameWindow.ThisGameWindow.actors)] = shot6;
                                break;
                        }
                        
                        // we have fired, so set the lastShot timer
                        lastShot = DateTime.Now;
                    } // end shoot
                }// end if cooldown
                #endregion

                #region Movement
                // decide if we want to change location/speeds
                if (posY > (2 * img.Height))
                {
                    vY = 0;
                    // if boss is moving slowly vX
                    if (vX < 5 &&
                        vX > -5)
                    {
                        // then speed up
                        vX = 2 * (vX + 1);
                    }
                }
                #endregion
        }