Ejemplo n.º 1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            MaxUsers             = 4;
            XGravity             = 0;
            YGravity             = 0;
            AirFriction          = 0.3;
            CollisionPrecision   = 1;
            PossibleInputModules = new List <InputModule>();
            PossibleInputModules.Add(new LeftKeyboardInputModule(this));
            PossibleInputModules.Add(new RightKeyboardInputModule(this));
            PossibleInputModules.Add(new GamepadInputModule(this, PlayerIndex.One));
            PossibleInputModules.Add(new GamepadInputModule(this, PlayerIndex.Two));
            PossibleInputModules.Add(new GamepadInputModule(this, PlayerIndex.Three));
            PossibleInputModules.Add(new GamepadInputModule(this, PlayerIndex.Four));
            PossibleInputs = new List <string>();
            PossibleInputs.Add("jump");
            PossibleInputs.Add("up");
            PossibleInputs.Add("down");
            PossibleInputs.Add("left");
            PossibleInputs.Add("right");
            PossibleInputs.Add("dash");
            PossibleInputs.Add("special");
            UserColorOrder = new List <Color>();
            UserColorOrder.Add(Color.Red);
            UserColorOrder.Add(Color.Blue);
            UserColorOrder.Add(Color.Green);
            UserColorOrder.Add(Color.Yellow);
            UserColorOrder.Add(Color.Purple);
            UserColorOrder.Add(Color.Cyan);
            UserColorOrder.Add(Color.Orange);
            UserColorOrder.Add(Color.White);
            UserColorOrder.Add(Color.Black);
            ListenForUsers = true;
            firstStep      = false;
            Users          = new List <User>();
            Entities       = new List <Entity>();
            Platforms      = new List <Platform>();
            UIElements     = new List <UIElement>();
            //--begin testing purposes--
            //Users.Add(new User(this, 0, new LeftKeyboardInputModule(this)));
            //--end testing purposes--
            CurrentGamemode = Gamemode.LoadFromFile("gamemode_default.lua", this);
            base.Initialize();

            Events.Emit("initialize");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// loads a gamemode from a lua file
        /// </summary>
        /// <param name="filename">the lua file to load the gamemode from</param>
        /// <param name="game">the game</param>
        /// <returns>the created gamemode</returns>
        public static Gamemode LoadFromFile(string filename, SSCGame game)
        {
            Lua state = new Lua();

            state.LoadCLRPackage();
            state.DoFile(filename);
            Gamemode gamemode = new Gamemode();

            state.GetFunction("OnCreation")?.Call(gamemode, game);
            gamemode.OnStart  = state.GetFunction("OnStart");
            gamemode.OnUpdate = state.GetFunction("OnUpdate");
            game.Events.On("update", () =>
            {
                gamemode.OnUpdate?.Call();
            });
            gamemode.OnNewUser = state.GetFunction("OnNewUser");
            return(gamemode);
        }