Exemple #1
0
 public void FeedbackMessage(string message, Color color, int duration = 1000)
 {
     var feedbackEnt = GetEntityByTag ("hud_feedback");
     var seq = new Sequence ();
     seq.Add (new ActionEntity (feedbackEnt, (_) => {
         feedbackEnt.Get<Drawable> ().DrawColor = color;
     }));
     seq.Add (new Timeline(new ActionEntity (feedbackEnt, (_) => {
         feedbackEnt.Get<Text> ().Message = message;
     }), duration));
     seq.Add (new ActionEntity (feedbackEnt, (_) => {
         feedbackEnt.Get<Text> ().Message = string.Empty;
     }));
     feedbackEnt.Get<Execute> ().AddNew (seq);
 }
Exemple #2
0
        public void SpawnEffect(Point pos, string name, float duration)
        {
            var sprites = (ISpriteSheets)Game.Services.GetService (typeof(ISpriteSheets));

            var ent = CreateEntity ();
            ent.Register (new Execute ());
            ent.Register (new Sprite (sprites.GetSprite (name)));
            ent.Register (new Drawable (new Vector2(pos.X * Globals.CELL_WIDTH, pos.Y * Globals.CELL_HEIGHT)));

            var seq = new Sequence ();
            seq.Add (new AnimSprite(ent, duration));
            seq.Add (new ActionEntity (ent, (_) => {
                RemoveEntityByTag(ent.Tag);
            }));

            ent.Get<Execute> ().Add (seq);
        }
Exemple #3
0
        public override void OnActivated()
        {
            var sprites = (ISpriteSheets)Game.Services.GetService (typeof(ISpriteSheets));
            var world = (IWorld)Game.Services.GetService (typeof(IWorld));
            var gameState = (IGameState)Game.Services.GetService (typeof(IGameState));

            var mapGrid = world.GetLevel(gameState.Level);

            var player = CreateEntity ("player");

            player.Register (new State<PlayerState> (PlayerState.Idle));
            player.Register (new Health (gameState.PlayerHealth, gameState.PlayerHealthMax,
                                            () => OnHealthChanged(player)));
            player.Register (new Attack (Archetypes.Weapons[gameState.PlayerWeaponID]["attack"], Archetypes.Weapons[gameState.PlayerWeaponID]["attack_distance"], gameState.PlayerWeaponID));
            player.Register (new PointLight ((PointLight.DistanceType)gameState.PlayerViewDistanceType, Color.White));
            player.Register (new MoveSpeed (gameState.PlayerMoveSpeed));
            player.Register (new IFFSystem (Globals.IFF_PLAYER_ID, 2));
            player.Register (new Attackable (OnAttacked));
            player.Register (new Position (mapGrid.StairDown.X, mapGrid.StairDown.Y));
            player.Register (new Execute ());
            player.Register (new Poisonable (OnPoisoned));
            player.Register (new Sprite (sprites.GetSprite (string.Format("player_{0:D2}", gameState.PlayerSpriteID))));
            player.Register (new Drawable (new Vector2(mapGrid.StairDown.X * Globals.CELL_WIDTH, mapGrid.StairDown.Y * Globals.CELL_HEIGHT)));
            player.Register (new Clickable (new Rectangle (0, 0, Globals.CELL_WIDTH * Globals.WORLD_WIDTH, Globals.CELL_HEIGHT * Globals.WORLD_HEIGHT)));
            player.Register (new Consumable<ConsumableTypes> ());
            player.Register (new CriticalHit ());
            player.Register (new MoneyMultiplier (gameState.PlayerMoneyMultiplier));
            player.Register (new AttackMultiplier (gameState.PlayerAttackMultiplier));
            player.Register (new PoisonChanceMultiplier (gameState.PlayerPoisonChanceMultiplier));
            player.Register (new AttackDistanceMultiplier (gameState.PlayerAttackDistanceMultiplier));
            player.Register (new AttackSpeed (gameState.PlayerAttackSpeed));

            if (gameState.PlayerArmorID >= 0) {
                player.Register (new Armor (Archetypes.Armors [gameState.PlayerArmorID] ["defence"], gameState.PlayerArmorID));
            }
            player.Get<Consumable<ConsumableTypes>> ().Refill (ConsumableTypes.Money, gameState.PlayerMoney);
            player.Get<Consumable<ConsumableTypes>> ().Refill (ConsumableTypes.Antitod, gameState.PlayerAntitodPotions);

            player.Get<Clickable> ().OnMoved += OnMoveToPosition;
            player.Get<Clickable> ().OnTouched += OnAction;

            var seq = new Sequence ();
            seq.Add (new ActionEntity (player, OnEnterToLevel));
            var blink = new Loop(new ActionEntity(player, (_) => {
                if (player.Get<Drawable>().DrawAlpha == 0.0f) {
                    player.Get<Drawable>().DrawAlpha = 1.0f;
                } else {
                    player.Get<Drawable>().DrawAlpha = 0.0f;
                }
            }), 250);
            seq.Add (new Timeline (blink, Globals.PLAYER_SPAWN_SEC * 1000));
            seq.Add (new ActionEntity (player, (_AppDomain) => {
                player.Get<Drawable>().DrawAlpha = 1.0f;
            }));
            seq.Add (new Loop (new ActionEntity (player, (_) => {
                UpdatePlayer (player);
            })));
            player.Get<Execute>().Add(seq, "player_update_loop");

            m_toMove = mapGrid.StairDown;
            StartIdle (player);
        }
Exemple #4
0
        private void UpdatePlayer(Entity player)
        {
            var world = (IWorld)Game.Services.GetService (typeof(IWorld));
            var gameState = (IGameState)Game.Services.GetService (typeof(IGameState));

            if (KeyboardUtils.IsKeyPressed (Keys.Q))
                m_isLevelCompleted = true;
            else if (KeyboardUtils.IsKeyPressed (Keys.M)) {
                player.Get<Consumable<ConsumableTypes>> ().Refill (ConsumableTypes.Money, 100);
            } else if (KeyboardUtils.IsKeyPressed (Keys.S)) {
                var stats = (IStatistics)Game.Services.GetService (typeof(IStatistics));
                stats.Dump ();
            }

            var director = (IDirector)Game.Services.GetService (typeof(IDirector));
            if (m_isLevelCompleted) {
                gameState.NextLevel ();
                director.ActivateScene ("inter");
                return;
            }

            var mapGrid = world.GetLevel(gameState.Level);
            var mapPos = player.Get<Position>().MapPos;

            if (player.Get<State<PlayerState>>().EState == PlayerState.Idle) {

                if (mapPos.X < m_toMove.X && mapGrid.GetID (mapPos.X + 1, mapPos.Y) != MapGridTypes.ID.Blocked)
                    mapPos.X++;
                if (mapPos.X > m_toMove.X && mapGrid.GetID (mapPos.X - 1, mapPos.Y) != MapGridTypes.ID.Blocked)
                    mapPos.X--;
                if (mapPos.Y < m_toMove.Y && mapGrid.GetID (mapPos.X, mapPos.Y + 1) != MapGridTypes.ID.Blocked)
                    mapPos.Y++;
                if (mapPos.Y > m_toMove.Y && mapGrid.GetID (mapPos.X, mapPos.Y - 1) != MapGridTypes.ID.Blocked)
                    mapPos.Y--;

                if (mapGrid.GetID (mapPos.X, mapPos.Y) != MapGridTypes.ID.Blocked && mapPos != player.Get<Position> ().MapPos) {
                    var seq = new Sequence ();
                    seq.Add (new MoveSpriteTo (player, new Vector2 (mapPos.X * Globals.CELL_WIDTH, mapPos.Y * Globals.CELL_HEIGHT), player.Get<MoveSpeed>().Speed));
                    seq.Add (new ActionEntity (player, (_) => {
                        player.Get<Position> ().MapPos = mapPos;
                    }));
                    seq.Add (new ActionEntity (player, OnEndMove));

                    player.Get<Execute> ().AddNew (seq, "movement");
                    player.Get<State<PlayerState>> ().EState = PlayerState.Moving;
                }
            }
        }
Exemple #5
0
        private void OnAction(Point clickPos, Entity _)
        {
            var world = (IWorld)Game.Services.GetService (typeof(IWorld));
            var gameState = (IGameState)Game.Services.GetService (typeof(IGameState));
            var mapGrid = world.GetLevel(gameState.Level);

            var actionPos = mapGrid.ScreenToWorld (clickPos.X, clickPos.Y);
            var player = GetEntityByTag("player");
            var mapPos = player.Get<Position>().MapPos;

            var actionPosID = mapGrid.GetID (actionPos.X, actionPos.Y);
            var playerPosID = mapGrid.GetID (mapPos.X, mapPos.Y);
            var state = player.Get<State<PlayerState>> ().EState;

            if (state != PlayerState.Idle ||
                actionPosID == MapGridTypes.ID.Blocked ||
                actionPosID != playerPosID ||
                actionPos == mapPos)
                return;

            var effects = (EffectsLayer)Scene.GetLayer ("effects");
            var items = (ItemsLayer)Scene.GetLayer ("items");
            var monsters = (MonstersLayer)Scene.GetLayer ("monsters");

            float distMult = player.Get<AttackDistanceMultiplier> ().Multiplier;

            if (Utils.Dist(mapPos, actionPos) <= (int)(player.Get<Attack>().Distance * distMult)) {
                var mapLine = mapGrid.GetLine (mapPos, actionPos);
                if (mapLine.Any() && !mapLine.Any (e => e.Type == MapGridTypes.ID.Blocked)) {
                    var seq = new Sequence ();
                    int weaponId = player.Get<Attack> ().ArchetypeID;
                    string weaponSpriteName = string.Format ("weapon_{0:D2}", Archetypes.Weapons [weaponId] ["sprite_index"]);
                    effects.SpawnEffect (actionPos, weaponSpriteName, player.Get<AttackSpeed> ().Speed);

                    var actionTargets = items.GetAllEntities ().Where (e => e.Has<Position> ()).ToList ();
                    actionTargets.AddRange (monsters.GetAllEntities ().Where (e => e.Has<Position> ()));
                    var target = actionTargets.FirstOrDefault (m => m.Get<Position> ().MapPos == actionPos);
                    if (target != default(Entity)) {
                        if (target.Has<IFFSystem> ()) {
                            if (player.Get<IFFSystem> ().IsFoe (target)) {
                                seq.Add (new AttackEntity (player, target));
                            }
                        }
                    }
                    seq.Add (new Delay (player.Get<AttackSpeed> ().Speed));
                    seq.Add (new ActionEntity (player, StartIdle));
                    player.Get<Execute> ().Add (seq, "attack");
                    player.Get<State<PlayerState>> ().EState = PlayerState.Attacking;
                }
            }
        }
Exemple #6
0
        void DoPatrol(Entity monster, IEnumerable<Entity> targets)
        {
            var world = (IWorld)Game.Services.GetService (typeof(IWorld));
            var gameState = (IGameState)Game.Services.GetService (typeof(IGameState));
            var map = world.GetLevel(gameState.Level);

            var foes = new List<Entity> ();
            if (monster.Has<IFFSystem> ())
                foes = monster.Get<IFFSystem> ().GetFoes (targets).ToList();

            var newPos = monster.Get<Position> ().MapPos;
            if (monster.Get<LookDirection> ().Direction == Utils.Direction.Down)
                newPos.Y++;
            else if (monster.Get<LookDirection> ().Direction == Utils.Direction.Up)
                newPos.Y--;
            else if (monster.Get<LookDirection> ().Direction == Utils.Direction.Right)
                newPos.X++;
            else if (monster.Get<LookDirection> ().Direction == Utils.Direction.Left)
                newPos.X--;

            if (map.GetID (newPos.X, newPos.Y) != monster.Get<AllowedMapArea>().Area) {
                monster.Get<Patrol> ().Steps = 0;
                monster.Get<Execute> ().Add (new ActionEntity (monster, (_) => {
                    StartPatrol (monster);
                }), "patrol_loop");
            } else {
                var foe = foes.FirstOrDefault (e => e.Get<Position> ().MapPos == newPos);
                if (foe != null) {
                    var seq = new Sequence ();
                    seq.Add (new Delay (Utils.ThrowDice(monster.Get<AttackSpeed>().Speed)));
                    seq.Add (new AttackEntity (monster, foe));
                    seq.Add (new TryPoisonEntity (monster, foe));
                    seq.Add (new Delay (monster.Get<AttackSpeed>().Speed));
                    seq.Add (new ActionEntity (monster, (_) => {
                        StartPatrol (monster);
                    }));
                    monster.Get<Execute> ().Add (seq, "patrol_loop");
                } else {
                    var seq = new Sequence ();
                    seq.Add (new MoveSpriteTo (monster, new Vector2 (newPos.X * Globals.CELL_WIDTH, newPos.Y * Globals.CELL_HEIGHT), monster.Get<MoveSpeed> ().Speed));
                    seq.Add (new ActionEntity (monster, (_) => {
                        monster.Get<Position> ().MapPos = newPos;
                    }));
                    seq.Add (new ActionEntity (monster, (_) => {
                        monster.Get<Patrol> ().Steps--;
                    }));
                    seq.Add (new ActionEntity (monster, (_) => {
                        StartPatrol (monster);
                    }));
                    monster.Get<Execute> ().Add (seq, "patrol_loop");
                }
            }
        }
Exemple #7
0
        public void DropLoot(Point pos, Dictionary<string, int>[] loots, int maxWeight)
        {
            var sprites = (ISpriteSheets)Game.Services.GetService (typeof(ISpriteSheets));

            loots.Shuffle ();

            foreach (var arch in loots) {
                var w = Utils.ThrowDice (maxWeight);
                var lootType = (LootTypes)arch ["loot_type"];

                if (arch ["spawn_weight"] >= w && arch["spawn_weight"] <= maxWeight) {
                    var ent = CreateEntity ();
                    ent.Register (new Drawable (new Vector2 (pos.X * Globals.CELL_WIDTH, pos.Y * Globals.CELL_HEIGHT)));
                    ent.Register (new Position (pos.X, pos.Y));
                    ent.Register (new PointLight (PointLight.DistanceType.Small, Color.Gold));
                    ent.Register (new State<LootTypes> (lootType));
                    ent.Register (new Execute ());

                    var seq = new Sequence ();
                    seq.Add (new Delay (arch ["lifetime_sec"] * 1000));
                    seq.Add (new ActionEntity (ent, (_) => {
                        var blink = new Loop(new ActionEntity(ent, (__) => {
                            if (ent.Get<Drawable>().DrawAlpha == 0.0f) {
                                ent.Get<Drawable>().DrawAlpha = 1.0f;
                            } else {
                                ent.Get<Drawable>().DrawAlpha = 0.0f;
                            }
                        }), 250);
                        ent.Get<Execute>().Add(blink, "blink_loop");
                    }));
                    seq.Add (new Delay (arch ["lifetime_sec"] * 500));
                    seq.Add (new ActionEntity (ent, (_) => {
                        RemoveEntityByTag(ent.Tag);
                    }));
                    ent.Get<Execute> ().Add (seq, "lifetime");

                    if (lootType == LootTypes.Money) {
                        ent.Register (new Sprite (sprites.GetSprite ("money_01")));
                        ent.Register (new Triggerable ((from) => OnMoneyTriggered (ent, from)));
                        ent.Register (new Loot (arch["money"]));
                    } else if (lootType == LootTypes.Health) {
                        ent.Register (new Sprite (sprites.GetSprite ("health_potion_01")));
                        ent.Register (new Triggerable ((from) => OnHealthTriggered (ent, from)));
                        ent.Register (new Loot (arch ["health"]));
                    } else if (lootType == LootTypes.Armor) {
                        var armorSprite = string.Format ("armor_{0:D2}", Archetypes.Armors [arch ["armor_index"]] ["sprite_index"]);
                        ent.Register (new Sprite (sprites.GetSprite (armorSprite)));
                        ent.Register (new Triggerable ((from) => OnArmorTriggered (ent, from)));
                        ent.Register (new Loot (arch ["armor_index"]));
                        ent.Register (new Price (arch ["price"]));
                    } else if (lootType == LootTypes.Weapon) {
                        var weaponSprite = string.Format ("weapon_{0:D2}", Archetypes.Weapons [arch ["weapon_index"]] ["sprite_index"]);
                        ent.Register (new Sprite (sprites.GetSprite (weaponSprite)));
                        ent.Register (new Triggerable ((from) => OnWeaponTriggered (ent, from)));
                        ent.Register (new Loot (arch ["weapon_index"]));
                        ent.Register (new Price (arch ["price"]));
                    } else {
                        ent.Register (new Sprite (sprites.GetSprite ("antitod_potion_01")));
                        ent.Register (new Triggerable ((from) => OnAntitodTriggered (ent, from)));
                    }
                    break;
                }
            }
        }
Exemple #8
0
        public override void OnActivated()
        {
            var gameState = (IGameState)Game.Services.GetService (typeof(IGameState));

            var spawner = CreateEntity ();
            int spawnDelay = Globals.TRASH_SPAWN_DELAY_MSEC [gameState.Level];
            spawner.Register (new Execute ());
            spawner.Get<Execute> ().Add (new Loop (new ActionEntity (spawner, SpawnTrash), spawnDelay));

            spawner = CreateEntity ();
            spawnDelay = Globals.CHEST_SPAWN_DELAY_SEC [gameState.Level] * 1000;
            spawner.Register (new Execute ());

            var seq = new Sequence ();
            seq.Add (new ActionEntity (spawner, SpawnChest));
            seq.Add (new Loop (new ActionEntity (spawner, SpawnChest), spawnDelay));
            spawner.Get<Execute> ().Add (seq);
        }