Exemple #1
0
        public void LoadArea()
        {
            this.IsGameOver = false;
            this.world      = GameFactory.LoadGame(DEFAULT_DATA);
            this.events     = new EventManager(this);
            this.events.QueueObject(this.world, 15);

            // by default always create the player object, which is indestructible
            if (!this.world.entities.ContainsKey(PLAYER_ID))
            {
                if (Random(100) < 50)
                {
                    this.CreateObject(PLAYER_ID, "bp_exekiel");
                }
                else
                {
                    this.CreateObject(PLAYER_ID, "bp_exekiel");
                }
            }
            var playerObject = GetObject(PLAYER_ID);

            playerObject.AI                      = new UserAI();
            playerObject.HasEnded                = true;
            playerObject.Visible                 = true;
            playerObject.OutObject.Color         = Color.White;
            this.world.worldView.ReferenceObject = GetObject(PLAYER_ID).OutObject;
            //this.AddLight (PLAYER_ID, 300, new Color(254, 250, 235));

            var wf = new WorldFactory();

            wf.Initialize(DEFAULT_LEVEL);
            wf.Generate(this.world);
            this.world.worldView.EnableGrid(false);

            if (world.StartCell.X != 0 && world.StartCell.Y != 0)
            {
                Move(PLAYER_ID, world.StartCell.X, world.StartCell.Y);
            }
            else
            {
                var done = false;
                do
                {
                    var x = Random(world.GridWidth - 1);
                    var y = Random(world.GridHeight - 1);
                    if (world.GetTile(x, y).Template.IsWalkable == true)
                    {
                        done = true;
                        this.Move(PLAYER_ID, x, y);
                    }
                } while(done != true);
            }
            this.world.CalculateFoV(playerObject.X, playerObject.Y, 6);
            this.events.DispatchAll();
            this.events.AcceptEvent = true;
            this.InitializeUserInterface();
            // XXX After the user interface is loaded!
            playerObject.ResetSkills();
            this.SelectedSkill = 1;
            Logger.Debug("Simulator", "LoadArea", "Starting fade at " + IoManager.Time.ToString());
            IoManager.FadeTo(Color.Transparent, 1500);
            IoManager.PlayMusic("intro");
            IoManager.SetNextMusicLoop("intro");
        }
Exemple #2
0
        public Entity CreateObject(string oid, string templateId, int gx = 0, int gy = 0)
        {
            var newEntity = GameFactory.LoadFromTemplate(templateId, oid);

            if (newEntity != null)
            {
                Logger.Debug("Simulator", "CreateObject", "OutObject " + new { newEntity.OutObject }.ToString());
                Logger.Debug("Simulator", "CreateObject", "Worldview " + new { this.world.worldView }.ToString());
                Logger.Debug("Simulator", "CreateObject", "Layer " + new { this.world.worldView.ObjectsLayer }.ToString());
                this.world.worldView.ObjectsLayer.AddObject(newEntity.OutObject);
                this.world.entities.Add(oid, newEntity);
                Move(oid, gx, gy);
                if (newEntity.OutObject.LightRadius > 1)
                {
                    AddLight(oid, newEntity.OutObject.LightRadius, newEntity.OutObject.LightColor);
                }
                else
                {
                    //CreateParticleOn (SPAWN_PARTICLE, newEntity);
                    //this.events.AppendEvent (new AiEvent (oid, 10));
                }
                if (newEntity.OutObject.animations.ContainsKey("SPAWN"))
                {
                    newEntity.OutObject.SetAnimation("SPAWN");
                    this.events.WaitFor(newEntity.OutObject.GetAnimationLength("SPAWN"));
                }
                this.events.Initiative++;
                this.events.QueueObject(newEntity, InitiativeCount /*createdEntityCount + 10*/);
                createdEntityCount++;
                newEntity.AI.OnCreate();
                newEntity.Visible         = this.world.InLos(gx, gy);
                newEntity.OutObject.Color = newEntity.Visible ? Color.White : Color.Transparent;
                if (newEntity.OutObject.animations.ContainsKey("CREATE"))
                {
                    newEntity.OutObject.SetAnimation("CREATE");
                    this.events.WaitFor(newEntity.OutObject.GetAnimationLength("CREATE"));
                }
                if (templateId == "e_efreet")
                {
                    this.CreateParticleOn("p_efreet", newEntity);
                }

                if (oid != PLAYER_ID)
                {
                    newEntity.OutIcon.ScaleX   = UI_SCALE;
                    newEntity.OutIcon.ScaleY   = UI_SCALE;
                    newEntity.OutIcon.Position = new Vector2f(IoManager.Width - UI_VERTICAL_START - newEntity.OutIcon.Width, UI_VERTICAL_START);
                    newEntity.Border           = new SolidBorder(UNSELECTED_SKILL_COLOR, 2f);
                    newEntity.OutIcon.AddDecorator(newEntity.Border);
                    newEntity.DamageBar            = new DamageBarDecorator(DAMAGE_BAR_COLOR);
                    newEntity.DamageBar.InvertAxis = true;
                    newEntity.OutIcon.AddDecorator(newEntity.DamageBar);
                }

                return(newEntity);
            }
            else
            {
                Logger.Warning("Simulator", "CreateObject", "cannot create " + oid + " " + templateId);
                return(null);
            }
        }