Exemple #1
0
        public override void OnUpdate(GameTime gameTime)
        {
            foreach (var e in Level.QueryEntity(Position, 16))
            {
                if (e != this && e.HasComponent <ComponentExperience>())
                {
                    var exp = e.GetComponent <ComponentExperience>();
                    GetComponent <ComponentMove>().MoveTo(e.X, e.Y);

                    if (Mathf.Distance(X, Y, e.X, e.Y) < 2f)
                    {
                        exp.TakeXP(this);
                        Remove();
                        break;
                    }
                }
            }

            foreach (var e in Level.QueryEntity(Position, Game.Unit))
            {
                if (e.HasComponent <ComponentExperience>(out var i))
                {
                    GetComponent <ComponentMove>().MoveTo(e.X, e.Y, 2f);

                    if (Mathf.Distance(e.X, e.Y, X, Y) < 3)
                    {
                        e.GetComponent <ComponentExperience>().TakeXP(Value);
                    }
                }
            }
        }
Exemple #2
0
 public bool IsStillRunning(Agent agent)
 {
     // Check if the target is still in this level and in range.
     return(!_taget.Removed && _taget.Level == agent.Owner.Level &&
            Mathf.Distance(_taget.X, _taget.Y, agent.Owner.X, agent.Owner.Y)
            < _range * 16f && agent.Owner.HasComponent <Attack>());
 }
Exemple #3
0
        public void Do()
        {
            if (_hasExplosed)
            {
                return;
            }
            _hasExplosed = true;

            var entities = Owner.Level.GetEntitiesOnArea(Owner.X, Owner.Y, _radius * Game.Unit);

            Owner.GameState.Camera.Thrauma += 0.2f;

            foreach (var e in entities)
            {
                if (e != Owner)
                {
                    var distance = Mathf.Distance(e.X, e.Y, Owner.X, Owner.Y);
                    e.GetComponent <Health>()?.Hurt(Owner, GetDammage(distance) * Rise.Rnd.NextFloat());

                    if (e == Owner.GameState.LocalPlayer?.Entity)
                    {
                        Owner.GameState.Camera.Thrauma += GetPower(distance);
                    }

                    if (Rise.Rnd.NextFloat() <= 0.3f)
                    {
                        e.GetComponent <Explode>()?.Do();
                        e.GetComponent <Breakable>()?.Break();
                        e.GetComponent <Burnable>()?.SetInFire();
                    }
                }
            }

            var pos = Owner.GetTilePosition();

            for (int x = -(int)_radius; x <= (int)_radius; x++)
            {
                for (int y = -(int)_radius; y <= (int)_radius; y++)
                {
                    var tilePos  = new Coordinates(pos.X + x, pos.Y + y);
                    var tile     = Owner.Level.GetTile(tilePos);
                    var distance = Mathf.Distance(tilePos.WorldX, tilePos.WorldY, Owner.X, Owner.Y);

                    if (distance < _radius * Game.Unit)
                    {
                        tile.Tag <DamageTile>()?.Hurt(GetDammage(distance) * Rise.Rnd.NextFloat(), tilePos, Owner.Level);

                        if (Rise.Rnd.NextDouble() * 1.25 < 1f - (distance / (_radius * Game.Unit)))
                        {
                            tile.Tag <BreakableTile>()?.Break(tilePos, Owner.Level);
                        }
                    }
                }
            }
        }
Exemple #4
0
        public override void Update(GameTime gameTime)
        {
            //if (Rise.Input.MouseScrollUp) _scrollOffset += Scale(16);
            //if (Rise.Input.MouseScrollDown) _scrollOffset -= Scale(16);

            if (Rise.Pointing.AreaDown(Bound) && !IsDown)
            {
                IsDown = true;

                _lastPoint = Rise.Pointing.GetAreaOver(Bound)[0];
                _downPoint = Rise.Pointing.GetAreaOver(Bound)[0];

                Logger.Log <ListWidget>("Down");
            }

            if (Rise.Pointing.AreaDown(Bound) && IsDown)
            {
                var newPoint = Rise.Pointing.GetAreaOver(Bound)[0];
                var delta    = _lastPoint.Y - newPoint.Y;
                _lastPoint = newPoint;

                _scrollOffset -= delta;
            }

            if (Rise.Pointing.AreaClick(Bound))
            {
                var dist = Mathf.Distance(_downPoint.ToVector2(), Rise.Pointing.GetAreaOver(Bound)[0].ToVector2());

                if (dist < 16)
                {
                    if (_overItem != null || AlowUnselecting)
                    {
                        SelectedItem = _overItem;
                    }
                }

                IsDown     = false;
                _lastPoint = Point.Zero;
                _downPoint = Point.Zero;
                Logger.Log <ListWidget>("Up");
            }

            if (!Rise.Pointing.AreaDown(Bound) && IsDown)
            {
                IsDown     = false;
                _lastPoint = Point.Zero;
                _downPoint = Point.Zero;
            }

            var maxScroll = _items.Count * Scale(ItemHeight + ItemMarging);

            _scrollOffset = Mathf.Clamp(_scrollOffset, -maxScroll + Math.Min(maxScroll, Host.Height), 0);
        }
Exemple #5
0
        public List <Entity> GetFacingEntities(int area)
        {
            var facingEntities = Level.GetEntitiesOnArea(GetFacingArea(area));

            facingEntities.Sort((a, b) =>
            {
                return(Mathf.Distance(a.X, a.Y, X, Y)
                       .CompareTo(Mathf.Distance(b.X, b.Y, X, Y)));
            });

            facingEntities.Remove(this);
            return(facingEntities);
        }
Exemple #6
0
    public PolygonEntity(float restitution, float Mass, Vector xpos, Vector v, Vector a, Layer layer, Vector[] _vertices, string filename) : base(restitution, Mass, xpos, v, a, filename, layer)
    {
        localSpaceVertices = new Vector[_vertices.Length];
        Array.Copy(_vertices, localSpaceVertices, _vertices.Length);

        vertices = new Vector[localSpaceVertices.Length];

        float EstWidth  = Mathf.Abs(GetSupportPoint(Vector.Right()).x - GetSupportPoint(Vector.Left()).x);
        float EstHeight = Mathf.Abs(GetSupportPoint(Vector.Up()).y - GetSupportPoint(Vector.Down()).y);

        inertia    = Mass * (((EstWidth * EstWidth) + (EstHeight * EstHeight)) * 1 / 6);
        invInertia = 1 / inertia;

        if (Utils.IsNearEqual(Mass, 0f, 0.01f))
        {
            invMass    = 0;
            invInertia = 0;
        }
        else
        {
            invMass = 1 / Mass;
        }
        float[] furthestdistance = new float[4];

        Vector supportPoint = GetSupportPoint(Vector.Left());

        furthestdistance[0] = Mathf.Abs(Mathf.Distance(0, 0, supportPoint.x, supportPoint.y));

        supportPoint        = GetSupportPoint(Vector.Right());
        furthestdistance[1] = Mathf.Abs(Mathf.Distance(0, 0, supportPoint.x, supportPoint.y));

        supportPoint        = GetSupportPoint(Vector.Up());
        furthestdistance[2] = Mathf.Abs(Mathf.Distance(0, 0, supportPoint.x, supportPoint.y));

        supportPoint        = GetSupportPoint(Vector.Down());
        furthestdistance[3] = Mathf.Abs(Mathf.Distance(0, 0, supportPoint.x, supportPoint.y));

        for (int i = 0; i < furthestdistance.Length; i++)
        {
            if (furthestdistance[i] > BoundingCircleRadius)
            {
                BoundingCircleRadius = furthestdistance[i];
            }
        }
    }
Exemple #7
0
        public void Detonate()
        {
            if (Detonated)
            {
                return;
            }
            Detonated = true;

            Owner.GameState.Camera.Thrauma += 0.2f;

            foreach (var c in Owner.Level.QueryCoordinates(Owner.Position, Range * Game.Unit))
            {
                // Apply damages to tiles.
                var tile     = Owner.Level.GetTile(c);
                var distance = Mathf.Distance(c.WorldX, c.WorldY, Owner.X, Owner.Y);
                tile.Tag <DamageTile>()?.Hurt(GetDamages(distance) * Rise.Rnd.NextFloat(), c, Owner.Level);

                if (Rise.Rnd.NextDouble() * 1.25 < 1f - distance / (Range * Game.Unit))
                {
                    tile.Tag <BreakableTile>()?.Break(c, Owner.Level);
                }

                // Apply damages to entities
                foreach (var e in Owner.Level.QueryEntity(c))
                {
                    if (DamageMyself || e != Owner)
                    {
                        e.GetComponent <ComponentHealth>()?.Hurt(Owner, GetDamages(distance) * Rise.Rnd.NextFloat());

                        if (e == Owner.GameState.LocalPlayer?.Entity)
                        {
                            Owner.GameState.Camera.Thrauma += GetPowerByDistance(distance);
                        }

                        if (Rise.Rnd.NextFloat() <= 0.3f)
                        {
                            e.GetComponent <ComponentExplosive>()?.Detonate();
                            e.GetComponent <ComponentBreakable>()?.Break();
                            e.GetComponent <ComponentFlammable>()?.SetInFire();
                        }
                    }
                }
            }
        }
        public override void Update(GameTime gameTime)
        {
            if (Target != null && (Target.Removed ||
                                   Target.Level != Agent.Owner.Level ||
                                   Mathf.Distance(Agent.Owner.Position, Target.Position) > FollowRange * Game.Unit))
            {
                Agent.Abort(AgentAbortReason.TagetLost);
                Target = null;
            }

            if (Target == null)
            {
                _targetsOnSight = Agent.Owner.Level.QueryEntity(Agent.Owner.Position, AgroRange * Game.Unit)
                                  .Where((e) => e.MemberOf(Targets) && CheckLineOfSight(e.Coordinates)).ToList();

                _targetsOnSight.Sort((a, b) => Mathf.Distance(a.Position, Agent.Owner.Position)
                                     .CompareTo(Mathf.Distance(b.Position, Agent.Owner.Position)));

                if (_targetsOnSight.Any())
                {
                    Target             = _targetsOnSight.First();
                    _lastTagetPosition = Target.Coordinates;
                    Agent.MoveTo(Target.Coordinates, MoveSpeedAgro, false, (int)(FollowRange + 4));
                }
            }
            else
            {
                if (Target.Coordinates != _lastTagetPosition &&
                    Mathf.Distance(Agent.Owner.Position, Target.Position) < FollowRange * Game.Unit &&
                    CheckLineOfSight(Target.Coordinates))
                {
                    Agent.Flush();
                    _lastTagetPosition = Target.Coordinates;
                    Agent.MoveTo(_lastTagetPosition, MoveSpeedAgro, false, (int)(FollowRange + 4));
                }
            }

            if (!Agent.IsBusy())
            {
                base.Update(gameTime);
            }
        }
Exemple #9
0
        public override void OnUpdate(GameTime gameTime)
        {
            var move = GetComponent <Move>();

            move.Do(SpeedX, SpeedY);
            SpeedX = SpeedX / 2;
            SpeedY = SpeedY / 2;

            var entities = Level.GetEntitiesOnArea(new Rectangle((int)X - 8, (int)Y - 8, 16, 16))
                           .Where((e) => e.GetComponent <Inventory>()?.AlowPickUp ?? false);

            foreach (var e in entities)
            {
                move.MoveTo(e.X, e.Y);
                if (Mathf.Distance(e.X, e.Y, X, Y) < 3 && Pickup(e))
                {
                    return;
                }
            }
        }
        public override void OnUpdate(GameTime gameTime)
        {
            var move = GetComponent <ComponentMove>();

            move.Do(SpeedX, SpeedY);
            SpeedX = SpeedX / 2;
            SpeedY = SpeedY / 2;

            foreach (var e in Level.QueryEntity(Position, Game.Unit))
            {
                if (e.HasComponent <ComponentInventory>(out var i) && i.AlowPickUp)
                {
                    move.MoveTo(e.X, e.Y, 2f);
                    if (Mathf.Distance(e.X, e.Y, X, Y) < 3 && Pickup(e))
                    {
                        return;
                    }
                }
            }
        }
Exemple #11
0
        public override void OnUpdate(GameTime gameTime)
        {
            Level.GetEntitiesOnArea(X, Y, 16);

            foreach (var e in Level.GetEntitiesOnArea(X, Y, 16))
            {
                if (e != this && e.HasComponent <Experience>())
                {
                    var exp = e.GetComponent <Experience>();
                    GetComponent <Move>().MoveTo(e.X, e.Y);

                    if (Mathf.Distance(X, Y, e.X, e.Y) < 2f)
                    {
                        exp.TakeXP(this);
                        Remove();
                        break;
                    }
                }
            }
        }
Exemple #12
0
        public override void Update(GameTime gameTime)
        {
            if (!Agent.IsBusy() && Target != null && (Target.Level != Agent.Owner.Level ||
                                                      Mathf.Distance(Agent.Owner.Position, Target.Position) > FollowRange * Game.Unit))
            {
                Agent.Abort(AgentAbortReason.TagetLost);
                Target = null;
            }

            if (Target == null)
            {
                _targetsOnSight = Agent.Owner.Level.GetEntitiesOnArea(Agent.Owner.Position, AgroRange * Game.Unit)
                                  .Where((e) => e.Blueprint == ENTITIES.PLAYER && CheckLineOfSight(e.GetTilePosition())).ToList();

                _targetsOnSight.Sort((a, b) => Mathf.Distance(a.Position, Agent.Owner.Position)
                                     .CompareTo(Mathf.Distance(b.Position, Agent.Owner.Position)));

                if (_targetsOnSight.Any())
                {
                    Target             = _targetsOnSight.First();
                    _lastTagetPosition = Target.GetTilePosition();
                    Agent.MoveTo(Target.GetTilePosition(), MoveSpeedAgro, true, (int)(FollowRange + 4));
                }
            }
            else
            {
                if (Target.GetTilePosition() != _lastTagetPosition &&
                    Mathf.Distance(Agent.Owner.Position, Target.Position) < FollowRange * Game.Unit &&
                    CheckLineOfSight(Target.GetTilePosition()))
                {
                    Agent.Flush();
                    _lastTagetPosition = Target.GetTilePosition();
                    Agent.MoveTo(_lastTagetPosition, MoveSpeedAgro, true, (int)(FollowRange + 4));
                }
            }

            if (!Agent.IsBusy())
            {
                base.Update(gameTime);
            }
        }
Exemple #13
0
 public float DistanceTo(Node node)
 {
     return(Mathf.Distance(X, Y, node.X, node.Y));
 }
Exemple #14
0
        public void Update(GameTime gameTime)
        {
            var game        = Player.GameState;
            var input       = Rise.Input;
            var screenBound = Rise.Graphic.GetBound();

            if (!game.CurrentMenu?.PauseGame ?? false)
            {
                if (game.CurrentMenu == null || !game.CurrentMenu.PauseGame)
                {
                    if (input.KeyDown(Keys.Z) != input.KeyDown(Keys.S))
                    {
                        if (input.KeyDown(Keys.Z))
                        {
                            HandleInput(PlayerInput.MoveUp);
                        }
                        if (input.KeyDown(Keys.S))
                        {
                            HandleInput(PlayerInput.MoveDown);
                        }
                    }

                    if (input.KeyDown(Keys.Q) != input.KeyDown(Keys.D))
                    {
                        if (input.KeyDown(Keys.Q))
                        {
                            HandleInput(PlayerInput.MoveLeft);
                        }
                        if (input.KeyDown(Keys.D))
                        {
                            HandleInput(PlayerInput.MoveRight);
                        }
                    }

                    if (input.KeyDown(Keys.J))
                    {
                        HandleInput(PlayerInput.Attack);
                    }
                    if (input.KeyPress(Keys.K))
                    {
                        HandleInput(PlayerInput.Action);
                    }
                    if (input.KeyPress(Keys.L))
                    {
                        HandleInput(PlayerInput.Pickup);
                    }
                    if (input.KeyPress(Keys.A))
                    {
                        HandleInput(PlayerInput.DropItem);
                    }
                    if (input.KeyPress(Keys.X))
                    {
                        HandleInput(PlayerInput.AddWaypoint);
                    }
                    if (input.KeyPress(Keys.Add) || input.KeyPress(Keys.Up))
                    {
                        HandleInput(PlayerInput.ZoomIn);
                    }
                    if (input.KeyPress(Keys.Subtract) || input.KeyPress(Keys.Down))
                    {
                        HandleInput(PlayerInput.ZoomOut);
                    }
                }

                if (Rise.Platform.Family == PlatformFamily.Mobile && Rise.Pointing.AreaDown(screenBound))
                {
                    var mousePositionOnScreen = Rise.Pointing.GetAreaOver(screenBound)[0].ToVector2();
                    var mousePositionInWorld  = game.Camera.ToWorldSpace(mousePositionOnScreen);
                    var screenCenter          = Rise.Graphic.GetCenter();

                    if (Mathf.Distance(mousePositionOnScreen.X, mousePositionOnScreen.Y, screenCenter.X, screenCenter.Y) < Math.Min(Rise.Graphic.GetHeight(), Rise.Graphic.GetWidth()) / 2)
                    {
                        Player.GetComponent <Move>().MoveTo(mousePositionInWorld.X, mousePositionInWorld.Y, 1f, true);
                    }
                }
            }

            if (input.KeyPress(Keys.E) || input.KeyPress(Keys.Escape))
            {
                HandleInput(PlayerInput.OpenMenu);
            }
        }
Exemple #15
0
        public List <Entity> GetEntitiesOnArea(float cx, float cy, float radius)
        {
            var entities = GetEntitiesOnArea(new RectangleF(cx - radius, cy - radius, radius * 2, radius * 2));

            return(entities.Where(e => Mathf.Distance(e.X, e.Y, cx, cy) <= radius).ToList());
        }
 public float Distance(Coordinates to)
 {
     return(Mathf.Distance(X, Y, to.X, to.Y));
 }