Esempio n. 1
0
File: Entity.cs Progetto: oas/MiNET
        public bool IsColliding(BoundingBox bbox, Entity other)
        {
            //if (!Compare((int) KnownPosition.X, (int) other.KnownPosition.X, 5)) return false;
            //if (!Compare((int) KnownPosition.Z, (int) other.KnownPosition.Z, 5)) return false;
            if (!Compare((int)KnownPosition.X, (int)other.KnownPosition.X, 4))
            {
                return(false);
            }
            if (!Compare((int)KnownPosition.Z, (int)other.KnownPosition.Z, 4))
            {
                return(false);
            }
            if (!bbox.Intersects(other.GetBoundingBox()))
            {
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        public override void OnTick()
        {
            base.OnTick();

            if (KnownPosition.Y <= 0 ||
                (Velocity.Distance <= 0 && DespawnOnImpact) ||
                (Velocity.Distance <= 0 && !DespawnOnImpact && Ttl <= 0))
            {
                DespawnEntity();
                return;
            }

            Ttl--;

            if (KnownPosition.Y <= 0 || Velocity.Distance <= 0)
            {
                return;
            }

            //var bbox = GetBoundingBox();

            Entity entityCollided = CheckEntityCollide(KnownPosition.ToVector3());

            bool collided = false;

            if (entityCollided != null)
            {
                SetIntersectLocation(entityCollided.GetBoundingBox(), KnownPosition);
                entityCollided.HealthManager.TakeHit(this, 2, DamageCause.Projectile);
                collided = true;
            }
            else
            {
                //collided = CheckBlockCollide(KnownPosition);
                if (!collided)
                {
                    var velocity2 = Velocity;
                    velocity2 *= (1.0d - Drag);
                    velocity2 -= new Vector3(0, Gravity, 0);
                    double distance = velocity2.Distance;
                    velocity2 = velocity2.Normalize() / 2;

                    for (int i = 0; i < Math.Ceiling(distance) * 2; i++)
                    {
                        PlayerLocation nextPos = (PlayerLocation)KnownPosition.Clone();
                        nextPos.X += (float)velocity2.X * i;
                        nextPos.Y += (float)velocity2.Y * i;
                        nextPos.Z += (float)velocity2.Z * i;

                        BlockCoordinates coord = new BlockCoordinates(nextPos);
                        Block            block = Level.GetBlock(coord);
                        collided = block.Id != 0 && (block.GetBoundingBox()).Contains(nextPos.ToVector3());
                        if (collided)
                        {
                            var substBlock = new Block(57)
                            {
                                Coordinates = block.Coordinates
                            };
                            //Level.SetBlock(substBlock);
                            //KnownPosition = nextPos;
                            SetIntersectLocation(block.GetBoundingBox(), KnownPosition);
                            break;
                        }
                    }
                }
            }

            if (collided)
            {
                Velocity = Vector3.Zero;
            }
            else
            {
                KnownPosition.X += (float)Velocity.X;
                KnownPosition.Y += (float)Velocity.Y;
                KnownPosition.Z += (float)Velocity.Z;

                Velocity *= (1.0 - Drag);
                Velocity -= new Vector3(0, Gravity, 0);

                var k = Math.Sqrt((Velocity.X * Velocity.X) + (Velocity.Z * Velocity.Z));
                KnownPosition.Yaw   = (float)(Math.Atan2(Velocity.X, Velocity.Z) * 180f / Math.PI);
                KnownPosition.Pitch = (float)(Math.Atan2(Velocity.Y, k) * 180f / Math.PI);
            }

            // For debugging of flight-path
            if (BroadcastMovement)
            {
                BroadcastMoveAndMotion();
            }
        }