Exemplo n.º 1
0
        public override void Update(float mFrameTime)
        {
            const int speed = 170;
            var nextX = _game.NextX;
            var nextY = _game.NextY;
            var nextAction = _game.NextAction;

            _fireDelay -= 1*mFrameTime;

            if (_fireDelay < 0 && nextAction == 1)
            {
                var fireAngle = Utils.Math.Angles.TowardsDegrees(new SSVector2F(_cBody.Position.X, _cBody.Position.Y), new SSVector2F(_game.GameWindow.Camera.MousePosition.X * 100, _game.GameWindow.Camera.MousePosition.Y * 100));
                _game.Factory.Bullet(_cBody.Position.X, _cBody.Position.Y, fireAngle, 500, false);
                _fireDelay = 4;

                _cRender.Animation = Assets.GetAnimation("charfiring");
            }

            if (nextAction == 0) _cRender.Animation = Assets.GetAnimation("charidle");

            if (nextX == 0 && nextY == 0)
            {
                _cMovement.Stop();
                return;
            }

            var angle = new SSVector2F(_game.NextX, _game.NextY).ToAngleDegrees();
            _cMovement.Angle = angle;
            _cMovement.Speed = speed;
        }
Exemplo n.º 2
0
        public void Draw()
        {
            var p0 = new SSVector2F(_cBody.X.ToPixels(), _cBody.Y.ToPixels());
            var p1 = p0 + Utils.Math.Angles.ToVectorDegrees(Angle - Amplitude)*66;
            var p2 = p0 + Utils.Math.Angles.ToVectorDegrees(Angle + Amplitude)*66;

            var v0 = new Vertex(new Vector2f(p0.X, p0.Y)) {Color = new Color(255, 0, 0, 125)};
            var v1 = new Vertex(new Vector2f(p1.X, p1.Y)) {Color = new Color(255, 0, 0, 1)};
            var v2 = new Vertex(new Vector2f(p2.X, p2.Y)) {Color = new Color(255, 0, 0, 1)};

            _game.GameWindow.RenderWindow.Draw(new[] {v0, v1, v2}, PrimitiveType.Triangles);
        }
Exemplo n.º 3
0
 public SSVector2I(SSVector2F mVector2F)
 {
     _x = (int) mVector2F.X;
     _y = (int) mVector2F.Y;
 }
Exemplo n.º 4
0
        public override void Update(float mFrameTime)
        {
            Targets.Clear();

            var thisPoint = new SSVector2F(_cBody.Position);

            foreach (var target in Manager.GetEntitiesByTag(TargetTag))
            {
                var body = target.GetComponentUnSafe<CBody>();

                SSVector2I[] targetPoints =
                    {
                        new SSVector2I(body.X, body.Y),
                        new SSVector2I(body.Left, body.Top),
                        new SSVector2I(body.Left, body.Bottom),
                        new SSVector2I(body.Right, body.Top),
                        new SSVector2I(body.Right, body.Bottom)
                    };

                foreach (var targetPoint in targetPoints)
                {
                    var angleVector = Utils.Math.Angles.ToVectorDegrees(180 + Angle);
                    var spanVector = thisPoint - targetPoint;

                    var checkAngle = Math.Abs(angleVector.GetAngleBetween(spanVector));

                    if (double.IsNaN(checkAngle) || checkAngle > Amplitude) continue;

                    var polygons = _cShadower.ShadowCaster.Polygons;
                    if (polygons.Any(x => x.IsIntersecting(targetPoint, 100))) continue;

                    Targets.Add(new Tuple<Entity, SSVector2I>(target, targetPoint));
                    break;
                }
            }
        }
Exemplo n.º 5
0
        public void Update(float mFrameTime)
        {
            if (_isStatic) return;

            PreviousPosition = Position;

            var tempVelocity = new SSVector2F(Velocity.X*mFrameTime, Velocity.Y*mFrameTime);
            var tempPosition = new SSVector2F(Position.X + tempVelocity.X, Position.Y + tempVelocity.Y);

            Position = new SSVector2I((int) tempPosition.X, (int) tempPosition.Y);

            var checkedBodies = new HashSet<Body> {this};
            var bodiesToCheck = World.GetBodies(this);

            foreach (var body in bodiesToCheck.OrderBy(x => Velocity.X > 0 ? x.X : -x.X))
            {
                if (checkedBodies.Contains(body)) continue;
                checkedBodies.Add(body);

                if (!IsOverlapping(body)) continue;

                if (OnCollision != null) OnCollision(new CollisionInfo(mFrameTime, body.UserData, body));
                if (body.OnCollision != null) body.OnCollision(new CollisionInfo(mFrameTime, UserData, this));

                if (GroupsToIgnoreResolve.Any(x => body.Groups.Contains(x))) continue;

                int encrX = 0, encrY = 0;

                if (Bottom < body.Bottom && Bottom >= body.Top) encrY = body.Top - Bottom;
                else if (Top > body.Top && Top <= body.Bottom) encrY = body.Bottom - Top;

                if (Left < body.Left && Right >= body.Left) encrX = body.Left - Right;
                else if (Right > body.Right && Left <= body.Right) encrX = body.Right - Left;

                var overlapX = Left < body.Left ? Right - body.Left : body.Right - Left;
                var overlapY = Top < body.Top ? Bottom - body.Top : body.Bottom - Top;

                Position += overlapX > overlapY ? new SSVector2I(0, encrY) : new SSVector2I(encrX, 0);
            }

            World.UpdateBody(this);
        }
Exemplo n.º 6
0
 private static Vector2f GetDrawPosition(SSVector2F mPosition)
 {
     return new Vector2f(mPosition.X * TDUtils.TileSize + TDUtils.TileSize / 2f, mPosition.Y * TDUtils.TileSize + TDUtils.TileSize / 2f);
 }
Exemplo n.º 7
0
 public bool Equals(SSVector2F mVector)
 {
     return _x == mVector._x && _y == mVector._y;
 }
Exemplo n.º 8
0
 public double GetDotProduct(SSVector2F mVector)
 {
     return X*mVector.X + Y*mVector.Y;
 }
Exemplo n.º 9
0
 public double GetAngleBetween(SSVector2F mVector)
 {
     var cos = GetDotProduct(mVector)/(GetLength()*mVector.GetLength());
     return Utils.Math.Angles.ToDegrees((float) Math.Acos(cos));
 }