Example #1
0
 public void BindTexture(Texture texture)
 {
     if (boundTextures.Peek() == texture.ID)
         return;
     GL.BindTexture(TextureTarget.Texture2D, texture.ID);
     boundTextures.Pop();
     boundTextures.Push(texture.ID);
 }
Example #2
0
        public MainMenu(Game game)
            : base(game)
        {
            rnd = new Random();
            logo = new Texture("resources/logo.png");
            menuTexture = new Texture("resources/menu.png");
            backgroundTexture = new Texture("resources/background.png");
            backgroundScale = 1.3f;

            menuItems = new List<MainMenuItem>();
            AddMenuItem(0, 0, 235, 36, OnNewGame);
            AddMenuItem(0, 55, 175, 104, null);
            AddMenuItem(0, 112, 134, 151, null);
            AddMenuItem(0, 170, 98, 218, OnQuit);
        }
Example #3
0
        public GameSession(Game game)
            : base(game)
        {
            backgroundTexture = new Texture("resources/background.png");
            Texture gameTexture = new Texture("resources/blocks.png");
            Texture[] textures = CreateBlockTextures(gameTexture);
            GameBlock[] regularBlocks = CreateColoredBlocks(textures, regularBlockColors, false);
            GameBlock[] hardBlocks = CreateColoredBlocks(textures, hardBlockColors, true);
            barTexture = gameTexture.Slice(6, 88, 243, 66);
            gameOverTexture = gameTexture.Slice(5, 166, 238, 45);

            leftPane = new GamePane(this, regularBlocks, hardBlocks, 40.0f, 30.0f);
            rightPane = new GamePane(this, regularBlocks, hardBlocks, 430.0f, 30.0f);
            running = true;
        }
Example #4
0
        /// <summary>
        /// Like DrawRectangle but will also emit texture coordinates for the texture
        /// given.  This however will not bind the texture.  This has to happen
        /// separately upfront.  The reason for this is that texture switches are
        /// quite expensive and it makes sense to not bind them every time you draw
        /// if there are better ways to handle that.
        /// </summary>
        public void DrawTexturedRectangle(float width, float height, Texture tex)
        {
            // TODO: consider switching to vertex arrays
            float fac_x = (float)tex.Width / tex.StoredWidth;
            float fac_y = (float)tex.Height / tex.StoredHeight;
            float off_x = (float)tex.OffsetX / tex.StoredWidth;
            float off_y = (float)tex.OffsetY / tex.StoredHeight;

            GL.Begin(BeginMode.Quads);
            GL.TexCoord2(off_x, off_y);
            GL.Vertex3(0.0f, 0.0f, 0.0f);
            GL.TexCoord2(off_x + fac_x, off_y);
            GL.Vertex3(width, 0.0f, 0.0f);
            GL.TexCoord2(off_x + fac_x, off_y + fac_y);
            GL.Vertex3(width, height, 0.0f);
            GL.TexCoord2(off_x, off_y + fac_y);
            GL.Vertex3(0.0f, height, 0.0f);
            GL.End();
        }
Example #5
0
        public GamePane(GameSession session, GameBlock[] regularBlocks, GameBlock[] hardBlocks,
                        float posX, float posY)
        {
            this.session = session;
            this.regularBlocks = regularBlocks;
            this.hardBlocks = hardBlocks;
            this.rnd = new Random(session.Game.Random.Next());
            grid = new GameBlockState[Columns, Rows];
            position = new Vector2(posX, posY);
            jitter = 0.0f;
            scrollY = 0.0f;
            scrollSpeed = DefaultScrollSpeed;
            cursorColumn = 0;
            cursorRow = 1;
            cursorTexture = regularBlocks[0].Texture;
            activeAnimations = new HashSet<GameBlockAnimation>();

            for (int column = 0; column < Columns; column++)
                for (int row = 0; row < Rows; row++)
                    grid[column, row] = new GameBlockState(this, column, row,
                                                           (float)rnd.NextDouble());

            PopulateWithRandomBlocks(7);
        }
Example #6
0
        public void Update(FrameEventArgs args)
        {
            jitter = (jitter + (float)args.Time * 7.0f) % 360.0f;

            if (!gameOver) {
                scrollY += (float)args.Time * (fastScrollMode ? 150.0f : scrollSpeed);
                if (scrollY >= BlockSize) {
                    scrollY -= BlockSize;
                    InsertNewRow(false);
                    MoveCursorUp();
                }
            }

            if (Math.Sin(jitter * 50) > 0.5f)
                cursorTexture = regularBlocks[rnd.Next() % regularBlocks.Length].Texture;

            HashSet<GameBlockAnimation> toDelete = new HashSet<GameBlockAnimation>();
            foreach (GameBlockAnimation blockAnimation in activeAnimations)
                if (!blockAnimation.Update(args))
                    toDelete.Add(blockAnimation);
            foreach (GameBlockAnimation blockAnimation in toDelete)
                activeAnimations.Remove(blockAnimation);

            for (int column = 0; column < Columns; column++)
                for (int row = 0; row < Rows; row++)
                    this[column, row].UpdateAnimation(args);
        }
Example #7
0
 protected GameBlock[] CreateColoredBlocks(Texture[] textures, List<Color4> colors,
                                           bool hard)
 {
     List<GameBlock> blocks = new List<GameBlock>();
     foreach (Texture texture in textures)
         foreach (Color4 color in colors)
             blocks.Add(new GameBlock(texture, color, hard));
     return blocks.ToArray();
 }
Example #8
0
 protected Texture[] CreateBlockTextures(Texture gameTexture)
 {
     List<Texture> blockTextures = new List<Texture>();
     for (int row = 0; row < 2; row++)
         for (int column = 0; column < 6; column++)
             blockTextures.Add(gameTexture.Slice(5 + column * 40, 5 + row * 40, 34, 34));
     return blockTextures.ToArray();
 }
Example #9
0
 public GameBlock(Texture texture, Color4 color, bool hard)
 {
     this.texture = texture;
     this.color = color;
     this.hard = hard;
 }
Example #10
0
 public MainMenuItem(TriggerDelegate trigger, Texture texture, int x, int y,
                     int width, int height)
 {
     this.texture = texture;
     this.trigger = trigger;
     this.x = x;
     this.y = y;
     this.width = width;
     this.height = height;
 }
Example #11
0
 public TextureSlice(Texture tex, int offsetX, int offsetY, int width, int height)
     : base(width, height, tex.StoredWidth, tex.StoredHeight, offsetX, offsetY)
 {
     parent = tex;
 }