Ejemplo n.º 1
0
        public Collide Check()
        {
            Collide Result = new Collide();

            foreach (Heal Heal in this.Heals)
            {
                if (IsCollides(
                        Heal.Position, Heal.Size,
                        Player.GetPosition(), Player.GetSize(),
                        10, 10)
                    )
                {
                    Result.Type   = CollideType.TakeHeal;
                    Result.Heal   = Heal;
                    Result.Bullet = null;
                    Result.Enemy  = null;
                    return(Result);
                }
            }

            foreach (Enemy Enemy in this.Enemies)
            {
                // collide
                if (IsCollides(
                        Enemy.GetPosition(), Enemy.GetSize(),
                        Player.GetPosition(), Player.GetSize(),
                        15, 20)
                    )
                {
                    Result.Type   = CollideType.Collide;
                    Result.Enemy  = Enemy;
                    Result.Bullet = null;
                    return(Result);
                }

                // hits by player
                foreach (Bullet Bullet in this.Bullets)
                {
                    if (Bullet.CheckType(BulletType.Player))
                    {
                        if (IsCollides(Enemy.GetPosition(), Enemy.GetSize(),
                                       Bullet.GetPosition(), Bullet.GetSize(), 0, 10))
                        {
                            Result.Type   = CollideType.HitInEnemy;
                            Result.Enemy  = Enemy;
                            Result.Bullet = Bullet;
                            return(Result);
                        }
                    }
                }
            }

            // hits by enemy
            foreach (Bullet Bullet in this.Bullets)
            {
                if (Bullet.CheckType(BulletType.Enemy))
                {
                    if (IsCollides(Bullet.GetPosition(), Bullet.GetSize(),
                                   Player.GetPosition(), Player.GetSize(), 5, 5))
                    {
                        Result.Type   = CollideType.HitInPlayer;
                        Result.Enemy  = null;
                        Result.Bullet = Bullet;
                        return(Result);
                    }
                }
            }

            return(Result);
        }
Ejemplo n.º 2
0
        public void Timer(Object sender, EventArgs e)
        {
            int ticks = Environment.TickCount;

            if (ticks > this.LastTime + 1000 / Game.FramesPerSecond)
            {
                Collide collide = this.Collision.Check();

                if (this.GameStatus == GameStatus.Game || this.GameStatus == GameStatus.End)
                {
                    for (int i = this.Bullets.Count - 1; i != -1; i--)
                    {
                        int result = this.Bullets[i].Move(this.Scene);

                        if (result == 0)
                        {
                            this.Bullets.RemoveAt(i);
                        }
                    }

                    IEnumerable <Explosion> ReverseExplosion = this.Explosions.Reverse <Explosion>();
                    foreach (Explosion explosion in ReverseExplosion)
                    {
                        if (explosion.IsDone())
                        {
                            this.Explosions.Remove(explosion);
                        }
                        else
                        {
                            explosion.Update();
                        }
                    }

                    foreach (Heal heal in this.Heals)
                    {
                        heal.Update();
                    }

                    if (collide.Type == CollideType.TakeHeal)
                    {
                        this.Player.AddHealth(1);
                        this.Heals.Remove(collide.Heal);
                    }

                    if (collide.Type == CollideType.HitInEnemy)
                    {
                        this.IncreaseScore();
                        this.AddExplosion(collide.Enemy);

                        Random rand = new Random();
                        if (rand.Next(5) == 0)
                        {
                            this.AddHeal(collide.Enemy);
                        }

                        this.Enemies.Remove(collide.Enemy);
                        this.Bullets.Remove(collide.Bullet);
                    }

                    this.LastTime = ticks;
                }

                if (this.GameStatus == GameStatus.Game)
                {
                    IEnumerable <Enemy> ReverseEnemy = this.Enemies.Reverse <Enemy>();
                    foreach (Enemy enemy in ReverseEnemy)
                    {
                        int result = enemy.Move(this.Scene);

                        if (ticks > this.LastEnemyShootTime + this.EnemyShootDelay)
                        {
                            enemy.Shoot(ref this.Bullets);

                            this.LastEnemyShootTime = ticks;
                        }

                        if (result == 0)
                        {
                            this.Enemies.Remove(enemy);
                        }
                    }

                    if (ticks > this.LastIncreaseLevelTime + Game.IncreaseLevelDelay)
                    {
                        this.EnemyCreateDelay = Game.BaseEnemyCreateDelay - Game.StepEnemyCreateDelay * this.GameLevel;
                        this.EnemyShootDelay  = Game.BaseEnemyShootDelay - Game.StepEnemyShootDelay * this.GameLevel;
                        this.EnemySpeed       = Game.BaseEnemySpeed + Game.StepEnemySpeed * this.GameLevel / 2;
                        this.EnemyShootSpeed  = Game.BaseEnemyShootSpeed + Game.StepEnemyShootSpeed * this.GameLevel;

                        if (this.GameLevel < Game.MaxLevel)
                        {
                            this.GameLevel++;
                        }

                        this.LastIncreaseLevelTime = ticks;
                    }

                    if (ticks > this.EnemyCreateTime + this.EnemyCreateDelay)
                    {
                        Random rand = new Random();

                        Enemy enemy = new Enemy((Bitmap)game.Properties.Resources.ResourceManager.GetObject("enemy" + rand.Next(this.MaxEnemyImages)));
                        enemy.SetProportionalSize(60);
                        enemy.SetSpeed(this.EnemySpeed);
                        enemy.CharacterShoot.SetReloadTime(500);
                        enemy.CharacterShoot.SetSpeed(this.EnemyShootSpeed);
                        enemy.CharacterShoot.SetWidth(15);
                        enemy.CharacterShoot.SetImage(game.Properties.Resources.laser_red);
                        enemy.CharacterShoot.SetOffset(new Point(
                                                           enemy.GetSize().Width / 2,
                                                           enemy.GetSize().Height / 2
                                                           ));
                        enemy.SetPosition(new Point(
                                              rand.Next(this.Scene.Size.Width - enemy.GetSize().Width),
                                              -enemy.GetSize().Height
                                              ));

                        this.Enemies.Add(enemy);

                        this.EnemyCreateTime = ticks;
                    }

                    if (this.PlayerStatus.MouseHold)
                    {
                        this.Player.Shoot(ref this.Bullets);
                    }


                    if (this.Score > 0 && this.Score % 10 == 0 && !this.LevelUpdated)
                    {
                        if (this.PlayerLevel < Game.MaxPlayerLevel)
                        {
                            this.PlayerLevel++;
                            this.LevelUpdated = true;

                            this.Player.CharacterShoot.SetSpeed(Game.BasePlayerShootSpeed + Game.StepPlayerShootSpeed * this.PlayerLevel);
                            this.Player.CharacterShoot.SetReloadTime(Game.BasePlayerReloadTime + Game.StepPlayerReloadTime * this.PlayerLevel);
                        }
                    }
                    else if (this.Score % 10 == 1)
                    {
                        this.LevelUpdated = false;
                    }

                    if (collide.Type == CollideType.HitInPlayer || collide.Type == CollideType.Collide)
                    {
                        this.AddExplosion(this.Player);

                        this.Player.AddHealth(-1);
                        if (this.Player.GetHealth() < 1)
                        {
                            this.GameStatus = GameStatus.End;
                        }
                    }

                    if (collide.Type == CollideType.HitInPlayer)
                    {
                        this.Bullets.Remove(collide.Bullet);
                    }
                    else if (collide.Type == CollideType.Collide)
                    {
                        this.AddExplosion(collide.Enemy);
                        this.Enemies.Remove(collide.Enemy);
                    }

                    this.LastTime = ticks;
                }
            }
        }