Пример #1
0
    private void LoadCurrentTilemap()
    {
        var selectedIdx = _optionButton.Selected;

        if (selectedIdx == -1)
        {
            return;
        }

        var tileMap = _levels[_optionButton.Selected];

        if (_tileWorld != null)
        {
            RemoveChild(_tileWorld);
            _tileWorld.QueueFree();
        }

        _tileWorld = new TileWorld
        {
            TileMap     = tileMap,
            GameSpeed   = GameSpeed,
            StartPaused = StartPaused
        };
        AddChild(_tileWorld);
    }
    private void DestroyTiles(fix2 position, fix radius)
    {
        TileWorld         tileWorld = CommonReads.GetTileWorld(Accessor);
        NativeList <int2> tiles     = new NativeList <int2>(Allocator.Temp);

        var transformTileRequests = GetSingletonBuffer <SystemRequestTransformTile>();

        Job.WithCode(() =>
        {
            TilePhysics.GetAllTilesWithin(position, radius, tiles);

            for (int i = 0; i < tiles.Length; i++)
            {
                Entity tileEntity           = tileWorld.GetEntity(tiles[i]);
                TileFlagComponent tileFlags = tileWorld.GetFlags(tileEntity);

                if (!tileFlags.IsOutOfGrid && tileFlags.IsDestructible)
                {
                    // remove ladder and terrain flags
                    tileFlags.Value &= ~(TileFlags.Ladder | TileFlags.Terrain);
                    transformTileRequests.Add(new SystemRequestTransformTile()
                    {
                        Tile         = tiles[i],
                        NewTileFlags = tileFlags
                    });
                }
            }
        }).Run();
    }
Пример #3
0
        public void Draw(TileWorld world)
        {
            Engine.GraphicsDevice.Clear(ClearColor);

            //sorting out jerks
            /*camDiff = transform.Position - camDiffLast;
            camDiffLast = transform.Position;
            accum += camDiff.X;
            ++num;
            if(Math.Abs(accum/num - camDiff.X) > accum/num * 0.3)
                Console.WriteLine(world.gt + " " + world.gts + " " + camDiff.X);*/

            DrawWorld(world);
            SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null,
                (1 == 0) ? Matrix.Identity : transform.TransformMatrix);
            foreach (RenderableComponent c in renderables)
            {
                switch(c.Type)
                {
                    case "Sprite":
                        Sprite sprite = ((SpriteComponent)c).Sprite;
                        SpriteBatch.Draw(sprite.Texture, world.WorldToPixelCoordinates(c.Owner.Position), sprite.CurrentTextureFrame, sprite.Tint);
                        break;
                }

            }
            SpriteBatch.End();
            renderables.Clear();
            renderAlreadyProcessed = false;
        }
Пример #4
0
 public WorldUpdateInterface(TileWorld world, IFeatureResolver biome, IFeatureResolver landform, BetterTileMap biomeTileMap, BetterTileMap landformTileMap) : base(world)
 {
     _biomeResolver    = biome;
     _landformResolver = landform;
     _biomeTileMap     = biomeTileMap;
     _landformTileMap  = landformTileMap;
 }
Пример #5
0
 public WorldState()
 {
     VriskaEngine.RenderSystem.CurrentResolution = RenderSubsystem.Resolutions["800x600"];
     VriskaEngine.ClearColor = Color.Black;
     World = new TileWorld();
     World.AddEntity(Entities.Title, new Vector2(-2, 0));
     World.AddEntity(Entities.PonySprite, new Vector2(0, 0));
 }
Пример #6
0
    static StartUp()
    {
        GameEnv = new GameEnv();
        GameEnv.Init();
        GameEnv.Load();


        World = new TileWorld(GameEnv.FeatureWorld, 7, 5);
        GameEnv.WFeatureDesert.AddFeature(World[1, 1]);
        Debug.Log($"DataRepresentation of Landform {GameEnv.WFeatureFlatland.DataRepresentation} {GameEnv.WFeatureHills.DataRepresentation} {GameEnv.WFeatureMountains.DataRepresentation} {GameEnv.WFeatureHighMountains.DataRepresentation} bits={GameEnv.WFeatureLandform.DataIdentifier.Bits}");
    }
Пример #7
0
 public Zone(TileWorld world)
 {
     tileMap = new Tile[TileWorld.ZoneSize, TileWorld.ZoneSize];
     for (int y = 0; y < tileMap.GetLength(0); ++y)
     {
         for (int x = 0; x < tileMap.GetLength(1); ++x)
         {
             tileMap[y, x] = new Tile(world);
         }
     }
 }
    public static bool SetTile(TileWorld World, Tile tile, Vector2 Pos)
    {
        TileChunk chunk = World.GetChunk(Mathf.RoundToInt(Pos.x), Mathf.RoundToInt(Pos.y));
        if (chunk == null)
            return false;

        TileWorldPos pos = GetTilePos(Pos);

        chunk.World.SetTile(pos.x, pos.y, tile);

        return true;
    }
Пример #9
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        TileWorld script = (TileWorld)target;

        if (GUILayout.Button("Rebuild Tile Set"))
        {
            script.Build();
        }
        if (GUILayout.Button("Validate Map"))
        {
            script.ValidateTiles();
        }
    }
Пример #10
0
        public static IView CreateView(IConsole console)
        {
            var root = new RootKey("root");

            YieldManager ym = new YieldManagerImpl(new Key(root, "yield"));
            var          fw = new FeatureWorld(1, ym);

            fw.Lock();

            var world = new TileWorld(fw, 50, 50, WorldMode.Master);
            var view  = new WorldView(console, world);

            view.Renderers.Add(new TestCRenderer());
            return(view);
        }
Пример #11
0
    public static bool SetTile(TileWorld World, Tile tile, Vector2 Pos)
    {
        TileChunk chunk = World.GetChunk(Mathf.RoundToInt(Pos.x), Mathf.RoundToInt(Pos.y));

        if (chunk == null)
        {
            return(false);
        }

        TileWorldPos pos = GetTilePos(Pos);

        chunk.World.SetTile(pos.x, pos.y, tile);

        return(true);
    }
    public void GenerateCaves(TileWorld world)
    {
        map = tileCaveGen.GenerateMap(TileWorld.WorldSizeInPixelsX, TileWorld.WorldSizeInPixelsY);

        for (int xi = 0; xi < TileWorld.WorldSizeInPixelsX; xi++)
        {
            for (int yi = 0; yi < TileWorld.WorldSizeInPixelsY; yi++)
            {
                if (map[xi, yi] != 1)
                {
                    if (world.GetTile((-TileWorld.WorldX * 16 + xi) + 1, -TileWorld.WorldY * 16 + yi).Type != Tile.TileType.Dirt)
                    {
                        world.SetTile(-TileWorld.WorldX * 16 + xi, -TileWorld.WorldY * 16 + yi, new TileAir());
                    }
                }
            }
        }
    }
    public void GenerateCaves(TileWorld world)
    {
        map = tileCaveGen.GenerateMap(TileWorld.WorldSizeInPixelsX, TileWorld.WorldSizeInPixelsY);

        for (int xi = 0; xi < TileWorld.WorldSizeInPixelsX; xi++)
        {
            for (int yi = 0; yi < TileWorld.WorldSizeInPixelsY; yi++)
            {
                if (map[xi, yi] != 1)
                {
                    if (world.GetTile((-TileWorld.WorldX * 16 + xi) + 1, -TileWorld.WorldY * 16 + yi).Type != Tile.TileType.Dirt)
                    {
                        world.SetTile(-TileWorld.WorldX * 16 + xi, -TileWorld.WorldY * 16 + yi, new TileAir());
                    }
                }
            }
        }
    }
Пример #14
0
    protected override void OnUpdate()
    {
        var       transformTileRequests = GetSingletonBuffer <SystemRequestTransformTile>();
        TileWorld tileWorld             = CommonReads.GetTileWorld(Accessor);

        Entities.ForEach((Entity entity, in DestroyTileOnOverlapTag destroyOnOverlapWithTile, in FixTranslation position) =>
        {
            int2 tile = Helpers.GetTile(position);
            TileFlagComponent tileFlags = tileWorld.GetFlags(tile);

            if (tileFlags.IsDestructible && !tileFlags.IsEmpty)
            {
                transformTileRequests.Add(new SystemRequestTransformTile()
                {
                    NewTileFlags = TileFlagComponent.Empty,
                    Tile         = tile
                });
            }
        }).Run();
Пример #15
0
        private static void Main()
        {
            var env = new GameEnv();

            env.Init();
            env.Load();
            Console.WriteLine("Done");
            new Civilization("Kappaland", env.CivilisationRegister);


            //world creation
            var worldMaster = new TileWorld(env.FeatureWorld, 5, 5, WorldHolder.BaseWorld, WorldMode.Master, env.CivilizationManager, true, true);
            var worldSlave  = new TileWorld(env.FeatureWorld, 5, 5, WorldHolder.BaseWorld, WorldMode.Slave, env.CivilizationManager, true, true);
            var syncer      = new SyncWorldInterface(worldSlave);

            worldMaster.RegisterUpdate(syncer.ScheduleUpdate);

            Console.WriteLine("Test start");
            // ReSharper disable once InconsistentNaming
            var tile3_3M = worldMaster[3, 3];
            var tile3_3S = worldSlave[3, 3];



            Console.WriteLine("Testing sync between master and slave");
            Console.WriteLine(env.WFeatureBiome.GetFeature(tile3_3M).Name);
            env.WFeatureDesert.AddFeature(tile3_3M);
            Console.WriteLine(env.WFeatureBiome.GetFeature(tile3_3M).Name);
            Console.WriteLine(env.WFeatureBiome.GetFeature(tile3_3S).Name);
            env.WFeatureHighMountains.AddFeature(tile3_3M);
            Console.WriteLine(env.WFeatureLandform.GetFeature(tile3_3M).Name);
            Console.WriteLine(env.WFeatureLandform.GetFeature(tile3_3S).Name);


            Console.WriteLine("Testing changestate");
            var worldState = new RectChangeState(worldMaster, new Rect(0, 0, 1, 1), env.WFeatureBiome);

            var tile0_0M = worldMaster[0, 0];
            var tile0_0C = worldState[0, 0];
            var tile1_1C = worldState[1, 1];

            env.WFeatureDesert.AddFeature(tile0_0C);
            Console.WriteLine($"Master 0,0: {env.WFeatureBiome.GetFeature(tile0_0M).Name}");
            Console.WriteLine($"Change 0,0: {env.WFeatureBiome.GetFeature(tile0_0C).Name}");
            try {
                env.WFeatureHighMountains.AddFeature(tile0_0C);
                Console.WriteLine("Setting within bound of ChangeState of wrong feature type succeeded, this should not happen");
            } catch (Exception e) {
                Console.WriteLine($"Setting feature not applicable to ChangeState resulted in {e.GetType()}: {e.Message}");
            }
            try {
                env.WFeatureDesert.AddFeature(tile1_1C);
                Console.WriteLine("Setting outside bound of ChangeState succeeded, this should not happen");
            } catch (Exception e) {
                Console.WriteLine($"Setting outside bound of ChangeState resulted in {e.GetType()}: {e.Message}");
            }


            Console.WriteLine("Testing cities");
            var romeM = new City(tile3_3M, "Rome", env.CivilizationRome);

            env.CityManager.AddCity(romeM, true);

            var romeS = env.CityManager.GetCity(tile3_3S);

            Console.WriteLine(romeS.Name);

            romeM.SetName("Neo Roma");
            Console.WriteLine(romeS.Name);
        }
Пример #16
0
 public static bool RaycastTerrain(TileWorld tileWorld, fix2 start, fix2 end, fix bevel, out int2 result)
 {
     return(Raycast(start, end, bevel, new TerrainTilePredicate(tileWorld), out result));
 }
    protected override void OnUpdate()
    {
        TileWorld    tileWorld    = CommonReads.GetTileWorld(Accessor);
        PhysicsWorld physicsWorld = _physicsWorldSystem.PhysicsWorld;

        Entities
        .WithReadOnly(tileWorld)
        .WithReadOnly(physicsWorld)
        .ForEach((Entity entity, ref NavAgentFootingState footing, in FixTranslation fixTranslation, in PhysicsColliderBlob colliderRef, in PhysicsVelocity velocity) =>
        {
            if (!colliderRef.Collider.IsCreated)
            {
                return;
            }

            ref Collider collider = ref colliderRef.Collider.Value;
            fix pawnRadius        = (fix)collider.Radius;
            fix pawnFeetXOffset   = pawnRadius * (fix)0.8f;
            fix2 belowLeftFoot    = new fix2(fixTranslation.Value.x - pawnFeetXOffset, fixTranslation.Value.y - pawnRadius - (fix)0.05);
            fix2 belowRightFoot   = new fix2(fixTranslation.Value.x + pawnFeetXOffset, fixTranslation.Value.y - pawnRadius - (fix)0.05);
            fix2 belowLongDick    = new fix2(fixTranslation.Value.x, fixTranslation.Value.y - pawnRadius - (fix)0.05);


            // GOTO Ladder IF on ladder && (already has footing on ladder || already has footing on ground)
            if (tileWorld.GetFlags(Helpers.GetTile(fixTranslation)).IsLadder &&
                (footing.Value == NavAgentFooting.Ladder || footing.Value == NavAgentFooting.Ground))
            {
                footing.Value = NavAgentFooting.Ladder;
            }
            else
            {
                OverlapPointInput detectTerrain = new OverlapPointInput()
                {
                    Filter = SimulationGameConstants.Physics.CharacterFilter.Data,
                };

                OverlapPointInput detectTerrainLeftFoot  = detectTerrain;
                detectTerrainLeftFoot.Position           = (float2)belowLeftFoot;
                OverlapPointInput detectTerrainLongDick  = detectTerrain;
                detectTerrainLongDick.Position           = (float2)belowLongDick;
                OverlapPointInput detectTerrainRightFoot = detectTerrain;
                detectTerrainRightFoot.Position          = (float2)belowRightFoot;

                // GOTO Ground IF above terrain && (previously grounded || previously ladder || previously airControl and not jumping || velocity is low)
                if ((physicsWorld.OverlapPoint(detectTerrainLeftFoot) || physicsWorld.OverlapPoint(detectTerrainLongDick) || physicsWorld.OverlapPoint(detectTerrainRightFoot)) &&
                    (footing.Value == NavAgentFooting.Ground ||
                     footing.Value == NavAgentFooting.Ladder ||
                     (footing.Value == NavAgentFooting.AirControl && velocity.Linear.y <= (fix)0.5) ||
                     velocity.Linear.lengthSquared < 4))
                {
                    footing.Value = NavAgentFooting.Ground;
                }
                else
                {
                    // GOTO air control IF in mid-air && was not in None
                    if (footing.Value != NavAgentFooting.None)
                    {
                        footing.Value = NavAgentFooting.AirControl;
                    }
                }
            }
        }).Run();
Пример #18
0
 public void DrawWorld(TileWorld world)
 {
     Area a = world.CurrentArea;
     FloatRectangle r = world.WorldCameraBounds();
     SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, null,
             transform.TransformMatrix);
     //Sprite s;
     for (int y = (int)Math.Floor(r.Top); y <= Math.Ceiling(r.Bottom); ++y)
     {
         for (int x = (int)Math.Floor(r.Left); x <= Math.Ceiling(r.Right)+4; ++x)
         {
             Sprite s = a.GetTile(x, y).Sprite;
             SpriteBatch.Draw(s.Texture, world.WorldToPixelCoordinates(new Vector2(x, y)), s.Tint);
         }
     }
     SpriteBatch.End();
 }
 public void ModifyTerrain(TileWorld world)
 {
     GenerateCaves(world);
     GenerateOreVeins(world);
 }
 public void GenerateOreVeins(TileWorld world)
 {
 }
Пример #21
0
 public Tile(TileWorld world)
     : base(-1, world)
 {
     //this.Add(new PositionComponent
 }
Пример #22
0
 public SyncWorldInterface(TileWorld world) : base(world)
 {
 }
Пример #23
0
 protected WorldInterface(TileWorld world)
 {
     World = world;
 }
 public void ModifyTerrain(TileWorld world)
 {
     GenerateCaves(world);
     GenerateOreVeins(world);
 }
Пример #25
0
 public static bool RaycastTerrain(TileWorld tileWorld, fix2 start, fix2 end, fix bevel)
 {
     return(RaycastTerrain(tileWorld, start, end, bevel, out _));
 }
 public void GenerateOreVeins(TileWorld world)
 {
 }
Пример #27
0
 public TerrainTilePredicate(TileWorld tileWorld)
 {
     TileWorld = tileWorld;
 }