예제 #1
0
        public override void Initialize()
        {
            //graphics = new GraphicsDeviceManager(this);

            pb = new PrimitiveBatch(Game.GraphicsDevice);

            land = LanderTextToVector.GetPoints(String.Format("{0}\\{1}.txt", Game.Content.RootDirectory, terrainName)).ToArray();

            landingPads = LanderTextToVector.GetPoints(String.Format("{0}\\{1}.txt", Game.Content.RootDirectory, padName)).ToArray();

            landColor = Color.White;
            padColor  = Color.ForestGreen;

            int height = Game.GraphicsDevice.Viewport.Height;
            int width  = Game.GraphicsDevice.Viewport.Width;

            xScale = (int)((width / horizontalTerrainParts - 1));
            yScale = 0 - (int)((height * (2.0f / 3.0f)) / verticalTerrainParts);

            for (int i = 0; i < land.Length; ++i)
            {
                land[i].X *= (xScale);
                land[i].Y *= yScale;
                land[i].Y += (height);
            }
            for (int i = 0; i < landingPads.Length; ++i)
            {
                landingPads[i].X *= xScale;
                landingPads[i].Y *= yScale;
                landingPads[i].Y += height;
            }

            base.Initialize();
        }
예제 #2
0
        public override void Initialize()
        {
            pb           = new PrimitiveBatch(Game.GraphicsDevice);
            isThrusting  = false;
            gravityPerMS = gravity / 1000.0f;
            thrustPower  = 0 - (gravityPerMS * 2.0f);
            VectorFont.Initialize(Game);
            fullLander = new LanderParts(new List <Vector2>(), new Vector2(15.0f, 5.0f));
            Fuel       = 100;
            angleRad   = MathHelper.ToRadians(0);

            rocketBoosterEffect = Game.Content.Load <SoundEffect>("RocketThrust");

            #region initialize parts
            landerCan = new LanderParts(LanderTextToVector.GetPoints(string.Format("{0}\\{1}", Game.Content.RootDirectory, "LanderCan.txt")), fullLander.Position);

            manCan = new LanderParts(LanderTextToVector.GetPoints(string.Format("{0}\\{1}", Game.Content.RootDirectory, "ManCap.txt")), fullLander.Position);

            thrust1 = new LanderParts(LanderTextToVector.GetPoints(string.Format("{0}\\{1}", Game.Content.RootDirectory, "Thrust.txt")), fullLander.Position);
            thrust2 = new LanderParts(LanderTextToVector.GetXMirrorPoints(string.Format("{0}\\{1}", Game.Content.RootDirectory, "Thrust.txt")), fullLander.Position);

            thruster = new LanderParts(LanderTextToVector.GetPoints(string.Format("{0}\\{1}", Game.Content.RootDirectory, "Thruster.txt")), fullLander.Position);

            legRight = new LanderParts(LanderTextToVector.GetPoints(string.Format("{0}\\{1}", Game.Content.RootDirectory, "LegR.txt")), fullLander.Position);
            legLeft  = new LanderParts(LanderTextToVector.GetXMirrorPoints(string.Format("{0}\\{1}", Game.Content.RootDirectory, "LegR.txt")), fullLander.Position);
            #endregion

            #region construct lander
            LinkedList <Vector2> tempLander = new LinkedList <Vector2>();
            Vector2 partPosition            = new Vector2(0f, 0f);

            foreach (Vector2 v2 in manCan.Part)
            {
                tempLander.AddLast(v2 + partPosition);
            }
            partPosition.Y += 4;
            foreach (Vector2 v2 in landerCan.Part)
            {
                tempLander.AddLast(v2 + partPosition);
            }
            partPosition.Y += 3;
            partPosition.X -= 5;
            foreach (Vector2 v2 in legLeft.Part)
            {
                tempLander.AddLast(v2 + partPosition);
            }
            partPosition.X += 11;
            foreach (Vector2 v2 in legRight.Part)
            {
                tempLander.AddLast(v2 + partPosition);
            }
            partPosition.X -= 5;
            partPosition.Y += 3;
            foreach (Vector2 v2 in thruster.Part)
            {
                tempLander.AddLast(v2 + partPosition);
            }

            partPosition.Y += 1;

            thrustLocation = new Vector2(partPosition.X * landerScale, partPosition.Y * landerScale);
            LinkedListNode <Vector2> node = tempLander.First;

            for (int i = 0; i < tempLander.Count; ++i)
            {
                node.Value *= landerScale;
                node        = node.Next;
                if (i < thrust1.Part.Count)
                {
                    thrust1.Part[i] *= landerScale;
                    thrust2.Part[i] *= landerScale;
                }
            }

            float minimumLanderXPosition = 0;
            float maximumLanderXPosition = 0;
            float minimumLanderYPosition = 0;
            float maximumLanderYPosition = 0;

            foreach (Vector2 v2 in tempLander)
            {
                if (minimumLanderXPosition > v2.X)
                {
                    minimumLanderXPosition = v2.X;
                }
                if (maximumLanderXPosition < v2.X)
                {
                    maximumLanderXPosition = v2.X;
                }
                if (minimumLanderYPosition > v2.Y)
                {
                    minimumLanderYPosition = v2.Y;
                }
                if (maximumLanderYPosition < v2.Y)
                {
                    maximumLanderYPosition = v2.Y;
                }
            }
            Vector2 cornerModifier = new Vector2(0 - minimumLanderXPosition, 0 - minimumLanderYPosition);
            thrustLocation += cornerModifier;
            for (int i = 0; i < thrust1.Part.Count; ++i)
            {
                thrust1.Part[i] += thrustLocation;
                thrust2.Part[i] += thrustLocation;
            }
            landerCenter = new Vector2((maximumLanderXPosition - minimumLanderXPosition) / 2, (maximumLanderYPosition - minimumLanderYPosition) / 2);
            foreach (Vector2 v2 in tempLander)
            {
                fullLander.Part.Add(v2 + cornerModifier);
            }
            #endregion

            Start();
            oldKeyboardState     = new KeyboardState();
            landerColor          = Color.Silver;
            thrustColor          = Color.OrangeRed;
            fullLanderUnmodified = new List <Vector2>(fullLander.Part);
            thrust1Unmodified    = new List <Vector2>(thrust1.Part);
            thrust2Unmodified    = new List <Vector2>(thrust2.Part);

            base.Initialize();
        }