示例#1
0
        static void Main(string[] args)
        {
            Raylib.InitWindow(1280, 720, "prototype");
            Raylib.SetWindowState(ConfigFlag.FLAG_WINDOW_RESIZABLE);
            var camera = new Camera2D(Vector2.Zero, Vector2.Zero, 0, 1);

            var thing = new InverseKinematics();

            var cameraFollowMouse = false;
            var clickMousePos     = Vector2.Zero;
            var clickCameraPos    = Vector2.Zero;

            while (!Raylib.WindowShouldClose())
            {
                if (Raylib.IsKeyPressed(KeyboardKey.KEY_UP))
                {
                    camera.zoom += 0.5f;
                    var m = Raylib.GetMousePosition();
                    camera.target = m;
                    camera.offset = new Vector2(Raylib.GetScreenWidth(), Raylib.GetScreenHeight()) / 2;
                    cameraPos     = camera.target - camera.offset;
                }
                if (Raylib.IsKeyPressed(KeyboardKey.KEY_DOWN) && camera.zoom > 0.5f)
                {
                    camera.zoom -= 0.5f;
                }

                if (Raylib.IsMouseButtonPressed(MouseButton.MOUSE_MIDDLE_BUTTON))
                {
                    cameraFollowMouse = true;
                    clickMousePos     = Raylib.GetMousePosition();
                    clickCameraPos    = camera.target;
                }
                if (Raylib.IsMouseButtonReleased(MouseButton.MOUSE_MIDDLE_BUTTON))
                {
                    cameraFollowMouse = false;
                }

                if (cameraFollowMouse)
                {
                    camera.target = clickCameraPos + (clickMousePos - Raylib.GetMousePosition()) / camera.zoom;
                }

                Raylib.BeginDrawing();
                Raylib.ClearBackground(Color.BLACK);

                Raylib.BeginMode2D(camera);
                if (Raylib.GetFrameTime() < 0.25)
                {
                    thing.Update();
                }
                Raylib.EndMode2D();

                Raylib.EndDrawing();
            }
        }
示例#2
0
        public static void DrawAll() //Draws all gameobjects in the current scene, and a beginmode2D to draw everything relative to the in game camera.
        {
            Raylib.BeginDrawing();
            Raylib.BeginMode2D(camera);
            Raylib.ClearBackground(Color.WHITE);

            foreach (GameObject d in gameObjectsInScene)
            {
                d.Draw();
            }
            Raylib.EndMode2D();
            Raylib.EndDrawing();
        }
示例#3
0
        public void Draw(RenderTexture2D target)
        {
            Raylib.BeginDrawing();
            {
                Raylib.BeginTextureMode(target);

                Raylib.ClearBackground(new Color(36, 36, 36, 255));

                Raylib.BeginMode2D(_camera);

                DrawGlobal();

                switch (GameState.CurrentPhase)
                {
                case EGamePhase.InitialPlacement:
                    DrawInitialPlacementCamera();
                    break;

                case EGamePhase.Expanding:
                    DrawConnections();
                    DrawExpandingCamera();
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                Raylib.EndMode2D();

                DrawGlobalUi();

                switch (GameState.CurrentPhase)
                {
                case EGamePhase.InitialPlacement:
                    DrawInitialPlacementUi();
                    break;

                case EGamePhase.Expanding:
                    DrawExpandingUi();
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                Raylib.EndTextureMode();
            }

            Raylib.EndDrawing();
        }
示例#4
0
        static void Main(string[] args)
        {
            _ents  = new List <Entity>();
            _world = new World(new Vector2 {
                X = 0, Y = 0
            });

            Raylib.InitWindow(ScreenWidth, ScreenHeight, "C# Raylib Game");

            _cam      = new Camera2D();
            _cam.zoom = 1;
            var player = new Player.Player(_world, new BodyDef
            {
                awake      = true,
                enabled    = true,
                allowSleep = false,
                position   = new Vector2(Raylib.GetScreenWidth() / 2, Raylib.GetScreenHeight() / 2),
                type       = BodyType.Dynamic
            });


            _ents.Add(player);


            while (!Raylib.WindowShouldClose())
            {
                _cam.target = System.Numerics.Vector2.Lerp(_cam.target,
                                                           new System.Numerics.Vector2(player.Body.GetPosition().X, player.Body.GetPosition().Y), 0.01f);

                _cam.offset = new System.Numerics.Vector2(Raylib.GetScreenWidth() / 2, Raylib.GetScreenHeight() / 2);

                //Physics step
                _world.Step(1.0f / 60.0f, 6, 2);

                Raylib.BeginDrawing();
                Raylib.ClearBackground(Raylib_cs.Color.DARKGRAY);
                Raylib.BeginMode2D(_cam);
                Raylib.DrawRectangle(0, 0, 128, 127, Raylib_cs.Color.RED);
                foreach (var e in _ents)
                {
                    e.Tick(Raylib.GetFrameTime());
                    e.Render(Raylib.GetFrameTime());
                }
                Raylib.EndMode2D();
                Raylib.EndDrawing();
            }
        }
示例#5
0
        public void Draw()
        {
            var height = Raylib.GetScreenHeight();
            var width  = Raylib.GetScreenWidth();

            Raylib.BeginMode2D(camera);
            {
                foreach (var o in objects)
                {
                    Raylib.DrawTextureEx(Texture.Tile[o.Name].texture, new Vector2(o.X, o.Y), 0, 1, Color.WHITE);
                }

                if (showGrid)
                {
                    var p = PointToTile(camera.target - camera.offset / camera.zoom - new Vector2(cellSize));
                    for (var y = (int)p.Y; y < camera.target.Y + (height - camera.offset.Y) / camera.zoom; y += cellSize)
                    {
                        for (var x = (int)p.X; x < camera.target.X + (width - camera.offset.X) / camera.zoom; x += cellSize)
                        {
                            if (y == 0 || y % 1080 == 0)
                            {
                                Raylib.DrawLineEx(new Vector2(x, y), new Vector2(x + cellSize, y), 5, Color.BLACK);
                            }
                            if (x == 0)
                            {
                                Raylib.DrawLineEx(new Vector2(x, y), new Vector2(x, y + cellSize), 5, Color.BLACK);
                            }
                            Raylib.DrawLine(x, y, x + cellSize, y, Color.BLACK);
                            Raylib.DrawLine(x, y, x, y + cellSize, Color.BLACK);
                        }
                    }
                }
            }
            Raylib.EndMode2D();

            Raylib.DrawRectangle(0, 0, width - bannedX, bannedY, new Color(0, 0, 0, 100));
            Raylib.DrawRectangle(width - bannedX, 0, bannedX, height, new Color(0, 0, 0, 100));

            fileNameBox.Draw();
            foreach (var button in tileButtons)
            {
                button.Draw();
            }
        }
示例#6
0
        public void Draw()
        {
            camera.zoom = (float)Raylib.GetScreenHeight() / 1080f;
            Raylib.BeginMode2D(camera);

            foreach (var o in mapData)
            {
                Raylib.DrawTextureEx(Texture.Tile[o.Name].texture, new Vector2(o.X, o.Y), 0, 1, Color.WHITE);
            }

            foreach (var m in monsters)
            {
                m.Draw();
            }

            player.Draw();

            //foreach (var body in bodies) body.Body.Draw(new Color(100, 0, 0, 100));

            Raylib.EndMode2D();
        }
示例#7
0
        public static void DrawTooltip(Vector2 Pos, string Text, Color?Clr = null, bool Offset = true)
        {
            if (CurrentDrawState == DrawState.NONE)
            {
                throw new Exception("Can not tooltip outside drawing functions");
            }

            if (Offset)
            {
                Pos += new Vector2(8);
            }

            if (CurrentDrawState == DrawState.WORLD)
            {
                Pos = Raylib.GetWorldToScreen2D(Pos, GameCamera);
                Raylib.EndMode2D();
            }

            int FontSize = 10;
            int YPadding = 2;
            int XPadding = 5;

            string[] Lines    = Text.Trim().Split('\n');
            int      MaxWidth = Lines.Select(L => Raylib.MeasureText(L, FontSize)).Max();


            Raylib.DrawRectangle((int)Pos.X, (int)Pos.Y, MaxWidth + XPadding * 2, Lines.Length * FontSize + (Lines.Length + 2) * YPadding, GUIPanelColor);

            for (int i = 0; i < Lines.Length; i++)
            {
                Raylib.DrawText(Lines[i], (int)Pos.X + XPadding, (int)Pos.Y + YPadding * (i + 1) + FontSize * i, FontSize, Clr ?? Color.WHITE);
            }

            if (CurrentDrawState == DrawState.WORLD)
            {
                Raylib.BeginMode2D(GameCamera);
            }
        }
示例#8
0
        public override void Render()
        {
            Raylib.BeginDrawing();
            Raylib.BeginMode2D(cam);
            Raylib.ClearBackground(Color.LIGHTGRAY);

            RenderGrid();
            currentProject.Simulation.Render(GetMousePositionInWorld());
            if (state == EditorState.OutputToInput)
            {
                Raylib.DrawLineBezier(tempOutput.Item2.GetOutputPosition(tempOutput.Item1), GetMousePositionInWorld(), 2f, Color.WHITE);
            }

            if (state == EditorState.RectangleSelecting)
            {
                Raylib.DrawRectangleRec(selectionRec, Color.BLUE.Opacity(0.3f));
                Raylib.DrawRectangleLinesEx(selectionRec, 1, Color.BLUE.Opacity(0.8f));
            }
            Raylib.EndMode2D();

            controller.Draw();
            Raylib.EndDrawing();
        }
示例#9
0
        public static void DrawBar(Vector2 Pos, float Amt, Color Clr)
        {
            if (CurrentDrawState == DrawState.NONE)
            {
                throw new Exception("Can not tooltip outside drawing functions");
            }

            if (CurrentDrawState == DrawState.WORLD)
            {
                Pos = Raylib.GetWorldToScreen2D(Pos, GameCamera);
                Raylib.EndMode2D();
            }

            const int Padding = 2;
            const int Width   = 48;
            const int Height  = 8;

            Pos -= new Vector2(Width / 2, Height / 2);

            if (Amt < 0)
            {
                Amt = 0;
            }
            else if (Amt > 1)
            {
                Amt = 1;
            }

            Raylib.DrawRectangle((int)Pos.X, (int)Pos.Y, Width, Height, GUIPanelColor);
            Raylib.DrawRectangle((int)Pos.X + Padding, (int)Pos.Y + Padding, (int)((Width - Padding * 2) * Amt), Height - Padding * 2, Clr);

            if (CurrentDrawState == DrawState.WORLD)
            {
                Raylib.BeginMode2D(GameCamera);
            }
        }
示例#10
0
        static void Main(string[] args)
        {
            //beskriv en kod snutt så att man vet vad den gör
            //utvärderqa varför du valt en specifik grej, tex varför jag valt en while loop här ist för en for osv
            //skapa fiender i gräset - här kan metoder, klasser, random generator osv användas
            //kolla checklista för november projekt
            //sätt in lite fler saker i metoder
            //gräs fiender - när inGrass == true och spelar GÅR --> random generator för fiende, ksk ha ett visst antal fiender
            //när man stöter på en fiende --> byt gamestate


            //INITIATE VALUES
            int screenWidth  = 1920;
            int screenHeight = 1000;

            Raylib.InitWindow(screenWidth, screenHeight, "The Legend of Bianca");
            Raylib.SetTargetFPS(60);

            //GAME VALUES
            string gameState = "game";
            int    scl       = 200;
            int    velocity  = 5;
            bool   moving    = false;
            Random r         = new Random();
            int    enemy     = r.Next(3);

            //CAMERA VALUES
            Rectangle player = new Rectangle(340, 830, scl / 2, scl / 2);
            Camera2D  camera = new Camera2D();

            camera.offset   = new Vector2(screenWidth / 2, screenHeight / 2);
            camera.rotation = 0.0f;
            camera.zoom     = 1.0f;

            //TILE VALUES
            List <string> tileMap = new List <string>()
            {
                ".", ".", ".", "#", ".", ".", ".", ".", "#", ".", ".", ".",
                ".", ".", ".", "#", ".", ".", ".", ".", "#", ".", ".", ".",
                ".", ".", ".", "#", ".", ".", ".", ".", "#", ".", ".", ".",
                ".", ".", ".", "#", ".", ".", ".", ".", "#", ".", ".", ".",
                ".", ".", ".", "#", ".", ".", ".", ".", "#", ".", ".", ".",
                "#", "#", "#", "#", "#", "#", "#", "#", "#", "#", "#", "#",
                ".", ".", ".", ".", ".", ".", ".", ".", "#", ".", ".", ".",
                ".", ".", ".", ".", ".", ".", ".", ".", "#", ".", ".", ".",
                ".", ".", ".", ".", ".", ".", ".", ".", "#", ".", ".", ".",
                ".", ".", ".", ".", ".", ".", ".", ".", "#", ".", ".", ".",
            };

            int cols = 12;
            int rows = 10;

            List <Rectangle> grassTiles = new List <Rectangle>();

            while (!Raylib.WindowShouldClose())
            {
                if (gameState == "game")
                {
                    velocity = 5;

                    //GRASS COLLISION
                    //denhär har du skrivit micke dont grade me
                    for (int i = 0; i < tileMap.Count; i++)
                    {
                        if (tileMap[i] == ".")
                        {
                            int x = i % cols;//denhär fattar jag inte
                            int y = i / cols;
                            grassTiles.Add(new Rectangle(x * scl, y * scl, scl, scl));
                        }
                    }
                    for (int i = 0; i < grassTiles.Count; i++)
                    {
                        if (Raylib.CheckCollisionRecs(player, grassTiles[i]) && moving == true)
                        {
                            velocity = 3;
                        }
                    }

                    //MOVEMENT CONTROLS
                    if (Raylib.IsKeyDown(KeyboardKey.KEY_RIGHT) || Raylib.IsKeyDown(KeyboardKey.KEY_D))
                    {
                        player.x += velocity;
                        moving    = true;
                    }
                    if (Raylib.IsKeyDown(KeyboardKey.KEY_LEFT) || Raylib.IsKeyDown(KeyboardKey.KEY_A))
                    {
                        player.x -= velocity;
                        moving    = true;
                    }
                    if (Raylib.IsKeyDown(KeyboardKey.KEY_DOWN) || Raylib.IsKeyDown(KeyboardKey.KEY_S))
                    {
                        player.y += velocity;
                        moving    = true;
                    }
                    if (Raylib.IsKeyDown(KeyboardKey.KEY_UP) || Raylib.IsKeyDown(KeyboardKey.KEY_W))
                    {
                        player.y -= velocity;
                        moving    = true;
                    }

                    //BORDER CONTROL
                    int returnPosX = border((int)player.x, 0, (int)cols * (int)scl - (int)player.width);
                    player.x = returnPosX;
                    int returnPosY = border((int)player.y, 0, (int)rows * (int)scl - (int)player.width);
                    player.y = returnPosY;

                    //CAMERA
                    camera.target = new Vector2(player.x + player.width / 2, player.y + player.height / 2);

                    //BEGIN DRAW
                    Raylib.BeginDrawing();
                    Raylib.ClearBackground(Color.WHITE);
                    Raylib.BeginMode2D(camera);

                    //DRAW LEVEL
                    for (int i = 0; i < rows; i++)
                    {
                        for (int j = 0; j < cols; j++)
                        {
                            if (tileMap[i * cols + j] == ".")
                            {
                                Raylib.DrawRectangle(j * scl, i * scl, scl, scl, Color.DARKGREEN);
                            }
                            else
                            {
                                Raylib.DrawRectangle(j * scl, i * scl, scl, scl, Color.DARKBROWN);
                            }
                        }
                    }
                    //  {".",".",".","#",".",".",".",".","#",".",".",".",
                    //   ".",".",".","#",".",".",".",".","#",".",".",".",
                    //   ".",".",".","#",".",".",".",".","#",".",".",".",
                    //   ".",".",".","#",".",".",".",".","#",".",".",".",
                    //   ".",".",".","#",".",".",".",".","#",".",".",".",
                    //   "#","#","#","#","#","#","#","#","#","#","#","#",
                    //   ".",".",".",".",".",".",".",".","#",".",".",".",
                    //   ".",".",".",".",".",".",".",".","#",".",".",".",
                    //   ".",".",".",".",".",".",".",".","#",".",".",".",
                    //   ".",".",".",".",".",".",".",".","#",".",".",".",};

                    //DRAW OUTLINE
                    for (int i = 0; i < 12; i++)
                    {
                        Raylib.DrawLine(scl * i, 0, scl * i, rows * scl, Color.BLACK);
                        Raylib.DrawLine(0, scl * i, cols * scl, scl * i, Color.BLACK);
                    }

                    //DRAW PLAYER
                    Raylib.DrawRectangleRec(player, Color.RED);
                    Raylib.DrawLine((int)camera.target.X, -screenHeight * 10, (int)camera.target.X, screenHeight * 10, Color.GREEN);
                    Raylib.DrawLine(-screenWidth * 10, (int)camera.target.Y, screenWidth * 10, (int)camera.target.Y, Color.GREEN);
                    Raylib.EndMode2D();
                    Raylib.EndDrawing();
                }
            }
        }
示例#11
0
        /// <summary>
        /// Display all Entities that are Visible using thier RenderLayer order
        /// </summary>
        public virtual void Render()
        {
            //-------------------------------------------------------------------------------
            // Get all RenderComponent, sort them, low -> high
            //-------------------------------------------------------------------------------
            List <RenderComponent> ComponentsToRender = new List <RenderComponent>();

            //
            // Find all Entities (in case some were removed/added)
            //
            GameEntities  = EntityContext.GetEntities().Where(e => e.EntityType == 0).ToList();
            SceneEntities = EntityContext.GetEntities().Where(e => e.EntityType == 1).ToList();

            foreach (Entity ent in GameEntities)
            {
                if (!(ent.Get <Transform>().Enabled&& ent.Get <Transform>().Visiable))
                {
                    continue;
                }

                //
                // Ask Entitas for all components attached to "ent" entity
                //
                Entitas.IComponent[] allComp = ent.GetComponents();                       //this entity's component
                foreach (Entitas.IComponent comp in allComp)                              //get the renderable ones
                {
                    if (comp is IRenderable)
                    {
                        RenderComponent myComp = (RenderComponent)comp;
                        ComponentsToRender.Add(myComp);
                    }
                }
            }

            //-------------------------------------------------------------------------------
            //   CAMERA DISPLAY  BeginMode2D
            //-------------------------------------------------------------------------------

            if (CameraEnabled && CameraEntityToFollow != null)
            {
                //    need to get the entity that is target of camera -> target Get<Transform>().Position
                //    Any component that is in view of the camera, is drawn first

                switch (CameraType2D)
                {
                case Camera2DType.FollowPlayer:
                    UpdateCameraCenter();
                    break;

                case Camera2DType.FollowInsideMap:
                    UpdateCameraInsideMap();
                    break;

                case Camera2DType.FollowCenterSmooth:
                    UpdateCameraCenterSmoothFollow();
                    break;
                }
                Raylib.BeginMode2D(Camera);
            }

            //-------------------------------------------------------------------------------
            //   RENDER ORDER  sorting (low to high) then render
            //-------------------------------------------------------------------------------
            foreach (RenderComponent myComp in ComponentsToRender.OrderBy(e => e.RenderLayer))
            {
                myComp.Render();                                                                                        //call draw method
            }
            //-------------------------------------------------------------------------------
            //   CAMERA DISPLAY  EndMode2D
            //-------------------------------------------------------------------------------
            if (CameraEnabled && CameraEntityToFollow != null)
            {
                if (Global.DebugRenderEnabled)
                {
                    //
                    // display camera position
                    //
                    int screenHeight = Global.SceneHeight;
                    int screenWidth  = Global.SceneWidth;

                    int tx = (int)CameraEntityToFollow.Get <Transform>().Position.X;
                    int ty = (int)CameraEntityToFollow.Get <Transform>().Position.Y;

                    Raylib.DrawLine(tx, -screenHeight * 10, tx, screenHeight * 10, Color.GREEN);    //Verticval
                    Raylib.DrawLine(-screenWidth * 10, ty, screenWidth * 10, ty, Color.GREEN);      //Horizontal

                    //tx = (int)Global.WindowCenter.X;
                    //ty = (int)Global.WindowCenter.Y;
                    //Raylib.DrawLine(tx, -screenHeight * 10, tx, screenHeight * 10, Color.RED);    //Verticval
                    //Raylib.DrawLine(-screenWidth * 10, ty, screenWidth * 10, ty, Color.RED);      //Horizontal
                }
                Raylib.EndMode2D();
            }
            //-------------------------------------------------------------------------------
            //   U I  ENTITIES , they are drawn on top of all other game entities
            //-------------------------------------------------------------------------------
            foreach (Entity ent in SceneEntities)
            {
                if (!ent.Get <Transform>().Enabled)
                {
                    continue;
                }

                if (!ent.Get <Transform>().Visiable)
                {
                    continue;
                }

                Entitas.IComponent[] allComp = ent.GetComponents();                         //this entity's component
                foreach (Entitas.IComponent comp in allComp)
                {
                    if (comp is IRenderable)
                    {
                        RenderComponent myComp = (RenderComponent)comp;
                        myComp.Render();                                                            //call draw method
                    }
                }
            }

            //-----------------
            // Scene debug
            //-----------------
            if (Global.DebugRenderEnabled)
            {
                Raylib.DrawText(Raylib.GetMousePosition().ToString(), 10, 10, 20, Color.WHITE);

                if (CameraEnabled && CameraEntityToFollow != null)
                {
                    Raylib.DrawFPS(10, 30);
                    Raylib.DrawText("Zoom" + Camera.zoom.ToString(), 10, 50, 20, Color.WHITE);
                }
                else
                {
                    Raylib.DrawFPS(10, 30);
                }
            }
        }
示例#12
0
        static void Main(string[] args)
        {
            // Initialization
            //--------------------------------------------------------------------------------------
            int       MAX_BUILDINGS = 100;
            Random    r             = new Random();
            const int screenWidth   = 800;
            const int screenHeight  = 450;

            Raylib.InitWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera");
            Rectangle player = new Rectangle(400, 280, 40, 40);

            Rectangle[] buildings   = new Rectangle[MAX_BUILDINGS];
            Color[]     buildColors = new Color[MAX_BUILDINGS];
            float       spacing     = 0;

            for (int i = 0; i < MAX_BUILDINGS; i++)
            {
                buildings[i].width  = r.Next(50, 200);
                buildings[i].height = r.Next(100, 800);
                buildings[i].y      = screenHeight - 130 - buildings[i].height;
                buildings[i].x      = -6000 + spacing;
                spacing            += buildings[i].width;
                buildColors[i]      = new Color(r.Next(200, 240), r.Next(200, 240), r.Next(200, 250), 255);
            }
            Camera2D camera = new Camera2D();

            camera.target   = new Vector2(player.x + 20, player.y + 20);
            camera.offset   = new Vector2(screenWidth / 2, screenHeight / 2);
            camera.rotation = 0.0f;
            camera.zoom     = 1.0f;
            Raylib.SetTargetFPS(60);                   // Set our game to run at 60 frames-per-second
                                                       //--------------------------------------------------------------------------------------
                                                       // Main game loop
            while (!Raylib.WindowShouldClose())        // Detect window close button or ESC key
            {
                // Update
                //----------------------------------------------------------------------------------

                // Player movement
                if (Raylib.IsKeyDown(KeyboardKey.KEY_RIGHT))
                {
                    player.x += 2;
                }
                else if (Raylib.IsKeyDown(KeyboardKey.KEY_LEFT))
                {
                    player.x -= 2;
                }
                // Camera target follows player
                camera.target = new Vector2(player.x + 20, player.y + 20);
                // Camera rotation controls
                if (Raylib.IsKeyDown(KeyboardKey.KEY_A))
                {
                    camera.rotation--;
                }
                else if (Raylib.IsKeyDown(KeyboardKey.KEY_S))
                {
                    camera.rotation++;
                }
                // Limit camera rotation to 80 degrees (-40 to 40)
                if (camera.rotation > 40)
                {
                    camera.rotation = 40;
                }
                else if (camera.rotation < -40)
                {
                    camera.rotation = -40;
                }
                // Camera zoom controls
                camera.zoom += Raylib.GetMouseWheelMove() * 0.05f;
                if (camera.zoom > 3.0f)
                {
                    camera.zoom = 3.0f;
                }
                else if (camera.zoom < 0.1f)
                {
                    camera.zoom = 0.1f;
                }
                // Camera reset (zoom and rotation)
                if (Raylib.IsKeyPressed(KeyboardKey.KEY_R))
                {
                    camera.zoom     = 1.0f;
                    camera.rotation = 0.0f;
                }
                //----------------------------------------------------------------------------------
                // Draw
                //----------------------------------------------------------------------------------
                Raylib.BeginDrawing();
                Raylib.ClearBackground(Color.RAYWHITE);
                Raylib.BeginMode2D(camera);
                Raylib.DrawRectangle(-6000, 320, 13000, 8000, Color.DARKGRAY);
                for (int i = 0; i < MAX_BUILDINGS; i++)
                {
                    Raylib.DrawRectangleRec(buildings[i], buildColors[i]);
                }
                Raylib.DrawRectangleRec(player, Color.RED);
                Raylib.DrawLine((int)camera.target.X, -screenHeight * 10, (int)camera.target.X, screenHeight * 10, Color.GREEN);
                Raylib.DrawLine(-screenWidth * 10, (int)camera.target.Y, screenWidth * 10, (int)camera.target.Y, Color.GREEN);
                Raylib.EndMode2D();
                Raylib.DrawText("SCREEN AREA", 640, 10, 20, Color.RED);
                Raylib.DrawRectangle(0, 0, screenWidth, 5, Color.RED);
                Raylib.DrawRectangle(0, 5, 5, screenHeight - 10, Color.RED);
                Raylib.DrawRectangle(screenWidth - 5, 5, 5, screenHeight - 10, Color.RED);
                Raylib.DrawRectangle(0, screenHeight - 5, screenWidth, 5, Color.RED);
                Raylib.DrawRectangle(10, 10, 250, 113, Raylib.Fade(Color.SKYBLUE, 0.5f));
                Raylib.DrawRectangleLines(10, 10, 250, 113, Color.BLUE);
                Raylib.DrawText("Free 2d camera controls:", 20, 20, 10, Color.BLACK);
                Raylib.DrawText("- Right/Left to move Offset", 40, 40, 10, Color.DARKGRAY);
                Raylib.DrawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, Color.DARKGRAY);
                Raylib.DrawText("- A / S to Rotate", 40, 80, 10, Color.DARKGRAY);
                Raylib.DrawText("- R to reset Zoom and Rotation", 40, 100, 10, Color.DARKGRAY);
                Raylib.EndDrawing();
                //----------------------------------------------------------------------------------
            }
            // De-Initialization
            //--------------------------------------------------------------------------------------
        }
        static void Main(string[] args)
        {
            //fönsteret
            Raylib.InitWindow(1000, 700, "CUBE");
            //antal fps
            Raylib.SetTargetFPS(60);

            //den röda karatären
            Rectangle block = new Rectangle(100, 50, 50, 50);
            //mappen
            Rectangle worldMap = new Rectangle(-200, -200, 900, 700);
            //avataren som man rör på
            Rectangle avatar = new Rectangle(400 - 20, 300 - 20, 40, 40);
            //pratbubblan
            Rectangle textBox = new Rectangle(150, -55, 250, 50);

            //detta användes aldrig, men skulle ha varit för att ta main karaktären till en annan värld.
            float timerMaxValue     = 60;
            float timerCurrentValue = timerMaxValue;
            //detta är för namnet
            int         MAX_INPUT_CHARS = 9;
            List <char> name            = new List <char>();
            //även för namnet, står att den inte användes men namn input funkar inte utan den. Kollar man dessutom längre ner används den

            bool mouseOnText = false;

            //för att kunna gå när karaktärn ska göra de.
            bool walkA = true;
            bool walkS = true;
            bool walkD = true;
            bool walkW = true;
            //kameran som följer karaktären.
            Camera2D camera = new Camera2D();


            camera.zoom = 1;
            //camera.target = new Vector2(400, 300);



            while (!Raylib.WindowShouldClose())
            {
                //kollar kolllision för mina karaktärer
                bool areOverlapping = Raylib.CheckCollisionRecs(block, avatar);

                // Raylib Drawing
                Raylib.BeginDrawing();
                Raylib.ClearBackground(Color.BLACK);

                Raylib.BeginMode2D(camera);
                Raylib.DrawRectangleRec(worldMap, Color.WHITE);
                Raylib.DrawText("use WASD to move", 100, 100, 50, Color.BLACK);
                Raylib.DrawRectangleRec(block, Color.RED);
                Raylib.DrawRectangleRec(avatar, Color.ORANGE);

                thisIsNotTheWASDKeys();

                //detta är för att min karaktär ska kunna gå under the drawing
                if (Raylib.IsKeyDown(KeyboardKey.KEY_A) && walkA == true)
                {
                    avatar.x        -= 3f;
                    camera.offset.X += 3f;
                }
                if (Raylib.IsKeyDown(KeyboardKey.KEY_D) && walkD == true)
                {
                    avatar.x        += 3f;
                    camera.offset.X -= 3f;
                }
                if (Raylib.IsKeyDown(KeyboardKey.KEY_S) && walkS == true)
                {
                    avatar.y        += 3f;
                    camera.offset.Y -= 3f;
                }
                if (Raylib.IsKeyDown(KeyboardKey.KEY_W) && walkW == true)
                {
                    avatar.y        -= 3f;
                    camera.offset.Y += 3f;
                }


                //detta är för när karaktärerna kolliderar, då ska man så still under sekvensen.
                if (areOverlapping == true)

                {
                    walkA = false;
                    walkD = false;
                    walkS = false;
                    walkW = false;
                    Raylib.DrawText("type your name and press enter", -150, -200, 20, Color.BLACK);
                    //"prat" sekvensen
                    Raylib.DrawText("... oh hey kid, wait you are not supposed to be here", -180, -100, 30, Color.RED);
                    Raylib.DrawText("who are you?", -100, -50, 30, Color.RED);
                    Raylib.DrawRectangleRec(textBox, Color.GRAY);
                    if (Raylib.CheckCollisionPointRec(Raylib.GetMousePosition(), textBox))
                    {
                        mouseOnText = true;
                    }
                    else
                    {
                        mouseOnText = false;
                    }

                    {
                        // Get char pressed (unicode character) on the queue
                        int key = Raylib.GetCharPressed();

                        // Check if more characters have been pressed on the same frame
                        while (key > 0)
                        {
                            //NOTE: Only allow keys in range [32..125]
                            if ((key >= 32) && (key <= 125) && (name.Count < MAX_INPUT_CHARS))
                            {
                                name.Add((char)key);
                            }

                            key = Raylib.GetCharPressed();  // Check next character in the queue
                        }

                        if (Raylib.IsKeyPressed(KeyboardKey.KEY_BACKSPACE))
                        {
                            if (name.Count > 0)
                            {
                                name.RemoveAt(name.Count - 1);
                            }
                        }
                        //detta är för att namnet ska kunna visas på skrämen
                        string namestr = new string(name.ToArray());
                        Raylib.DrawText(namestr, 170, -55, 40, Color.RED);

                        // så att karaktären ska gå efter prat sekevensen
                        if (Raylib.IsKeyDown(KeyboardKey.KEY_ENTER))
                        {
                            areOverlapping = false;
                            walkA          = true;
                            walkD          = true;
                            walkS          = true;
                            walkW          = true;
                            mouseOnText    = false;

                            //namnet ska visas över karaktären.
                            int xA = (int)avatar.x;
                            int yA = (int)avatar.y;
                            Raylib.DrawText(namestr, xA + 20, yA - 40, 30, Color.ORANGE);
                        }
                    }
                }
                Raylib.EndMode2D();

                Raylib.EndDrawing();
            }
        }
示例#14
0
        static void Start()
        {
            const int Width  = 1366;
            const int Height = 768;

            Raylib.InitWindow(Width, Height, "Harvesturr");
            Raylib.SetTargetFPS(60);

            GUILoadStyle("jungle");

            GUIPanelColor = Raylib.Fade(Color.BLACK, 0.8f);
            GameCamera    = new Camera2D(new Vector2(Width, Height) / 2, Vector2.Zero, 0, 2);

            GameMap.Load("test");

            if (DebugPerformance)
            {
                const float Dist = 50;

                Rectangle Rect   = GameMap.GetBounds();
                Vector2   Pos    = new Vector2(Rect.x, Rect.y) + new Vector2(10);
                int       XCount = (int)(Rect.width / Dist);
                int       YCount = (int)(Rect.height / Dist);

                for (int X = 0; X < XCount; X++)
                {
                    for (int Y = 0; Y < YCount; Y++)
                    {
                        Spawn(new UnitConduit(Pos + new Vector2(X, Y) * Dist));
                    }
                }
            }
            else
            {
                for (int i = 0; i < 100; i++)
                {
                    Spawn(new UnitMineral(GameMap.RandomMineralPoint(), Utils.Random(0, 100) > 80));
                }
            }

            Spawn(new UnitAlienUfo(Vector2.Zero));

            GameTools.AddRange(IsGameToolAttribute.CreateAllGameTools());
            Resources = 50;

            if (DebugView)
            {
                Resources = int.MaxValue;
            }

            // Test

            /*UnitConduit ConduitA = new UnitConduit(new Vector2(314.844f, 167.216f));
             * UnitConduit ConduitB = new UnitConduit(new Vector2(380.955f, 166.661f));
             * UnitConduit ConduitC = new UnitConduit(new Vector2(348.513f, 215.875f));
             *
             * Spawn(ConduitA);
             * Spawn(ConduitB);
             * Spawn(ConduitC);
             * Spawn(new UnitEnergyPacket(ConduitA, ConduitB));*/

            GameTimer.Restart();

            while (!Raylib.WindowShouldClose())
            {
                float FrameTime = Raylib.GetFrameTime();
                Time = (float)GameTimer.Elapsed.TotalSeconds;

                ScreenWidth  = Raylib.GetScreenWidth();
                ScreenHeight = Raylib.GetScreenHeight();

                Lockstep(Time, 1.0f / 60, 1.0f / 10);

                /*if (FrameTime < 0.5f)
                 *      Update(FrameTime);
                 * else
                 *      Console.WriteLine("Skipping update, frame time {0} s", FrameTime);*/

                Raylib.BeginDrawing();
                Raylib.ClearBackground(Color.SKYBLUE);

                Raylib.BeginMode2D(GameCamera);
                CurrentDrawState = DrawState.WORLD;
                DrawWorld();
                Raylib.EndMode2D();

                CurrentDrawState = DrawState.SCREEN;
                DrawScreen();
                Raylib.EndDrawing();

                CurrentDrawState = DrawState.NONE;
            }

            Raylib.CloseWindow();
        }