Exemple #1
0
        public static void afterLoadingMap(StaticGod god)
        {
            // ##### TEST ######
            var player = god.scene.FindEntity(EntityNames.player);
            var tiled  = god.tiled;
            var actors = tiled.GetObjectGroup("actors");

            if (actors == null)
            {
                return;
            }

            var actor       = actors.Objects[0];
            var pos         = actor.tilePos(tiled);
            var actorEntity = god.scene.CreateEntity("script-test");

            actorEntity.SetParent(god.scene.FindEntity(EntityNames.tiled));
            var factory = EntityFactory
                          .begin(actorEntity, god.posUtil)
                          .body(pos, Dir9.S, true, true)
                          .viewWodi8(Content.Chips.Wodi8.Cook_a)
                          .script(RlHooks.testScript(player, actorEntity, "aaaaa\nbbbb\ncccccc\nddddddddddddd:"));

            god.gameCx.entities.Add(actorEntity);
        }
Exemple #2
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);
        }
Exemple #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);
        }