Exemplo n.º 1
0
        void drawTiles()
        {
            SpriteBatch sb = ScreenManager.Globals.sb;

            sb.Begin(rasterizerState: ScreenManager.Globals.ClipState, blendState: BlendState.AlphaBlend);
            sb.GraphicsDevice.ScissorRectangle = pixelArea;

            //Camera is at top left corner of drawArea

            Coordinate tilePos     = (Coordinate)Vector2.Transform(cameraPos, toTile);
            Vector4    tileAreaAdj = new Vector4(tileArea.X + tilePos.X, tileArea.Y + tilePos.Y, tileArea.Z + tilePos.X, tileArea.W + tilePos.Y);

            for (int i = tileAreaAdj.X < tileAreaAdj.Y ? (int)tileAreaAdj.X : (int)tileAreaAdj.Y; i < (tileAreaAdj.Z > tileAreaAdj.W ? tileAreaAdj.Z : tileAreaAdj.W); i++)
            {
                Line2D l1 = new Line2D(Vector2.Transform(new Vector2(tileAreaAdj.X, i), toPixel) - cameraPos, Vector2.Transform(new Vector2(tileAreaAdj.Z, i), toPixel) - cameraPos, 1, TempGlobals.BorderColors[1] * 0.5f);
                Line2D l2 = new Line2D(Vector2.Transform(new Vector2(i, tileAreaAdj.Y), toPixel) - cameraPos, Vector2.Transform(new Vector2(i, tileAreaAdj.W), toPixel) - cameraPos, 1, TempGlobals.BorderColors[1] * 0.3f);
                l1.Draw(sb);
                l2.Draw(sb);
            }

            Line2D originX = new Line2D(Vector2.Transform(new Vector2(tileAreaAdj.X, -1), toPixel) - cameraPos - new Vector2(0, 1), Vector2.Transform(new Vector2(tileAreaAdj.Z, -1), toPixel) - cameraPos - new Vector2(0, 1), 1.5f, TempGlobals.BorderColors[1]);
            Line2D originY = new Line2D(Vector2.Transform(new Vector2(-1, tileAreaAdj.Y), toPixel) - cameraPos, Vector2.Transform(new Vector2(-1, tileAreaAdj.W), toPixel) - cameraPos, 1.5f, TempGlobals.BorderColors[1]);

            originX.Draw(sb);
            originY.Draw(sb);


            for (int y = (int)tileAreaAdj.Y; y < tileAreaAdj.W; y++)
            {
                if (y >= 0 && y < sim.map.GetLength(1))
                {
                    for (int x = (int)tileAreaAdj.X; x < tileAreaAdj.Z; x++)
                    {
                        if (x >= 0)
                        {
                            if (x >= sim.map.GetLength(0))
                            {
                                break;
                            }
                            Tile       tile     = sim.map[x, y, cameraLevel];
                            TileData   data     = sim.TileTypes[tile.ID];
                            Coordinate position = (Coordinate)Vector2.Transform(new Vector2(x, y), toPixel) - cameraPos;
                            //sb.Draw(data.Spritesheet, position, data.SampleArea, Color.White);
                            RenderTiles.Draw(position, tile, data, (cameraLevel == 0 ? aDozed : uDozed), sb);
                            if (mouseTile.X != -1 && mouseTile.X == x && mouseTile.Y == y)
                            {
                                sb.Draw(cursor, position - new Coordinate(cursor.Width / 2, cursor.Height), Color.White);
                            }
                        }
                    }
                }
            }
            sb.End();
        }
Exemplo n.º 2
0
        public override void Draw(SpriteBatch sb)
        {
            sb.End();

            sb.Begin(rasterizerState: ScreenManager.Globals.ClipState);
            sb.Draw(currentMap ? mapImage : tilesImage, targetArea, croppedArea, Color.White);
            sb.GraphicsDevice.ScissorRectangle = targetArea;
            for (int i = 0; i < 4; i++)
            {
                Line2D.Draw(viewportPoints[i], viewportPoints[(i + 1) % 4], TempGlobals.BorderColors[1], (Coordinate)targetArea.Location, sb, 1);
            }
            sb.End();

            sb.Begin();
        }
Exemplo n.º 3
0
        public void Render(object Sender, FrameEventArgs E)
        {
            GL.Clear(ClearBufferMask.ColorBufferBit);

            //   PlayerView.Setup(800, 800);
            //   PlayerView.Update();
            //   Spritebatch.Begin();


            CurrentShader.Enable();
            // Sprite.Rect.DebugMode = Debug.None;
            // Sprite.Rect.SetFillColor(Color.Blue);

            LineTest.SetFillColor(Color.Red);
            LineTest.SetOrigin(LineTest.Center);
            //    LineTest.SetPosition(new Vector2(.10f * x, .10f * y));
            // LineTest.SetRotation(mov, Axis.Z);
            LineTest.Update();
            LineTest.Draw();

            //LineTest.SetFillColor(Color.Blue);
            //LineTest.SetOrigin(LineTest.Center);
            ////    LineTest.SetPosition(new Vector2(.10f * x, .10f * y));
            //LineTest.SetRotation(90f, Axis.Z);
            //LineTest.Update();
            //LineTest.Draw();

            //TriangleTest.SetFillColor(Color.Blue);
            //TriangleTest.SetOrigin(TriangleTest.BottomLeft);
            //TriangleTest.SetScale(scal);
            //TriangleTest.SetRotation(-mov, Axis.Z);
            //TriangleTest.SetPosition(new Vector2(scale, scale));
            //TriangleTest.Update();
            //TriangleTest.Draw();


            //Sprite.SetOrigin(Sprite.Rect.Center);
            //Sprite.SetScale(new Vector2(scale, scale)); //+ (.001f * x), scale + (.001f * y)));
            //Sprite.SetRotation(mov, Axis.Z);
            //Sprite.SetPosition(new Vector2(scale, scale));
            //Sprite.Update();
            //Sprite.Draw();

            ////    Sprite.SetOrigin(new Vector2(-.5f, -.5f));
            //Sprite.SetScale(new Vector2(scale, scale));
            //Sprite.SetRotation(mov);
            //Sprite.SetPosition(new Vector2(scale * x, -scale * y));
            //Sprite.Update();
            //Sprite.Draw();

            ////   Sprite.SetOrigin(new Vector2(-.5f, -.5f));
            //Sprite.SetScale(new Vector2(scale, scale));
            //Sprite.SetRotation(mov);
            //Sprite.SetPosition(new Vector2(-scale * x, scale * y));
            //Sprite.Update();
            //Sprite.Draw();

            ////  Sprite.Rect.DebugMode = Debug.Wireframe;
            ////    Sprite.SetOrigin(new Vector2(-.5f, -.5f));
            //Sprite.SetScale(new Vector2(scale, scale)); ;
            //Sprite.SetRotation(mov);
            //Sprite.SetPosition(new Vector2(scale * x, scale * y));
            //Sprite.Update();
            //Sprite.Draw();


            //  Texture.Unbind();
            CurrentShader.Disable();


            GameScreen.SwapBuffers();



            frames++;
            if (Timekeeper.GetElapsed().Seconds >= 1)
            {
                RobustConsole.Write(LogLevel.Debug, "RobustEngine", "Render() FPS " + frames);
                Timekeeper.Start();
                frames = 0;
            }
            // RobustConsole.Write(LogLevel.Debug, "RobustEngine", "Render() MS " + Timekeeper.GetTime().Milliseconds.ToString());
        }