Example #1
0
    private void RawTeleport(Map map, Vector2Int location, OrthoDir?facing = null)
    {
        if (Avatar == null)
        {
            AddInitialAvatar(map);
        }
        else
        {
            Avatar.transform.SetParent(map.objectLayer.transform, false);
        }
        Avatar.GetComponent <MapEvent>().SetPosition(location);
        if (facing != null)
        {
            Avatar.Chara.Facing = facing.GetValueOrDefault(OrthoDir.North);
        }

        if (ActiveMap != null)
        {
            ActiveMap.OnTeleportAway();
            Destroy(ActiveMap.gameObject);
        }

        ActiveMap = map;
        ActiveMap.OnTeleportTo();
        Global.Instance().Dispatch.Signal(EventTeleport, ActiveMap);
        Avatar.OnTeleport();
    }
Example #2
0
 public AddItem(ActiveMap map, int itemSlot)
 {
     this.itemSlot = itemSlot;
     Item item = map.Items[itemSlot];
     sprite = Data.GameData.ItemDex[item.ItemIndex].Sprite;
     itemLoc = item.ItemLoc;
 }
Example #3
0
        void frame_MouseClick(Element sender, MouseEventArgs e)
        {
            var   player     = (Player)ActiveMap.Player;
            var   mdir       = Vector2.Normalize(e.CurrentPosition - player.Position);
            var   launchPort = player.Position + mdir * (player.Radius + 5); //launch stuff from slightly in front of player
            float launchVel  = 300f + player.Velocity.Length();

            var carrier = new DeviceTransporter(launchPort, 15);

            carrier.Velocity = launchVel * mdir;
            SpawnObject <Actor>(carrier);

            if (e.isClicked(MouseButtons.Left))
            {
                var c = new Charge(50, 15);
                ActiveMap.AddObject(c);
                carrier.AddDevice(c);
            }
            if (e.isClicked(MouseButtons.Right))
            {
                var s = new Sensor(60f);
                ActiveMap.AddObject(s);
                carrier.AddDevice(s);
            }
        }
Example #4
0
    protected void InitializeApple()
    {
        Apple apple = GetApple();

        apple.Move(ActiveMap.RandomFreeNode);
        ActiveMap.AddItem(apple);
    }
Example #5
0
 private void GenerateStartingResources()
 {
     for (var i = 0; i < 100; i++)
     {
         ActiveMap.AddEntity(ResourceMasterList.GetDefaultClone("wood"), new Point(12, 12));
     }
 }
Example #6
0
    /// <summary>
    /// DO NOT USE FOR SIMULATION!!
    /// It's intended use is to render things, like units, above the map, respecting the map height visual.
    /// </summary>
    public static float GetElevationOfPosition(FractionalHex position, ActiveMap customActiveMap = null)
    {
        ActiveMap activeMap;

        if (customActiveMap == null)
        {
            activeMap = MapManager.ActiveMap;
            Debug.Assert(activeMap != null, "The Active Map is null!!!");
        }
        else
        {
            activeMap = customActiveMap;
        }


        Hex            standingHex = position.Round();
        GeographicTile geographicTile;

        if (!activeMap.map.GeographicMapValues.TryGetValue(standingHex, out geographicTile))
        {
            Debug.LogWarning($"There is no map hex on the {position} of the map! returning 0 extra height");
            return(0);
        }
        if (!geographicTile.IsSlope)
        {
            int level = GeographicTile.GetValueOfHeight(geographicTile.heightLevel);
            return(level * activeMap.heightPerElevationUnit);
        }
        var slopeData = geographicTile.slopeData;

        bool isSimpleSlope;
        SimpleSlopeDirection simpleSlopeDirection;
        DoubleSlopeDirection doubleSlopeDirection;

        GetTheDirectionAndTypeOfSlope(slopeData, out isSimpleSlope, out simpleSlopeDirection, out doubleSlopeDirection);


        var positionRelativeToHex = position - (FractionalHex)standingHex;

        if (isSimpleSlope)
        {
            int bottomLevel;
            int upperLevel;
            GetHeightLevels(simpleSlopeDirection, slopeData, out bottomLevel, out upperLevel);
            float lerpFactor = GetInterpolationValue(simpleSlopeDirection, positionRelativeToHex);

            return(Mathf.Lerp((float)bottomLevel, (float)upperLevel, lerpFactor) * activeMap.heightPerElevationUnit);
        }
        else
        {
            int bottomLevel;
            int upperLevel;
            GetHeightLevels(doubleSlopeDirection, slopeData, out bottomLevel, out upperLevel);
            float lerpFactor = GetInterpolationValue(doubleSlopeDirection, positionRelativeToHex);


            return(Mathf.Lerp((float)bottomLevel, (float)upperLevel, lerpFactor) * activeMap.heightPerElevationUnit);
        }
    }
Example #7
0
        public AddItem(ActiveMap map, int itemSlot)
        {
            this.itemSlot = itemSlot;
            Item item = map.Items[itemSlot];

            sprite  = Data.GameData.ItemDex[item.ItemIndex].Sprite;
            itemLoc = item.ItemLoc;
        }
Example #8
0
 public virtual void SpawnObject <T>(T obj)
 {
     ActiveMap.AddObject(obj as WorldObject);
     if (obj is IRigidBody)
     {
         PhysicsManager.ActiveBodies.Add(obj as IRigidBody);
     }
 }
Example #9
0
 public virtual void KillObject <T>(T obj)
 {
     ActiveMap.SafelyRemoveObject(obj as WorldObject);
     if (obj is IRigidBody)
     {
         PhysicsManager.SafeDelete(obj as IRigidBody);
     }
 }
Example #10
0
 public override void Update(GameTime time)
 {
     if (!UIManager.Update(time))
     {
         base.Exit();
     }
     ActiveMap.UpdateDynamicObjects(time);
     PhysicsManager.Update(time.ElapsedGameTime.Milliseconds / 1000f);
 }
Example #11
0
    public void LinePath()
    {
        var geoMap = new Dictionary <Hex, GeographicTile>
        {
            {
                new Hex(0, 0),
                new GeographicTile()
                {
                    heightLevel = MapHeight.l0,
                    walkable    = false
                }
            },
            {
                new Hex(1, -1),
                new GeographicTile()
                {
                    heightLevel = MapHeight.l0,
                    walkable    = true
                }
            },
            {
                new Hex(1, 0),
                new GeographicTile()
                {
                    heightLevel = MapHeight.l0,
                    walkable    = true
                }
            },
            {
                new Hex(0, 1),
                new GeographicTile()
                {
                    heightLevel = MapHeight.l0,
                    walkable    = true
                }
            }
        };
        RuntimeMap map       = new RuntimeMap(geoMap, 100);
        var        layout    = new Layout(Orientation.pointy, new FixVector2(1, 1), new FixVector2(0, 0));
        ActiveMap  activeMap = new ActiveMap(map, layout);

        var simplifiedPath = PathFindingSystem.HexFunnelAlgorithm
                             (
            new List <Hex>()
        {
            new Hex(0, 1),
            new Hex(1, 0),
            new Hex(1, -1)
        }, true, activeMap
                             );


        Assert.AreEqual(2, simplifiedPath.Count);
        Assert.AreEqual(new Hex(1, 0), simplifiedPath[0]);
        Assert.AreEqual(new Hex(1, -1), simplifiedPath[1]);
    }
Example #12
0
        /// Updates this save state and the active map
        public void update(GameTime gameTime)
        {
            string nextMap = ActiveMap.OtherMap;

            if (nextMap != null)
            {
                load(Game, nextMap);
            }
            ActiveMap.update(gameTime);
            Team.update(gameTime);
        }
Example #13
0
    public void Start()
    {
        Global.Instance().Memory.RegisterMemoryPopulater(this);
        DebugMapMarker debugMap = FindObjectOfType <DebugMapMarker>();

        if (debugMap != null)
        {
            ActiveMap = FindObjectOfType <Map>();
            Avatar    = ActiveMap.GetComponentInChildren <AvatarEvent>();
        }
    }
Example #14
0
        public override void Update(Microsoft.Xna.Framework.GameTime time)
        {
            if (!UIManager.Update(time))
            {
                base.Exit();
            }

            ActiveMap.UpdateDynamicObjects(time);
            PhysicsManager.Update(time.ElapsedGameTime.Milliseconds / 1000f);
            PlayerProfile.UpdateTime(time.ElapsedGameTime);
        }
Example #15
0
 private void AddInitialAvatar(Memory memory = null)
 {
     Avatar = Instantiate <GameObject>(Resources.Load <GameObject>("Prefabs/Map3D/Avatar3D")).GetComponent <AvatarEvent>();
     if (memory != null)
     {
         Avatar.PopulateFromMemory(memory);
     }
     Avatar.transform.parent = ActiveMap.LowestObjectLayer().transform;
     ActiveMap.OnTeleportTo();
     Camera.target = Avatar.GetComponent <MapEvent>();
     Camera.ManualUpdate();
 }
Example #16
0
 public override void Update(GameTime time)
 {
     if (!UIManager.Update(time)) // Allows exit event to close game
     {
         base.Exit();
     }
     ActiveMap.UpdateDynamicObjects(time);
     PhysicsManager.Update(time.ElapsedGameTime.Milliseconds / 10f);
     if (PlayerManger.Health <= 0)
     {
         this.EndGame();
     }
 }
Example #17
0
 protected override ActiveMap loadMap(string id)
 {
     ActiveMap map = new ActiveMap();
     if (File.Exists(id))
     {
         using (BinaryReader reader = new BinaryReader(File.OpenRead(id)))
         {
             ((BasicMap)map).Load(reader);
         }
     }
     else
     {
         map.CreateBlank(10, 10);
     }
     return map;
 }
Example #18
0
    public void TheSlopeEdgeOfASlopeAndOtherSlopeEdgeOfTheSameHeightAreTraversables()
    {
        var geoMap = new Dictionary <Hex, GeographicTile>
        {
            {
                new Hex(0, 0),
                new GeographicTile()
                {
                    walkable    = true,
                    heightLevel = MapHeight.l3 | MapHeight.l4,
                    slopeData   = new SlopeData()
                    {
                        isSlope        = true,
                        heightSide_0tr = MapHeight.l3,
                        heightSide_1r  = MapHeight.l3 | MapHeight.l4,
                        heightSide_2dr = MapHeight.l4,
                        heightSide_3dl = MapHeight.l4,
                        heightSide_4l  = MapHeight.l3 | MapHeight.l4,
                        heightSide_5tl = MapHeight.l3
                    }
                }
            },
            {
                new Hex(1, 0),
                new GeographicTile()
                {
                    walkable    = true,
                    heightLevel = MapHeight.l3 | MapHeight.l4,
                    slopeData   = new SlopeData()
                    {
                        isSlope        = true,
                        heightSide_0tr = MapHeight.l3,
                        heightSide_1r  = MapHeight.l3 | MapHeight.l4,
                        heightSide_2dr = MapHeight.l4,
                        heightSide_3dl = MapHeight.l4,
                        heightSide_4l  = MapHeight.l3 | MapHeight.l4,
                        heightSide_5tl = MapHeight.l3
                    }
                }
            }
        };
        RuntimeMap map       = new RuntimeMap(geoMap, 100);
        var        layout    = new Layout(Orientation.pointy, new FixVector2(1, 1), new FixVector2(0, 0));
        ActiveMap  activeMap = new ActiveMap(map, layout);

        Assert.IsTrue(MapUtilities.IsTraversable(new Hex(0, 0), new Hex(1, 0), MapUtilities.MapType.GEOGRAPHYC, activeMap));
    }
Example #19
0
        public static void HandleMapDone()
        {
            WindowSwitcher.GameWindow.MapViewer.ActiveMap = ActiveMap;

            PlayerManager.MyPlayer.MapID = ActiveMap.MapID;
            ActiveMap.DoOverlayChecks();
            if (PlayerManager.MyPlayer.Darkness > -2)
            {
                Logic.Graphics.Renderers.Screen.ScreenRenderer.RenderOptions.SetDarkness(PlayerManager.MyPlayer.Darkness);
            }
            else
            {
                Logic.Graphics.Renderers.Screen.ScreenRenderer.RenderOptions.SetDarkness(ActiveMap.Darkness);
            }
            Logic.Graphics.Renderers.Screen.ScreenRenderer.DeactivateOffscreenSprites();
            //Logic.Graphics.Renderers.Screen.ScreenRenderer.RenderOptions.SetOverlay((Enums.Overlay)Maps.MapHelper.ActiveMap.Overlay);
            //Logic.Graphics.Renderers.Screen.ScreenRenderer.RenderOptions.SetOverlay(Enums.Overlay.Sandstorm);
            //Logic.Graphics.Renderers.Screen.ScreenRenderer.RenderOptions.SetWea(Maps.MapHelper.ActiveMap.Weather);

            Logic.Graphics.Effects.Overlays.ScreenOverlays.MapChangeInfoOverlay infoOverlay = Logic.Graphics.Renderers.Screen.ScreenRenderer.RenderOptions.ScreenOverlay as Logic.Graphics.Effects.Overlays.ScreenOverlays.MapChangeInfoOverlay;
            if (infoOverlay != null)
            {
                if (infoOverlay.MinTimePassed)
                {
                    Logic.Graphics.Renderers.Screen.ScreenRenderer.RenderOptions.ScreenOverlay = null;
                }
            }
            PlayerManager.MyPlayer.SetCurrentRoom();
            //Music.Music.AudioPlayer.PlayMusic(ActiveMap.Music);
            ((Client.Logic.Music.Bass.BassAudioPlayer)Logic.Music.Music.AudioPlayer).FadeToNext(ActiveMap.Music, 1000);

            if (Stories.StoryProcessor.ActiveStory != null && Stories.StoryProcessor.ActiveStory.Segments[Stories.StoryProcessor.ActiveStory.State.CurrentSegment].Action == Enums.StoryAction.Warp)
            {
                if (ActiveMap.MapID == ((Stories.Segments.WarpSegment)Stories.StoryProcessor.ActiveStory.Segments[Stories.StoryProcessor.ActiveStory.State.CurrentSegment]).Map)
                {
                    if (Stories.StoryProcessor.ActiveStory.State.StoryPaused)
                    {
                        Stories.StoryProcessor.ActiveStory.State.Unpause();
                        Stories.StoryProcessor.ActiveStory.State.StoryPaused = false;
                    }
                }
            }
            Globals.GettingMap  = false;
            Globals.RefreshLock = false;

            Messenger.SendMapLoaded();
        }
Example #20
0
    private void RawTeleport(Map map, IntVector2 location)
    {
        Assert.IsNotNull(ActiveMap);
        Assert.IsNotNull(Avatar);

        int layerIndex = Avatar.GetComponent <MapEvent>().LayerIndex;

        Avatar.transform.parent = null;
        Layer parentLayer = map.LayerAtIndex(layerIndex);

        Avatar.transform.parent = parentLayer.gameObject.transform;

        ActiveMap.OnTeleportAway();
        Object.Destroy(ActiveMap.gameObject);
        ActiveMap = map;
        ActiveMap.OnTeleportTo();
        Avatar.GetComponent <MapEvent>().SetLocation(location);
    }
Example #21
0
    private void RawTeleport(Map map, Vector2Int location, OrthoDir?facing = null)
    {
        IsTransitioning = true;
        activeMapName   = null;
        if (Avatar == null)
        {
            AddInitialAvatar(map);
        }
        else
        {
            Avatar.transform.SetParent(map.objectLayer.transform, false);
        }
        Avatar.GetComponent <MapEvent>().SetPosition(location);
        if (facing != null)
        {
            Avatar.Chara.Facing = facing.GetValueOrDefault(OrthoDir.North);
        }

        if (map != ActiveMap)
        {
            if (ActiveMap != null)
            {
                ActiveMap.OnTeleportAway();
                if (ActiveMap.transform.parent != null)
                {
                    DestroyImmediate(ActiveMap.transform.parent.gameObject);
                }
                else
                {
                    DestroyImmediate(ActiveMap.gameObject);
                }
            }

            ActiveMap = map;
            ActiveMap.OnTeleportTo();
            camera        = null;
            Camera.target = Avatar.Event;
            Global.Instance().Dispatch.Signal(EventTeleport, ActiveMap);
            Avatar.OnTeleport();
        }
        StartCoroutine(CoUtils.RunAfterDelay(0.2f, () => {
            IsTransitioning = false;
        }));
    }
Example #22
0
    protected override void OnUpdate()
    {
        ActiveMap map = MapManager.ActiveMap;

        if (map == null)
        {
            Debug.LogWarning("Create a map before the use of the selection system");
            return;
        }
        //select ->
        if (Input.GetMouseButtonUp(0))
        {
            var mouseHexPos = map.layout.PixelToFractionaHex(Input.mousePosition, Camera.main);
            if (CollisionSystem.PointCast(mouseHexPos, out Entity colliderEntity))
            {
                if (EntityManager.HasComponent <Parent>(colliderEntity))
                {
                    var parent = EntityManager.GetSharedComponentData <Parent>(colliderEntity).ParentEntity;
                    if (SelectIfSelectable(parent))
                    {
                    }
                    else
                    {
                        SelectIfSelectable(colliderEntity);
                    }
                }
                else
                {
                    SelectIfSelectable(colliderEntity);
                }
            }
            else
            {
                Deselct();
            }
        }

        //on selected death ->
        Entities.WithAll <SelectionSystemStateData>().WithNone <Selectable>().ForEach((Entity entity) =>
        {
            PostUpdateCommands.RemoveComponent <SelectionSystemStateData>(entity);
        });
    }
Example #23
0
        void frame_KeyPressDown(Element sender, KeyEventArgs e)
        {
            switch (e.InterestingKeys[0])
            {
            case Keys.G:
                gactive = !gactive;
                if (gactive)
                {
                    PhysicsManager.AddUniversalForce(DefaultForces.Gravity);
                }
                else
                {
                    PhysicsManager.RemoveUniversalForce(DefaultForces.Gravity);
                }
                break;

            case Keys.X:
                var br = new BombRoid(new Vector2((float)MathUtils.Rand.Next(60, (int)winSize.Width - 60), winSize.Height), 25);
                br.Mass     = 100;
                br.Velocity = -1000 * Vector2.UnitY;
                br.FuseTime = .1f;
                ActiveMap.AddObject(br);
                PhysicsManager.ActiveBodies.Add(br);
                break;

            case Keys.C:
                var gr = new InertRoid(new Vector2((float)MathUtils.Rand.Next(60, (int)winSize.Width - 60), winSize.Height), 25);
                gr.Mass     = 100;
                gr.Velocity = -1000 * Vector2.UnitY;
                ActiveMap.AddObject(gr);
                PhysicsManager.ActiveBodies.Add(gr);
                break;

            case Keys.OemPeriod:
                draw = !draw;
                break;

            case Keys.Space:

                break;
            }
        }
Example #24
0
    public void SlopeEdgeAndTileOfDiferentHeightAreNotTraversables()
    {
        var geoMap = new Dictionary <Hex, GeographicTile>
        {
            {
                new Hex(0, 1),
                new GeographicTile()
                {
                    walkable    = true,
                    heightLevel = MapHeight.l0,
                    slopeData   = new SlopeData()
                    {
                        isSlope = false,
                    }
                }
            },
            {
                new Hex(0, 0),
                new GeographicTile()
                {
                    walkable    = true,
                    heightLevel = MapHeight.l0,
                    slopeData   = new SlopeData()
                    {
                        isSlope        = true,
                        heightSide_0tr = MapHeight.l1,
                        heightSide_1r  = MapHeight.l1,
                        heightSide_2dr = MapHeight.l0 | MapHeight.l1,
                        heightSide_3dl = MapHeight.l0,
                        heightSide_4l  = MapHeight.l0,
                        heightSide_5tl = MapHeight.l0 | MapHeight.l1
                    }
                }
            }
        };
        RuntimeMap map       = new RuntimeMap(geoMap, 100);
        var        layout    = new Layout(Orientation.pointy, new FixVector2(1, 1), new FixVector2(0, 0));
        ActiveMap  activeMap = new ActiveMap(map, layout);


        Assert.IsFalse(MapUtilities.IsTraversable(new Hex(0, 1), new Hex(0, 0), MapUtilities.MapType.GEOGRAPHYC, activeMap));
    }
Example #25
0
    public void TestElevatioFunction_OnDouble_T()
    {
        var geoMap = new Dictionary <Hex, GeographicTile>
        {
            {
                new Hex(0, 0),
                new GeographicTile()
                {
                    heightLevel = MapHeight.l0,
                    slopeData   = new SlopeData()
                    {
                        isSlope        = true,
                        heightSide_0tr = MapHeight.l1,
                        heightSide_1r  = MapHeight.l0,
                        heightSide_2dr = MapHeight.l0,
                        heightSide_3dl = MapHeight.l0,
                        heightSide_4l  = MapHeight.l0,
                        heightSide_5tl = MapHeight.l1
                    }
                }
            }
        };
        RuntimeMap map       = new RuntimeMap(geoMap, 100);
        var        layout    = new Layout(Orientation.pointy, new FixVector2(1, 1), new FixVector2(0, 0));
        ActiveMap  activeMap = new ActiveMap(map, layout);


        var elevation1 = MapUtilities.GetElevationOfPosition(new FractionalHex(Fix64.Zero, Fix64.Zero), activeMap);
        var elevation2 = MapUtilities.GetElevationOfPosition(new FractionalHex(-(Fix64)0.2886835f, (Fix64)0.577367f, -(Fix64)0.2886835f), activeMap);
        var elevation3 = MapUtilities.GetElevationOfPosition(new FractionalHex((Fix64)0.2886835f, -(Fix64)0.577367f, (Fix64)0.2886835f), activeMap);
        var elevation4 = MapUtilities.GetElevationOfPosition(new FractionalHex((Fix64)0.2886835f, (Fix64)0.2886835f, -(Fix64)0.577367f), activeMap);

        //var elevation5 = activeMap.GetElevationOfPosition(new FractionalHex(-(Fix64)0.5f, Fix64.Zero, (Fix64)0.5));
        //var elevation6 = activeMap.GetElevationOfPosition(new FractionalHex(-(Fix64)0.25f, Fix64.Zero, (Fix64)0.25f));

        Assert.AreEqual(50, elevation1);
        Assert.AreEqual(100, elevation2);
        Assert.AreEqual(0, elevation3);
        Assert.AreEqual(100, elevation4);
        //Assert.AreEqual(0, elevation5);
        //Assert.AreEqual(0, elevation6);
    }
Example #26
0
        void frame_MouseOver(Element sender, MouseEventArgs e)
        {
            ((IRigidBody)ActiveMap.Player).Rotation = MathUtils.GetAngle(e.CurrentPosition - ((IRigidBody)ActiveMap.Player).Position);

            if (e.isDown(MouseButtons.Right))
            {
                var rad = PhysicsManager.QTbodies.Query(Region.FromCircle(e.CurrentPosition, 10));
                foreach (var gr in rad)
                {
                    if (gr is InertRoid)
                    {
                        KillObject((Actor)gr);

                        var gra = (InertRoid)gr;
                        var br  = new BombRoid(gra.Position, gra.Radius);
                        ActiveMap.AddObject(br);
                        PhysicsManager.ActiveBodies.Add(br);
                    }
                }
            }
        }
Example #27
0
    /// <summary>
    /// gets if there is clear direct path bewtween the two points.
    /// </summary>
    public static bool PathToPointIsClear(FractionalHex position, FractionalHex point, ActiveMap customActiveMap = null, bool pathIsClearEvenIfDestPointIsBlocked = false)
    {
        ActiveMap activeMap;

        if (customActiveMap == null)
        {
            activeMap = MapManager.ActiveMap;
            Debug.Assert(activeMap != null, "The Active Map is null!!!");
        }
        else
        {
            activeMap = customActiveMap;
        }

        Hex pointHex        = point.Round();
        var hexesInBewtween = Hex.HexesInBetween(position, point);

        for (int i = 0; i < hexesInBewtween.Count - 1; i++)
        {
            Hex hexA = hexesInBewtween[i];
            Hex hexB = hexesInBewtween[i + 1];

            if (pointHex == hexB && pathIsClearEvenIfDestPointIsBlocked)
            {
                if (!MapUtilities.IsTraversable(hexA, hexB, MapUtilities.MapType.GEOGRAPHYC, activeMap))
                {
                    return(false);
                }
            }
            else
            {
                if (!MapUtilities.IsTraversable(hexA, hexB, MapUtilities.MapType.MOVEMENT, activeMap))
                {
                    return(false);
                }
            }
        }
        return(true);
    }
Example #28
0
        public override void Update(GameTime time)
        {
            if (!UIManager.Update(time))
            {
                base.Exit();
            }
            ActiveMap.UpdateDynamicObjects(time);
            PhysicsManager.Update(time.ElapsedGameTime.Milliseconds / 1000f);

            if (!time.IsRunningSlowly)
            {
                dint -= time.ElapsedGameTime.Milliseconds / 1000f;
                if (dint <= 0.0f)
                {
                    dynamic obj;
                    if (MathUtils.Rand.Next(0, 2) == 0)
                    {
                        obj = new BombRoid(new Vector2((float)MathUtils.Rand.Next(60, (int)winSize.Width - 60), (float)MathUtils.Rand.Next(60, (int)winSize.Height - 60)), MathUtils.Rand.Next(2, 10));
                    }
                    else
                    {
                        obj = new InertRoid(new Vector2((float)MathUtils.Rand.Next(60, (int)winSize.Width - 60), (float)MathUtils.Rand.Next(60, (int)winSize.Height - 60)), MathUtils.Rand.Next(2, 10));
                    }
                    obj.Velocity = 1000 * (float)MathUtils.Rand.NextDouble() * MathUtils.RandDirection();
                    PhysicsManager.ActiveBodies.Add(obj);
                    ActiveMap.AddObject(obj);

                    Console.WriteLine(PhysicsManager.ActiveBodies.Count.ToString() + " bodies");
                    dint = delay;
                }
            }
            else
            {
                Console.Write(PhysicsManager.ActiveBodies.Count.ToString() + " bodies     ");
                Console.WriteLine("SLOW - HIT PERIOD TO DISABLE GRFX");
                dint = 0.0f;
            }
        }
Example #29
0
    public void  UnitMap_NotWalkableTilesAreNotTraversables()
    {
        var geoMap = new Dictionary <Hex, GeographicTile>
        {
            {
                new Hex(0, 0),
                new GeographicTile()
                {
                    walkable    = true,
                    heightLevel = MapHeight.l0,
                    slopeData   = new SlopeData()
                    {
                        isSlope = false,
                    }
                }
            },
            {
                new Hex(-1, 1),
                new GeographicTile()
                {
                    walkable    = true,
                    heightLevel = MapHeight.l0,
                    slopeData   = new SlopeData()
                    {
                        isSlope = false,
                    }
                }
            }
        };
        RuntimeMap map       = new RuntimeMap(geoMap, 100);
        var        layout    = new Layout(Orientation.pointy, new FixVector2(1, 1), new FixVector2(0, 0));
        ActiveMap  activeMap = new ActiveMap(map, layout);

        activeMap.map.SetUnitOcupationMapValue(new Hex(0, 0), false);


        Assert.IsFalse(MapUtilities.IsTraversable(new Hex(-1, 1), new Hex(0, 0), MapUtilities.MapType.UNIT, activeMap));
    }
Example #30
0
    public void SameHeightTilesAreTaversables()
    {
        var geoMap = new Dictionary <Hex, GeographicTile>
        {
            {
                new Hex(0, 0),
                new GeographicTile()
                {
                    walkable    = true,
                    heightLevel = MapHeight.l0,
                    slopeData   = new SlopeData()
                    {
                        isSlope = false,
                    }
                }
            },
            {
                new Hex(-1, 1),
                new GeographicTile()
                {
                    walkable    = true,
                    heightLevel = MapHeight.l0,
                    slopeData   = new SlopeData()
                    {
                        isSlope = false,
                    }
                }
            }
        };
        RuntimeMap map       = new RuntimeMap(geoMap, 100);
        var        layout    = new Layout(Orientation.pointy, new FixVector2(1, 1), new FixVector2(0, 0));
        ActiveMap  activeMap = new ActiveMap(map, layout);


        Assert.IsTrue(MapUtilities.IsTraversable(new Hex(-1, 1), new Hex(0, 0), MapUtilities.MapType.GEOGRAPHYC, activeMap));
    }
Example #31
0
    private static void SpawnFOWTeamViewObjects(int[] teams, LeanGameObjectPool pool, ActiveMap map)
    {
        //aca debo entregar una lista con todas las entidades que generan vision de un team y cual es su rango.
        var visionPointOfTeam = SightSystem.GetVisionPointsForEachTeam(teams);

        foreach (var point in visionPointOfTeam)
        {
            //debo agragarle la altura
            var elevation = MapUtilities.GetElevationOfPosition(point.center);
            var fixPositionNoElevation = map.layout.HexToWorld(point.center);
            var fixScale = map.layout.size * point.radius;

            var position      = new Vector3((float)fixPositionNoElevation.x, (float)fixPositionNoElevation.y + elevation);
            var scale         = new Vector3((float)fixScale.x, (float)fixScale.y) * 2;
            var spawnedObject = pool.Spawn(position, Quaternion.identity);
            spawnedObject.transform.localScale = scale;
        }
    }
Example #32
0
        public SetMap(ActiveMap map, int floor)
        {
            this.map = new DisplayMap();
            this.map.MapArray = new Tile[map.Width, map.Height];
            for (int y = 0; y < map.Height; y++)
            {
                for (int x = 0; x < map.Width; x++)
                {
                    this.map.MapArray[x, y] = new Tile(map.MapArray[x, y]);
                }
            }

            this.map.GroundLayers = new List<TileAnim[,]>();
            for (int i = 0; i < map.GroundLayers.Count; i++)
            {
                this.map.GroundLayers.Add(new TileAnim[map.Width, map.Height]);
                for (int y = 0; y < map.Height; y++)
                {
                    for (int x = 0; x < map.Width; x++)
                    {
                        this.map.GroundLayers[i][x, y] = map.GroundLayers[i].Tiles[x, y];
                    }
                }
            }

            this.map.PropBackLayers = new List<TileAnim[,]>();
            for (int i = 0; i < map.PropBackLayers.Count; i++)
            {
                this.map.PropBackLayers.Add(new TileAnim[map.Width, map.Height]);
                for (int y = 0; y < map.Height; y++)
                {
                    for (int x = 0; x < map.Width; x++)
                    {
                        this.map.PropBackLayers[i][x, y] = map.PropBackLayers[i].Tiles[x, y];
                    }
                }
            }

            this.map.PropFrontLayers = new List<TileAnim[,]>();
            for (int i = 0; i < map.PropFrontLayers.Count; i++)
            {
                this.map.PropFrontLayers.Add(new TileAnim[map.Width, map.Height]);
                for (int y = 0; y < map.Height; y++)
                {
                    for (int x = 0; x < map.Width; x++)
                    {
                        this.map.PropFrontLayers[i][x, y] = map.PropFrontLayers[i].Tiles[x, y];
                    }
                }
            }

            this.map.FringeLayers = new List<TileAnim[,]>();
            for (int i = 0; i < map.FringeLayers.Count; i++)
            {
                this.map.FringeLayers.Add(new TileAnim[map.Width, map.Height]);
                for (int y = 0; y < map.Height; y++)
                {
                    for (int x = 0; x < map.Width; x++)
                    {
                        this.map.FringeLayers[i][x, y] = map.FringeLayers[i].Tiles[x, y];
                    }
                }
            }

            this.floor = floor;
        }
Example #33
0
    /// <summary>
    /// It returns true if there is a collision with the map, false otherwise. The 'out' list comntains the most important corners that are colliding and the distance of the overlap.On priority order:
    /// 1-collision with a hex outside the map
    /// 2-collision with an unwalkable hex(mapa geografico)
    /// 3-collision with an unwalkable hex(construcciones/mapa de movimiento)
    /// </summary>
    private static bool CollisionTestAgainstMap(Fix64 colliderArea, FractionalHex position, ActiveMap activeMap, out List <FractionalHex> collisionResponseVectors)
    {
        collisionResponseVectors = new List <FractionalHex>();

        bool outsideMapCollision    = false;
        bool geographycHexCollision = false;
        bool movementMapCollision   = false;
        var  collisionResponseVectorsToOutsideMapCollitions         = new List <FractionalHex>();
        var  collisionResponseVectorsThatCauseGeographycCollisions  = new List <FractionalHex>();
        var  collisionResponseVectorsThatCauseMovementMapCollisions = new List <FractionalHex>();


        Hex centerHex = position.Round();

        //hace un check en todas las esquinas del area de colision.
        for (int i = 0; i < 6; i++)
        {
            var direction = Hex.directions[i];
            var corner    = position + ((FractionalHex)direction * colliderArea);

            Hex hexThatCanHaveACollision = centerHex + direction;
            if (corner.Round() == centerHex)
            {
                continue;
            }
            else if (hexThatCanHaveACollision != corner.Round())
            {
                continue;
            }

            if (!activeMap.map.MovementMapValues.TryGetValue(corner.Round(), out bool walkable))
            {
                outsideMapCollision = true;
                var collisionResponseVector = -(FractionalHex)direction * GetCollisionDistance(centerHex, corner);
                collisionResponseVectorsToOutsideMapCollitions.Add(collisionResponseVector);
            }
            else
            {
                if (!MapUtilities.IsTraversable(corner.Round(), centerHex, MapUtilities.MapType.GEOGRAPHYC))
                {
                    geographycHexCollision = true;
                    var collisionResponseVector = -(FractionalHex)direction * GetCollisionDistance(centerHex, corner);
                    collisionResponseVectorsThatCauseGeographycCollisions.Add(collisionResponseVector);
                }
                else if (!walkable)
                {
                    movementMapCollision = true;
                    var collisionResponseVector = -(FractionalHex)direction * GetCollisionDistance(centerHex, corner);
                    collisionResponseVectorsThatCauseMovementMapCollisions.Add(collisionResponseVector);
                }
            }
        }
        if (outsideMapCollision)
        {
            collisionResponseVectors = collisionResponseVectorsToOutsideMapCollitions;
            return(true);
        }
        else if (geographycHexCollision)
        {
            collisionResponseVectors = collisionResponseVectorsThatCauseGeographycCollisions;
            return(true);
        }
        else if (movementMapCollision)
        {
            collisionResponseVectors = collisionResponseVectorsThatCauseMovementMapCollisions;
            return(true);
        }
        else
        {
            return(false);
        }
    }