Пример #1
0
        public World(ContentManager Content, Game1 game, Player player, string filename)
        {
            this.game    = game;
            this.Content = Content;
            this.scripts = new Queue <ScriptChain>();
            this.ui      = new UiSystem(Content);

            lua = new Lua();
            lua.LoadCLRPackage();

            this.player = player;
            this.player.setWorld(this);

            lua["l"]      = new LuaAPI(game, this, ui, this.player, Content);
            lua["player"] = this.player;
            lua.DoString(@"
                import ('Lakeside2', 'Lakeside2')
                import ('Lakeside2', 'Lakeside2.UI')
                import ('Lakeside2', 'Lakeside2.Scripting')");

            camera = new TilemapCamera(null);
            TileMap map;

            if (filename == null)
            {
                map = new TileMap(Content, 20, 10);
            }
            else
            {
                map = SerializableMap.Load(Content, filename);
            }
            setMap(map);
            camera.setCenteringEntity(this.player);
        }
Пример #2
0
        public void onInput(InputHandler input)
        {
            // normal game controls
            if (!editing)
            {
                bool interacting = ui.onInput(input);
                if (!interacting && scripts.Count == 0)
                {
                    player.onInput(input);

                    if (input.isCommandPressed(Bindings.Start))
                    {
                        ui.pushElement(new UiPauseMenu(game, Content, player, map.filename, false),
                                       new Vector2(Tile.TILE_SIZE, Tile.TILE_SIZE));
                    }
                }
            }
            else
            {
                editor.onInput(input);
            }

            // enter/exit editing mode
            if (input.isKeyPressed(Keys.F1))
            {
                editing = !editing;
                if (editing)
                {
                    editor = new WorldEditor(Content, this);
                }
                else
                {
                    editor = null;
                    camera.setCenteringEntity(player); // editing mode stole this
                    resetEntities();                   // reload entities for ones created in the editor
                }
            }
        }