Beispiel #1
0
        private bool ForEachRay(Entity oShadow, object p1, object p2, object p3)
        {
            ShadowRegion shadow = (ShadowRegion)oShadow;

            if (_Shadow == shadow)
            {
                return(true);
            }
            LightSource light = (LightSource)p1;

            Vector3 dir  = light.Position - Position;
            Vector3 diff = shadow.Position - Position;
            float   t    = (diff.X * dir.X + diff.Y * dir.Y) / (dir.X * dir.X + dir.Y * dir.Y);

            if (t < 0.0f)
            {
                t = 0.0f;
            }
            if (t > 1.0f)
            {
                t = 1.0f;
            }
            Vector3 closest = Position + t * dir;
            Vector3 d       = shadow.Position - closest;
            float   distsqr = d.X * d.X + d.Y * d.Y;

            return(distsqr > shadow.Radius * shadow.Radius);
        }
Beispiel #2
0
        public Tile(Screen parent, Vector3 position, String texName, bool collidable)
            : base(((collidable) ? parent.Walls : parent.Tiles), position, new Vector3(TileWidth, TileHeight, 1f), Vector3.Zero)
        {
            base.Initialize();

            // Animations
            _Animations = new AnimationSet();
            _Animations.AddAnimation(new Animation(texName, "Normal", 1, 1, 1.0f));

            if (collidable)
            {
                // Collision settings
                _CollisionType   = CollisionType.Passive;
                _Radius         *= 1.5f;
                _CollisionRadius = _Radius * 0.6f;
                _Shadow          = new ShadowRegion(this, _Position, _Radius);
                _Size.Z          = _Size.X;
            }
            else
            {
                CollisionType = CollisionType.None;
            }

            _EntityClass = texName.Substring(21, (texName.Length - 25));
        }