Esempio n. 1
0
        public void Menu()
        {
            if (state == "Menu")
            {
                mousepos = Raylib.GetMousePosition();
                Raylib.DrawText("Welcome To Doodle Jump", 100, 150, 50, Color.BLUE);
                Raylib.DrawRectangleRec(button1, Color.DARKBLUE);
                Raylib.DrawRectangleRec(button2, Color.DARKBLUE);
                Raylib.DrawText("Play", 350, 300, 50, background);
                Raylib.DrawText("Highscore", 275, 600, 50, background);
                if (Raylib.CheckCollisionPointRec(mousepos, button1) && Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON))
                {
                    state = "game";
                }
                if (Raylib.CheckCollisionPointRec(mousepos, button2) && Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON))
                {
                    state = "Scores";
                }
            }

            if (state == "Scores")
            {
                DisplayScores();
            }
        }
Esempio n. 2
0
        public List <Creation> searchCreations(World world)
        {
            List <Creation> creations = new List <Creation>();

            /*for (int i = position.x - 5; i < position.x + 5; i++) {
             *  for (int j = position.y - 5; j < position.y + 5; j++) {
             *      for (int a = 0; a < world.map[i][j].creations.Count; a++) {
             *          creations.Add(world.map[i][j].creations[a]);
             *      }
             *  }
             * }*/
            for (int i = 0; i < world.detectors.Count; i++)
            {
                Rectangle detector = new Rectangle(world.detectors[i].position.x, world.detectors[i].position.y, world.detectors[i].wh.x, world.detectors[i].wh.y);
                if (Raylib.CheckCollisionPointRec(new System.Numerics.Vector2(position.x, position.y), detector))
                {
                    if (!world.detectors[i].creations.Contains(this))
                    {
                        world.detectors[i].creations.Add(this);
                    }
                    foreach (Creation creation in world.detectors[i].creations)
                    {
                        if (creation != this)
                        {
                            creations.Add(creation);
                        }
                    }
                }
                else if (world.detectors[i].creations.Contains(this))
                {
                    world.detectors[i].creations.Remove(this);
                }
            }
            return(creations);
        }
Esempio n. 3
0
 private void CheckDetector(World world)
 {
     if (detectorLocation != null)
     {
         Rectangle detector = new Rectangle(detectorLocation.position.x, detectorLocation.position.y, detectorLocation.wh.x, detectorLocation.wh.y);
         if (Raylib.CheckCollisionPointRec(new System.Numerics.Vector2(position.x, position.y), detector))
         {
             return;
         }
     }
     for (int i = 0; i < world.detectors.Count; i++)
     {
         Rectangle detector2 = new Rectangle(world.detectors[i].position.x, world.detectors[i].position.y, world.detectors[i].wh.x, world.detectors[i].wh.y);
         if (Raylib.CheckCollisionPointRec(new System.Numerics.Vector2(position.x, position.y), detector2))
         {
             if (!world.detectors[i].creations.Contains(this))
             {
                 world.detectors[i].creations.Add(this);
             }
             detectorLocation = world.detectors[i];
         }
         else if (world.detectors[i].creations.Contains(this))
         {
             world.detectors[i].creations.Remove(this);
         }
     }
 }
Esempio n. 4
0
 public void ChatBox()
 {
     dt += Raylib.GetFrameTime();
     if (Raylib.CheckCollisionPointRec(Raylib.GetMousePosition(), inputBox))
     {
         key = Raylib.GetKeyPressed();
         if (key >= 32 && key <= 255 && letterCount < maxInput && key != 0)
         {
             written[letterCount] = key;
             name[letterCount]    = (char)key;
             letterCount++;
         }
         if (Raylib.IsKeyDown(KeyboardKey.KEY_BACKSPACE) && dt > 0.1)
         {
             letterCount--;
             if (letterCount < 0)
             {
                 letterCount = 0;
             }
             name[letterCount] = '\0';
             dt = 0;
         }
         if (Raylib.IsKeyReleased(KeyboardKey.KEY_ENTER))
         {
             //FIX:
             if (name[0] == '!')
             {
                 activeServer.SendMessage("COMMAND", new string(name).Replace("\0", string.Empty));
             }
             else
             {
                 activeServer.SendMessage("MESSAGE", new string(name).Replace("\0", string.Empty));
             }
             for (int i = 0; i < name.Length; i++)
             {
                 name[i]     = '\0';
                 letterCount = 0;
             }
         }
     }
     //Upload Picture function
     if (Raylib.CheckCollisionPointRec(Raylib.GetMousePosition(), openImage) && Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON))
     {
         CommonOpenFileDialog fileExplorer = new CommonOpenFileDialog();
         fileExplorer.InitialDirectory = @"C:\Users\" + Environment.UserName + @"\Pictures";
         fileExplorer.Filters.Add(new CommonFileDialogFilter("", "*.PNG;*.JPG"));
         if (fileExplorer.ShowDialog() == CommonFileDialogResult.Ok)
         {
             activeServer.SendMessage("MESSAGE", imagePath: fileExplorer.FileName);
         }
     }
     Raylib.DrawRectangle((int)inputBox.x, (int)inputBox.y, (int)inputBox.height, (int)inputBox.width, Color.BLUE);
     iconTexture.height = 80;
     iconTexture.width  = 80;
     Raylib.DrawTexture(iconTexture, 670, 730, Color.WHITE);
     DrawTextRec(font, new string(name), inputBox, 16, 1, true, Color.WHITE);
 }
Esempio n. 5
0
 public static IEnumerable <GameUnit> Pick(Vector2 WorldPos, bool PickUnpickable = false)
 {
     foreach (var U in GetAllGameUnits(PickUnpickable))
     {
         if (Raylib.CheckCollisionPointRec(WorldPos, U.GetBoundingRect()))
         {
             yield return(U);
         }
     }
 }
Esempio n. 6
0
 public void Update(Simulator sim, Vector2 mousePosInWorld)
 {
     if (Raylib.IsMouseButtonPressed(MouseButton.MOUSE_RIGHT_BUTTON))
     {
         if (Raylib.CheckCollisionPointRec(mousePosInWorld, Box))
         {
             Value = Value == LogicValue.HIGH ? LogicValue.LOW : LogicValue.HIGH;
         }
     }
 }
Esempio n. 7
0
 protected bool IfHover()
 {
     if (Raylib.CheckCollisionPointRec(mousePosition, hitbox))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 8
0
 public DrawableComponent GetComponentFromPosition(Vector2 position)
 {
     foreach (DrawableComponent dc in AllComponents)
     {
         if (Raylib.CheckCollisionPointRec(position, dc.Box))
         {
             return(dc);
         }
     }
     return(null);
 }
Esempio n. 9
0
 public void GameOver()
 {
     mousepos = Raylib.GetMousePosition();
     Raylib.DrawRectangleRec(button3, Color.DARKBLUE);
     Raylib.DrawText("Menu", 350, 200, 50, background);
     if (Raylib.CheckCollisionPointRec(mousepos, button3) && Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON))
     {
         state = "Menu";
         reset = true;
     }
     Raylib.DrawText("Game Over", 230, 400, 50, Color.BLUE);
     Raylib.DrawText("Last Run: " + score, 230, 480, 20, Color.BLUE);
 }
Esempio n. 10
0
 public bool TryGetComponentFromWorldPosition(Vector2 position, [NotNullWhen(true)] out Component?comp)
 {
     foreach (Component c in this.AllComponents)
     {
         if (Raylib.CheckCollisionPointRec(position, c.GetRectangle()))
         {
             comp = c;
             return(true);
         }
     }
     comp = null;
     return(false);
 }
Esempio n. 11
0
        public void ServerListUI(List <Server> serverList)
        {
            int y = 10;

            foreach (Server server in serverList)
            {
                Raylib.DrawRectangle(10, y, 50, 50, Color.GRAY);
                Raylib.DrawTexture(server.ServerImageTexture, 10, y, Color.WHITE);
                if (ActiveServer != null)
                {
                    DrawText("Current Server: " + ActiveServer.serverName, 950, 10, 16, Color.WHITE);
                }
                if (Raylib.CheckCollisionPointRec(Raylib.GetMousePosition(), new Rectangle(10, y, 50, 50)) && Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON))
                {
                    activeServer = server;
                }
                y += 60;
            }
        }
Esempio n. 12
0
        // ta-bort-instans-av-spaceship metod
        protected bool Delete()
        {
            Vector2[] point = new Vector2[3];
            // lägger in de tre hörnen i en vector2 array med tre plattser
            for (int index = 0; index < 3; index++)
            {
                if (index == 0)
                {
                    point[index].X = xPlanePos;
                    point[index].Y = yPlanePos;
                }
                else
                {
                    point[index].X = pointTriangle[index].X;
                    point[index].Y = pointTriangle[index].Y;
                }
            }
            // tittar om någon av de tre hörnen kolliderar med asteroiden,
            // detta görs för alla asteroider i listan asteroidList
            for (int index = asteroidList.Count - 1; index > -1; index--)
            {
                for (int i = 0; i < 3; i++)
                {
                    if (Raylib.CheckCollisionPointCircle(point[i], asteroidList[index].GetCirclePos, asteroidList[index].GetAsteroidHitboxSize))
                    {
                        return(true);
                    }
                }
            }

            for (int index = LimitScreen.LimitList.Count - 1; index > -1; index--)
            {
                if (LimitScreen.LimitList[index].LimitActive && Raylib.CheckCollisionPointRec(pointTriangle[0], LimitScreen.LimitList[index].LimitRectangle))
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 13
0
        public void DisplayScores()
        {
            mousepos = Raylib.GetMousePosition();
            Raylib.DrawRectangleRec(button3, Color.DARKBLUE);
            Raylib.DrawText("Back", 350, 200, 50, background);
            if (Raylib.CheckCollisionPointRec(mousepos, button3) && Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON))
            {
                state = "Menu";
            }
            Raylib.DrawText("Highscores:", 250, 450, 40, Color.BLUE);

            for (int i = 0; i < scores.Count; i++)
            {
                if (i == 0)
                {
                    Raylib.DrawText((i + 1 + "   :") + scores[i], 250, 20 * i + 500, 30, Color.BLUE);
                }
                else
                {
                    Raylib.DrawText((i + 1 + "  :") + scores[i], 250, 20 * i + 500, 30, Color.BLUE);
                }
            }
        }
        private void GroundChecker()
        {
            // Check if colliding with ground object

            // Very inefficient way of getting all ground objects
            List <GameObject> groundObjects = gameObjects.FindAll(x => x is Ground);

            isGrounded = false;
            foreach (GameObject groundObject in groundObjects)
            {
                // Check head
                foreach (Vector2 headChecker in headCheckers)
                {
                    if (Raylib.CheckCollisionPointRec(headChecker + new Vector2(rect.x, rect.y), groundObject.rect))
                    {
                        velocity.Y = 0;
                        Rectangle overlapRect = Raylib.GetCollisionRec(rect, groundObject.rect);
                        position.Y += overlapRect.height + 1;
                        break;
                    }
                }

                // Check feet
                foreach (Vector2 groundChecker in feetCheckers)
                {
                    if (Raylib.CheckCollisionPointRec(groundChecker + new Vector2(rect.x, rect.y), groundObject.rect))
                    {
                        velocity.Y = 0;
                        Rectangle overlapRect = Raylib.GetCollisionRec(rect, groundObject.rect);
                        position.Y -= overlapRect.height;
                        isGrounded  = true;
                        break;
                    }
                }
            }
        }
Esempio n. 15
0
        static void Main(string[] args)
        {
            int screenWidth  = 1920;
            int screenHeight = 1000;

            Raylib.InitWindow(screenWidth, screenHeight, "5000 IQ GAME");
            Raylib.SetTargetFPS(60);

            string gamestate = "level1";

            Rectangle startButton = new Rectangle(900, 350, 90, 30);

            Rectangle tree = new Rectangle(1230, 300, 400, 600);

            Rectangle apple = new Rectangle(1500, 350, 50, 50);

            bool appleIsReal = false;

            Rectangle answer2 = new Rectangle(360, 360, 50, 50);


            //KOMPONENTERNA I LISTEN
            List <Rectangle> rectangles = new List <Rectangle>();

            rectangles.Add(new Rectangle(10, 10, 20, 20));
            rectangles.Add(new Rectangle(20, 20, 20, 20));
            rectangles.Add(new Rectangle(30, 30, 20, 20));
            rectangles.Add(new Rectangle(40, 40, 20, 20));



            //VAD SOM HÄNDER NÄR VI ÄR INNE I SPELET
            while (!Raylib.WindowShouldClose())
            {
                if (gamestate == "level1")
                {
                    //LOGIK
                    //OM MAN KLICKAR PÅ startbutton SÅ BYTER VI TILL level2
                    if (Raylib.CheckCollisionPointRec(Raylib.GetMousePosition(), startButton) && Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON))
                    {
                        gamestate = "level2";
                    }
                    //DRAW
                    Raylib.BeginDrawing();
                    Raylib.ClearBackground(Color.WHITE);


                    Raylib.DrawRectangleRec(startButton, Color.WHITE);
                    Raylib.DrawText("5000 IQ TEST", 250, 150, 200, Color.BLACK);
                    Raylib.DrawText("Press PLAY to begin", 800, 350, 30, Color.BLACK);
                    Raylib.DrawText("PLAY", 1000, 680, 130, Color.MAGENTA);
                    Raylib.DrawText("PLAY", 100, 600, 100, Color.BLUE);
                    Raylib.DrawText("PLAY", 500, 800, 80, Color.GREEN);
                    Raylib.DrawText("PLAY", 800, 500, 90, Color.RED);
                    Raylib.DrawText("PLAY", 1600, 650, 110, Color.YELLOW);

                    Raylib.EndDrawing();
                }

                else if (gamestate == "level2")
                {
                    //LOGIK

                    if (Raylib.CheckCollisionPointRec(Raylib.GetMousePosition(), tree) && Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON))
                    {
                        appleIsReal = true;
                    }

                    if (Raylib.CheckCollisionPointRec(Raylib.GetMousePosition(), answer2) && Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON))
                    {
                        gamestate = "level3";
                    }


                    //DRAW
                    Raylib.BeginDrawing();
                    Raylib.ClearBackground(Color.WHITE);
                    Raylib.DrawRectangle(1400, 600, 60, 300, Color.BROWN);
                    Raylib.DrawCircle(1430, 500, 200, Color.DARKGREEN);
                    Raylib.DrawRectangle(1480, 320, 50, 50, Color.RED);
                    Raylib.DrawRectangle(1300, 370, 50, 50, Color.RED);
                    Raylib.DrawRectangle(1400, 420, 50, 50, Color.RED);
                    Raylib.DrawRectangle(1350, 580, 50, 50, Color.RED);

                    DrawKeypad();
                    Raylib.DrawText("How many apples are in the tree?", 120, 250, 30, Color.BLACK);

                    //APPLE FALLING
                    if (appleIsReal)
                    {
                        Raylib.DrawRectangleRec(apple, Color.RED);
                    }

                    if (appleIsReal && apple.y < 600)
                    {
                        apple.y += 3;
                    }
                    Raylib.EndDrawing();
                }
                else if (gamestate == "level3")
                {
                    Raylib.BeginDrawing();
                    Raylib.ClearBackground(Color.WHITE);


                    //VI GÅR FRÅN 0 OCH GÅR UPP ETT STEG VARJE GÅNG TILLS REKTANGLARNA I LISTAN TAR S**T

                    for (int i = 0; i < rectangles.Count; i++)
                    {
                        Raylib.DrawRectangleRec(rectangles[i], Color.BLACK);
                    }

                    Raylib.EndDrawing();
                }
            }
        }
Esempio n. 16
0
        static void Main(string[] args)
        {
            Raylib.InitWindow(500, 700, "Sänka Skepp");
            Raylib.SetTargetFPS(60);
            int              height        = Raylib.GetScreenHeight();
            int              width         = Raylib.GetScreenWidth();
            string           state         = "menu";
            string           state2        = "playerPlace";
            int              distance      = 100;
            bool             playerHasShot = false;
            float            timer         = 1;
            Random           generator     = new Random();
            List <int>       playerBoats   = new List <int>();
            List <int>       botBoats      = new List <int>();
            List <int>       playerShots   = new List <int>();
            List <int>       botShots      = new List <int>();
            List <int>       playerHits    = new List <int>();
            List <int>       botHits       = new List <int>();
            int              whichBoat     = 1;
            int              botsShot      = 0;
            int              playersShot   = 0;
            bool             didItHit      = false;
            List <Rectangle> grid          = new List <Rectangle>();

            for (int x = 0; x < 5; x++)
            {
                for (int y = 0; y < 5; y++)
                {
                    Rectangle r = new Rectangle(y * 100, x * 100, 99, 99);
                    grid.Add(r);
                }
            }

            while (!Raylib.WindowShouldClose())
            {
                Raylib.BeginDrawing();
                Raylib.ClearBackground(Color.BLACK);

                //Skriver ut introtext
                if (state == "menu")
                {
                    Raylib.DrawText("Welcome to Battleship", width / 2 - 130, 200, 25, Color.WHITE);
                    Raylib.DrawText("Press enter to continue", width / 2 - 125, 250, 20, Color.WHITE);
                    Raylib.DrawText("Press H for rules", width / 2 - 110, 300, 20, Color.WHITE);
                    if (Raylib.IsKeyPressed(KeyboardKey.KEY_ENTER))
                    {
                        state = "place";
                    }
                    if (Raylib.IsKeyPressed(KeyboardKey.KEY_H))
                    {
                        state = "rules";
                    }
                }
                //Skriver ut reglerna om spelaren vill
                if (state == "rules")
                {
                    Raylib.DrawText("Rules:", 225, 250, 20, Color.WHITE);
                    Raylib.DrawText("The rules are simple. First you will place your boats.", 50, 270, 15, Color.WHITE);
                    Raylib.DrawText("When placing the boats the square you put your boat in will", 20, 290, 15, Color.WHITE);
                    Raylib.DrawText("become red. When all your boats are placed in the enemy will", 20, 310, 15, Color.WHITE);
                    Raylib.DrawText("randomize a tile and shoot it. If there is a boat there the tile", 20, 330, 15, Color.WHITE);
                    Raylib.DrawText("will become red but if it misses the tile will turn yellow. Now it's your", 20, 350, 15, Color.WHITE);
                    Raylib.DrawText("time to attack. Press a tile and the tile will become red if you hit ", 20, 370, 15, Color.WHITE);
                    Raylib.DrawText("and yellow if you miss.", 200, 390, 15, Color.WHITE);
                    Raylib.DrawText("Press Enter to go back", 100, 410, 25, Color.WHITE);
                    if (Raylib.IsKeyPressed(KeyboardKey.KEY_ENTER))
                    {
                        state = "menu";
                    }
                }
                //Byter state till att börja placera båtar
                if (state == "place")
                {
                    //Ritar ut griden
                    for (int i = 0; i < 6; i++)
                    {
                        Raylib.DrawLine(i * distance, 1, i * distance, 500, Color.WHITE);
                        Raylib.DrawLine(1, i * distance, 500, i * distance, Color.WHITE);
                    }
                    for (int i = 0; i < 25; i++)
                    {
                        Raylib.DrawRectangleRec(grid[i], Color.BLUE);
                    }

                    if (state2 == "playerPlace")
                    {
                        if (whichBoat < 6)
                        {
                            Raylib.DrawText("Place boat nr: " + whichBoat, 50, 510, 20, Color.WHITE);
                        }
                        Vector2 mousePosition = new Vector2(Raylib.GetMouseX(), Raylib.GetMouseY());

                        //Tar reda på vilken rektangel som clickades och lägger till den som en av spelarens båtar
                        int whichRectangleWasClicked = 0;
                        if (whichBoat < 6)
                        {
                            for (int i = 0; i < 25; i++)
                            {
                                if (Raylib.CheckCollisionPointRec(mousePosition, grid[i]) && Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON))
                                {
                                    if (!playerBoats.Contains(i))
                                    {
                                        whichRectangleWasClicked = i;
                                        playerBoats.Add(whichRectangleWasClicked);
                                        whichBoat++;
                                    }
                                }
                            }
                        }
                        for (int i = 0; i < playerBoats.Count; i++)
                        {
                            Raylib.DrawRectangleRec(grid[playerBoats[i]], Color.RED);
                        }
                        if (whichBoat >= 6)
                        {
                            //Gör så spelaren hinner se sina båtar innan den byter state
                            timer -= Raylib.GetFrameTime();
                            if (timer < 0)
                            {
                                state2 = "botplace";
                            }
                        }
                    }

                    //Randomiserar vilka rutor boten ska placera sina båtar på
                    if (state2 == "botplace")
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            int p = generator.Next(0, 25);
                            while (botBoats.Contains(p))
                            {
                                p = generator.Next(0, 25);
                            }
                            botBoats.Add(p);
                        }
                    }
                    //Byter state om båda har fem båtar
                    if (botBoats.Count == 5 && playerBoats.Count == 5)
                    {
                        state  = "battle";
                        state2 = "botShot";
                        timer  = 5;
                    }
                }
                if (state == "battle")
                {
                    //Ritar ut griden
                    for (int i = 0; i < 6; i++)
                    {
                        Raylib.DrawLine(i * distance, 1, i * distance, 500, Color.WHITE);
                        Raylib.DrawLine(1, i * distance, 500, i * distance, Color.WHITE);
                    }
                    for (int i = 0; i < 25; i++)
                    {
                        Raylib.DrawRectangleRec(grid[i], Color.BLUE);
                    }

                    //Väljer vilken ruta botten ska skjuta på
                    if (state2 == "botShot")
                    {
                        int p = generator.Next(0, 25);
                        //kollar så botten inte skjuter på samma ställe där den redan skjutit
                        while (botHits.Contains(p) || botShots.Contains(p))
                        {
                            p = generator.Next(0, 25);
                        }
                        if (playerBoats.Contains(p))
                        {
                            botHits.Add(p);
                            didItHit = true;
                        }
                        else
                        {
                            botShots.Add(p);
                        }
                        //Tittar om boten har träffat alla spelarens båtar
                        if (botHits.Count < 4)
                        {
                            botsShot = p;
                            state2   = "showBotShot";
                            timer    = 5;
                        }
                        else if (botHits.Count == 5)
                        {
                            state = "botWins";
                        }
                    }
                    //Visar bottens skott
                    if (state2 == "showBotShot")
                    {
                        if (didItHit)
                        {
                            Raylib.DrawText("The bot shot at square " + botsShot + " and hit", 50, 530, 20, Color.WHITE);
                        }
                        else
                        {
                            Raylib.DrawText("The bot shot at square " + botsShot + " and missed", 50, 530, 20, Color.WHITE);
                        }
                        if (botShots.Count > 0)
                        {
                            for (int i = 0; i < botShots.Count; i++)
                            {
                                Raylib.DrawRectangleRec(grid[botShots[i]], Color.YELLOW);
                            }
                        }
                        if (botHits.Count > 0)
                        {
                            for (int i = 0; i < botHits.Count; i++)
                            {
                                Raylib.DrawRectangleRec(grid[botHits[i]], Color.RED);
                            }
                        }
                        timer -= Raylib.GetFrameTime();
                        if (timer < 0)
                        {
                            state2        = "playerShot";
                            playerHasShot = false;
                            didItHit      = false;
                        }
                    }


                    if (state2 == "playerShot")
                    {
                        Raylib.DrawText("Your turn to shoot.", 50, 510, 20, Color.WHITE);
                        //Ritar ut spelarens föregående skott
                        if (playerShots.Count > 0)
                        {
                            for (int i = 0; i < playerShots.Count; i++)
                            {
                                Raylib.DrawRectangleRec(grid[playerShots[i]], Color.YELLOW);
                            }
                        }
                        if (playerHits.Count > 0)
                        {
                            for (int i = 0; i < playerHits.Count; i++)
                            {
                                Raylib.DrawRectangleRec(grid[playerHits[i]], Color.RED);
                            }
                        }

                        //Tar reda på vart spelaren clickade och skjuter där
                        Vector2 mousePosition = new Vector2(Raylib.GetMouseX(), Raylib.GetMouseY());

                        for (int i = 0; i < 25; i++)
                        {
                            if (Raylib.CheckCollisionPointRec(mousePosition, grid[i]) && Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON))
                            {
                                //Tittar om skottet träffade
                                if (!playerShots.Contains(i) && !playerHits.Contains(i))
                                {
                                    if (botBoats.Contains(i))
                                    {
                                        playerHits.Add(i);
                                        playerHasShot = true;
                                        playersShot   = i;
                                        didItHit      = true;
                                    }
                                    else
                                    {
                                        playerShots.Add(i);
                                        playerHasShot = true;
                                        playersShot   = i;
                                    }
                                }
                            }
                        }
                        //Tittar om spelaren har träffat alla båtar
                        if (playerHasShot && playerHits.Count <= 4)
                        {
                            state2 = "showPlayerShots";
                            timer  = 5;
                        }
                        if (playerHits.Count >= 5)
                        {
                            state = "playerWins";
                        }
                    }
                    //Visar spelarens skott
                    if (state2 == "showPlayerShots")
                    {
                        if (didItHit)
                        {
                            Raylib.DrawText("You shot at square " + playersShot + " and hit", 50, 530, 20, Color.WHITE);
                        }
                        else
                        {
                            Raylib.DrawText("You shot at square " + playersShot + " and missed", 50, 530, 20, Color.WHITE);
                        }

                        if (playerShots.Count > 0)
                        {
                            for (int i = 0; i < playerShots.Count; i++)
                            {
                                Raylib.DrawRectangleRec(grid[playerShots[i]], Color.YELLOW);
                            }
                        }
                        if (playerHits.Count > 0)
                        {
                            for (int i = 0; i < playerHits.Count; i++)
                            {
                                Raylib.DrawRectangleRec(grid[playerHits[i]], Color.RED);
                            }
                        }
                        timer -= Raylib.GetFrameTime();
                        if (timer < 0)
                        {
                            state2   = "botShot";
                            didItHit = false;
                        }
                    }
                }
                //Skriver ut grattis om spelaren eller botten van
                if (state == "playerWins")
                {
                    Raylib.DrawText("Congratulations You Win", width / 2 - 130, 200, 25, Color.WHITE);
                    Raylib.DrawText("To play again press enter", width / 2 - 125, 250, 20, Color.WHITE);
                    if (Raylib.IsKeyPressed(KeyboardKey.KEY_ENTER))
                    {
                        state = "reset";
                    }
                }
                if (state == "botWins")
                {
                    Raylib.DrawText("Oh no, you lost", width / 2 - 130, 200, 25, Color.WHITE);
                    Raylib.DrawText("To play again press enter", width / 2 - 125, 250, 20, Color.WHITE);
                    if (Raylib.IsKeyPressed(KeyboardKey.KEY_ENTER))
                    {
                        state = "reset";
                    }
                }
                //Återställer alla värden till startvärden för att man ska kunna köra igen
                if (state == "reset")
                {
                    state         = "menu";
                    state2        = "playerPlace";
                    playerHasShot = false;
                    timer         = 1;
                    playerBoats.Clear();
                    botBoats.Clear();
                    playerShots.Clear();
                    botShots.Clear();
                    playerHits.Clear();
                    botHits.Clear();
                    whichBoat   = 1;
                    botsShot    = 0;
                    playersShot = 0;
                    didItHit    = false;
                }

                Raylib.EndDrawing();
            }
        }
        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();
            }
        }
 // This will check if the mouse is within the bounds of the button.
 public override bool IsHovered()
 {
     return(Raylib.CheckCollisionPointRec(Raylib.GetMousePosition(), btnBounds));
 }
Esempio n. 19
0
        // https://stackoverflow.com/a/49886367
        private void TryPickUpRock()
        {
            List <(int index, int x, int y, float roation, float scale)> rocksToRemove = new List <(int index, int x, int y, float roation, float scale)>()
            {
            };

            foreach (var rock in rocks.rockTypesAndLocations)
            {
                // Old code, couldn't handle rotation of rocks
                //bool matchX = false;
                //bool matchY = false;
                //if (x > (rock.x - (rocks.GetTexture(rock.index).width*rock.scale)))
                //if (x < rock.x)
                // matchX = true;
                //if (y+40 > (rock.y - (rocks.GetTexture(rock.index).height*rock.scale)))
                //if (y+40 < rock.y)
                //matchY = true;
                //if (matchX && matchY)
                //rocksToRemove.Add(rock);

                System.Drawing.RectangleF clientRectangle = new System.Drawing.RectangleF(rock.x, rock.y, (rocks.GetTexture(rock.index).width *rock.scale), (rocks.GetTexture(rock.index).height *rock.scale));

                // Create Matrix and rotate points.
                // Note: requires libgdiplus
                Matrix matrix = new Matrix();
                var    p      = new System.Drawing.PointF[] {
                    clientRectangle.Location,
                    new System.Drawing.PointF(clientRectangle.Right, clientRectangle.Top),
                    new System.Drawing.PointF(clientRectangle.Right, clientRectangle.Bottom),
                    new System.Drawing.PointF(clientRectangle.Left, clientRectangle.Bottom)
                };
                matrix.RotateAt(rock.rotation, new System.Drawing.PointF(clientRectangle.X, clientRectangle.Top));
                matrix.TransformPoints(p);

                var astronautRectangle = new Raylib_cs.Rectangle(x + 50, y + 10, 50, 110);

                // Detect if we're touching the corners of the rocks.
                if (Raylib.CheckCollisionPointRec(new Vector2(p[0].X, p[0].Y), astronautRectangle))
                {
                    rocksToRemove.Add(rock);
                }
                if (Raylib.CheckCollisionPointRec(new Vector2(p[1].X, p[1].Y), astronautRectangle))
                {
                    rocksToRemove.Add(rock);
                }
                if (Raylib.CheckCollisionPointRec(new Vector2(p[2].X, p[2].Y), astronautRectangle))
                {
                    rocksToRemove.Add(rock);
                }
                if (Raylib.CheckCollisionPointRec(new Vector2(p[3].X, p[3].Y), astronautRectangle))
                {
                    rocksToRemove.Add(rock);
                }

                var sideOneMidpoint   = new ParametricLine(p[0], p[1]);
                var sideTwoMidpoint   = new ParametricLine(p[1], p[2]);
                var sideThreeMidpoint = new ParametricLine(p[2], p[3]);
                var sideFourMidpoint  = new ParametricLine(p[3], p[0]);

                // Detect if touching midpoint of rock edge.
                if (Raylib.CheckCollisionPointRec(new Vector2(sideOneMidpoint.Fraction(1.0f / 2.0f).X, sideOneMidpoint.Fraction(1.0f / 2.0f).Y), astronautRectangle))
                {
                    rocksToRemove.Add(rock);
                }
                if (Raylib.CheckCollisionPointRec(new Vector2(sideTwoMidpoint.Fraction(1.0f / 2.0f).X, sideOneMidpoint.Fraction(1.0f / 2.0f).Y), astronautRectangle))
                {
                    rocksToRemove.Add(rock);
                }
                if (Raylib.CheckCollisionPointRec(new Vector2(sideThreeMidpoint.Fraction(1.0f / 2.0f).X, sideOneMidpoint.Fraction(1.0f / 2.0f).Y), astronautRectangle))
                {
                    rocksToRemove.Add(rock);
                }
                if (Raylib.CheckCollisionPointRec(new Vector2(sideFourMidpoint.Fraction(1.0f / 2.0f).X, sideOneMidpoint.Fraction(1.0f / 2.0f).Y), astronautRectangle))
                {
                    rocksToRemove.Add(rock);
                }
            }
            foreach (var rock in rocksToRemove)
            {
                collectRocks.rocksCollected++;
                rocks.rockTypesAndLocations.Remove(rock);
            }
            if (rocksToRemove.Count == 0)
            {
                IsMoving = false;
            }
        }
Esempio n. 20
0
        static void Main(string[] args)
        {
            string modelName = args.Length > 0 ? args[0] : "default";

            string modelPath = "resources/models/" + modelName;

            if (!File.Exists(modelPath + "/map.bmp") || !File.Exists(modelPath + "/spawn.yml"))
            {
                Console.WriteLine("Wrong model title!");
                return;
            }
            World world = new World(modelPath + "/map.bmp");

            screenWidth  = world.GetMapWidth();
            screenHeight = world.GetMapHeight();
            Raylib.InitWindow(screenWidth, screenHeight, "WorldTens");

            string spawnYaml    = System.IO.File.ReadAllText("resources/models/" + modelName + "/spawn.yml");
            var    deserializer = new YamlDotNet.Serialization.Deserializer();

            CreationSet[] creationSets = deserializer.Deserialize <CreationSet[]>(spawnYaml);

            for (int i = 0; i < creationSets.Length; i++)
            {
                for (int j = 0; j < creationSets[i].count; j++)
                {
                    Creation creation = new Creation(new Vector2(
                                                         creationSets[i].posX, creationSets[i].posY
                                                         ), creationSets[i].mind);

                    creation.politStatus = creationSets[i].politStatus;
                    creation.GetDetectorFirstTime(world).creations.Add(creation);
                }
            }

            while (!Raylib.WindowShouldClose())
            {
                world.DecreaseTens(Raylib.GetFrameTime());

                Raylib.BeginDrawing();

                if (OperatingSystem.IsWindows() || args.Length < 2 || (args.Length > 1 && args[1] != "time"))
                {
                    Raylib.ClearBackground(Color.WHITE);
                    world.DrawOptimized();
                    Raylib.DrawText("Good luck in WorldTens!", 10, 10, 14, Color.BLACK);
                    Raylib.DrawText(iterations.ToString(), 0, screenHeight - 20, 20, Color.BLACK);
                    Raylib.DrawText(world.GetTension().ToString(), screenWidth - 100, 10, 20, Color.BLACK);
                    Raylib.DrawText("FPS: " + Raylib.GetFPS().ToString(), 350, 0, 20, Color.BLACK);
                }

                if (iterTmp >= iterMax || iterations == 0 || OperatingSystem.IsWindows() || (args.Length > 1 && args[1] == "redraw"))
                {
                    Raylib.ClearBackground(Color.WHITE);
                    for (int i = 0; i < world.map.Count; i++)
                    {
                        for (int j = 0; j < world.map[i].Count; j++)
                        {
                            world.DrawMapPixel(new Vector2(i, j));
                        }
                    }
                    Raylib.DrawText("Good luck in WorldTens!", 10, 10, 14, Color.BLACK);
                    Raylib.DrawText(iterations.ToString(), 0, screenHeight - 20, 20, Color.BLACK);
                    Raylib.DrawText(world.GetTension().ToString(), screenWidth - 100, 10, 20, Color.BLACK);
                    Raylib.DrawText("FPS: " + Raylib.GetFPS().ToString(), 350, 0, 20, Color.BLACK);
                    iterTmp = 0;
                }

                for (int i = 0; i < world.detectors.Count; i++)
                {
                    int             citizensCounter = 0;
                    List <Creation> citizens        = new List <Creation>();
                    for (int j = 0; j < world.detectors[i].creations.Count; j++)
                    {
                        Creation creation = world.detectors[i].creations[j];
                        //if (world.map[creation.position.x][creation.position.y].city) {
                        citizensCounter++;
                        citizens.Add(creation);
                        //}
                        Vector2 prevPos = new Vector2(creation.position.x, creation.position.y);
                        creation.DoAction(Raylib.GetFrameTime(), world);
                        world.DrawMapPixel(prevPos);

                        world.DrawMapPixel(creation.position);

                        if (creation.alive)
                        {
                            Raylib.DrawPixel(creation.position.x, creation.position.y, Color.RED);
                        }
                        else
                        {
                            Raylib.DrawPixel(creation.position.x, creation.position.y, Color.BROWN);
                            world.detectors[i].creations.Remove(creation);
                        }
                    }
                    if (citizensCounter > 2)
                    {
                        if (world.countries.Count == 0)
                        {
                            world.CreateCountry(citizens, i);
                        }
                        int enemyCounter   = 0;
                        int citizenCounter = 0;
                        foreach (Creation citizen in citizens)
                        {
                            if (citizen.country == null && world.detectors[i].country == null)
                            {
                                world.CreateCountry(citizens, i);
                            }
                            if (world.detectors[i].country == citizen.country)
                            {
                                citizenCounter++;
                            }
                            else
                            {
                                enemyCounter++;
                            }
                        }
                        if (enemyCounter > citizenCounter)
                        {
                            Country dominator = null;
                            foreach (Creation citizen in citizens)
                            {
                                if (citizen.country != world.detectors[i].country)
                                {
                                    world.detectors[i].country = citizen.country;
                                    dominator = citizen.country;
                                    break;
                                }
                            }
                            foreach (Creation citizen in citizens)
                            {
                                if (citizen.country != world.detectors[i].country)
                                {
                                    citizen.country = world.detectors[i].country;
                                }
                            }
                            if (dominator == null)
                            {
                                world.CreateCountry(citizens, i);
                            }
                            Console.WriteLine("territory captured");
                        }
                    }
                    if (world.year != yearCalc)
                    {
                        foreach (Country country in world.countries)
                        {
                            if (world.detectors[i].country == country)
                            {
                                country.CalculateWars(world);
                                country.CalculateRequirements(world);
                                country.ExecuteRequirements(citizens);
                            }
                        }
                    }
                    citizens = null;
                }

                if (world.year != yearCalc)
                {
                    yearCalc = world.year;
                }
                iterations++;
                iterTmp++;
                world.AddTime();

                if (Raylib.IsKeyDown(KeyboardKey.KEY_KP_MULTIPLY))
                {
                    world.IncreaseTens(100, world.countries[0]);
                }

                if (Raylib.IsKeyDown(KeyboardKey.KEY_J))
                {
                    Console.WriteLine(world.GetTension());
                }

                if (Raylib.IsKeyDown(KeyboardKey.KEY_K))
                {
                    foreach (MapDetectorSquare detector in world.detectors)
                    {
                        if (detector.country != null)
                        {
                            Random random = new Random(detector.country.ident);
                            int    red    = random.Next(255);
                            int    blue   = new Random(detector.country.blue).Next(255);
                            int    green  = new Random(detector.country.green).Next(255);
                            Raylib.DrawRectangle(detector.position.x, detector.position.y, detector.wh.x, detector.wh.y, new Color(red, blue, green, 100));
                        }
                    }
                }

                if (Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON))
                {
                    mouseSelPos = Raylib.GetMousePosition();
                }

                if (Raylib.IsMouseButtonReleased(MouseButton.MOUSE_LEFT_BUTTON))
                {
                    mouseReleasePos = Raylib.GetMousePosition();

                    Rectangle rect = new Rectangle(mouseSelPos.X, mouseReleasePos.Y, Math.Abs(mouseReleasePos.X - mouseSelPos.X), Math.Abs(mouseReleasePos.Y - mouseSelPos.Y));
                    foreach (MapDetectorSquare detector in world.detectors)
                    {
                        foreach (Creation creation in detector.creations)
                        {
                            if (Raylib.CheckCollisionPointRec(new System.Numerics.Vector2(creation.position.x, creation.position.y), rect))
                            {
                                if (creation.country != null)
                                {
                                    Console.WriteLine("Country: " + creation.country.ident);
                                }
                                else
                                {
                                    Console.WriteLine("Country: null");
                                }
                                Console.WriteLine("PolitStatus: " + creation.politStatus);
                                Vector2 dest = creation.GetDesination();
                                if (dest != null)
                                {
                                    Console.WriteLine("Destination: {0}, {1}", dest.x, dest.y);
                                }
                                else
                                {
                                    Console.WriteLine("Destination: None");
                                }
                            }
                        }
                    }
                }

                Raylib.EndDrawing();
            }

            Raylib.CloseWindow();
        }
Esempio n. 21
0
        static int enemy(int screenX, int screenY, int score, int miss, List <EnemyStruct> enemyList, List <EnemyStruct> enemyList1, List <EnemyStruct> enemyList2)
        {
            //för crit-system
            Random generator = new Random();

            //enemies
            for (int i = 0; i < enemyList.Count; i++)
            {
                Raylib.DrawRectangleRec(enemyList[i].rect, Color.RED);

                Vector2 mousePos = Raylib.GetMousePosition();


                if (Raylib.CheckCollisionPointRec(mousePos, enemyList[i].rect) && Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON))
                {
                    score = score += 10;
                    //slumpad crit system
                    // detta kan vara i en metod
                    int crit = generator.Next(0, 101);

                    if (crit >= 90)
                    {
                        score = score += 15;
                    }


                    //Raylib. ta bort rectangeln enemies[den som är klickad på]

                    Rectangle tmp = enemyList[i].rect;
                    tmp.y             = -900;
                    enemyList[i].rect = tmp;
                    //enemies.Remove(enemies);
                }

                if (enemyList[i].rect.x >= screenX + 100)
                {
                    Rectangle tmp = enemyList[i].rect;
                    tmp.y             = -900;
                    enemyList[i].rect = tmp;
                }
            }

            //enemies1
            for (int i = 0; i < enemyList1.Count; i++)

            {
                Raylib.DrawRectangleRec(enemyList1[i].rect, Color.RED);

                Vector2 mousePos = Raylib.GetMousePosition();


                if (Raylib.CheckCollisionPointRec(mousePos, enemyList1[i].rect) && Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON))
                {
                    score = score += 10;
                    //slumpad crit system

                    int crit = generator.Next(0, 101);

                    if (crit >= 90)
                    {
                        score = score += 15;
                    }

                    Rectangle tmp = enemyList1[i].rect;
                    tmp.y = -900;
                    enemyList1[i].rect = tmp;
                    //enemies.Remove(enemies);
                }
                if (enemyList1[i].rect.x <= -100)
                {
                    Rectangle tmp = enemyList1[i].rect;
                    tmp.y = -900;
                    enemyList1[i].rect = tmp;
                }
            }

            //enemies2
            for (int i = 0; i < enemyList2.Count; i++)

            {
                Raylib.DrawRectangleRec(enemyList2[i].rect, Color.RED);

                Vector2 mousePos = Raylib.GetMousePosition();


                if (Raylib.CheckCollisionPointRec(mousePos, enemyList2[i].rect) && Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON))
                {
                    score = score += 10;
                    //slumpad crit system
                    //det är inte så tydlig kanske men den funkar när man spelar

                    int crit = generator.Next(0, 101);

                    if (crit >= 90)
                    {
                        score = score += 15;
                    }

                    Rectangle tmp = enemyList2[i].rect;
                    tmp.y = -900;
                    enemyList2[i].rect = tmp;
                }

                if (enemyList2[i].rect.x >= screenX + 100)
                {
                    Rectangle tmp = enemyList2[i].rect;
                    tmp.y = -900;
                    enemyList2[i].rect = tmp;
                }
            }

            enemyList.RemoveAll(enemy => enemy.rect.y < 0);
            enemyList1.RemoveAll(enemy => enemy.rect.y < 0);
            enemyList2.RemoveAll(enemy => enemy.rect.y < 0);

            return(score);
            //return miss;
        }
Esempio n. 22
0
        static void Main(string[] args)
        {
            //INITIATE VALUES
            int screenWidth  = 1920;
            int screenHeight = 1000;

            Raylib.InitWindow(screenWidth, screenHeight, "Mitt Spel");
            Raylib.SetTargetFPS(144);

            //IMAGE VALUES
            //Background
            Texture2D cloudImg      = Raylib.LoadTexture("cloud.png");
            Texture2D backGroundImg = Raylib.LoadTexture("himmelBakgrund.png");
            Texture2D doorImg       = Raylib.LoadTexture("tunnel.png");
            //Player
            Texture2D playerMovingImg1        = Raylib.LoadTexture("playerMoving1.png");
            Texture2D playerMovingFlipImg1    = Raylib.LoadTexture("playerMovingFlip1.png");
            Texture2D playerNotMovingImg1     = Raylib.LoadTexture("playerNotMoving1.png");
            Texture2D playerNotMovingImg2     = Raylib.LoadTexture("playerNotMoving2.png");
            Texture2D playerNotMovingFlipImg1 = Raylib.LoadTexture("playerNotMovingFlip1.png");
            Texture2D playerNotMovingFlipImg2 = Raylib.LoadTexture("playerNotMovingFlip2.png");
            //Buttons
            Texture2D startNewGameImg     = Raylib.LoadTexture("startNewGame.png");
            Texture2D yesButtonImg        = Raylib.LoadTexture("yesButton.png");
            Texture2D yesButtonPressedImg = Raylib.LoadTexture("yesButtonPressed.png");
            Texture2D noButtonImg         = Raylib.LoadTexture("noButton.png");
            Texture2D noButtonPressedImg  = Raylib.LoadTexture("noButtonPressed.png");
            Texture2D newGameButtonImg    = Raylib.LoadTexture("NewGameButton.png");

            //GAME VALUES
            float   backgroundMoving = 0f;
            bool    isGrounded       = true;
            string  gameState        = "intro";
            Vector2 mousePosition    = Raylib.GetMousePosition();
            bool    mousePressed     = Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON);

            //BUTTON VALUES
            Rectangle yesButton              = new Rectangle(screenWidth / 3 - 60, screenHeight / 2 - 20, 190, 140);
            Rectangle noButton               = new Rectangle(screenWidth / 3 + screenWidth / 3, screenHeight / 2 - 20, 190, 140);
            Rectangle newGameButton          = new Rectangle(100, 400, 440, 130);
            bool      collisionYesButton     = Raylib.CheckCollisionPointRec(mousePosition, yesButton);
            bool      yesButtonPressed       = false;
            bool      collisionNoButton      = Raylib.CheckCollisionPointRec(mousePosition, noButton);
            bool      noButtonPressed        = false;
            bool      collisionNewGameButton = Raylib.CheckCollisionPointRec(mousePosition, newGameButton);
            bool      newGameButtonPressed   = false;
            int       buttonTimer            = 0;

            //PLAYER VALUES
            float gravity           = 10;
            float playerXpos        = 100;
            float playerYpos        = 800;
            bool  playerFlip        = false;
            bool  playerMoving      = false;
            float playerMovingCount = 0;
            //player size
            Rectangle player = new Rectangle((int)playerXpos, (int)playerYpos - 10, 120, 160);

            //ENEMY values
            // float enemyXpos = 1400;
            // float enemyYpos = 650;
            // float enemySpeed = 0.8f;

            //SPIKES VALUES
            Rectangle spikes = new Rectangle(300, 630, 50, 150);

            //KEY VALUES
            bool      counterActivated = false;
            int       keyCounter       = 0;
            int       totalTime        = 3;
            int       keyCountDown     = totalTime;
            Rectangle closedAreaKey    = new Rectangle(20, 545, 50, 50);
            Rectangle nextLevelKey     = new Rectangle(20, 20, 20, 20);

            //COLOR VALUES
            Color transparentColor = new Color(0, 0, 0, 210);

            //MENU VALUES
            bool isPaused = false;

            //HEALTH VALUES
            float playerHealth   = 180;
            float healthBarWidth = 0;

            //DEATH STATE VALUES
            string[] message   = { "du suger", "lmao du dog igen :)", "så nära.. inte", "hur dålig kan man vara", "d e ett basic fkn spel just finish already", "hahahhahahahahahaha", "försök igen" };
            Random   generator = new Random();
            int      r         = generator.Next(message.Length);


            while (!Raylib.WindowShouldClose())
            {
                //STATE = INTRO
                if (gameState == "intro")
                {
                    mousePosition          = Raylib.GetMousePosition();
                    collisionNewGameButton = Raylib.CheckCollisionPointRec(mousePosition, newGameButton);
                    //GRAFIK
                    Raylib.BeginDrawing();
                    Raylib.ClearBackground(Color.PINK);
                    Raylib.DrawText("SHUU", 100, 50, 30, Color.BLACK);
                    //NEW GAME BUTTON
                    Raylib.DrawRectangle((int)newGameButton.x, (int)newGameButton.y, (int)newGameButton.width, (int)newGameButton.height, Color.RED);
                    Raylib.DrawTextureEx(newGameButtonImg, new Vector2(100, 400), 0, 10f, Color.WHITE);

                    if (collisionNewGameButton && Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON))
                    {
                        newGameButtonPressed = true;
                    }
                    if (newGameButtonPressed == true)
                    {
                        collisionYesButton = Raylib.CheckCollisionPointRec(mousePosition, yesButton);
                        collisionNoButton  = Raylib.CheckCollisionPointRec(mousePosition, noButton);

                        Raylib.DrawRectangle(0, 0, 1920, 1000, transparentColor);
                        Raylib.DrawTextureEx(startNewGameImg, new Vector2(screenWidth / 2 - 310, 200), 0, 10f, Color.WHITE);

                        Raylib.DrawRectangle((int)yesButton.x, (int)yesButton.y, (int)yesButton.width, (int)yesButton.height, Color.RED);
                        Raylib.DrawRectangle((int)noButton.x, (int)noButton.y, (int)noButton.width, (int)noButton.height, Color.RED);

                        //KOLLA OM SPELAREN STARTAR SPELET
                        if (collisionYesButton)
                        {
                            if (Raylib.IsMouseButtonDown(MouseButton.MOUSE_LEFT_BUTTON))
                            {
                                yesButtonPressed = true;
                                Raylib.DrawTextureEx(yesButtonPressedImg, new Vector2(screenWidth / 3 - 60, screenHeight / 2), 0, 10f, Color.WHITE);
                            }

                            else
                            {
                                Raylib.DrawTextureEx(yesButtonImg, new Vector2(screenWidth / 3 - 60, screenHeight / 2 - 20), 0, 10f, Color.WHITE);
                            }
                        }

                        else
                        {
                            Raylib.DrawTextureEx(yesButtonImg, new Vector2(screenWidth / 3 - 60, screenHeight / 2 - 20), 0, 10f, Color.WHITE);
                        }

                        if (Raylib.IsMouseButtonUp(MouseButton.MOUSE_LEFT_BUTTON) && yesButtonPressed == true)
                        {
                            buttonTimer += 1;

                            if (buttonTimer >= 30)
                            {
                                yesButtonPressed     = false;
                                newGameButtonPressed = false;
                                buttonTimer          = 0;
                                gameState            = "game";
                            }
                        }

                        if (collisionNoButton)
                        {
                            if (Raylib.IsMouseButtonDown(MouseButton.MOUSE_LEFT_BUTTON))
                            {
                                noButtonPressed = true;
                                Raylib.DrawTextureEx(noButtonPressedImg, new Vector2(screenWidth / 3 + screenWidth / 3, screenHeight / 2), 0, 10f, Color.WHITE);
                            }

                            else
                            {
                                Raylib.DrawTextureEx(noButtonImg, new Vector2(screenWidth / 3 + screenWidth / 3, screenHeight / 2 - 20), 0, 10f, Color.WHITE);
                            }
                        }

                        else
                        {
                            Raylib.DrawTextureEx(noButtonImg, new Vector2(screenWidth / 3 + screenWidth / 3, screenHeight / 2 - 20), 0, 10f, Color.WHITE);
                        }

                        if (Raylib.IsMouseButtonUp(MouseButton.MOUSE_LEFT_BUTTON) && noButtonPressed == true)
                        {
                            buttonTimer += 1;

                            if (buttonTimer >= 20)
                            {
                                noButtonPressed      = false;
                                newGameButtonPressed = false;
                            }
                        }
                    }
                    Raylib.EndDrawing();
                }

                //STATE = GAME
                if (gameState == "game")
                {
                    //GRAVITY
                    playerYpos += gravity;

                    //PLAYER MOVEMENT METOD
                    (bool pMoving, bool pFlip, float pX, float bgMoving)result = PlayerMovement(playerMoving, playerFlip, playerXpos, backgroundMoving);

                    playerMoving     = result.pMoving;
                    playerFlip       = result.pFlip;
                    playerXpos       = result.pX;
                    backgroundMoving = result.bgMoving;

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

                    //DRAW BACKGROUND
                    Raylib.DrawTextureEx(backGroundImg, new Vector2(0, 0), 0f, 10f, Color.WHITE);
                    //DRAW GROUND
                    Raylib.DrawRectangle(0, 900, 1920, 100, Color.GREEN);
                    //DRAW PLATFORMS
                    Raylib.DrawRectangle(0, 605, 250, 50, Color.RED);
                    Raylib.DrawRectangle(250, 605, 50, 200, Color.GREEN);
                    Raylib.DrawRectangle(500, 780, 1000, 200, Color.PURPLE);
                    Raylib.DrawRectangle(1450, 200, 50, 580, Color.LIME);
                    Raylib.DrawRectangle(650, 500, 800, 50, Color.YELLOW);
                    Raylib.DrawRectangle(0, 365, 400, 50, Color.PINK);
                    Raylib.DrawRectangle(200, 180, 1720, 20, Color.BLUE);
                    //DRAW SPIKES1
                    Raylib.DrawTriangle(new Vector2(300, 605), new Vector2(300, 655), new Vector2(350, 630), Color.BLUE);
                    Raylib.DrawTriangle(new Vector2(300, 655), new Vector2(300, 705), new Vector2(350, 680), Color.BLUE);
                    Raylib.DrawTriangle(new Vector2(300, 705), new Vector2(300, 755), new Vector2(350, 730), Color.BLUE);
                    Raylib.DrawTriangle(new Vector2(300, 755), new Vector2(300, 805), new Vector2(350, 780), Color.BLUE);
                    //DRAW SPIKES2
                    // Raylib.DrawTriangle(new Vector2(600, 775), new Vector2(650, 800), new Vector2(650, 750), Color.BLACK);
                    // Raylib.DrawTriangle(new Vector2(600, 825), new Vector2(650, 850), new Vector2(650, 800), Color.BLACK);
                    // Raylib.DrawTriangle(new Vector2(600, 875), new Vector2(650, 900), new Vector2(650, 850), Color.BLACK);
                    // Raylib.DrawTriangle(new Vector2(600, 925), new Vector2(650, 950), new Vector2(650, 900), Color.BLACK);

                    //DRAW DOOR
                    Raylib.DrawTextureEx(doorImg, new Vector2(1800, 5), 0.0f, 10f, Color.WHITE);

                    //DRAW PLAYER RECTANGLE
                    player = new Rectangle((int)playerXpos, (int)playerYpos - 10, 120, 160);
                    Raylib.DrawRectangleRec(player, Color.YELLOW);

                    //SCREEN COLLISION
                    if (playerXpos <= 0)
                    {
                        playerXpos = 0;
                    }
                    if (playerXpos >= 1800)
                    {
                        playerXpos = 1800;
                    }
                    if (playerYpos <= 0)
                    {
                        playerYpos = 0;
                        gravity    = 0;
                    }


                    //PLATFORM COLLISION
                    //player-width = 120 | player-height = 150
                    if (playerXpos > 380 && playerXpos < 390 && playerYpos > 590 && playerYpos < 900)
                    {
                        //checks purple platform collision: left
                        playerXpos = 380;
                    }

                    if (playerXpos > 380 && playerXpos <= 1500 && playerYpos > 630 && playerYpos < 680)
                    {
                        //checks purple platform collision: up
                        isGrounded = true;
                        playerYpos = 630;
                    }
                    if (playerXpos > 530 && playerXpos <= 1500 && playerYpos > 500 && playerYpos < 560)
                    {
                        //checks yellow platform collision: down
                        playerYpos = 560;
                        gravity    = 0;
                    }
                    if (playerXpos > 530 && playerXpos <= 1500 && playerYpos > 350 && playerYpos < 400)
                    {
                        //checks yellow platform collision: up
                        playerYpos = 350;
                        isGrounded = true;
                    }
                    if (playerXpos >= 530 && playerXpos < 540 && playerYpos >= 350 && playerYpos <= 550)
                    {
                        //checks yellow platform collision: left
                        playerXpos = 530;
                    }
                    if (playerXpos >= 0 && playerXpos < 270 && playerYpos > 455 && playerYpos < 505)
                    {
                        //checks red and green platform collision: up
                        playerYpos = 455;
                        isGrounded = true;
                    }
                    if (playerXpos >= 0 && playerXpos <= 130 && playerYpos > 605 && playerYpos < 655)
                    {
                        //checks red platform collision: down
                        playerYpos = 655;
                        gravity    = 0;
                    }
                    if (playerXpos > 130 && playerXpos < 270 && playerYpos > 755 && playerYpos <= 805)
                    {
                        //checks green platform collision: down
                        playerYpos = 805;
                        gravity    = 0;
                    }
                    if (playerXpos >= 130 && playerXpos < 180 && playerYpos > 655 && playerYpos <= 805)
                    {
                        //checks green platform collision: left
                        playerXpos = 130;
                    }

                    if (playerXpos >= 0 && playerXpos < 400 && playerYpos > 215 && playerYpos <= 265)
                    {
                        //checks pink platform collision: up
                        playerYpos = 215;
                        isGrounded = true;
                    }
                    if (playerXpos >= 0 && playerXpos < 400 && playerYpos > 375 && playerYpos <= 425)
                    {
                        //checks pink platform collision: down
                        playerYpos = 425;
                        gravity    = 0;
                    }
                    if (playerXpos >= 80 && playerXpos <= 1920 && playerYpos > 30 && playerYpos <= 50)
                    {
                        //checks blue platform collision: up
                        playerYpos = 30;
                        isGrounded = true;
                    }
                    if (playerXpos >= 80 && playerXpos < 100 && playerYpos > 30 && playerYpos <= 200)
                    {
                        //checks blue platform collision: left
                        playerXpos = 80;
                    }
                    if (playerXpos >= 80 && playerXpos <= 1920 && playerYpos > 180 && playerYpos <= 200)
                    {
                        //checks blue platform collision: down
                        playerYpos = 200;
                        gravity    = 0;
                    }
                    if (playerXpos >= 1330 && playerXpos < 1480 && playerYpos > 200 && playerYpos < 780)
                    {
                        //checks lime platform collision: left
                        playerXpos = 1330;
                    }

                    //KEY
                    if (Raylib.CheckCollisionRecs(closedAreaKey, player))
                    {
                        counterActivated = true;
                    }
                    if (counterActivated == true)
                    {
                        keyCounter++;
                        if (keyCounter == 144)
                        {
                            keyCountDown--;
                            keyCounter = 0;
                        }
                        if (keyCountDown < 0)
                        {
                            keyCounter       = 0;
                            keyCountDown     = totalTime;
                            counterActivated = false;
                        }

                        Raylib.DrawRectangleRec(closedAreaKey, Color.BLACK);
                        Raylib.DrawText("" + keyCountDown, 20, 540, 20, Color.YELLOW);
                    }
                    else
                    {
                        Raylib.DrawRectangleRec(closedAreaKey, Color.RED);
                    }


                    //EXTRA KEY
                    //EXTRA AREA

                    //spikes rect
                    //   Raylib.DrawRectangleRec(spikes, Color.BLACK);


                    //SPIKES COLLISION
                    if (Raylib.CheckCollisionRecs(player, spikes))
                    {
                        r         = generator.Next(message.Length);
                        gameState = "dead";
                    }

                    //DEBUG FUNCTION
                    Raylib.DrawText("X: " + playerXpos + " Y: " + playerYpos, 100, 100, 32, Color.BLACK);
                    // if (Raylib.IsKeyPressed(KeyboardKey.KEY_P))
                    // {
                    //     playerHealth -= 20;
                    // }


                    //PLAYER MOVEMENT
                    if (Raylib.IsKeyDown(KeyboardKey.KEY_A) || (Raylib.IsKeyDown(KeyboardKey.KEY_LEFT)))
                    {
                        Raylib.DrawTextureEx(playerMovingFlipImg1, new Vector2(playerXpos, playerYpos), 0.0f, 10.0f, Color.WHITE);
                        // Raylib.DrawRectangle((int)playerXpos, (int)playerYpos, playerMovingFlipImg1.width * 10, playerMovingFlipImg1.height * 10, Color.RED);
                    }

                    else if (Raylib.IsKeyDown(KeyboardKey.KEY_D) || (Raylib.IsKeyDown(KeyboardKey.KEY_RIGHT)))
                    {
                        Raylib.DrawTextureEx(playerMovingImg1, new Vector2(playerXpos, playerYpos), 0.0f, 10.0f, Color.WHITE);
                        // Raylib.DrawRectangle((int)playerXpos, (int)playerYpos, playerMovingFlipImg1.width * 10, playerMovingFlipImg1.height * 10, Color.RED);
                    }

                    //PLAYER IDLE (LEFT)
                    if (playerMoving == false && playerFlip == true)
                    {
                        if (isGrounded == true)
                        {
                            if (playerMovingCount < 50)
                            {
                                Raylib.DrawTextureEx(playerNotMovingFlipImg1, new Vector2(playerXpos, playerYpos - 10), 0, 10f, Color.WHITE);
                            }
                            else if (playerMovingCount >= 50)
                            {
                                Raylib.DrawTextureEx(playerNotMovingFlipImg2, new Vector2(playerXpos, playerYpos), 0, 10f, Color.WHITE);
                            }
                            playerMovingCount += 1f;

                            if (playerMovingCount >= 100)
                            {
                                playerMovingCount = 0;
                            }
                        }
                        //JUMP
                        else if (isGrounded == false)
                        {
                            Raylib.DrawTextureEx(playerNotMovingFlipImg1, new Vector2(playerXpos, playerYpos - 10), 0, 10f, Color.WHITE);
                        }
                    }

                    //PLAYER IDLE (RIGHT)
                    else if (playerMoving == false && playerFlip == false)
                    {
                        if (isGrounded == true)
                        {
                            if (playerMovingCount < 50)
                            {
                                Raylib.DrawTextureEx(playerNotMovingImg1, new Vector2(playerXpos, playerYpos - 10), 0, 10f, Color.WHITE);
                            }
                            else if (playerMovingCount >= 50)
                            {
                                Raylib.DrawTextureEx(playerNotMovingImg2, new Vector2(playerXpos, playerYpos), 0, 10f, Color.WHITE);
                            }
                            playerMovingCount += 1f;

                            if (playerMovingCount >= 100)
                            {
                                playerMovingCount = 0;
                            }
                        }
                        //JUMP
                        else if (isGrounded == false)
                        {
                            Raylib.DrawTextureEx(playerNotMovingImg1, new Vector2(playerXpos, playerYpos - 10), 0, 10f, Color.WHITE);
                        }
                    }

                    //PLAYER JUMP
                    if (Raylib.IsKeyPressed(KeyboardKey.KEY_SPACE) && isGrounded == true)
                    {
                        gravity      = -10;
                        playerMoving = true;
                        isGrounded   = false;
                    }

                    if (gravity < 10)
                    {
                        gravity += 0.15f;
                    }

                    //PLAYER COLLISION TO GROUND
                    if (playerYpos >= 820)
                    {
                        playerYpos = 820;
                        isGrounded = true;
                    }
                    else if (playerYpos < 820)
                    {
                        isGrounded = false;
                    }

                    //PLAYER HEALTH
                    healthBarWidth = playerHealth;
                    Raylib.DrawRectangle((int)playerXpos - 20, (int)playerYpos - 50, (int)healthBarWidth, 20, Color.RED);


                    //ENEMY MOVEMENT
                    // if (enemyXpos <= 1200)
                    // {
                    //     enemySpeed = 0.8f;
                    // }
                    // else if (enemyXpos >= 1700)
                    // {
                    //     enemySpeed = -0.8f;
                    // }
                    // enemyXpos += enemySpeed;

                    // //RITA FIENDE
                    // Raylib.DrawCircle((int)enemyXpos - 10, (int)enemyYpos - 10, 20, Color.BLUE);


                    //KOLLA OM SPELAREN FÅR PAUSA SPELET
                    if (Raylib.IsKeyPressed(KeyboardKey.KEY_TAB) && isPaused == false)
                    {
                        isPaused  = true;
                        gameState = "pause";
                    }
                    //BYT PAUSE BOOL
                    if (isPaused == true)
                    {
                        isPaused = false;
                    }


                    Raylib.EndDrawing();
                }
                //////////////////////////////////////////////////////////////////////////////////////////////////
                //-------------------------------------------PAUSE MENU-------------------------------------------
                //////////////////////////////////////////////////////////////////////////////////////////////////

                if (gameState == "pause")
                {
                    Raylib.BeginDrawing();
                    Raylib.ClearBackground(Color.RED);
                    Raylib.DrawText("UR GAME IS PAUSED", 150, 100, 48, Color.BLACK);
                    Raylib.EndDrawing();
                    //-------------------------------------------ENTER GAME SCREEN FROM PAUS MENU-------------------------------------------
                    if (Raylib.IsKeyPressed(KeyboardKey.KEY_TAB) && isPaused == false)
                    {
                        isPaused  = true;
                        gameState = "game";
                    }
                    else if (Raylib.IsKeyPressed(KeyboardKey.KEY_TAB) && isPaused == true)
                    {
                        isPaused = false;
                    }
                }
                if (gameState == "dead")
                {
                    Raylib.BeginDrawing();
                    Raylib.ClearBackground(Color.RED);
                    Raylib.DrawText("You are dead", 420, 100, 150, Color.BLACK);
                    Raylib.DrawText("Random message:   " + message[r], 300, screenHeight / 2, 50, Color.BLACK);
                    Raylib.DrawText("Press 'Enter' to try again", 200, screenHeight / 2 + 100, 100, Color.BLACK);
                    Raylib.EndDrawing();


                    if (Raylib.IsKeyPressed(KeyboardKey.KEY_ENTER))
                    {
                        playerXpos = 100;
                        playerYpos = 850;
                        playerFlip = false;
                        gameState  = "game";
                    }



                    // if(menuTarget == 1)
                    // {
                    //     menuColor = Color.GRAY;
                    // }
                    // else
                    // {
                    //     menuColor = Color.WHITE;
                    // }
                }
            }
        }