Exemple #1
0
 public void DrawHUD()
 {
     if (Game.Level != 6)
     {
         //Lives
         Spritebatch.DrawSprite(head, new RectangleF(position.X - 300, position.Y - 210, 32, 32));
         DialogBox.DrawString("x" + Lives.ToString(), position.X - 268, position.Y - 210);
         //Coins
         Spritebatch.DrawSprite(coin, new RectangleF(position.X + 180, position.Y - 210, 32, 32));
         DialogBox.DrawString("x" + Coins.ToString(), position.X + 212, position.Y - 210);
     }
     else
     {
         DialogBox.DrawString("The", position.X - 48, position.Y - 164);
         DialogBox.DrawString("End", position.X - 48, position.Y - 132);
     }
 }
Exemple #2
0
        //Render - draw stuff here
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            base.OnRenderFrame(e);

            if (slevel == "menu")
            {
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
                GL.ClearColor(Color.FromArgb(255, 10, 10, 10));
                Spritebatch.Begin(this);
                view.ApplyTransforms();
                foreach (GameObject o in ObjectHandler.objects)
                {
                    o.Draw(Color.FromArgb(255, 90, 90, 90));
                }

                for (int x = 0; x < level.Width; x++)
                {
                    for (int y = 0; y < level.Height; y++)
                    {
                        int        tileSize  = 70;
                        RectangleF sourceRec = new RectangleF(0, 0, 0, 0);

                        sourceRec = new RectangleF(level[x, y].tileX, level[x, y].tileY, tileSize, tileSize);

                        GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
                        GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
                        Spritebatch.DrawSprite(tileSet, new RectangleF(x * GRIDSIZE, y * GRIDSIZE, GRIDSIZE + 1, GRIDSIZE + 1), Color.FromArgb(255, 90, 90, 90), sourceRec);
                    }
                }
            }
            else
            {
                List <Enemy> afterdraw = new List <Enemy>(); //Enemies drawn after tiles - above them. (atm all except piranhas)
                Color        tilec     = Color.LightGray;
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
                if (slevel.Contains("story"))
                {
                    GL.ClearColor(Color.FromArgb(255, 0, 0, 0));
                }
                else if (Level == 1)
                {
                    GL.ClearColor(Color.FromArgb(255, 10, 10, 10));
                    tilec = Color.LightGray;
                }
                else if (Level == 2)
                {
                    GL.ClearColor(Color.FromArgb(255, 0, 20, 20));
                    tilec = Color.LightGray;
                }
                else if (Level == 3 || Level == 4 || Level == 5)
                {
                    GL.ClearColor(Color.FromArgb(255, 0, 0, 16));
                    tilec = Color.Gray;
                }
                else if (Level == 6)
                {
                    GL.ClearColor(Color.FromArgb(255, 16, 16, 16));
                    tilec = Color.Gray;
                }


                Spritebatch.Begin(this);
                view.ApplyTransforms();

                if (!slevel.Contains("story"))
                {
                    foreach (GameObject o in ObjectHandler.objects)
                    {
                        o.Draw(tilec);
                    }
                }

                List <Tuple <Block, Vector2> > afterdraws = new List <Tuple <Block, Vector2> >();
                if (!slevel.Contains("story"))
                {
                    for (int x = 0; x < level.Width; x++)
                    {
                        for (int y = 0; y < level.Height; y++)
                        {
                            if (level[x, y].type == BlockType.Empty)
                            {
                                Tuple <Block, Vector2> t = new Tuple <Block, Vector2>(level[x, y], new Vector2(x, y));
                                afterdraws.Add(t);
                                continue;
                            }
                            int        tileSize  = 70;
                            RectangleF sourceRec = new RectangleF(0, 0, 0, 0);

                            sourceRec = new RectangleF(level[x, y].tileX, level[x, y].tileY, tileSize, tileSize);

                            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
                            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
                            Spritebatch.DrawSprite(tileSet, new RectangleF(x * GRIDSIZE, y * GRIDSIZE, GRIDSIZE + 1, GRIDSIZE + 1), tilec, sourceRec);
                        }
                    }
                }
                if (!slevel.Contains("story"))
                {
                    foreach (Enemy ex in enemies)
                    {
                        if (ex.enemyType == 5)
                        {
                            ex.Draw();
                        }
                        else
                        {
                            afterdraw.Add(ex);
                        }
                    }
                }
                if (!slevel.Contains("story"))
                {
                    player.Draw(tilec);
                }
                foreach (Tuple <Block, Vector2> t in afterdraws.ToArray())
                {
                    int        tileSize  = 70;
                    RectangleF sourceRec = new RectangleF(0, 0, 0, 0);

                    sourceRec = new RectangleF(t.Item1.tileX, t.Item1.tileY, tileSize, tileSize);

                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
                    Spritebatch.DrawSprite(tileSet, new RectangleF(t.Item2.X * GRIDSIZE, t.Item2.Y * GRIDSIZE, GRIDSIZE + 1, GRIDSIZE + 1), tilec, sourceRec);
                }
                foreach (Enemy ex in afterdraw)
                {
                    ex.Draw();
                }

                if (!slevel.Contains("story"))
                {
                    view.DrawHUD();
                }
                if (slevel.Contains("story"))
                {
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
                    DialogBox.DrawString(view.Position.X - 288, view.Position.Y);
                }
            }
            this.SwapBuffers();
        }