Ejemplo n.º 1
0
            public GameObject BuildObject(GameInstance g, int nb_players)
            {
                GameObject o = null;
                Vector2    p = new Vector2(0, 0);

                Type type = Type.GetType(type_str);

                if (type == typeof(Bomb))
                {
                    o = new Bomb(p);
                }
                if (type == typeof(Coin))
                {
                    o = new Coin(p);
                }
                if (type == typeof(Fireball))
                {
                    o = new Fireball(p);
                }
                if (type == typeof(FireGreen))
                {
                    o = new FireGreen(p);
                }
                if (type == typeof(FirePoison))
                {
                    o = new FirePoison(p);
                }
                if (type == typeof(FirePink))
                {
                    o = new FirePink(p);
                }
                if (type == typeof(Food))
                {
                    o = new Food(p);
                }
                if (type == typeof(Monstar))
                {
                    o = new Monstar(p, g, Controller.Direction.RIGHT);
                }
                if (type == typeof(Player))
                {
                    o = new Player(p, g.GetNewScorePosition(nb_players), g, -1);
                }

                return(o);
            }
Ejemplo n.º 2
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++;
                }
            }
        }