Ejemplo n.º 1
0
        public void update(GameTime gameTime, QuadTree quadTree)
        {
            if (!beamOn)
            {
                return;
            }
            beamQuanta.Clear();
            //beamQuantum = new Rectangle((int) position.X, (int) position.Y, 1, 3);

            beamDirection = new Vector2((float)Math.Sin(rotation), (float)-Math.Cos(rotation));
            Ray2 ray = new Ray2(position, beamDirection * beamLength);


            distToTarget = 1;

            // find targets within line of fire
            /*List<Tangible> possibleCollisions = quadTree.retrieveNeighbors(owner);*/

            /* This method and may result in missed ships.
             * A different retriever using a raycast
             * will likely be necessary. -Tristan-*/

            List <Tangible> possibleCollisions = GameplayScreen.targets;

            Tangible currentTarget = null;

            foreach (Tangible target in possibleCollisions)
            {
                if (target != owner && target.isActive)
                {
                    if (ray.intersectsToRange(target.getHitBox()))
                    {
                        float temp = ray.getDistance();
                        if (temp <= distToTarget)
                        {
                            // fine hit detection
                            narrowCheck(target, temp, ref currentTarget);
                        }
                    }
                }
            }

            if (currentTarget != null)
            {
                doDamage(currentTarget, gameTime);
            }

            frameIndex = startQuanta;

            for (int i = 0; i < beamLength * distToTarget; ++i)
            {
                beamQuanta.Add(getNextQuanta());
                if (++frameIndex > 4)
                {
                    frameIndex = 0;
                }
            }

            if (--startQuanta < 0)
            {
                startQuanta = 4;
            }
            beamOn = false;
        }