예제 #1
0
        public static void init(StaticGod god)
        {
            string initialStage = Content.Stages.@Static;

            god.ctrlCx = ControlContext.create(new VInput());
            RlSceneSetup.loadTiledMap(god, initialStage);
            setup(god);

            RlHooks.afterInit(god);
        }
예제 #2
0
파일: RlScene.cs 프로젝트: toyboot4e/Rot
        public override void OnStart()
        {
            base.OnStart();

            this.god  = new StaticGod();
            god.scene = this;
            RlSceneSetup.init(god);

#if DEBUG
            RlInspectorSpawn.spawn(god);
#endif
        }
예제 #3
0
        /// <summary> Loads a tiled map and updates contexts dependent on it </summary>
        public static void loadTiledMap(StaticGod god, string path)
        {
            // dispose all the entities except the player
            if (god.gameCx != null)
            {
                for (int i = 0; i < god.gameCx.entities.Count; i++)
                {
                    var e = god.gameCx.entities[i];
                    if (e == null)
                    {
                        Nez.Debug.Log("Null found as an entity in the roguelike world when clearing it");
                        god.gameCx.entities.RemoveAt(i);
                        continue;
                    }
                    if (e.has <Player>())
                    {
                        continue;
                    }
                    god.gameCx.entities.RemoveAt(i);
                    i--;
                    e.Destroy();
                }
            }

            // dispose the previous tiled map if there is one
            var tiledEntity = god.scene.FindEntity(EntityNames.tiled);

            if (tiledEntity == null)
            {
                tiledEntity = god.scene.CreateEntity(EntityNames.tiled);
            }
            else
            {
                tiledEntity.rm <TiledMapRenderer>();
            }

            { // load tiled map & update contexts
                god.tiled = god.scene.Content.LoadTiledMap(path);

                var tiledComp = tiledEntity
                                // .add(new TiledMapRenderer(tiled, collisionLayerName: "collision"))
                                .add(new TiledMapRenderer(god.tiled))
                                .zCx(layer: Layers.Stage, depth: Depths.Stage);

                // restore all contexts
                god.posUtil   = new PosUtil(god.tiled, god.scene.Camera);
                god.gameCx    = new RlGameContext(new TiledRlStage(god.tiled), new RotEntityList());
                god.gameState = new RlGameState(god.gameCx.evHub, god.gameCx.entities as iRlActorIterator);
                god.rules?.replCtx(god.gameCx);
                god.view?.replCtx(god.gameCx, god.posUtil);
            }

            // FIXME: player is always created when loading a map
            var player = EntityFactory.genPlayer(god.scene, god.gameCx.stage as TiledRlStage, god.posUtil, god.tiled).entity;

            player.SetParent(tiledEntity);
            god.gameCx.entities.Add(player);
            setupFollowCamera(god.scene, player, god.tiled);

            RlSceneSetup.centeriszeTiledIfNeeded(god.tiled, tiledEntity);
            RlHooks.afterLoadingMap(god);
        }