示例#1
0
        public Game(Context ctx)
        {
            this.ctx = ctx;

            state = GameState.UNDEFINED;

            systems = new GameSystems();
            systems.Add(new AnimSystem());
            systems.Add(new MovementSystem());
            systems.Add(new MapSystem(ctx.config.Get <MapSystemConfig>()));
            systems.Add(new CameraSystem());
            systems.Add(new EntitySystem());

            systems.Init(systems, ctx);

            ActionSystem actionSys = new ActionSystem(assemblyNames: "Game");

            actionSys.OnActionSystemRegistered += iActionSystem => {
                if (iActionSystem is IGameSystem gs)
                {
                    gs.Init(systems, ctx);
                }
            };
            actionSys.RegisterSystems();

            MapSystem mapSystem = systems.Get <MapSystem>();

            mapSystem.Load(new[] {
                0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
                0x1, 0xB, 0xB, 0xB, 0xB, 0x1000A, 0xB, 0xB, 0xB, 0x1, 0x1, 0x1,
                0x1, 0xB, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xB, 0x1, 0x1, 0x1,
                0x1, 0xB, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xB, 0x1, 0x1, 0x1,
                0x1, 0xB, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xB, 0x1, 0x1, 0x1,
                0x1, 0xB, 0xB, 0xB, 0xB, 0xB, 0xB, 0xB, 0xB, 0x1, 0x1, 0x1,
                0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
                0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
            }, 12, "Entrance");

            player = systems.Get <EntitySystem>().CreatePlayer("Player");
            int spawnpoint = mapSystem.Map.Spawnpoint;

            player.SetLocalPosition(mapSystem.Map.IndexToWorldPos(spawnpoint));

            ctx.eventPump.Dispatch();
            // systems.Get<CameraSystem>().SetTarget(player.transform);
        }
示例#2
0
        public void Update(float dt)
        {
            switch (state)
            {
            case GameState.UNDEFINED:
                state = GameState.AWAITING_PLAYER_INPUT;
                break;

            case GameState.AWAITING_PLAYER_INPUT:
                InputState inputState = GetInputState();
                UpdateSelection(inputState.mousePos);
                if (!GetInputCmd(inputState, out inputCmd))
                {
                    break;
                }
                state = GameState.RESOLVE_PLAYER_ACTIONS;
                break;

            case GameState.RESOLVE_PLAYER_ACTIONS:
                switch (inputCmd)
                {
                case InputCommand.WALK:
                    // systems.Get<MovementSystem>().Move(player,
                    //                                    );
                    break;

                case InputCommand.INTERACT:
                    // resolve actions -> new animations
                    break;
                }
                // if left click mouse => walk
                // if left click mouse + shift => sneak
                // if right click mouse => resolve equipped actions with target item
                // get spent energy from energy system
                // make energy available for npcs
                // run npc ai => decide what to do, resolve actions
                // start animations
                // Verbs.Main(this, player, PositionSystem.Get("Selection"));

                inputCmd = InputCommand.UNDEFINED; // consume the command
                state    = GameState.RESOLVE_NPC_ACTIONS;
                break;

            case GameState.RESOLVE_NPC_ACTIONS:
                // update npc ai
                // resolve actions -> new animations
                state = GameState.WILL_UPDATE_SYSTEMS;
                break;

            case GameState.WILL_UPDATE_SYSTEMS:
                ctx.eventPump.Dispatch();
                systems.Get <AnimSystem>().Run();
                state = GameState.UPDATE_SYSTEMS;
                break;

            case GameState.UPDATE_SYSTEMS:
                if (systems.Get <AnimSystem>().IsRunning)
                {
                    // update sight system
                    // update audio system
                    // update position system
                    break;
                }
                state = GameState.AWAITING_PLAYER_INPUT;
                break;
            }
        }