Ejemplo n.º 1
0
        public override void Draw(SpriteBatch theSpriteBatch, DebugViewXNA debugView, Matrix projection, Matrix view)
        {
            //Create a single body with multiple fixtures
            this.mtheSpriteBatch = theSpriteBatch;

            Vector2 spritePos = base.mSpriteBody.Position * MeterInPixels;

            theSpriteBatch.Draw(base.mSpriteSheetTexture, spritePos, base.Source,
                Color.White, base.mSpriteBody.Rotation, base.spriteOrigin,
                new Vector2(base.WidthScale, base.HeightScale), SpriteEffects.None, 0f);

            mShipParticles.Draw();

            foreach (SpriteObjects.Shot aShot in mShots)
            {
                if (aShot.Visible == true)
                    aShot.Draw(theSpriteBatch);
            }

            foreach (SpriteObjects.AlternateShot aShot in altShots)
            {
                if (aShot.Visible == true)
                    aShot.Draw(theSpriteBatch);
            }

            if (isAIControlled)
            {
                for (int x = 0; x < numberOfRayCasts; x++)
                {
                    if (raycastHitList[x])
                    {
                        debugView.BeginCustomDraw(ref projection, ref view);
                        debugView.DrawPoint(raycastPointList[x], .5f, new Color(0.4f, 0.9f, 0.4f));

                        debugView.DrawSegment(raycastStartPointList[x], raycastPointList[x], new Color(0.8f, 0.8f, 0.8f));

                        Vector2 head = raycastPointList[x] + 0.5f * raycastNormalList[x];
                        debugView.DrawSegment(raycastPointList[x], head, new Color(0.9f, 0.9f, 0.4f));
                        debugView.EndCustomDraw();

                        //d = √ (x₂ - x₁)^2 + (y₂ - y₁)^2
                        double x1 = raycastStartPointList[x].X;
                        double x2 = raycastPointList[x].X;
                        double y1 = raycastStartPointList[x].Y;
                        double y2 = raycastPointList[x].Y;

                        double xPoints = (x2 - x1) * (x2 - x1);
                        double yPoints = (y2 - y1) * (y2 - y1);

                        float totalLength = (float) Math.Sqrt((xPoints + yPoints));

                        if(rayCastLengths.Count < numberOfRayCasts) {
                            rayCastLengths.Add(totalLength);
                        } else {
                            rayCastLengths[x] = totalLength;
                        }

                        //Console.WriteLine("Total length of ship line ["+x+"] = " + totalLength);

                    }
                    else
                    {
                        debugView.BeginCustomDraw(ref projection, ref view);
                        debugView.DrawSegment(raycastStartPointList[x], raycastEndPointList[x], new Color(0.8f, 0.8f, 0.8f));
                        debugView.EndCustomDraw();

                        // Could do the same calculation with start and enpoints here but
                        //its a bit pointless since the number will always be the constant

                        if (rayCastLengths.Count < numberOfRayCasts)
                        {
                            rayCastLengths.Add(-BASE_SHIP_RAYCAST_LENGTH);
                        }
                        else
                        {
                            rayCastLengths[x] = -BASE_SHIP_RAYCAST_LENGTH;
                        }
                    }
                }
            }
        }