Beispiel #1
0
        public void Update(float elapsed)
        {
            if (!game.Level.Current.StopFalling)
            {
                time += elapsed;
                while (time > game.Level.Current.interval)
                {
                    if (game.Level.Current.BombActiv && random.Next(0, 5) == 0)
                    {
                        NonPlayerObject bomb = new Bomb(new Vector2(0, -30));

                        int X = random.Next(0, TimGame.GAME_WIDTH - bomb.Size.X);
                        bomb.Position = new Vector2(X, bomb.Position.Y);
                        Player playerAimed = game.players[random.Next(0, game.players.Count)];

                        Rectangle r1 = new Rectangle(bomb.Position.ToPoint(), bomb.Size);
                        Rectangle r2 = new Rectangle(playerAimed.Position.ToPoint(), playerAimed.Size);
                        bomb.ApplyNewImpulsion(new Vector2(Collision.direction_between(r1, r2, false).X * 0.04f, 0));
                        EnemiesList.Add(bomb);
                    }
                    else
                    {
                        NonPlayerObject enemy = null;
                        if (game.Level.Current.FireballActiv && random.Next(0, 4) != 0)
                        {
                            // a chance to have a poison
                            if (random.Next(0, 2) == 0)
                            {
                                int randF = random.Next(0, 3);
                                if (randF == 0)
                                {
                                    enemy = new FirePoison(new Vector2(0, -30));
                                }
                                else if (randF == 1)
                                {
                                    enemy = new FirePink(new Vector2(0, -30));
                                }
                                else
                                {
                                    enemy = new FireGreen(new Vector2(0, -30));
                                }
                            }

                            else                             // a regular fireball
                            {
                                enemy = new Fireball(new Vector2(0, -30));
                            }
                        }
                        else if (game.Level.Current.FireballActiv)
                        {
                            // a chance to have a cake
                            if (random.Next(0, 4) == 0)
                            {
                                enemy = new Food(new Vector2(0, -30));
                            }
                            else
                            {
                                enemy = new Coin(new Vector2(0, -30));
                            }
                        }
                        int X = random.Next(0, TimGame.GAME_WIDTH - enemy.Size.X);
                        enemy.Position = new Vector2(X, enemy.Position.Y);
                        EnemiesList.Add(enemy);
                    }
                    time -= game.Level.Current.interval;
                }
            }

            // Delete enemies that are out of bounds
            EnemiesList.RemoveAll((e => e.IsOutOfBounds()));

            // Autodestruct ennemies on the ground
            if (EnemiesList.Count != 0)
            {
                EnemiesList.FindAll(game.Level.Current.map.pMap.nearTheGround).ForEach((e => e.SufferDamage()));
            }

            // Delete enemies that are dead
            int i = 0;

            while (i < EnemiesList.Count)
            {
                NonPlayerObject e = EnemiesList[i];
                if (e.Dead)
                {
                    EnemiesList.Remove(e);
                    game.AddToScores(10);
                }
                else
                {
                    i++;
                }
            }
        }
Beispiel #2
0
        protected override void ApplyCollision(Vector2 imp, PhysicalObject obj, float elapsed)
        {
            base.ApplyCollision(imp, obj, elapsed);

            if (obj is NonPlayerObject)
            {
                NonPlayerObject e = (NonPlayerObject)obj;
                e.TouchPlayer();
                // Bonus
                if (e.Bonus > 0 || e.Life > 0)
                {
                    Life.incr(e.Life);
                    Score.incr(e.Bonus);
                    color           = Color.Yellow;
                    last_bonus_time = 0f;
                }

                switch (e.poisonState)
                {
                case NonPlayerObject.PoisonState.Horizontal:
                    if (!flipH)
                    {
                        poison_remaining_time += time_poison;
                        flipH = true;
                        color = Color.DarkViolet;
                        //last_damage_time = 0f; // It is for the color + immunity
                    }
                    break;

                case NonPlayerObject.PoisonState.Vertical:
                    if (!flipV)
                    {
                        poison_remaining_time += time_poison;
                        flipV = true;
                        color = Color.DarkViolet;
                        //last_damage_time = 0f; // It is for the color + immunity
                    }
                    break;

                case NonPlayerObject.PoisonState.Rotation:
                    if (!rotation)
                    {
                        poison_remaining_time += time_poison;
                        rotation = true;
                        color    = Color.DarkViolet;
                        //last_damage_time = 0f; // It is for the color + immunity
                    }
                    break;

                case NonPlayerObject.PoisonState.Nothing:
                    break;
                }

                // Damage
                int damage = 0;
                if (e is Monstar)
                {
                    if (!e.Damaged)                     // If e is damaged, it is because the collision has already been treated
                    {
                        float y_player = position.Y + Size.Y;
                        float y_e      = e.Position.Y + e.Size.Y / 2;
                        if (y_player < y_e)
                        {
                            velocity.Y = 0;                             // To give an impression of bouncing
                            e.SufferDamage();
                        }
                        else
                        {
                            damage = e.Damage;
                            e.SufferDamage();
                        }
                    }
                }
                else
                {
                    damage = e.Damage;
                }
                // If we are not invincible ..
                if (last_damage_time >= time_invicibility)
                {
                    if (damage > 0)
                    {
                        Life.decr(damage);
                        color            = Color.IndianRed;
                        last_damage_time = 0f;
                    }
                }
            }
        }