Beispiel #1
0
        public void Movement(List <plate> plates)
        {
            bool collision = false;

            if (Raylib.IsKeyDown(KeyboardKey.KEY_LEFT) && rect.x >= 20)
            {
                rect.x -= 20;
            }
            if (Raylib.IsKeyDown(KeyboardKey.KEY_RIGHT) && rect.x <= 750)
            {
                rect.x += 20;
            }
            for (int i = 0; i < plates.Count; i++)
            {
                if (!collision)
                {
                    collision = Raylib.CheckCollisionRecs(plates[i].rect, rect);
                }
            }
            if (collision && speed > 0)
            {
                speed = -20;
            }
            else
            {
                speed += 1;
            }
            rect.y += speed;
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Raylib.InitWindow(800, 600, "Kollisioner");
            Raylib.SetTargetFPS(60);

            Rectangle first = new Rectangle(10, 10, 50, 50);

            Rectangle second = new Rectangle(35, 35, 50, 50);

            Color semiTransparent = new Color(255, 0, 0, 128);


            while (!Raylib.WindowShouldClose())
            {
                first.x += 0.5f;


                Raylib.BeginDrawing();

                Raylib.ClearBackground(Color.SKYBLUE);

                Raylib.DrawRectangleRec(first, semiTransparent);
                Raylib.DrawRectangleRec(second, semiTransparent);

                if (Raylib.CheckCollisionRecs(first, second))
                {
                    Raylib.DrawText("YES", 100, 100, 64, Color.BLACK);
                }

                Raylib.EndDrawing();
            }
        }
Beispiel #3
0
        public override void Update()
        {
            rectangle.x += speed.X;
            rectangle.y += speed.Y;

            if (rectangle.x > 800 - 20 || rectangle.x < 0)
            {
                speed.X = -speed.X;
            }
            if (rectangle.y > 600 - 20 || rectangle.y < 0)
            {
                speed.Y = -speed.Y;
            }

            foreach (GameObject p in GameObject.gameObjects)
            {
                if (p != this)
                {
                    if (Raylib.CheckCollisionRecs(rectangle, p.rectangle))
                    {
                        speed.X = -speed.X;
                    }
                }
            }
        }
Beispiel #4
0
    public void SelectInRect(Rectangle rec)
    {
        foreach (Component c in this.AllComponents)
        {
            if (Raylib.CheckCollisionRecs(rec, c.GetRectangle()))
            {
                this.Select(c);
            }
        }

        foreach (Wire wire in this.AllWires)
        {
            List <WireNode> wireNodes = wire.Graph.Vertices.ToList();

            foreach (WireNode wn in wireNodes)
            {
                if (wn is JunctionWireNode)
                {
                    if (Raylib.CheckCollisionCircleRec(wn.GetPosition(), 5, rec))
                    {
                        this.Select(wn);
                    }
                }
            }
        }
    }
Beispiel #5
0
 //Player collision with a platform function
 public void Collision(Platform platform)
 {
     if (Raylib.CheckCollisionRecs(this.rec, platform.rec) && platform.active)
     {
         //Up
         if (oldY + this.rec.height <= platform.rec.y)
         {
             g          = 0;
             accY       = 0;
             grounded   = true;
             this.rec.y = platform.rec.y - this.rec.height;
         }
         //Down
         else if (oldY >= platform.rec.y + platform.rec.height)
         {
             this.rec.y = platform.rec.y + platform.rec.height;
         }
         //Left
         else if (oldX + this.rec.width <= platform.rec.x)
         {
             this.rec.x = platform.rec.x - this.rec.width;
         }
         //Right
         else if (oldX >= platform.rec.x + platform.rec.width)
         {
             this.rec.x = platform.rec.x + platform.rec.width;
         }
     }
     //Readd gravity if not colliding
     else
     {
         g = 3;
     }
 }
Beispiel #6
0
        //Update all instances of this class
        public static void UpdateAll()
        {
            foreach (Shell shell in shells)
            {
                shell.Update();


                if (shell.shellPosition.Y < 0 || shell.shellPosition.X < 0 || shell.shellPosition.X > 1920 || shell.shellPosition.Y > 1080)
                {
                    shellsToRemove.Add(shell);
                }
                foreach (Enemy enemy in Enemy.enemies)
                {
                    if (Raylib.CheckCollisionRecs(enemy.enemyHitBox, shell.shellHitBox))
                    {
                        shellsToRemove.Add(shell);
                        Enemy.enemiesToRemove.Add(enemy);
                        Player.score += 1;
                    }
                }
            }

            reloadCurrentValue -= Raylib.GetFrameTime();

            foreach (Shell shell in shellsToRemove)
            {
                shells.Remove(shell);
            }
            shellsToRemove.Clear();
        }
Beispiel #7
0
 public void update()
 {
     Raylib.DrawRectangleRec(shipRec, Color.PINK);
     if (Raylib.IsKeyDown(KeyboardKey.KEY_RIGHT) && shipRec.x <= 750)
     {
         shipRec.x += movementSpeed;
         //ifall spelaren klickar på höger pill så flyttas spelaren åt höger förutom ifall spelaren skulle flyttas utanför fönstret
     }
     if (Raylib.IsKeyDown(KeyboardKey.KEY_LEFT) && shipRec.x != 0)
     {
         shipRec.x -= movementSpeed;
     }
     if (Raylib.IsKeyDown(KeyboardKey.KEY_UP) && shipRec.y >= 0)
     {
         shipRec.y -= movementSpeed;
     }
     if (Raylib.IsKeyDown(KeyboardKey.KEY_DOWN) && shipRec.y <= 550)
     {
         shipRec.y += movementSpeed;
     }
     for (int i = 0; i < Meteorite.allMeteorites.Count; i++)
     {
         if (Raylib.CheckCollisionRecs(shipRec, Meteorite.allMeteorites[i].meteoriteRec))
         {
             //går igenom alla metiorites och kollar ifall de koliderar med spelaren. Ifall det händer så förlorar spelaren ett hp.
             //När spelaren förlorar alla 3hp så skrivs det ut att man dog, men man kan just nu fortsätta spela
             Meteorite.allMeteorites.RemoveAt(i);
             hp--;
             if (hp <= 0)
             {
                 System.Console.WriteLine("You dead!");
             }
         }
     }
 }
        public override void Update()
        {
            rect.x += xMovement;
            rect.y += yMovement;

            for (int i = 0; i < Paddle.gameObjects.Count; i++)
            {
                if (Raylib.CheckCollisionRecs(rect, Paddle.gameObjects[i].rect))
                {
                    xMovement = -xMovement;
                }
            }



            if (rect.y > 600 - rect.height || rect.y < 0)
            {
                yMovement = -yMovement;
            }

            if (rect.x > 800 - rect.width || rect.x < 0)
            {
                xMovement = -xMovement;
            }
        }
        static void Main(string[] args)
        {
            Raylib.InitWindow(800, 600, "Kollisoner");

            Rectangle playerRect = new Rectangle(0, 0, 100, 50);
            Rectangle enemyRect  = new Rectangle(50, 60, 30, 30);

            Color red = new Color(255, 0, 0, 128);

            while (!Raylib.WindowShouldClose())
            {
                //playerRect.x += 0.1f;
                playerRect.y += 0.01f;

                Raylib.BeginDrawing();

                Raylib.ClearBackground(Color.LIGHTGRAY);

                Raylib.DrawRectangleRec(playerRect, red);
                Raylib.DrawRectangleRec(enemyRect, red);

                if (Raylib.CheckCollisionRecs(playerRect, enemyRect))
                {
                    Raylib.DrawText("Colliding!", 0, 550, 32, Color.BLACK);
                }

                Raylib.EndDrawing();
            }
        }
        public void Update()
        {
            bulletsCopy = bullets;

            if (initKey == KeyboardKey.KEY_W)
            {
                bulletRec.y -= 6f;
            }

            else if (initKey == KeyboardKey.KEY_S)
            {
                bulletRec.y += 6f;
            }

            else if (initKey == KeyboardKey.KEY_D)
            {
                bulletRec.x += 6f;
            }

            else if (initKey == KeyboardKey.KEY_A)
            {
                bulletRec.x -= 6f;
            }

            else if (initKey == KeyboardKey.KEY_O)
            {
                bulletRec.x += 6f;
                bulletRec.y += 6f;
            }

            else if (initKey == KeyboardKey.KEY_P)
            {
                bulletRec.x -= 6f;
                bulletRec.y += 6f;
            }

            else if (initKey == KeyboardKey.KEY_K)
            {
                bulletRec.x += 6f;
                bulletRec.y -= 6f;
            }

            else if (initKey == KeyboardKey.KEY_L)
            {
                bulletRec.x -= 6f;
                bulletRec.y -= 6f;
            }

            foreach (Enemy e in Enemy.enemies)
            {
                if (Raylib.CheckCollisionRecs(bulletRec, e.enemyRec) && destroyThis == false)
                {
                    this.destroyThis = true;
                    e.DestroyThis    = true;
                }
            }
        }
Beispiel #11
0
        static void CheckCollision()
        {
            if (p1.y > windowHeight)
            {
                RestartGameMode();
            }
            int nonTouchingObstacles = obstacles.Count;

            for (int i = 0; i < obstacles.Count; i++)
            {
                Obstacle  obstacle      = obstacles[i];
                Rectangle r2            = new Rectangle(-x + obstacle.x, obstacle.y, obstacle.width, obstacle.height);
                bool      isOverlapping = Raylib.CheckCollisionRecs(p1, r2);
                if (isOverlapping && obstacle.type != "goal" && obstacle.type != "danger")
                {
                    if (x + p1.x <= x + r2.x && p1.y + p1.height + yVelocity > r2.y && p1.y < r2.y + r2.height - yVelocity)
                    {
                        x         = r2.x + x - p1.x - p1.width;
                        xVelocity = 0;
                    }
                    if (p1.x + p1.width >= r2.x + r2.width && p1.y + p1.height + yVelocity > r2.y && p1.y < r2.y + r2.height - yVelocity)
                    {
                        x         = r2.x + x + r2.width - p1.x;
                        xVelocity = 0;
                    }
                    if (p1.y + p1.height + yVelocity <= r2.y && p1.x + p1.width > r2.x && p1.x < r2.x + r2.width)
                    {
                        touchingGround = true;
                        jumping        = false;
                        p1.y           = r2.y - p1.height;
                        yVelocity      = 0;
                    }
                    if (p1.y + yVelocity >= r2.y + r2.height && p1.x + p1.width > r2.x && p1.x < r2.x + r2.width)
                    {
                        jumping   = false;
                        p1.y      = r2.y + r2.height;
                        yVelocity = 0;
                    }
                }
                if (isOverlapping && obstacle.type == "goal")
                {
                    gameState = "goal";
                }
                if (isOverlapping && obstacle.type == "danger")
                {
                    RestartGameMode();
                }
                if (!(p1.y + p1.height == r2.y && p1.x + p1.width > r2.x && p1.x < r2.x + r2.width) && !jumping)
                {
                    nonTouchingObstacles--;
                }
            }
            if (nonTouchingObstacles == 0)
            {
                touchingGround = false;
            }
        }
Beispiel #12
0
 public static IEnumerable <GameUnit> Pick(Rectangle Rect, bool PickUnpickable = false)
 {
     foreach (var U in GetAllGameUnits(PickUnpickable))
     {
         if (Raylib.CheckCollisionRecs(Rect, U.GetBoundingRect()))
         {
             yield return(U);
         }
     }
 }
Beispiel #13
0
        public void Update()
        {
            if (bounceCount == 7)
            {
                if (Math.Abs(speed.X) <= diffScale)
                {
                    if (speed.X > 0)
                    {
                        speed.X += 1;
                        speed.Y += 1;
                    }
                    else
                    {
                        speed.X -= 1;
                        speed.Y -= 1;
                    }
                }
                bounceCount = 0;
            }

            rect.x += speed.X;
            rect.y += speed.Y;
            if (rect.x > 800 - 20 || rect.x < 0)
            {
                bool side = false;

                if (rect.x < 0)
                {
                    side = false;
                }
                else
                {
                    side = true;
                }
                score.CalculateScore(side);
                speed.X = -speed.X;
                rect.x  = 800 / 2 - 10;
                rect.y  = 600 / 2 - 10;
            }

            if (rect.y > 600 - 20 || rect.y < 0)
            {
                speed.Y = -speed.Y;
            }

            foreach (Paddle p in Paddle.paddles)
            {
                if (Raylib.CheckCollisionRecs(rect, p.rectangle))
                {
                    speed.X = -speed.X;
                    bounceCount++;
                }
            }
        }
Beispiel #14
0
 public void SelectComponentsInRectangle(Rectangle rec)
 {
     ClearSelectedComponents();
     foreach (DrawableComponent dc in AllComponents)
     {
         if (Raylib.CheckCollisionRecs(rec, dc.Box))
         {
             AddSelectedComponent(dc);
         }
     }
 }
Beispiel #15
0
 public void CheckCollistion()
 {
     for (int i = 0; i < Meteor.allMeteors.Count; i++)
     {
         if (Raylib.CheckCollisionRecs(player, Meteor.allMeteors[i].meteor))
         {
             hp--;
             Meteor.allMeteors.RemoveAt(i);
         }
     }
 }
Beispiel #16
0
        private bool Delete()
        {
            for (int index = lineList.Count - 1; index > 0; index--)
            {
                if (Raylib.CheckCollisionRecs(lineList[index].GetRect, rectangle) == true)
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #17
0
        public void Update()
        {
            Raylib.DrawRectangleRec(this.piece, Color.RED);
            //kolla kollission med snakehead, if yes då kör grow och spawna ny food annars inget
            bool eaten = Raylib.CheckCollisionRecs(this.piece, head.piece);

            if (eaten == true)
            {
                head.Grow();
                this.piece.x = generator.Next(50) * 10;
                this.piece.y = generator.Next(50) * 10;
            }
        }
Beispiel #18
0
        //Bool for checking if playertwo is on road
        public bool PlayerTwoCollidesWithRoads(Car car, Map map)
        {
            for (int i = 0; i < map.roads.Count; i++)
            {
                playerTwoIsOnRoad = Raylib.CheckCollisionRecs(playerTwoRec, map.roads[i]);

                if (playerTwoIsOnRoad == true)
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #19
0
 static (List <Enemy>, Rectangle) BulletCollision(List <Enemy> enemyList, Rectangle bltRec)
 {
     //COLLISION BETWEEN BULLET AND ENEMY
     for (int i = 0; i < enemyList.Count; i++)
     {
         Rectangle enemyRec = new Rectangle(enemyList[i].x, enemyList[i].y, enemyList[i].width, enemyList[i].height);
         if (Raylib.CheckCollisionRecs(bltRec, enemyRec) && enemyList[i].isDead == false)
         {
             enemyList[i].isDead = true;
             bltRec.y            = -40;
         }
     }
     return(enemyList, bltRec);
 }
Beispiel #20
0
 private void CheckCollision()
 {
     for (int i = 0; i < Bullet.allBullets.Count; i++)
     {
         if (Raylib.CheckCollisionRecs(Bullet.allBullets[i].bullet, meteor))
         {
             allMeteors.Remove(this);
             Bullet.allBullets.RemoveAt(i);
             OnDeath();
         }
         //går igenom alla bullets och kollar ifall de colliderar med meteor
         //ifall det händer så förstörs meteor och bullet och onDeath metoden körs
     }
 }
Beispiel #21
0
 static void CheckCollision()
 {
     for (int i = 0; i < obstacles.Count; i++)
     {
         Obstacle  obstacle      = obstacles[i];
         Rectangle r2            = new Rectangle(obstacle.x + (int)x, obstacle.y, obstacle.width, obstacle.height);
         bool      isOverlapping = Raylib.CheckCollisionRecs(p1, r2);
         if (isOverlapping || p1.y + p1.height > windowHeight || p1.y < 0)
         {
             if (score > highScore)
             {
                 highScore = score;
                 System.IO.File.WriteAllText(@"highScore.txt", highScore.ToString());
             }
             gameState = "GameOver";
         }
     }
 }
        static void Main(string[] args)
        {
            Raylib.InitWindow(1000, 600, "IDFK");
            Raylib.SetTargetFPS(60);

            Rectangle player        = new Rectangle(200, 200, 50, 50);
            float     gravity       = 1f;
            bool      touchingFLoor = false;
            Rectangle floor         = new Rectangle(0, 500, 1000, 100);

            while (!Raylib.WindowShouldClose())
            {
                if (Raylib.CheckCollisionRecs(player, floor))
                {
                    touchingFLoor = true;
                }
                else
                {
                    touchingFLoor = false;
                }

                player.y += gravity;
                if (!touchingFLoor)
                {
                    gravity = gravity * 1.06f;
                }
                else
                {
                    gravity = 0f;
                }

                if (touchingFLoor && Raylib.IsKeyPressed(KeyboardKey.KEY_SPACE))
                {
                    gravity = -1;
                }

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

                Raylib.DrawRectangleRec(floor, Color.WHITE);
                Raylib.DrawRectangleRec(player, Color.WHITE);
                Raylib.EndDrawing();
            }
        }
Beispiel #23
0
        protected void CheckForCollision()
        {
            foreach (Collider item in colliderObjects) //for every collider
            {
                if (item != this)                      //we dont want to check collision between itself so if its not itself

                {
                    if (Raylib.CheckCollisionRecs(item.hitbox, hitbox))                    //Checks if a character is colliding with plattforms and makes then not fall through it also calls for OnCollision()
                    {
                        Rectangle colliding = Raylib.GetCollisionRec(item.hitbox, hitbox); //gets the colliding box between the two colliding objects

                        if (colliding.width <= colliding.height)                           //if the height of the colliding object is greater than the width we want to shove the box out of the colliding object to the side
                        {
                            if (colliding.x > hitbox.x + (hitbox.width / 2))               //checks wich way the object is supposed to be shoved, is it to the right or left?
                            {
                                hitbox.x   -= colliding.width;
                                position.X -= colliding.width;
                            }
                            else
                            {
                                hitbox.x   += colliding.width;
                                position.X += colliding.width;
                            }
                        }

                        if (colliding.height <= colliding.width)//if the width of the colliding object is greater than the height we want to shove the box out of the colliding object to the top
                        {
                            /*
                             * if(colliding.y > hitbox.y + (hitbox.height/2)){
                             *  hitbox.y += colliding.height;
                             * }
                             * else{
                             *
                             * }
                             */
                            hitbox.y  -= colliding.height;
                            velocity.Y = 0;//makes sure we dont get an infinate amount of velocity so the player doesnt fall through the ground
                        }

                        OnCollision(item);
                    }
                }
            }
        }
Beispiel #24
0
        public void update()
        {
            if (exists == false)
            {
                projectileRec = new Rectangle(ProjectileXPos, ProjectileYPos, width, height);
                exists        = true;
            }

            Raylib.DrawRectangleRec(projectileRec, Color.RED);
            projectileRec.y -= ProjectileSpeed;

            for (int i = 0; i < Meteorite.allMeteorites.Count; i++)
            {
                if (Raylib.CheckCollisionRecs(Meteorite.allMeteorites[i].meteoriteRec, this.projectileRec))
                {
                    Meteorite.allMeteorites.RemoveAt(i);
                    allProjectiles.Remove(this);
                }
            }
        }
Beispiel #25
0
        public static void UpdateAll()
        {
            foreach (NewEngine newEngine in NewEngine.newEngines)
            {
                foreach (Shell shell in Shell.shells)
                {
                    if (Raylib.CheckCollisionRecs(newEngine.newEngineHitBox, shell.shellHitBox))
                    {
                        Shell.shellsToRemove.Add(shell);
                        newEnginesToRemove.Add(newEngine);
                        Player.speed *= 2;
                    }
                }
            }

            foreach (NewEngine newEngine in newEnginesToRemove)
            {
                newEngines.Remove(newEngine);
            }
            newEnginesToRemove.Clear();
        }
Beispiel #26
0
        public static void UpdateAll()
        {
            foreach (MegaShot megaShot in MegaShot.megaShots)
            {
                foreach (Shell shell in Shell.shells)
                {
                    if (Raylib.CheckCollisionRecs(megaShot.megaShotHitBox, shell.shellHitBox))
                    {
                        Shell.shellsToRemove.Add(shell);
                        megaShotsToRemove.Add(megaShot);
                        Shell.shellTexture   = Raylib.LoadTexture(@"shellBig.png");
                        Player.recoil        = 20;
                        Shell.reloadMaxSpeed = 0.12f;
                    }
                }
            }

            foreach (MegaShot megaShot in megaShotsToRemove)
            {
                megaShots.Remove(megaShot);
            }
            megaShotsToRemove.Clear();
        }
Beispiel #27
0
        public static void UpdateAll()
        {
            foreach (AutoLoader autoLoader in AutoLoader.autoLoaders)
            {
                foreach (Shell shell in Shell.shells)
                {
                    if (Raylib.CheckCollisionRecs(autoLoader.autoLoaderHitBox, shell.shellHitBox))
                    {
                        Shell.shellsToRemove.Add(shell);
                        autoLoadersToRemove.Add(autoLoader);
                        if (Shell.reloadMaxValue > Shell.reloadMaxSpeed)
                        {
                            Shell.reloadMaxValue /= 2;
                        }
                    }
                }
            }

            foreach (AutoLoader autoLoader in autoLoadersToRemove)
            {
                autoLoaders.Remove(autoLoader);
            }
            autoLoadersToRemove.Clear();
        }
Beispiel #28
0
        private Tile currentlyChecking;                                                  // den tile som just nu kollas
        private void FindPath(Vector2 endPos)                                            //hittar en path från den nuvarande position
        {
            position.X = (float.Parse(Math.Round(position.X / 25).ToString()) * 25) + 6; //resetar positionen till griden så vi inte uppleverkonstig pathfind
            position.Y = (float.Parse(Math.Round(position.Y / 25).ToString()) * 25) + 6;
            alreadyChecked.Clear();                                                      //gör listorna klara för en ny sökning om något finns i dem
            needToCheck.Clear();

            checkForterrain.x = position.X;// sätter hitbox till positionen av spelaren
            checkForterrain.y = position.Y;

            currentlyChecking = new Tile(null, 0, new Vector2(checkForterrain.x, checkForterrain.y)); // sätter första tile till current position

            foreach (Vector2 posToCheck in movements)                                                 //kollar alla positioner runt current tile
            {
                checkForterrain.x  = position.X;
                checkForterrain.y  = position.Y;
                checkForterrain.x += posToCheck.X * movementSteps;//sätter hitbox till en positionerna runt som ska kolla
                checkForterrain.y += posToCheck.Y * movementSteps;
                bool didCollide = false;
                foreach (Terrain ter in Terrain.terrains)//kollar om hitbox kolliderar med någon terrain och om det gör det skapa ingen tile och om inte skapa en tile som är möjlig path
                {
                    if (Raylib.CheckCollisionRecs(checkForterrain, ter.body))
                    {
                        didCollide = true;
                        //System.Console.WriteLine(checkForterrain.x+ " " + checkForterrain.y);
                    }
                }
                if (!didCollide)
                {
                    needToCheck.Enqueue(new Tile(currentlyChecking, currentlyChecking.movementCost + 1, new Vector2(checkForterrain.x, checkForterrain.y)));//skapar en ny tile med current tile som parent och lägger till den i need to check queuen
                }
            }
            alreadyChecked.Add(currentlyChecking);//lägger till currentlychecking i listan av de som redan har checkats
            //System.Console.WriteLine(needToCheck.Count);

            bool GoalFound = false;

            while (needToCheck.Count > 0 && !GoalFound)    // sålänge de finns tiles att kolla på och målet inte har hittats
            {
                currentlyChecking = needToCheck.Dequeue(); // tar en tile från listan och gör det till den som är currently checking
                //System.Console.WriteLine("Checking: " + currentlyChecking.position);

                foreach (Vector2 posToCheck in movements)//kollar alla positioner runt current tile
                {
                    checkForterrain.x  = currentlyChecking.position.X;
                    checkForterrain.y  = currentlyChecking.position.Y;
                    checkForterrain.x += posToCheck.X * movementSteps;//sätter hitbox till en positionerna runt som ska kolla
                    checkForterrain.y += posToCheck.Y * movementSteps;



                    bool didCollide = false;
                    foreach (Terrain ter in Terrain.terrains)//kollar om hitbox kolliderar med någon terrain och om det gör det skapa ingen tile och om inte skapa en tile som är möjlig path
                    {
                        if (Raylib.CheckCollisionRecs(checkForterrain, ter.body))
                        {
                            didCollide = true;
                        }
                    }

                    if (!didCollide)
                    {
                        Vector2 currentPos = new Vector2(checkForterrain.x, checkForterrain.y);
                        foreach (Tile p in alreadyChecked)
                        {
                            if (p.position == currentPos)                            //om tile redan finns i alreadychecked och movmentkost är mindre än den tile lägg till den i check oxå
                            {
                                if (p.movementCost > currentlyChecking.movementCost + 1)
                                {
                                    needToCheck.Enqueue(new Tile(currentlyChecking, currentlyChecking.movementCost + 1, currentPos));
                                }
                            }
                            else
                            {
                                bool doesitExist = false;
                                foreach (Tile c in needToCheck)
                                {
                                    if (c.position == currentPos)                     //om tile redan finns i needtocheck så ska den inte finnas flera gånger
                                    {
                                        doesitExist = true;
                                    }
                                }
                                if (!doesitExist)
                                {
                                    if (!(checkForterrain.x < 0 || checkForterrain.y < 0 || checkForterrain.x > Raylib.GetScreenWidth() || checkForterrain.y > Raylib.GetScreenHeight()))// om den är innanför bounds
                                    {
                                        needToCheck.Enqueue(new Tile(currentlyChecking, currentlyChecking.movementCost + 1, currentPos));
                                    }
                                }
                            }
                        }
                    }
                    if (checkForterrain.x < endPos.X + 13 && checkForterrain.x > endPos.X - 13 && checkForterrain.y < endPos.Y + 13 && checkForterrain.y > endPos.Y - 13)//kollar om pathfinding är nära målet
                    {
                        //System.Console.WriteLine("GoalFound!!");
                        currentlyChecking = new Tile(currentlyChecking, currentlyChecking.movementCost + 1, new Vector2(checkForterrain.x, checkForterrain.y));
                        GoalFound         = true;
                    }
                }
                alreadyChecked.Add(currentlyChecking);// lägg till den som checkas i redan kollad
                //System.Console.WriteLine(needToCheck.Count);
            }
            //System.Console.WriteLine("starting draw");

            Tile           previousTile = currentlyChecking;
            List <Vector2> tempList     = new List <Vector2>();

            while (previousTile != null)// hämta path
            {
                //System.Console.WriteLine(previousTile.position);
                tempList.Add(previousTile.position);
                previousTile = previousTile.previousTile;
                //System.Console.WriteLine("haj");
            }

            for (int i = tempList.Count - 1; i >= 0; i--)// reversa listan och lägg till den i listan av movements som ska göra
            {
                movementsToMake.Add(tempList[i]);
            }
        }
Beispiel #29
0
        static void Main(string[] args)
        {
            //Define global variables
            const int windowX   = 1920;
            const int windowY   = 1000;
            string    gamestate = "intro";
            int       level     = 1;

            //Raylib initialization
            Raylib.InitWindow(windowX, windowY, "Dimensional Jumper");
            Raylib.InitAudioDevice();
            Raylib.SetTargetFPS(60);
            Sound song = Raylib.LoadSound("song.mp3");

            Raylib.SetMasterVolume(0.2f);

            //Menu variables
            int introMenuIndex = 0;

            Color[] menuColors     = { Color.BLACK, Color.GRAY, Color.GRAY, Color.GRAY };
            int     levelMenuIndex = 0;

            Color[] levelMenuColors = { Color.BLACK, Color.GRAY, Color.GRAY, Color.GRAY, Color.GRAY, Color.GRAY };
            string  musicText       = "Music ON";
            bool    musicToggle     = true;

            //Game variables
            Rectangle goalRec = new Rectangle(1700, 700, 100, 100);
            Player    p       = new Player();

            Platform[] platforms = new Platform[30];
            //Level one platforms
            platforms[0] = new Platform(new Rectangle(0, 200, windowX, 20), 1);
            platforms[1] = new Platform(new Rectangle(0, 400, windowX, 20), 2);
            platforms[2] = new Platform(new Rectangle(0, 600, windowX, 20), 1);
            platforms[3] = new Platform(new Rectangle(0, 800, windowX, 20), 2);
            //Level two platforms
            platforms[4] = new Platform(new Rectangle(0, 600, windowX, 400), 1);
            platforms[5] = new Platform(new Rectangle(700, 0, 200, windowY), 1);
            //Level three platforms
            platforms[6]  = new Platform(new Rectangle(100, 900, 200, 50), 1);
            platforms[7]  = new Platform(new Rectangle(500, 650, 200, 50), 2);
            platforms[8]  = new Platform(new Rectangle(100, 400, 200, 50), 1);
            platforms[9]  = new Platform(new Rectangle(600, 200, 200, 50), 2);
            platforms[10] = new Platform(new Rectangle(1200, 800, 200, 50), 1);
            //Level four platforms
            platforms[11] = new Platform(new Rectangle(200, 200, 20, 400), 1);
            platforms[12] = new Platform(new Rectangle(200, 200, 400, 20), 1);
            platforms[13] = new Platform(new Rectangle(580, 200, 20, 400), 1);
            platforms[14] = new Platform(new Rectangle(200, 600, 400, 20), 1);
            platforms[15] = new Platform(new Rectangle(800, 200, 20, 400), 1);
            platforms[16] = new Platform(new Rectangle(800, 200, 400, 20), 1);
            platforms[17] = new Platform(new Rectangle(1180, 200, 20, 400), 1);
            platforms[18] = new Platform(new Rectangle(800, 600, 400, 20), 1);
            platforms[19] = new Platform(new Rectangle(1400, 200, 20, 400), 1);
            platforms[20] = new Platform(new Rectangle(1400, 200, 400, 20), 1);
            platforms[21] = new Platform(new Rectangle(1780, 200, 20, 400), 1);
            platforms[22] = new Platform(new Rectangle(1400, 600, 400, 20), 1);
            //Level five platforms
            platforms[23] = new Platform(new Rectangle(200, 400, 200, 800), 1);
            platforms[24] = new Platform(new Rectangle(200, 600, 400, 600), 1);
            platforms[25] = new Platform(new Rectangle(200, 800, 600, 400), 1);
            platforms[26] = new Platform(new Rectangle(100, 960, 150, 20), 1);
            platforms[27] = new Platform(new Rectangle(100, 980, 800, 20), 2);

            Color gameBackground = Color.SKYBLUE;

            int[] platformStartIndexes = { 0, 4, 6, 11, 23, 28 };
            int   dimension            = 1;
            int   dimensionFlipFrame   = -200;

            //Score keeping variables
            int frameCount  = 0;
            int deathCount  = 0;
            int secondCount = 0;
            int minuteCount = 0;

            //Main Game loop
            while (!Raylib.WindowShouldClose())
            {
                //Reloops the song when it ends
                if (!Raylib.IsSoundPlaying(song) && musicToggle)
                {
                    Raylib.PlaySound(song);
                }

                if (gamestate == "intro")
                {
                    //Logic Introscreen
                    //Menu selecting and coloring
                    if (Raylib.IsKeyPressed(KeyboardKey.KEY_S))
                    {
                        menuColors[introMenuIndex] = Color.GRAY;
                        if (introMenuIndex == menuColors.Length - 1)
                        {
                            introMenuIndex = 0;
                        }
                        else
                        {
                            introMenuIndex++;
                        }
                        menuColors[introMenuIndex] = Color.BLACK;
                    }
                    else if (Raylib.IsKeyPressed(KeyboardKey.KEY_W))
                    {
                        menuColors[introMenuIndex] = Color.GRAY;
                        if (introMenuIndex == 0)
                        {
                            introMenuIndex = menuColors.Length - 1;
                        }
                        else
                        {
                            introMenuIndex--;
                        }
                        menuColors[introMenuIndex] = Color.BLACK;
                    }

                    //Menu confirming
                    if (Raylib.IsKeyPressed(KeyboardKey.KEY_ENTER))
                    {
                        switch (introMenuIndex)
                        {
                        //"Start Game"
                        case 0:
                            gamestate = "game";
                            for (int i = platformStartIndexes[level - 1]; i < platformStartIndexes[level]; i++)
                            {
                                platforms[i].checkDimension(dimension);
                            }
                            gameBackground = Color.SKYBLUE;


                            break;

                        //"Level select"
                        case 1:
                            gamestate = "levelSelect";
                            break;

                        //"Toggle music"
                        case 2:

                            if (musicToggle)
                            {
                                Raylib.PauseSound(song);
                                musicToggle = false;
                                musicText   = "Music OFF";
                            }
                            else
                            {
                                Raylib.ResumeSound(song);
                                musicToggle = true;
                                musicText   = "Music ON";
                            }
                            break;

                        //"Quit"
                        case 3:
                            gamestate = "end";
                            break;
                        }
                    }



                    //Drawing Introscreen
                    Raylib.BeginDrawing();
                    Raylib.ClearBackground(Color.PURPLE);

                    //Title
                    Raylib.DrawText("Dimensional", 50, 100, 100, Color.BLACK);
                    Raylib.DrawText("Jumper", 50, 200, 100, Color.BLACK);

                    //The menu
                    Raylib.DrawText("Play", 50, 400, 64, menuColors[0]);
                    Raylib.DrawText("Level Select", 50, 460, 64, menuColors[1]);
                    Raylib.DrawText(musicText, 50, 520, 64, menuColors[2]);
                    Raylib.DrawText("Exit", 50, 580, 64, menuColors[3]);


                    //Controls
                    Raylib.DrawText("W: Jump", 500, 400, 64, Color.GRAY);
                    Raylib.DrawText("A: Walk Left", 500, 460, 64, Color.GRAY);
                    Raylib.DrawText("D: Walk Right", 500, 520, 64, Color.GRAY);
                    Raylib.DrawText("SPACE: Switch Dimensions", 500, 580, 64, Color.GRAY);
                    Raylib.DrawText("TAB: Pause / Controls", 500, 640, 64, Color.GRAY);
                    Raylib.DrawText("ENTER: SELECT", 500, 700, 64, Color.GRAY);

                    Raylib.EndDrawing();
                }

                else if (gamestate == "levelSelect")
                {
                    //Level Select Logic
                    //Menu selecting and coloring
                    if (Raylib.IsKeyPressed(KeyboardKey.KEY_S))
                    {
                        levelMenuColors[levelMenuIndex] = Color.GRAY;
                        if (levelMenuIndex == levelMenuColors.Length - 1)
                        {
                            levelMenuIndex = 0;
                        }
                        else
                        {
                            levelMenuIndex++;
                        }
                        levelMenuColors[levelMenuIndex] = Color.BLACK;
                    }

                    else if (Raylib.IsKeyPressed(KeyboardKey.KEY_W))
                    {
                        levelMenuColors[levelMenuIndex] = Color.GRAY;
                        if (levelMenuIndex == 0)
                        {
                            levelMenuIndex = levelMenuColors.Length - 1;
                        }
                        else
                        {
                            levelMenuIndex--;
                        }
                        levelMenuColors[levelMenuIndex] = Color.BLACK;
                    }

                    //Menu confirming
                    if (Raylib.IsKeyPressed(KeyboardKey.KEY_ENTER))
                    {
                        //The level is case +1, case 0 is level 1
                        switch (levelMenuIndex)
                        {
                        case 0:
                            gamestate = "game";
                            level     = 1;
                            dimension = 1;
                            p.startX  = 100;
                            p.startY  = 50;
                            p.rec.x   = p.startX;
                            p.rec.y   = p.startY;
                            p.accY    = 0;
                            goalRec.x = 1700;
                            goalRec.y = 700;
                            for (int i = platformStartIndexes[level - 1]; i < platformStartIndexes[level]; i++)
                            {
                                platforms[i].checkDimension(dimension);
                            }
                            gameBackground = Color.SKYBLUE;
                            break;

                        case 1:
                            gamestate = "game";
                            level     = 2;
                            p.startX  = 100;
                            p.startY  = 100;
                            p.rec.x   = p.startX;
                            p.rec.y   = p.startY;
                            p.accY    = 0;
                            goalRec.x = 1750;
                            goalRec.y = 500;
                            dimension = 1;
                            for (int i = platformStartIndexes[level - 1]; i < platformStartIndexes[level]; i++)
                            {
                                platforms[i].checkDimension(dimension);
                            }
                            gameBackground = Color.SKYBLUE;
                            break;

                        case 2:
                            gamestate = "game";
                            level     = 3;
                            p.startX  = 120;
                            p.startY  = 600;
                            p.rec.x   = p.startX;
                            p.rec.y   = p.startY;
                            p.accY    = 0;
                            goalRec.x = 1750;
                            goalRec.y = 800;
                            dimension = 1;
                            for (int i = platformStartIndexes[level - 1]; i < platformStartIndexes[level]; i++)
                            {
                                platforms[i].checkDimension(dimension);
                            }
                            gameBackground = Color.SKYBLUE;
                            break;

                        case 3:
                            gamestate = "game";
                            level     = 4;
                            p.startX  = 400;
                            p.startY  = 400;
                            p.rec.x   = p.startX;
                            p.rec.y   = p.startY;
                            p.accY    = 0;
                            goalRec.x = 1550;
                            goalRec.y = 700;
                            dimension = 1;
                            for (int i = platformStartIndexes[level - 1]; i < platformStartIndexes[level]; i++)
                            {
                                platforms[i].checkDimension(dimension);
                            }
                            gameBackground = Color.SKYBLUE;
                            break;

                        case 4:
                            gamestate = "game";
                            level     = 5;
                            for (int i = platformStartIndexes[level - 1]; i < platformStartIndexes[level]; i++)
                            {
                                platforms[i].checkDimension(dimension);
                            }
                            gameBackground = Color.SKYBLUE;
                            p.startX       = 125;
                            p.startY       = 800;
                            p.rec.x        = p.startX;
                            p.rec.y        = p.startY;
                            p.accY         = 0;
                            goalRec.x      = 200;
                            goalRec.y      = 100;
                            dimension      = 1;
                            break;

                        case 5:
                            gamestate = "intro";
                            break;
                        }
                    }

                    //Level select Drawing
                    Raylib.BeginDrawing();
                    Raylib.ClearBackground(Color.PURPLE);

                    //Menu buttons
                    Raylib.DrawText("Level 1", 50, 400, 64, levelMenuColors[0]);
                    Raylib.DrawText("Level 2", 50, 460, 64, levelMenuColors[1]);
                    Raylib.DrawText("Level 3", 50, 520, 64, levelMenuColors[2]);
                    Raylib.DrawText("Level 4", 50, 580, 64, levelMenuColors[3]);
                    Raylib.DrawText("Level 5", 50, 640, 64, levelMenuColors[4]);
                    Raylib.DrawText("Back", 50, 700, 64, levelMenuColors[5]);

                    Raylib.EndDrawing();
                }

                else if (gamestate == "game")
                {
                    //Logic for the game
                    //Calculating the clock with framecount
                    frameCount++;
                    if ((frameCount % 60) == 0)
                    {
                        secondCount++;
                        if ((secondCount % 60) == 0)
                        {
                            minuteCount++;
                            secondCount = 0;
                        }
                    }

                    //Post dimension flip checks
                    if (dimensionFlipFrame + 1 == frameCount)
                    {
                        //If you collide the frame after you flip, you respawn
                        for (int i = platformStartIndexes[level - 1]; i < platformStartIndexes[level]; i++)
                        {
                            if (Raylib.CheckCollisionRecs(p.rec, platforms[i].rec) && platforms[i].active)
                            {
                                deathCount++;
                                p.rec.x = p.startX;
                                p.rec.y = p.startY;
                                p.accY  = 0;
                            }
                        }

                        //Because you cant be grounded after flip, this helps so you cant jump mid-air
                        if (p.grounded == true)
                        {
                            p.grounded = false;
                        }
                    }

                    //Function for the player movement
                    p.Update();

                    //Border collision
                    if (p.rec.y >= 1000 || p.rec.x >= 1920 || p.rec.x + p.rec.width <= 0)
                    {
                        deathCount++;
                        p.rec.x = p.startX;
                        p.rec.y = p.startY;
                        p.accY  = 0;
                    }

                    //Check player and platform collision
                    for (int i = platformStartIndexes[level - 1]; i < platformStartIndexes[level]; i++)
                    {
                        p.Collision(platforms[i]);
                    }

                    //Check goal Collision
                    if (Raylib.CheckCollisionRecs(goalRec, p.rec))
                    {
                        if (level == 1)
                        {
                            dimension = 1;
                            for (int i = platformStartIndexes[level - 1]; i < platformStartIndexes[level]; i++)
                            {
                                platforms[i].checkDimension(dimension);
                            }
                            gameBackground = Color.SKYBLUE;

                            level++;
                            p.startX  = 100;
                            p.startY  = 100;
                            p.rec.x   = p.startX;
                            p.rec.y   = p.startY;
                            p.accY    = 0;
                            goalRec.x = 1750;
                            goalRec.y = 500;
                        }
                        else if (level == 2)
                        {
                            level++;
                            dimension = 1;
                            for (int i = platformStartIndexes[level - 1]; i < platformStartIndexes[level]; i++)
                            {
                                platforms[i].checkDimension(dimension);
                            }
                            gameBackground = Color.SKYBLUE;


                            p.startX  = 120;
                            p.startY  = 600;
                            p.rec.x   = p.startX;
                            p.rec.y   = p.startY;
                            p.accY    = 0;
                            goalRec.x = 1750;
                            goalRec.y = 800;
                        }
                        else if (level == 3)
                        {
                            level++;
                            dimension = 1;
                            for (int i = platformStartIndexes[level - 1]; i < platformStartIndexes[level]; i++)
                            {
                                platforms[i].checkDimension(dimension);
                            }
                            gameBackground = Color.SKYBLUE;

                            p.startX  = 400;
                            p.startY  = 400;
                            p.rec.x   = p.startX;
                            p.rec.y   = p.startY;
                            p.accY    = 0;
                            goalRec.x = 1550;
                            goalRec.y = 700;
                        }
                        else if (level == 4)
                        {
                            level++;
                            dimension = 1;
                            for (int i = platformStartIndexes[level - 1]; i < platformStartIndexes[level]; i++)
                            {
                                platforms[i].checkDimension(dimension);
                            }
                            gameBackground = Color.SKYBLUE;
                            p.startX       = 125;
                            p.startY       = 800;
                            p.rec.x        = p.startX;
                            p.rec.y        = p.startY;
                            p.accY         = 0;
                            goalRec.x      = 200;
                            goalRec.y      = 100;
                        }
                        else if (level == 5)
                        {
                            gamestate = "finish";
                        }
                    }

                    //Check for controls
                    //Pause
                    if (Raylib.IsKeyPressed(KeyboardKey.KEY_TAB))
                    {
                        gamestate = "intro";
                    }

                    //Flip dimension
                    else if (Raylib.IsKeyPressed(KeyboardKey.KEY_SPACE))
                    {
                        if (dimension == 1)
                        {
                            gameBackground = new Color(15, 15, 15, 255);
                            dimension      = 2;
                        }
                        else
                        {
                            gameBackground = Color.SKYBLUE;
                            dimension      = 1;
                        }

                        for (int i = platformStartIndexes[level - 1]; i < platformStartIndexes[level]; i++)
                        {
                            platforms[i].checkDimension(dimension);
                        }

                        dimensionFlipFrame = frameCount;
                    }

                    //Drawing level
                    Raylib.BeginDrawing();
                    Raylib.ClearBackground(gameBackground);

                    //Score keeping
                    Raylib.DrawText("Death Count: " + deathCount, 25, 25, 64, Color.WHITE);
                    Raylib.DrawText("Time: " + minuteCount + ":" + secondCount, 1500, 25, 64, Color.WHITE);

                    //Draw the platforms
                    for (int i = platformStartIndexes[level - 1]; i < platformStartIndexes[level]; i++)
                    {
                        platforms[i].Draw();
                    }

                    //Draw the goal
                    Raylib.DrawRectangleRec(goalRec, Color.DARKGREEN);

                    //Draw the player
                    p.Draw();

                    Raylib.EndDrawing();
                }

                else if (gamestate == "finish")
                {
                    //Finish Screen logic
                    if (Raylib.IsKeyPressed(KeyboardKey.KEY_ENTER))
                    {
                        gamestate   = "intro";
                        level       = 1;
                        dimension   = 1;
                        p.startX    = 100;
                        p.startY    = 50;
                        p.rec.x     = p.startX;
                        p.rec.y     = p.startY;
                        deathCount  = 0;
                        secondCount = 0;
                        minuteCount = 0;
                    }
                    //Finish Screen Drawing
                    Raylib.BeginDrawing();
                    Raylib.ClearBackground(Color.PURPLE);

                    //Score
                    Raylib.DrawText("You won b", 50, 50, 64, Color.WHITE);
                    Raylib.DrawText("Time: " + minuteCount + ":" + secondCount, 450, 50, 64, Color.WHITE);
                    Raylib.DrawText("Deaths: " + deathCount, 800, 50, 64, Color.WHITE);
                    Raylib.DrawText("Press enter to get to menu", 50, 300, 64, Color.WHITE);

                    Raylib.EndDrawing();
                }

                //Quit
                else if (gamestate == "end")
                {
                    Raylib.CloseWindow();
                }

                //Debugging
                else
                {
                    Raylib.BeginDrawing();
                    Raylib.ClearBackground(Color.WHITE);
                    Raylib.EndDrawing();
                }
            }
            Raylib.CloseAudioDevice();
            Raylib.CloseWindow();
        }
Beispiel #30
0
        static void Main(string[] args)
        {
            string gamestate      = "menu"; // Det som bestämer vilken stat mitt spel är som menu, ingame eller gameover
            float  life           = 3;
            float  X              = 600;
            float  Y              = 500;
            int    score          = 0;
            Random randomAstroid  = new Random();
            Random astroidPos     = new Random();
            int    difficulty     = 100;
            string difficultyText = "Easy";
            float  shotTimer      = 0;
            float  shotTimerMax   = 0.5f;
            float  outTimerMax    = 3;
            float  outTimer       = 0;

            List <Rectangle> shots   = new List <Rectangle>();
            List <Rectangle> astroid = new List <Rectangle>();


            Raylib.SetTargetFPS(60);



            Raylib.InitWindow(1200, 800, "bra spel");
            while (!Raylib.WindowShouldClose())
            {
                if (gamestate == "menu")
                {
                    Raylib.BeginDrawing();
                    life = 3;

                    Raylib.ClearBackground(Color.LIGHTGRAY);
                    Raylib.DrawText("Bra spel", 350, 150, 120, Color.DARKBLUE);  // Menu


                    Raylib.DrawText("Press Space to play", 300, 650, 60, Color.DARKBLUE);

                    if (Raylib.IsKeyPressed(KeyboardKey.KEY_SPACE))
                    {
                        gamestate = "ingame";
                    }
                    Raylib.EndDrawing();
                }


                else if (gamestate == "ingame")
                {
                    Raylib.BeginDrawing();
                    if (Raylib.IsKeyDown(KeyboardKey.KEY_D))
                    {
                        X += 6f;
                    }
                    if (Raylib.IsKeyDown(KeyboardKey.KEY_A))  //controlls
                    {
                        X -= 6f;
                    }
                    if (Raylib.IsKeyDown(KeyboardKey.KEY_W))
                    {
                        Y -= 6f;
                    }
                    if (Raylib.IsKeyDown(KeyboardKey.KEY_S))
                    {
                        Y += 6f;
                    }



                    Raylib.ClearBackground(Color.BLACK);
                    Raylib.DrawRectangle(20, 400, 20, 20, Color.YELLOW);
                    Raylib.DrawRectangle(200, 100, 20, 20, Color.YELLOW);
                    Raylib.DrawRectangle(550, 230, 20, 20, Color.YELLOW);
                    Raylib.DrawRectangle(1050, 600, 20, 20, Color.YELLOW);
                    Raylib.DrawRectangle(800, 150, 20, 20, Color.YELLOW);
                    Raylib.DrawRectangle(90, 650, 20, 20, Color.YELLOW);
                    Raylib.DrawRectangle(450, 710, 20, 20, Color.YELLOW);
                    Raylib.DrawRectangle(810, 550, 20, 20, Color.YELLOW);
                    Raylib.DrawRectangle(250, 400, 20, 20, Color.YELLOW);

                    Raylib.DrawText("Health", 1000, 650, 40, Color.WHITE);



                    if (score > 10000 && score < 30000)
                    {
                        difficultyText = "Medium";
                        difficulty     = 50;
                    }


                    if (score > 30001 && score < 50000)
                    {
                        difficultyText = "Hard";
                        difficulty     = 25;
                    }

                    if (score > 50001 && score < 70000)
                    {
                        difficultyText = "OverKill";        //de olika svårighets graderna som går upp med hur högt score man har
                        difficulty     = 15;
                    }

                    if (score > 70001)
                    {
                        difficultyText = "DeathWish";
                        difficulty     = 2;
                    }


                    int aXPos = astroidPos.Next(1200);

                    int r = randomAstroid.Next(difficulty);
                    if (r == 1)
                    {
                        astroid.Add(new Rectangle(aXPos, 0, 50, 50));
                    }

                    if (X >= 1200 || Y >= 800 || 0 >= X || 0 >= Y)
                    {
                        outTimer += Raylib.GetFrameTime();
                        Raylib.DrawText("Get Back Or You Will Die!", 260, 300, 60, Color.RED);
                    }

                    if (outTimer >= outTimerMax)
                    {
                        life = 0;        //det som gör att man dör om man är utanför skärmen för länge
                    }

                    shotTimer += Raylib.GetFrameTime();
                    if (Raylib.IsKeyPressed(KeyboardKey.KEY_SPACE) && shotTimer > shotTimerMax)
                    {
                        shotTimer = 0;

                        shots.Add(new Rectangle(X + 15, Y, 20, 40));
                    }

                    for (int i = 0; i < shots.Count; i++) // Det som skapar skotten
                    {
                        Rectangle shot = shots[i];        // Det som flyttar skotten
                        shot.y  -= 9;
                        shots[i] = shot;

                        Raylib.DrawRectangleRec(shot, Color.RED);
                    }

                    shots.RemoveAll(shot => shot.y < 0);



                    Rectangle playerRec = new Rectangle((int)X, (int)Y, 50, 70);



                    for (int i = 0; i < astroid.Count; i++)
                    {
                        Rectangle a = astroid[i];               //skapar astroider
                        a.y       += 5;
                        astroid[i] = a;

                        Raylib.DrawRectangleRec(a, Color.GRAY);
                    }
                    foreach (Rectangle shot in shots)
                    {
                        astroid.RemoveAll(a => Raylib.CheckCollisionRecs(a, shot));
                    }


                    foreach (Rectangle rect in astroid)
                    {
                        if (Raylib.CheckCollisionRecs(playerRec, rect))  // Kollar om spelaren åker in i en astroid

                        {
                            life--;
                        }
                    }


                    astroid.RemoveAll(a => Raylib.CheckCollisionRecs(a, playerRec));



                    Raylib.DrawRectangleRec(playerRec, Color.LIGHTGRAY);
                    Raylib.DrawRectangle((int)X + 35, (int)Y + 50, 20, 25, Color.LIGHTGRAY);
                    Raylib.DrawRectangle((int)X - 7, (int)Y + 50, 20, 25, Color.LIGHTGRAY);  //Ritar ut spelaren
                    Raylib.DrawRectangle((int)X + 15, (int)Y + 10, 20, 25, Color.BLUE);
                    Raylib.DrawRectangle((int)X - 4, (int)Y + 74, 15, 12, Color.ORANGE);
                    Raylib.DrawRectangle((int)X + 38, (int)Y + 74, 15, 12, Color.ORANGE);
                    score = score + 10;
                    Raylib.DrawText("Score: " + score, 20, 20, 40, Color.PINK);
                    Raylib.DrawText("Difficulty: " + difficultyText, 750, 20, 40, Color.PINK);


                    if (life == 3)
                    {
                        Raylib.DrawRectangle(1000, 700, 35, 45, Color.RED);
                        Raylib.DrawRectangle(1050, 700, 35, 45, Color.RED);
                        Raylib.DrawRectangle(1100, 700, 35, 45, Color.RED);
                    }
                    if (life == 2)
                    {
                        Raylib.DrawRectangle(1000, 700, 35, 45, Color.RED);
                        Raylib.DrawRectangle(1050, 700, 35, 45, Color.RED);
                        Raylib.DrawRectangle(1100, 700, 35, 45, Color.GRAY);
                    }
                    if (life == 1)
                    {
                        Raylib.DrawRectangle(1000, 700, 35, 45, Color.RED);
                        Raylib.DrawRectangle(1050, 700, 35, 45, Color.GRAY);
                        Raylib.DrawRectangle(1100, 700, 35, 45, Color.GRAY);
                    }

                    if (life <= 0)
                    {
                        gamestate = "gameover";  //Om jag får 0 eller mindre liv så hamnar man i game over skärmen
                    }
                    if (Raylib.IsKeyPressed(KeyboardKey.KEY_B))
                    {
                        gamestate = "gameover";
                    }
                    if (Raylib.IsKeyPressed(KeyboardKey.KEY_O))
                    {
                        life = life - 1;
                    }
                    Raylib.EndDrawing();
                }

                else if (gamestate == "gameover")
                {
                    Raylib.BeginDrawing();
                    Raylib.ClearBackground(Color.GRAY);
                    Raylib.DrawText("Game Over", 300, 150, 120, Color.DARKBLUE);
                    Raylib.DrawText("Your Score: ", 270, 300, 100, Color.DARKBLUE);   //game over skärmen
                    Raylib.DrawText(" " + score, 270, 400, 200, Color.RED);
                    Raylib.DrawText("Press Space For Main Menu", 170, 650, 50, Color.RED);
                    if (Raylib.IsKeyPressed(KeyboardKey.KEY_SPACE))
                    {
                        gamestate = "menu";
                    }
                    Raylib.EndDrawing();
                }
            }
        }