Beispiel #1
0
        private void frmAdvancedProgrammingExtras2_Load(object sender, EventArgs e)
        {
            picHeroBullet.Visible   = false;
            picEnemyBullet0.Visible = false;
            picEnemyBullet1.Visible = false;
            picEnemyBullet2.Visible = false;
            picEnemyBullet3.Visible = false;
            picEnemyBullet4.Visible = false;
            picEnemyBullet5.Visible = false;

            tmrEnemies.Enabled        = true;
            tmrHero.Enabled           = true;
            tmrEnemyFireDelay.Enabled = true;
            tmrEnemyBullets.Enabled   = true;
            tmrHeroBullet.Enabled     = true;

            tmrEnemyBullets.Interval   = 1;
            tmrEnemies.Interval        = 1;
            tmrEnemyFireDelay.Interval = 1000;
            tmrHero.Interval           = 1;
            tmrHeroBullet.Interval     = 1;

            enemies      = new ShooterGameObject[6];
            enemyBullets = new ShooterGameObject[6];
            planets      = new ShooterGameObject[3];
            walls        = new ShooterGameObject[4];

            hero   = new ShooterGameObject(picHero, 5, Directions.STOP);
            bullet = new ShooterGameObject(picHeroBullet, 5, Directions.UP);

            enemies[0] = new ShooterGameObject(picEnemy0, 1, Directions.LEFT);
            enemies[1] = new ShooterGameObject(picEnemy1, 1, Directions.LEFT);
            enemies[2] = new ShooterGameObject(picEnemy2, 1, Directions.LEFT);
            enemies[3] = new ShooterGameObject(picEnemy3, 1, Directions.LEFT);
            enemies[4] = new ShooterGameObject(picEnemy4, 1, Directions.LEFT);
            enemies[5] = new ShooterGameObject(picEnemy5, 1, Directions.LEFT);

            enemyBullets[0] = new ShooterGameObject(picEnemyBullet0, 3, Directions.DOWN);
            enemyBullets[1] = new ShooterGameObject(picEnemyBullet1, 3, Directions.DOWN);
            enemyBullets[2] = new ShooterGameObject(picEnemyBullet2, 3, Directions.DOWN);
            enemyBullets[3] = new ShooterGameObject(picEnemyBullet3, 3, Directions.DOWN);
            enemyBullets[4] = new ShooterGameObject(picEnemyBullet4, 3, Directions.DOWN);
            enemyBullets[5] = new ShooterGameObject(picEnemyBullet5, 3, Directions.DOWN);

            planets[0] = new ShooterGameObject(picPlanet0, 0, Directions.STOP);
            planets[1] = new ShooterGameObject(picPlanet1, 0, Directions.STOP);
            planets[2] = new ShooterGameObject(picPlanet2, 0, Directions.STOP);

            walls[0] = new ShooterGameObject(picWall0, 0, Directions.STOP);
            walls[1] = new ShooterGameObject(picWall1, 0, Directions.STOP);
            walls[2] = new ShooterGameObject(picWall2, 0, Directions.STOP);
            walls[3] = new ShooterGameObject(picWall3, 0, Directions.STOP);
        }
 public void bounceOff(ShooterGameObject target)
 {
     if (direction == Directions.LEFT)
     {
         direction = Directions.RIGHT;
     }
     else if (direction == Directions.RIGHT)
     {
         direction = Directions.LEFT;
     }
     else if (direction == Directions.UP)
     {
         direction = Directions.DOWN;
     }
     else if (direction == Directions.DOWN)
     {
         direction = Directions.UP;
     }
 }
 public void stickTo(ShooterGameObject target)
 {
     if (direction == Directions.LEFT)
     {
         left = target.right + 1;
     }
     else if (direction == Directions.RIGHT)
     {
         left = target.left - width - 1;
     }
     else if (direction == Directions.UP)
     {
         top = target.bottom + 1;
     }
     else if (direction == Directions.DOWN)
     {
         top = target.top - height - 1;
     }
 }
 public bool isColliding(ShooterGameObject target)
 {
     if (((this.left >= target.left && this.left <= target.right) ||
          (this.right >= target.left && this.right <= target.right)) &&
         ((this.top >= target.top && this.top <= target.bottom) ||
          (this.bottom >= target.top && this.bottom <= target.bottom)))
     {
         return(true);
     }
     else if (((target.left >= this.left && target.left <= this.right) ||
               (target.right >= this.left && target.right <= this.right)) &&
              ((target.top >= this.top && target.top <= this.bottom) ||
               (target.bottom >= this.top && target.bottom <= this.bottom)))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
 public void centerOn(ShooterGameObject target)
 {
     left = target.middleX - (width / 2);
     top  = target.middleY - (height / 2);
     recalculate();
 }