Esempio n. 1
0
        public TextureFont LoadTextureFont(string filename)
        {
            var rv = TextureFont.CreateFromFile(FontsFolder + filename);

            TextureFonts.Add(rv.FontTexture.TextureId, rv);
            return(rv);
        }
Esempio n. 2
0
        protected override void Draw(GameTime gameTime)
        {
            mBackground.Render();

            mBackgroundBigBox.Render(new Rectangle((512 - 200) - 15, 40 - 12, 400 + 23, (768 - (40 + 41)) + 16));
            mBackgroundSmallBox.Render(new Rectangle((512 - 480) - 15 + 10, 40 - 10, 290 - 30, 300));
            mBackgroundSmallBox.Render(new Rectangle((512 + 240) - 15 - 10, 40 - 10, 290 - 30, 190));

            mTetrisGrid.Draw(gameTime);

            TextureFont.WriteText(512 + 230, 50, "Level: ");
            TextureFont.WriteText(512 + 400, 50, (mLevel + 1).ToString());
            TextureFont.WriteText(512 + 230, 90, "Score: ");
            TextureFont.WriteText(512 + 400, 90, mTetrisGrid.TotalScore.ToString());
            TextureFont.WriteText(512 + 230, 130, "Lines: ");
            TextureFont.WriteText(512 + 400, 130, mTetrisGrid.CrushedLines.ToString());
            TextureFont.WriteText(512 + 230, 170, "Highscore: ");
            TextureFont.WriteText(512 + 400, 170, mHighscore.ToString());

            base.Draw(gameTime);

            if (mTetrisGrid.GameOver)
            {
                spriteBatch.Begin();
                spriteBatch.DrawString(CopyrightFont, "Game Over", new Vector2(Window.ClientBounds.Width / 2 - 65, Window.ClientBounds.Height / 2 - 20), Color.White, 0, Vector2.Zero, 3f, SpriteEffects.None, 0);
                spriteBatch.End();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Creates an array of <see cref="TextureFont"/>-s from the <see cref="TrippyFontFile"/>.
        /// </summary>
        /// <param name="font">The <see cref="TrippyFontFile"/> to create fonts from.</param>
        /// <param name="graphicsDevice">The <see cref="GraphicsDevice"/> the <see cref="TextureFont"/>-s will use.</param>
        /// <param name="generateMipmaps">Whether to generate mipmaps for the texture's font.</param>
        public static TextureFont[] CreateFonts(this TrippyFontFile font, GraphicsDevice graphicsDevice, bool generateMipmaps = false)
        {
            if (graphicsDevice == null)
            {
                throw new ArgumentNullException(nameof(graphicsDevice));
            }

            if (font == null)
            {
                throw new ArgumentNullException(nameof(font));
            }

            font.ThrowIfAnyNull();

            Texture2D texture = new Texture2D(graphicsDevice, (uint)font.Image.Width, (uint)font.Image.Height, generateMipmaps);

            try
            {
                TextureFont[] textureFonts = new TextureFont[font.FontDatas.Length];
                for (int i = 0; i < textureFonts.Length; i++)
                {
                    textureFonts[i] = font.FontDatas[i].CreateFont(texture);
                }

                texture.SetData(font.Image);
                return(textureFonts);
            }
            catch
            {
                texture.Dispose();
                throw;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Called once at start to load content
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            background = Content.Load <Texture2D>("DiceTexture.png");
            CardImage  = Content.Load <Texture2D>("Fighter.png");
            CardBack   = Content.Load <Texture2D>("CardBack.png");
            Assassin   = Content.Load <Texture2D>("Assassin.png");
            Archer     = Content.Load <Texture2D>("Archer.png");
            cShip      = Content.Load <Texture2D>("Ship.png");

            cShipDir     = ShipDirection.Straight;
            cShipUseKeys = true;
            cShipShow    = false;

            ConsoleRect = new Texture2D(graphics.GraphicsDevice, 1, 1);
            ConsoleRect.SetData(new[] { Color.DarkGray });

            cFont = new TextureFont(Content.Load <Texture2D>("Font.png"));

            TestCont                = new Container(GraphicsDevice, background, 20, 250, 100, 200);
            TestCont.OpenEffect     = DisplayEffect.SlideRight;
            TestCont.CloseEffect    = DisplayEffect.SlideLeft;
            TestCont.EffectDuration = 500;

            TestCard                 = new CardDisplay(GraphicsDevice, 350, 250, cFont);
            TestCard.Top             = 105;
            TestCard.Left            = 325;
            TestCard.SendMouseEvents = true;
            TestCard.MouseDown      += new ContainerMouseButtonEventHandler(MouseLeftDown);

            cCard            = new CardInfo(CardType.Monster);
            cCard.Background = Content.Load <Texture2D>("CardBase.png");
            cCard.Image      = CardImage;
            cCard.Title      = "Shield Maiden";

            List <string> Lines = new List <string>();

            Lines.Add("Health: 5");
            Lines.Add("Attack: 3");
            Lines.Add("");
            Lines.Add("Women of Rohan");
            cCard.Description = Lines;
            cCard.Changed     = true;

            TestCard.Card = cCard;

            NestedCont = new Container(GraphicsDevice, null, 350, 600, 100, 100);
            NestedCont.BackgroundColor = Color.BurlyWood;
            NestedCont.Visible         = true;

            cTextTest = new TextBox(GraphicsDevice, null, GraphicsDevice.Viewport.Height - 150, GraphicsDevice.Viewport.Width - 200, 125, 175);
            cTextTest.BackgroundColor = Color.CornflowerBlue;
            cTextTest.FontColor       = Color.Bisque;
            cTextTest.Font            = cFont;
            cTextTest.Visible         = true;

            DevConsole.AddText("Viewport Bounds: X=" + GraphicsDevice.Viewport.Bounds.X + " Y=" + GraphicsDevice.Viewport.Bounds.Y + " Width=" + GraphicsDevice.Viewport.Bounds.Width + " Height=" + GraphicsDevice.Viewport.Bounds.Height);
        }
Esempio n. 5
0
 /// <summary>
 /// Load all graphics content (just our background texture).
 /// Use this method to make sure a device reset event is handled correctly.
 /// </summary>
 /// <param name="loadAllContent">Load everything?</param>
 protected override void LoadContent()
 {
     spriteBatch   = new SpriteBatch(GraphicsDevice);
     CopyrightFont = content.Load <SpriteFont>("Copyright");
     font          = new TextureFont(graphics.GraphicsDevice, content);
     base.LoadContent();
 }
        }         // Render()

        #endregion

        #region Unit testing
#if DEBUG
        public static void TestRenderSingleAsteroid()
        {
            //Model testModel1 = null;
            GameAsteroidManager asteroidManager = null;

            TestGame.Start(
                "TestRenderSingleAsteroid",
                delegate
            {
                //testModel1 = new Model("asteroid1");
                // Initialize asteroidManager and use last avialable level.
                asteroidManager = new GameAsteroidManager(
                    Level.LoadAllLevels()[0]);
            },
                delegate
            {
                // Render sky cube map as our background.
                BaseGame.skyCube.RenderSky(1.0f, BaseGame.remSkyBackgroundColor);

                asteroidManager.Render(null, null);

                //tst: render asteroid in center
                //asteroidManager.GetAsteroidModel(0).Render(
                //	Matrix.CreateScale(15, 15, 15));
                //testModel1.Render(Matrix.CreateScale(4));

                BaseGame.MeshRenderManager.Render();

                TextureFont.WriteText(2, 30,
                                      "cam pos=" + BaseGame.CameraPos);
            });
        }         // TestRenderSingleAsteroid()
Esempio n. 7
0
        }         // WriteCreditsWithLink(xPos, yPos, leftText)

        #endregion

        #region Run
        /// <summary>
        /// Run game screen. Called each frame.
        /// </summary>
        /// <param name="game">Form for access to asteroid manager and co</param>
        public void Run(RocketCommanderGame game)
        {
            // Render background
            game.RenderMenuBackground();

            // Credits
            int xPos = 50 * BaseGame.Width / 1024;
            int yPos = 180 * BaseGame.Height / 768;

            TextureFont.WriteText(xPos, yPos, Texts.Credits);

            WriteCreditsWithLink(xPos, yPos + 72, "Idea, Design, Programming",
                                 "Benjamin Nitschke (abi)",
                                 "http://abi.exdream.com", game);
            WriteCredits(xPos, yPos + 167, "Thanks fly out to",
                         "Christoph Rienäcker, Leif Griga, Boje Holtz,");
            WriteCredits(xPos, yPos + 217, "",
                         "Enrico Cieslik (Judge), ZMan (www.thezbuffer.com),");
            WriteCredits(xPos, yPos + 267, "",
                         "Dirk Primbs and Christina Storm of Microsoft and");
            WriteCredits(xPos, yPos + 317, "",
                         "and the XNA and .NET Teams at Microsoft :)");

            TextureFont.WriteText(xPos, 647 * BaseGame.Height / 768,
                                  "Dedicated to the great XNA Framework.");

            if (game.RenderMenuButton(MenuButton.Back,
                                      new Point(1024 - 230, 768 - 150)))
            {
                quit = true;
            }     // if
        }         // Run(game)
Esempio n. 8
0
        }         // Update()

        #endregion

        #region Unit Testing
#if DEBUG
        /// <summary>
        /// Test play sounds
        /// </summary>
        //[Test]
        public static void TestPlaySounds()
        {
            //int crazyCounter = 0;

            TestGame.Start(
                delegate
            {
                if (Input.MouseLeftButtonJustPressed ||
                    Input.GamePadAJustPressed)
                {
                    Sound.Play(Sounds.Bomb);
                }
                else if (Input.MouseRightButtonJustPressed ||
                         Input.GamePadBJustPressed)
                {
                    Sound.Play(Sounds.Click);
                }
                else if (Input.KeyboardKeyJustPressed(Keys.D1))
                {
                    Sound.Play(Sounds.GameMusic);
                }
                else if (Input.KeyboardKeyJustPressed(Keys.D2))
                {
                    Sound.Play(Sounds.MenuMusic);
                }
                else if (Input.KeyboardKeyJustPressed(Keys.D3))
                {
                    Sound.Play(Sounds.Explosion);
                }
                else if (Input.KeyboardKeyJustPressed(Keys.D4))
                {
                    Sound.Play(Sounds.Fuel);
                }
                else if (Input.KeyboardKeyJustPressed(Keys.D5))
                {
                    Sound.Play(Sounds.Victory);
                }
                else if (Input.KeyboardKeyJustPressed(Keys.D6))
                {
                    Sound.Play(Sounds.Defeat);
                }
                else if (Input.KeyboardKeyJustPressed(Keys.D7))
                {
                    Sound.PlayRocketMotorSound(0.75f);
                    Sound.ChangeRocketMotorPitchEffect(0.5f);
                }                         // else if
                else if (Input.KeyboardKeyJustPressed(Keys.D8))
                {
                    Sound.StopRocketMotorSound();
                }
                else if (Input.KeyboardKeyJustPressed(Keys.D9))
                {
                    Sound.Play(Sounds.Whosh);
                }

                TextureFont.WriteText(2, 30,
                                      "Press 1-8 or A/B or left/right mouse buttons to play back " +
                                      "sounds!");
            });
        }         // TestPlaySounds()
Esempio n. 9
0
        public EditorVisual(ViewRegistry registry)
        {
            _registry = registry;

            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.CullFace);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.Enable(EnableCap.Blend);
            GL.Enable(EnableCap.Texture2D);

            _raytraceVoxelPosition = Vector3.Zero;

            _chunkMeshes     = new Dictionary <Vector3I, VoxelMesh>();
            _chunkPartMeshes = new Dictionary <Vector3I, VoxelMesh>();

            _chunkGeometrys      = new Dictionary <Vector3I, VAO>();
            _chunkDepthGeometrys = new Dictionary <Vector3I, VAO>();
            _amountBuffers       = new Dictionary <Vector3I, BufferObject>();
            _idBuffers           = new Dictionary <Vector3I, BufferObject>();

            _renderToTexture          = new FBO[5];
            _renderToTextureWithDepth = new FBO[2];

            _textureIDs           = new Dictionary <int, int>();
            _materialTextureArray = new Texture(OpenGl4.TextureTarget.Texture2DArray);
            _crosshairs           = TextureLoader.FromBitmap(Resourcen.FadenkreuzBW);
            _groundTexture        = TextureLoader.FromBitmap(_registry.GetMaterialInfo(1).Texture);
            _font = new TextureFont(TextureLoader.FromBitmap(Resourcen.Coders_Crux), 16, 0, 0.6f, 0.9f, 0.75f);

            InitializeMaterialTextures();
        }
Esempio n. 10
0
        /// <summary>
        /// Load all external content files that are needed
        /// </summary>
        protected override void LoadContent()
        {
            TextureFont Font;

            Content.RootDirectory = INTERFACECONTENTDIR;

            Font = new TextureFont(Content.Load <Texture2D>("Font.png"));

            try {
                cDevConsole              = new GameConsole(cGraphDevMgr.GraphicsDevice, Content, "Font.png", cGraphDevMgr.GraphicsDevice.Viewport.Width, cGraphDevMgr.GraphicsDevice.Viewport.Height / 2);
                cDevConsole.AccessKey    = Keys.OemTilde;
                cDevConsole.UseAccessKey = true;
                cDevConsole.OpenEffect   = DisplayEffect.SlideDown;
                cDevConsole.CloseEffect  = DisplayEffect.SlideUp;
                cDevConsole.CommandSent += new CommandSentEventHandler(ConsoleCommandEvent);
            } catch (Exception ExErr) {
                System.Windows.Forms.MessageBox.Show("Failed to initialize console: " + ExErr.GetType().ToString() + " - " + ExErr.Message);
                Exit();
                return;
            }

            cTileSets = new TileSetManager(Content, INTERFACECONTENTDIR + @"\Tiles.XML", "/tilescene/tilesets");

            cSceneMgr = new TileSceneManager(cTileSets, INTERFACECONTENTDIR + @"\Tiles.XML", "/tilescene");

            cSpriteMgr = new SpriteManager(cTileSets, INTERFACECONTENTDIR + @"\Tiles.XML", "/tilescene");
        }
Esempio n. 11
0
        }         // Show()

        #endregion

        #region Unit Testing
#if DEBUG
        /// <summary>
        /// Test post screen glow
        /// </summary>
        public static void TestPostScreenGlow()
        {
            Model          testModel  = null;
            PostScreenGlow glowShader = null;

            TestGame.Start("TestPostScreenGlow",
                           delegate
            {
                testModel  = new Model("Asteroid2");
                glowShader = new PostScreenGlow();
            },
                           delegate
            {
                //Thread.Sleep(10);

                glowShader.Start();

                BaseGame.skyCube.RenderSky();

                testModel.Render(Vector3.Zero);
                BaseGame.MeshRenderManager.Render();

                if (Input.Keyboard.IsKeyDown(Keys.LeftAlt) == false &&
                    Input.GamePadAPressed == false)
                {
                    glowShader.Show();
                }
                else
                {
                    // Resolve first
                    glowShader.sceneMapTexture.Resolve(false);
                    started = false;

                    // Reset background buffer
                    RenderToTexture.ResetRenderTarget(true);
                    // Just show scene map
                    glowShader.sceneMapTexture.RenderOnScreen(BaseGame.ResolutionRect);
                }                         // else

                TextureFont.WriteText(2, 30,
                                      "Press left alt or A to just show the unchanged screen.");
                TextureFont.WriteText(2, 60,
                                      "Press space or B to see all menu post screen render passes.");

                //*TODO
                if (Input.Keyboard.IsKeyDown(Keys.Space) ||                        // == false)
                    Input.GamePadBPressed)
                {
                    glowShader.sceneMapTexture.RenderOnScreen(
                        new Rectangle(10, 10, 256, 256));
                    glowShader.downsampleMapTexture.RenderOnScreen(
                        new Rectangle(10 + 256 + 10, 10, 256, 256));
                    glowShader.blurMap1Texture.RenderOnScreen(
                        new Rectangle(10 + 256 + 10 + 256 + 10, 10, 256, 256));
                    glowShader.blurMap2Texture.RenderOnScreen(
                        new Rectangle(10, 10 + 256 + 10, 256, 256));
                } // if (Input.Keyboard.IsKeyDown)
            });
        }         // TestPostScreenGlow()
Esempio n. 12
0
        public CardDisplay(GraphicsDevice GraphDev, int Height, int Width, TextureFont Font) : base(GraphDev, Height, Width)
        {
            this.OpenEffect      = DisplayEffect.Fade;
            this.CloseEffect     = DisplayEffect.Fade;
            this.BackgroundColor = new Color(255, 255, 255, 0);
            cFont = Font;

            cIsFullCard = true;
        }
Esempio n. 13
0
        public FontGL(IContentLoader contentLoader)
        {
            //shdFont = context.CreateShader();
            //shdFont.FromStrings(Tools.ToString(Resourcen.texColorVert), Tools.ToString(Resourcen.texColorFrag));
            //locCamera = shdFont.GetResourceLocation(ShaderResourceType.Uniform, "camera");
            GL.Enable(EnableCap.Texture2D);             //TODO: only for non shader pipeline relevant -> remove at some point

            font = new TextureFont(contentLoader.Load <ITexture2D>("Video Phreak"), 10, 32, 1, 1, .7f);
        }
Esempio n. 14
0
 public View(IRenderState renderState, IContentLoader contentLoader)
 {
     renderState.Set(BlendStates.AlphaBlend);
     renderState.Set(new LineWidth(5f));
     texWhite = contentLoader.Load <ITexture2D>("white");
     texBlack = contentLoader.Load <ITexture2D>("black");
     texTable = contentLoader.Load <ITexture2D>("pool_table");
     font     = new TextureFont(contentLoader.Load <ITexture2D>("Fire 2"), 10, 32, 1.0f, 0.9f, 0.5f);
     GL.Enable(EnableCap.Texture2D);             //TODO: only for non shader pipeline relevant -> remove at some point
 }
Esempio n. 15
0
 /// <summary>
 /// Show car property bar for car selection to differentiate
 /// the different cars.
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="propertyName"></param>
 /// <param name="value"></param>
 private void ShowCarPropertyBar(int x, int y,
                                 string propertyName, float value)
 {
     TextureFont.WriteText(x, y, propertyName);
     RacingGameManager.UI.OptionsScreen.RenderOnScreen(
         //try1: new Rectangle(x + BaseGame.XToRes(150), y + BaseGame.YToRes(5),
         //BaseGame.XToRes((int)(145 * value)), BaseGame.YToRes(6)),
         new Rectangle(x, y + BaseGame.YToRes(29),
                       BaseGame.XToRes((int)(192 * value)), BaseGame.YToRes(6)),
         gfxBarFromOptionsScreen);
 }
Esempio n. 16
0
        public static TextureFont LoadFont(FontData fontData)
        {
            var texture = LoadTexture(fontData.FontSheet);

            var font = new TextureFont(texture, fontData)
            {
                Id = fontData.Id
            };

            return(font);
        }
Esempio n. 17
0
 private MyVisual()
 {
     //load font
     font = new TextureFont(TextureLoader.FromBitmap(Resourcen.Blood_Bath_2), 10, 32, .8f, 1, .7f);
     //background clear color
     GL.ClearColor(Color.Black);
     //for transparency in textures
     GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
     GL.Enable(EnableCap.Blend);         // for transparency in textures
     GL.Color3(Color.White);             //color is multiplied with texture color white == no change
 }
Esempio n. 18
0
        private MyVisual(IRenderState renderState, IContentLoader contentLoader)
        {
            //for transparency in textures we use blending
            renderState.Set(BlendStates.AlphaBlend);

            //load font
            font = new TextureFont(contentLoader.Load <ITexture2D>("Blood Bath 2"), 10, 32, .8f, 1, .7f);
            //background clear color
            renderState.Set(new ClearColorState(0, 0, 0, 1));

            GL.Enable(EnableCap.Texture2D);     //TODO: only for non shader pipeline relevant -> remove at some point
            GL.Color3(Color.White);             //color is multiplied with texture color white == no change
        }
Esempio n. 19
0
        public void ReadBinary()
        {
            TextureFont font = TextureFont.FromFile("./TestFiles/Arial 18.txf");

            Assert.IsNotNull(font);

            Assert.IsTrue(font.TextureData != null && font.TextureData.Length > 0);

            Assert.IsTrue(font.CharacterMap.Count == 224);
            Assert.IsTrue(font.CroppingData.Count == 224);

            Assert.IsTrue(font.CharacterMap[0] == ' ');
            Assert.IsTrue(font.CharacterMap[1] == '!');
        }
Esempio n. 20
0
        protected override void LoadContent()
        {
            cDrawBatch = new SpriteBatch(cGraphDevMgr.GraphicsDevice);

            cSolidTexture = new Texture2D(cGraphDevMgr.GraphicsDevice, 1, 1);
            //cSolidTexture.SetData (new[] { new Color(255, 255, 255, 100) });
            //cSolidTexture.SetData (new[] { new Color(0, 0, 0, 100) });
            cSolidTexture.SetData(new[] { Color.White });

            foreach (Textures CurrTexture in Enum.GetValues(typeof(Textures)))
            {
                cTextureDict.Add(CurrTexture, Content.Load <Texture2D>(Tools.EnumTools.GetEnumDescriptionAttribute(CurrTexture)));
            }

            //cShader = Content.Load<Effect>("ShaderEffect");
            //cShipShader = Content.Load<Effect>("BumpMap");
            //cShipShader.Parameters["NormalMap"].SetValue(cTextureDict[Textures.ShipNormal]);

            cFont                    = new TextureFont(cTextureDict[Textures.Font]);
            cDevConsole              = new MDLN.MGTools.GameConsole(cGraphDevMgr.GraphicsDevice, Content, Content.RootDirectory + "\\Font.png", 0, 0, cGraphDevMgr.GraphicsDevice.Viewport.Bounds.Width, cGraphDevMgr.GraphicsDevice.Viewport.Bounds.Height / 2);
            cDevConsole.CommandSent += CommandSentEventHandler;
            cDevConsole.OpenEffect   = DisplayEffect.SlideDown;
            cDevConsole.CloseEffect  = DisplayEffect.SlideUp;

            cPlayerShip = new Ship(cGraphDevMgr.GraphicsDevice, 50);
            cPlayerShip.BackgroundColor = new Color(100, 100, 100, 0);             //Set background completely transparent
            cPlayerShip.ShipTexture     = cTextureDict[Textures.Ship];
            cPlayerShip.Visible         = true;
            cPlayerShip.Top             = cGraphDevMgr.GraphicsDevice.Viewport.Bounds.Height / 2;
            cPlayerShip.Left            = cGraphDevMgr.GraphicsDevice.Viewport.Bounds.Width / 2;
            //cPlayerShip.ImageInitialAngle = 1.570796f; //Offset for image pointing up instead of right
            cPlayerShip.MouseRotate = true;

            cPlayerBullets = new ParticleEngine2D(cGraphDevMgr.GraphicsDevice);
            cPlayerBullets.DrawBlendingMode = BlendState.Additive;
            //cPlayerBullets.ShaderEffect = cShader;

            cEnemyBullets = new ParticleEngine2D(cGraphDevMgr.GraphicsDevice);
            cEnemyBullets.DrawBlendingMode = BlendState.Additive;

            cAsteroids = new ParticleEngine2D(cGraphDevMgr.GraphicsDevice);
            cAsteroids.WrapScreenEdges = true;

            cUFOs = new ParticleEngine2D(cGraphDevMgr.GraphicsDevice);
            //cUFOs.ShaderEffect = cShipShader;
            cUFOs.WrapScreenEdges = true;

            cSparkles = new ParticleEngine2D(cGraphDevMgr.GraphicsDevice);
            cSparkles.DrawBlendingMode = BlendState.Additive;
        }
Esempio n. 21
0
        }         // AddDistanceToBeDisplayed(screenPos, distance, alpha)

        /// <summary>
        /// Show all distances
        /// </summary>
        public void ShowAllDistances()        //TextureFont TextureFont)
        {
            foreach (PosAndDistance posDistance in remToDisplayDistance)
            {
                TextureFont.WriteSmallTextCentered(
                    posDistance.pos.X, posDistance.pos.Y + 40,
                    // Only display full numbers (round them up)
                    Texts.Distance + ": " +
                    (int)Math.Round(posDistance.distance / SectorDepth - 0.26f),
                    // Only display with half the alpha!
                    posDistance.alpha * 0.5f);
            }             // foreach  (posDistance)

            // Clear
            remToDisplayDistance.Clear();
        }         // ShowAllDistances()
Esempio n. 22
0
        protected override void OnLoad()
        {
            shaderProgram = SimpleShaderProgram.Create <VertexColorTexture>(graphicsDevice, 0, 0, true);

            particleTexture = Texture2DExtensions.FromFile(graphicsDevice, "particles.png");
            particleTexture.SetTextureFilters(TextureMinFilter.Nearest, TextureMagFilter.Nearest);
            rectangleTexture = Texture2DExtensions.FromFile(graphicsDevice, "rectangle.png");
            ballTexture      = Texture2DExtensions.FromFile(graphicsDevice, "ball.png");
            diamondTexture   = Texture2DExtensions.FromFile(graphicsDevice, "diamond.png");

            TextureFont[] fonts = TextureFontExtensions.FromFile(graphicsDevice, "font.tglf");
            comicSansFont = fonts[0];
            arialFont     = fonts[1];

            textureBatcher = new TextureBatcher(graphicsDevice);
            textureBatcher.SetShaderProgram(shaderProgram);

            graphicsDevice.DepthState = DepthState.None;
            graphicsDevice.BlendState = BlendState.NonPremultiplied;
            graphicsDevice.ClearColor = new Vector4(0.1f, 0.65f, 0.5f, 1f);

            MaxX = Window.Size.Width;
            MaxY = Window.Size.Height;

            Particle.texture = particleTexture;
            Diamond.texture  = diamondTexture;
            Ball.texture     = ballTexture;

            particles = new LinkedList <Particle>();

            diamonds = new Diamond[40];
            for (int i = 0; i < diamonds.Length; i++)
            {
                diamonds[i] = new Diamond();
            }

            balls = new Ball[40];
            for (int i = 0; i < balls.Length; i++)
            {
                balls[i] = new Ball();
            }

            stopwatch = Stopwatch.StartNew();

            graphicsDevice.CullFaceMode       = CullFaceMode.Back;
            graphicsDevice.FaceCullingEnabled = true;
        }
Esempio n. 23
0
        public override void Draw(GameTime gameTime)
        {
            TextureFont.WriteText(nextBlockRect.X + 5, nextBlockRect.Y + 10, "Next:");

            Rectangle gridRect    = new Rectangle(nextBlockRect.X + 5, nextBlockRect.Y + 43, nextBlockRect.Width - 15, nextBlockRect.Height - 46);
            int       blockWidth  = gridRect.Width / PreviewGridWidth;
            int       blockHeight = gridRect.Height / PreviewGridHeight;

            for (int x = 0; x < PreviewGridWidth; x++)
            {
                for (int y = 0; y < PreviewGridHeight; y++)
                {
                    int[,] blockData = TetrisGrid.BlockTypeShapesNormal[(int)nextBlockType];
                    bool isFilled = x > 0 && y > 0 && x - 1 < blockData.GetLength(0) && y - 1 < blockData.GetLength(1) && blockData[x - 1, y - 1] != 0;
                    game.BlockSprite.Render(new Rectangle(gridRect.X + x * blockWidth, gridRect.Y + y * blockHeight, blockWidth - 1, blockHeight - 1), TetrisGrid.BlockColor[isFilled ? (int)nextBlockType : 0]);
                }
            }
        }
Esempio n. 24
0
        }         // Update()

        #endregion

        #region Unit testing
        public static void TestXboxControllerInput()
        {
            TestGame.Start(
                delegate
            {
                if (Input.GamePadAJustPressed)
                {
                    Input.GamePadRumble(0.35f, 0.475f);
                }
                else if (Input.GamePadBJustPressed)
                {
                    Input.GamePadRumble(0.85f, 0.95f);
                }

                TextureFont.WriteText(30, 60, "Press A for a little gamepad rumble" +
                                      "and B for heavy gamepad rumble effect");
            });
        }         // TestXboxControllerInput()
Esempio n. 25
0
        }         // Update()

        #endregion

        #region Unit Testing
#if DEBUG
        /// <summary>
        /// Test space camera
        /// </summary>
        public static void TestSpaceCamera()
        {
            Model testModel = null;

            TestGame.Start("TestSpaceCamera",
                           delegate      // Init
            {
                testModel = new Model("asteroid4");
            },
                           delegate      // Render loop
            {
                // Just render testModel in the middle of the scene.
                testModel.Render(Vector3.Zero);

                TextureFont.WriteText(1, 20,
                                      "MoveFactorPerSecond=" + BaseGame.MoveFactorPerSecond);
            });
        }         // TestSpaceCamera()
        /// <summary>
        /// Render loading screen
        /// </summary>
        public bool Render()
        {
            SpriteBatch textBatch = new SpriteBatch(BaseGame.Device);
            Vector2     position  = new Vector2((BaseGame.Width / 2) - 50, (BaseGame.Height / 2) - 20);

            for (int i = 0; i < loadingText.Length; i++)
            {
                string charStr    = new string(loadingText[i], 1);
                int    charHeight = (int)(position.Y + 7 * Math.Abs(Math.Sin((i / 4f) + (-BaseGame.TotalTime * 3))));
                TextureFont.WriteText((int)position.X, charHeight, charStr, Color.Red);

                position.X += TextureFont.GetTextWidth(charStr);
            }

            TextureFont.WriteTextCentered(BaseGame.Width / 2, (int)position.Y + 40, loadingStatus);

            return(RacingGameManager.ContentLoaded);
        }
Esempio n. 27
0
        }         // WriteCredits(xPos, yPos, leftText)

        /// <summary>
        /// Write credits with link
        /// </summary>
        /// <param name="xPos">X coordinate</param>
        /// <param name="yPos">Y coordinate</param>
        /// <param name="leftText">Left text</param>
        /// <param name="rightText">Right text</param>
        /// <param name="linkText">Link text</param>
        private void WriteCreditsWithLink(int xPos, int yPos, string leftText,
                                          string rightText, string linkText, RocketCommanderGame game)
        {
            WriteCredits(xPos, yPos, leftText, rightText);

            // Process link (put below rightText)
            bool overLink = Input.MouseInBox(new Rectangle(
                                                 xPos + 440, yPos + 8 + TextureFont.Height, 400, TextureFont.Height));

            TextureFont.WriteText(xPos + 440, yPos /*+ 8*/ + TextureFont.Height, linkText,
                                  overLink ? Color.Red : Color.White);
            if (overLink &&
                Input.MouseLeftButtonJustPressed)
            {
#if !XBOX360
                new Thread(new ThreadStart(delegate
                {
                    Process.Start(linkText);
                })).Start();
                Thread.Sleep(100);
#endif
            }     // if
        }         // WriteCreditsWithLink(xPos, yPos, leftText)
Esempio n. 28
0
 public MyApplication()
 {
     gameWindow.Resize  += GameWindow_Resize;
     gameWindow.KeyDown += (sender, e) => { if (Key.Escape == e.Key)
                                            {
                                                gameWindow.Exit();
                                            }
     };
     gameWindow.MouseDown   += GameWindow_MouseDown;
     gameWindow.RenderFrame += GameWindow_RenderFrame;
     gameWindow.RenderFrame += (sender, e) => { gameWindow.SwapBuffers(); };
     GL.ClearColor(Color.Black);
     for (int x = 0; x < gridRes; ++x)
     {
         for (int y = 0; y < gridRes; ++y)
         {
             grid[x, y] = FieldType.EMPTY;
         }
     }
     texWhite = TextureLoader.FromBitmap(Resourcen.white);
     texBlack = TextureLoader.FromBitmap(Resourcen.black);
     texWater = TextureLoader.FromBitmap(Resourcen.water);
     font     = new TextureFont(TextureLoader.FromBitmap(Resourcen.Fire_2), 10, 32, 1.0f, 0.9f, 0.5f);
 }
Esempio n. 29
0
 public void SetFont(TextureFont font)
 {
     this.font = font;
 }
Esempio n. 30
0
        // Rest of car variables is automatically calculated below!
        #endregion

        #region Render
        /// <summary>
        /// Render
        /// </summary>
        /// <returns>Bool</returns>
        public bool Render()
        {
            if (BaseGame.AllowShadowMapping)
            {
                // Let camera point directly at the center, around 10 units away.
                BaseGame.ViewMatrix = Matrix.CreateLookAt(
                    new Vector3(0, 10.45f, 2.75f),
                    new Vector3(0, 0, -1),
                    new Vector3(0, 0, 1));

                // Let the light come from the front!
                Vector3 lightDir = -LensFlare.DefaultLightPos;
                lightDir = new Vector3(lightDir.X, lightDir.Y, -lightDir.Z);
                // LightDirection will normalize
                BaseGame.LightDirection = lightDir;

                // Show 3d cars
                // Rotate all 3 cars depending on the current selection
                float perCarRot = MathHelper.Pi * 2.0f / 3.0f;
                float newCarSelectionRotationZ =
                    RacingGameManager.currentCarNumber * perCarRot;
                carSelectionRotationZ = InterpolateRotation(
                    carSelectionRotationZ, newCarSelectionRotationZ,
                    BaseGame.MoveFactorPerSecond * 5.0f);
                // Prebuild all render matrices, we will use them for several times
                // here.
                Matrix[] renderMatrices = new Matrix[3];
                for (int carNum = 0; carNum < 3; carNum++)
                {
                    renderMatrices[carNum] =
                        Matrix.CreateRotationZ(BaseGame.TotalTime / 3.9f) *
                        Matrix.CreateTranslation(new Vector3(0, 5.0f, 0)) *
                        Matrix.CreateRotationZ(-carSelectionRotationZ + carNum * perCarRot) *
                        Matrix.CreateTranslation(new Vector3(1.5f, 0.0f, 1.0f));
                }
                // Last translation translates the position of the cars in the UI;

                // For shadows make sure the car position is the origin
                RacingGameManager.Player.SetCarPosition(Vector3.Zero,
                                                        new Vector3(0, 1, 0), new Vector3(0, 0, 1));

                // Generate shadows
                ShaderEffect.shadowMapping.GenerateShadows(
                    delegate
                {
                    for (int carNum = 0; carNum < 3; carNum++)
                    {
                        // Only the car throws shadows
                        RacingGameManager.CarModel.GenerateShadow(
                            renderMatrices[carNum]);
                    }
                });

                // Render shadows
                ShaderEffect.shadowMapping.RenderShadows(
                    delegate
                {
                    for (int carNum = 0; carNum < 3; carNum++)
                    {
                        // Both the car and the selection plate receive shadows
                        RacingGameManager.CarSelectionPlate.UseShadow(
                            renderMatrices[carNum]);
                        RacingGameManager.CarModel.UseShadow(renderMatrices[carNum]);
                    }
                });
            }

            // This starts both menu and in game post screen shader!
            // It will render into the sceneMap texture which we will use
            // later then.
            BaseGame.UI.PostScreenMenuShader.Start();

            // Render background and black bar
            BaseGame.UI.RenderMenuBackground();
            BaseGame.UI.RenderBlackBar(170, 390);

            // Immediately paint here, else post screen UI will
            // be drawn over!
            Texture.additiveSprite.End();
            Texture.alphaSprite.End();
            //SpriteHelper.DrawAllSprites();

            // Restart the sprites after the paint
            Texture.additiveSprite.Begin(SpriteBlendMode.Additive);
            Texture.alphaSprite.Begin(SpriteBlendMode.AlphaBlend);

            // Cars header
            int posX = 10;
            int posY = 18;

            if (Environment.OSVersion.Platform != PlatformID.Win32NT)
            {
                posX += 36;
                posY += 26;
            }

            BaseGame.UI.Headers.RenderOnScreenRelative1600(
                posX, posY, UIRenderer.HeaderChooseCarGfxRect);

            // Allow selecting the car color
            TextureFont.WriteText(BaseGame.XToRes(85), BaseGame.YToRes(512),
                                  "Car Color: ");
            for (int num = 0; num < RacingGameManager.CarColors.Count; num++)
            {
                Rectangle rect =
                    RacingGameManager.currentCarColor == num?
                    BaseGame.CalcRectangle(250 + num * 50 - 6, 500 - 6, 46 + 12, 46 + 12) :
                        BaseGame.CalcRectangle(250 + num * 50, 500, 46, 46);

                RacingGameManager.colorSelectionTexture.RenderOnScreen(
                    rect, RacingGameManager.colorSelectionTexture.GfxRectangle,
                    RacingGameManager.CarColors[num]);

                if (Input.MouseInBox(rect) &&
                    Input.MouseLeftButtonPressed)
                {
                    if (RacingGameManager.currentCarColor != num)
                    {
                        Sound.Play(Sound.Sounds.Highlight);
                    }
                    RacingGameManager.currentCarColor = num;
                }
            }

            // Show car maxSpeed, Acceleration and Mass values.
            // Also show braking, friction and engine values based on that.
            CarPhysics.SetCarVariablesForCarType(
                CarTypeMaxSpeed[RacingGameManager.currentCarNumber],
                CarTypeMass[RacingGameManager.currentCarNumber],
                CarTypeMaxAcceleration[RacingGameManager.currentCarNumber]);

            // Show info and helper texts
            //TextureFont.WriteText(30, BaseGame.YToRes(280),
            //    "Car: Left/Right");
            //TextureFont.WriteText(30, BaseGame.YToRes(370),
            //    "Color: Up/Down");

            // Calculate values
            float maxSpeed =
                -1.5f + 2.45f *
                (CarTypeMaxSpeed[RacingGameManager.currentCarNumber] /
                 CarPhysics.DefaultMaxSpeed);
            float acceleration =
                -1.25f + 1.85f *
                (CarTypeMaxAcceleration[RacingGameManager.currentCarNumber] /
                 CarPhysics.DefaultMaxAccelerationPerSec);
            float mass =
                -0.65f + 1.5f *
                (CarTypeMass[RacingGameManager.currentCarNumber] /
                 CarPhysics.DefaultCarMass);
            float braking =
                -0.2f + acceleration - mass + maxSpeed;
            float friction =
                -1 + (1 / mass + maxSpeed / 5);
            float engine =
                -0.2f + 0.5f * (maxSpeed / mass + acceleration - maxSpeed * 5 + 5);

            if (engine > 0.95f)
            {
                engine = 0.95f;
            }

            ShowCarPropertyBar(
                BaseGame.XToRes(1024 - 258), BaseGame.YToRes(190),
                "Max Speed: " +
                (int)(CarTypeMaxSpeed[RacingGameManager.currentCarNumber] /
                      CarPhysics.MphToMeterPerSec) + "mph",
                maxSpeed);
            ShowCarPropertyBar(
                BaseGame.XToRes(1024 - 258), BaseGame.YToRes(235),
                "Acceleration:", acceleration);
            ShowCarPropertyBar(
                BaseGame.XToRes(1024 - 258), BaseGame.YToRes(280),
                "Car Mass:",
                mass);
            ShowCarPropertyBar(
                BaseGame.XToRes(1024 - 258), BaseGame.YToRes(335),
                "Braking:", braking);
            ShowCarPropertyBar(
                BaseGame.XToRes(1024 - 258), BaseGame.YToRes(390),
                "Friction:", friction);
            ShowCarPropertyBar(
                BaseGame.XToRes(1024 - 258), BaseGame.YToRes(445),
                "Engine:", engine);

            // Also show bouncing arrow on top of car
            float arrowWave =
                (float)Math.Sin(BaseGame.TotalTime / 0.46f) *
                (float)Math.Cos(BaseGame.TotalTime / 0.285f);
            float     arrowScale = 0.75f - 0.065f * arrowWave;
            Rectangle arrowRect  = BaseGame.CalcRectangle(512, 120,
                                                          (int)Math.Round(UIRenderer.BigArrowGfxRect.Width * arrowScale),
                                                          (int)Math.Round(UIRenderer.BigArrowGfxRect.Width * arrowScale));

            arrowRect.X -= arrowRect.Width / 2;
            // Not displayed anymore ..

            // Show left/right arrows
            Rectangle selArrowGfxRect = UIRenderer.SelectionArrowGfxRect;
            Rectangle leftRect        = BaseGame.CalcRectangle(35, 250,
                                                               selArrowGfxRect.Width, selArrowGfxRect.Height);

            leftRect.Y  = BaseGame.YToRes(300 + 60) + arrowRect.Y / 3;
            leftRect.X += (int)Math.Round(BaseGame.XToRes(12) * arrowWave);
            BaseGame.UI.Buttons.RenderOnScreen(
                leftRect, new Rectangle(selArrowGfxRect.X + selArrowGfxRect.Width,
                                        selArrowGfxRect.Y, -selArrowGfxRect.Width, selArrowGfxRect.Height));

            Rectangle rightRect = BaseGame.CalcRectangle(
                1024 - 335 - selArrowGfxRect.Width, 250,
                selArrowGfxRect.Width, selArrowGfxRect.Height);

            rightRect.Y  = BaseGame.YToRes(300 + 60) + arrowRect.Y / 3;
            rightRect.X -= (int)Math.Round(BaseGame.XToRes(12) * arrowWave);
            BaseGame.UI.Buttons.RenderOnScreen(
                rightRect, UIRenderer.SelectionArrowGfxRect);

            // Also handle xbox controller input
            if (Input.GamePadLeftJustPressed ||
                Input.KeyboardLeftJustPressed ||
                Input.MouseLeftButtonJustPressed &&
                Input.MouseInBoxRelative(new Rectangle(512 + 50, 170, 512 - 150, 135)))
            {
                Sound.Play(Sound.Sounds.Highlight);
                RacingGameManager.currentCarNumber =
                    (RacingGameManager.currentCarNumber + 1) % 3;
            }
            else if (Input.GamePadRightJustPressed ||
                     Input.KeyboardRightJustPressed ||
                     Input.MouseLeftButtonJustPressed &&
                     Input.MouseInBoxRelative(new Rectangle(100, 170, 512 - 200, 135)))
            {
                Sound.Play(Sound.Sounds.Highlight);
                RacingGameManager.currentCarNumber =
                    (RacingGameManager.currentCarNumber + 2) % 3;
            }

            // Mouse input is handled in RacingGameManager.cs
            if (Input.GamePadUpJustPressed ||
                Input.KeyboardUpJustPressed)
            {
                Sound.Play(Sound.Sounds.Highlight);
                RacingGameManager.currentCarColor = (RacingGameManager.currentCarColor +
                                                     RacingGameManager.NumberOfCarColors - 1) %
                                                    RacingGameManager.NumberOfCarColors;
            }
            else if (Input.GamePadDownJustPressed ||
                     Input.KeyboardDownJustPressed)
            {
                Sound.Play(Sound.Sounds.Highlight);
                RacingGameManager.currentCarColor =
                    (RacingGameManager.currentCarColor + 1) %
                    RacingGameManager.NumberOfCarColors;
            }

            bool aButtonPressed = BaseGame.UI.RenderBottomButtons(false);

            if (Input.GamePadAJustPressed ||
                Input.KeyboardSpaceJustPressed ||
                aButtonPressed)
            {
                RacingGameManager.AddGameScreen(new TrackSelection());
                return(false);
            }

            if (Input.KeyboardEscapeJustPressed ||
                Input.GamePadBJustPressed ||
                Input.GamePadBackJustPressed ||
                BaseGame.UI.backButtonPressed)
            {
                return(true);
            }

            return(false);
        }