Exemplo n.º 1
0
        private bool running; // player running en-/disabled

        /// Handling user input, e.g. moving player, interacting
        /// with objects or opening menus (moving through menus
        /// is handled internally by the GSMXtended lib) (TODO)
        public override void HandleInput(InputState inputState)
        {
            base.HandleInput(inputState);
            GameConfig config = GameManager.Configuration;
            Besmash    game   = (Besmash)ScreenManager.Game;
            TileMap    map    = GameManager.ActiveSave.ActiveMap;
            Team       team   = GameManager.ActiveSave.Team;

            if (game.isActionTriggered("game", "menu"))
            {
                ScreenManager.AddScreen(new GameMenuScreen(this), null);
            }

            if (map.Slave != null)
            {
                bool inFight = map.State == TileMap.MapState.Fighting;

                if (!inFight)
                {
                    if (!running && team.Leader.AP >= 50 && game.isActionTriggered("game", "cancel", true))
                    {
                        running = true;
                        team.Player.ForEach(p => p.StepTimeMultiplier = 0.7f);
                    }
                }
                else
                {
                    running = false;
                }

                if (running && !game.isActionTriggered("game", "cancel", true) || team.Leader.AP == 0)
                {
                    running = false;
                    team.Player.ForEach(p => p.StepTimeMultiplier = 1);
                }

                if (game.isActionTriggered("game", "move_up", true))
                {
                    if (map.Slave.move(0, -1) && !inFight)
                    {
                        team.Player.ForEach(
                            p => p.AP = Math.Max(0, Math.Min(
                                                     p.MaxAP, p.AP + (running ? -10 : 10))));
                    }
                }

                if (game.isActionTriggered("game", "move_right", true))
                {
                    if (map.Slave.move(1, 0) && !inFight)
                    {
                        team.Player.ForEach(
                            p => p.AP = Math.Max(0, Math.Min(
                                                     p.MaxAP, p.AP + (running ? -10 : 10))));
                    }
                }

                if (game.isActionTriggered("game", "move_down", true))
                {
                    if (map.Slave.move(0, 1) && !inFight)
                    {
                        team.Player.ForEach(
                            p => p.AP = Math.Max(0, Math.Min(
                                                     p.MaxAP, p.AP + (running ? -10 : 10))));
                    }
                }

                if (game.isActionTriggered("game", "move_left", true))
                {
                    if (map.Slave.move(-1, 0) && !inFight)
                    {
                        team.Player.ForEach(
                            p => p.AP = Math.Max(0, Math.Min(
                                                     p.MaxAP, p.AP + (running ? -10 : 10))));
                    }
                }

                int x = map.Slave.Facing == Facing.East ? 1 :
                        map.Slave.Facing == Facing.West ? -1 : 0;

                int y = map.Slave.Facing == Facing.South ? 1 :
                        map.Slave.Facing == Facing.North ? -1 : 0;

                if (game.isActionTriggered("game", "interact"))
                {
                    map.getTiles(
                        (int)map.Slave.Position.X + x,
                        (int)map.Slave.Position.Y + y
                        ).ForEach(tile
                                  => tile.trigger(map.Slave));
                }

                if (game.isActionTriggered("game", "inspect"))
                {
                    // TODO
                }
            }

            // debug action: toggle debug pane
            if (game.isActionTriggered("debug", "action0"))
            {
                debugPane.toggle();
            }

            // debug action: give exp to (and level up) team leader
            if (game.isActionTriggered("debug", "action1"))
            {
                GameManager.ActiveSave.Team.Leader.Exp += 150;
                GameManager.ActiveSave.Team.Leader.levelUp();
            }

            // debug action: give exp to (and level up) first team member
            if (game.isActionTriggered("debug", "action2"))
            {
                GameManager.ActiveSave.Team.Members[0].Exp += 150;
                GameManager.ActiveSave.Team.Members[0].levelUp();
            }

            // debug action: teach ability to map slave
            if (game.isActionTriggered("debug", "action3"))
            {
                Player player = GameManager.ActiveSave.Team.Leader;
                if (player.Abilities.Where(a => a.Title == "Double Strike").Count() == 0)
                {
                    player.addAbility(
                        "objects/battle/abilities/double_strike",
                        GameManager.ActiveSave.ActiveMap.Content);
                }
            }

            // debug action: use first ability of map slave
            if (game.isActionTriggered("debug", "action4"))
            {
                GameManager.ActiveSave.Team.Leader
                .Abilities.Where(a => a.Title == "Double Strike")
                .ToList().ForEach(a => a.execute());
            }

            // debug action: applay ability effects attached to creatures
            if (game.isActionTriggered("debug", "action5"))
            {
                map.Entities.Where(e => e is Creature).Cast <Creature>()
                .Where(c => c.Effects.Count > 0).ToList()
                .ForEach(c => c.applyEffects());
            }

            // debug action: kill all enemies on map
            if (game.isActionTriggered("debug", "action6"))
            {
                map.Entities.Where(e => e is Enemy)
                .Cast <Enemy>().ToList()
                .ForEach(e => e.die());
            }

            // debug action: spawn entities
            if (game.isActionTriggered("debug", "action7"))
            {
                map.spawnEntities();
            }

            // debug action: 'kill' all enemies participating the battle
            if (game.isActionTriggered("debug", "action8"))
            {
                map.BattleMap.Participants
                .Where(e => e is Enemy).Cast <Enemy>()
                .ToList().ForEach(e => e.die());
            }

            // debug action: toggle battle overlay
            if (game.isActionTriggered("debug", "action9"))
            {
                if (map.State == TileMap.MapState.Fighting)
                {
                    GameManager.ActiveSave.ActiveMap
                    .setRoamingState();
                }
                else
                {
                    GameManager.ActiveSave.ActiveMap
                    .setFightingState(GameManager.ActiveSave.Team.Leader.Target);
                }
            }
        }
Exemplo n.º 2
0
        /// Loads the passed mapFile and sets it as active map
        public void load(Besmash game, string mapFile)
        {
            if (Content == null)
            {
                Content = new ContentManager(
                    game.Content.ServiceProvider,
                    game.Content.RootDirectory);
            }

            ContentManager mapContent = new ContentManager(
                Content.ServiceProvider,
                Content.RootDirectory
                );


            bool newGame;

            if ((newGame = Team == null))
            {
                Team = new Team(
                    (mapContent.Load <Player>("objects/world/entities/player/grey").clone() as Player),
                    (mapContent.Load <Player>("objects/world/entities/player/pink").clone() as Player)
                    );

                Team.Formation.Add(Team.Members[0], new Point(0, 1));
            }

            TileMap prevMap = ActiveMap;

            ActiveMap = Content.Load <TileMap>(mapFile);
            if (!ActiveMap.Initialized)
            {
                ActiveMap.init(game);
            }

            ActiveMap.onLoad(prevMap, Team);
            if (prevMap != null)
            {
                prevMap.unload();                 // TODO test!
            }
            ActiveMap.load(mapContent);
            ActiveMap.spawnEntities();
            LastMap = mapFile;
            Game    = game;

            // TODO testcode (battle start)
            ActiveMap.Entities.Where(e => e is Creature)
            .Cast <Creature>().ToList().ForEach(c => {
                if (c is Enemy)
                {
                    (c as Enemy)
                    .PlayerInRangeEvent += onPlayerInEnemyRange;
                }
            });

            if (newGame)
            {
                int i;
                Team.Player.ForEach(pl => {
                    for (i = 0; i < 3; ++i)  // TODO init level
                    {
                        pl.Exp = pl.MaxExp;
                        pl.levelUp();
                    }

                    pl.HP = pl.MaxHP;
                    pl.AP = pl.MaxAP;
                });
            }
        }
Exemplo n.º 3
0
 static void Main()
 {
     using (var game = new Besmash())
         game.Run();
 }
Exemplo n.º 4
0
 /// Loads the last map (or DEFAULT_MAP if none)
 /// and sets it as active map
 public void load(Besmash game)
 {
     load(game, LastMap);
 }