Esempio n. 1
0
 static void Menu()
 {
     sinceLastClick++;
     if (gameState == "levelSelect")
     {
         if (Raylib.IsKeyDown(KeyboardKey.KEY_UP))
         {
             yOffset -= 4;
         }
         if (Raylib.IsKeyDown(KeyboardKey.KEY_DOWN))
         {
             yOffset += 4;
         }
         if (yOffset < 0)
         {
             yOffset = 0;
         }
     }
     else
     {
         yOffset = 0;
     }
     drawing = false;
     for (int i = 0; i < windowHeight / 29; i++)
     {
         Raylib.DrawRectangle(0, i * 30, windowLength, 15, Color.LIGHTGRAY);
     }
     if (gameState == "levelSelect")
     {
         Raylib.DrawText("Use the down and up arrows to navigate", windowLength / 3 - 100, 5, 40, Color.DARKGRAY);
     }
     if (gameState == "menu")
     {
         MenuInstrucions();
     }
     for (int i = 0; i < buttons.Count; i++)
     {
         Obstacle button = buttons[i];
         Raylib.DrawRectangle((int)button.x, (int)button.y - yOffset, (int)button.width, (int)button.height, Color.DARKGRAY);
         Raylib.DrawRectangle((int)button.x + 10, (int)button.y + 10 - yOffset, (int)button.width - 20, (int)button.height - 20, Color.GRAY);
         Raylib.DrawText(button.type.ToUpper(), (int)(button.x + button.width / 10), (int)(button.y + button.height / 4) - yOffset, 80, Color.DARKGRAY);
         //remove button logic
         if (gameState == "levelSelect" && button.type != "back")
         {
             Raylib.DrawRectangle((int)button.x + (int)button.width + 60, (int)button.y - yOffset, (int)(button.height * 2.25), (int)button.height, Color.RED);
             Raylib.DrawText("remove level", (int)(button.x + button.width) + 80, (int)(button.y + button.height / 4) + 10 - yOffset, 40, Color.DARKGRAY);
         }
         if (Raylib.GetMouseX() > button.x + button.width + 60 && Raylib.GetMouseX() < button.x + button.width + 60 + button.height * 2.25 && Raylib.GetMouseY() > button.y - yOffset && Raylib.GetMouseY() < button.y + button.height - yOffset && button.type != "back" && gameState == "levelSelect")
         {
             Raylib.DrawRectangle((int)button.x + (int)button.width + 60, (int)button.y - yOffset, (int)(button.height * 2.25), (int)button.height, Color.PINK);
             Raylib.DrawText("remove level", (int)(button.x + button.width) + 80, (int)(button.y + button.height / 4) + 10 - yOffset, 40, Color.DARKGRAY);
             if (Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON))
             {
                 string targetFile = button.type + ".txt";
                 try
                 {
                     File.Delete(@"saveFolder/" + targetFile);
                 }
                 catch (SystemException)
                 {
                     throw;
                 }
                 string[] files = Directory.GetFiles(@"saveFolder");
                 levels.Clear();
                 foreach (string line in files)
                 {
                     string name = line;
                     name = ConvertName(name);
                     levels.Add(name.ToLower());
                 }
                 MenuButtons();
             }
         }
         //button logic
         if (Raylib.GetMouseX() > button.x && Raylib.GetMouseX() < button.x + button.width && Raylib.GetMouseY() > button.y - yOffset && Raylib.GetMouseY() < button.y + button.height - yOffset)
         {
             Raylib.DrawRectangle((int)button.x + 10, (int)button.y + 10 - yOffset, (int)button.width - 20, (int)button.height - 20, Color.LIGHTGRAY);
             Raylib.DrawText(button.type.ToUpper(), (int)(button.x + button.width / 10), (int)(button.y + button.height / 4) - yOffset, 80, Color.DARKGRAY);
             if (!levels.Contains(currentLevel) && button.type == "save")
             {
                 Raylib.DrawText("Open console application and enter name", (int)(button.x + 20), (int)button.y + ((int)button.height / 8) * 6 - yOffset, 22, Color.DARKGRAY);
             }
             if (!levels.Any() && button.type == "levels")
             {
                 Raylib.DrawText("You have no saved levels", (int)(button.x + 20), (int)button.y + ((int)button.height / 8) * 6 - yOffset, 22, Color.DARKGRAY);
             }
             if (Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON) && sinceLastClick > 3)
             {
                 sinceLastClick = 0;
                 if (button.type == "new")
                 {
                     allowBuild   = true;
                     currentLevel = "";
                     obstacles.Clear();
                     x         = 0;
                     gameState = "create";
                     buildType = "static";
                 }
                 else if (button.type == "levels" && levels.Any())
                 {
                     gameState = "levelSelect";
                     MenuButtons();
                 }
                 else if (button.type == "exit")
                 {
                     Environment.Exit(0);
                 }
                 else if (button.type == "resume")
                 {
                     gameState = lastGamemode;
                 }
                 else if (button.type == "save")
                 {
                     SaveStage();
                 }
                 else if (button.type == "restart")
                 {
                     x         = xStart;
                     p1.y      = yStart;
                     gameState = "game";
                     RestartGameMode();
                 }
                 else if (button.type == "menu")
                 {
                     gameState = "menu";
                     MenuButtons();
                 }
                 else if (levels.Contains(button.type))
                 {
                     currentLevel = button.type.ToLower();
                     gameState    = "gamemodeChoose";
                     MenuButtons();
                 }
                 else if (button.type == "play")
                 {
                     gameState = "game";
                     buildType = "editable";
                     RestartGameMode();
                     LoadStage();
                 }
                 else if (button.type == "edit")
                 {
                     gameState = "create";
                     buildType = "static";
                     RestartGameMode();
                     LoadStage();
                 }
                 else if (button.type == "back")
                 {
                     if (gameState == "levelSelect")
                     {
                         gameState = "menu";
                     }
                     else if (gameState == "gamemodeChoose")
                     {
                         gameState = "levelSelect";
                     }
                     MenuButtons();
                 }
             }
         }
     }
 }
Esempio n. 2
0
        private void ObstacleProperties(Obstacle obstacle)
        {
            ImGui.Checkbox("Show collider", ref obstacle.ShowCollider);
            ImGui.InputFloat3("Orientation", ref obstacle.Orientation);
            ImGui.InputFloat3("Position", ref obstacle.InitialPosition);

            ImGui.Separator();

            if (ImGui.BeginTabBar("ObstacleTabs"))
            {
                if (ImGui.BeginTabItem("Shape"))
                {
                    ImGui.Text($"Shape type: {obstacle.Shape}");

                    ImGui.Separator();

                    if (obstacle.Collider is BoxCollider box)  // TODO: handle zero cases; when the dimensions are zeroed, objects disappear!!!
                    {
                        ImGui.InputFloat3("Half extents", ref box.Size);
                    }
                    else if (obstacle.Collider is SphereCollider sphere)
                    {
                        ImGui.InputFloat("Radius", ref sphere.Radius);
                    }
                    else if (obstacle.Collider is CylinderCollider cylinder)
                    {
                        ImGui.InputFloat("Radius", ref cylinder.Radius);
                        ImGui.InputFloat("Half length", ref cylinder.HalfLength);
                    }
                    else if (obstacle.Collider is ConeCollider cone)
                    {
                        ImGui.InputFloat("Radius", ref cone.Radius);
                        ImGui.InputFloat("Height", ref cone.Height);
                    }

                    ImGui.EndTabItem();
                }

                if (ImGui.BeginTabItem("Physics"))
                {
                    int type = (int)obstacle.Type;
                    ImGui.Combo("Type", ref type,
                                PhysicsHandler.RigidBodyTypes,
                                PhysicsHandler.RigidBodyTypes.Length);
                    obstacle.Type = (RigidBodyType)type;

                    if (obstacle.Type == RigidBodyType.Dynamic)
                    {
                        ImGui.InputFloat("Mass", ref obstacle.Mass);
                    }
                    else
                    {
                        ImGui.PushStyleVar(ImGuiStyleVar.Alpha, 0.5f);
                        ImGui.InputFloat("Mass", ref obstacle.Mass, 0, 0, null, ImGuiInputTextFlags.ReadOnly);
                        ImGui.PopStyleVar();
                    }

                    ImGui.EndTabItem();
                }

                if (ImGui.BeginTabItem("Path"))
                {
                    if (obstacle.Type == RigidBodyType.Kinematic)
                    {
                        var quarterWidth = 0.25f * ImGui.GetWindowContentRegionWidth();

                        Path.Node current       = obstacle.Path.First.Child;
                        int       selectedIndex = -1;
                        ImGui.PushStyleVar(ImGuiStyleVar.ChildRounding, 5);
                        if (ImGui.BeginChild("ObstaclePath", new System.Numerics.Vector2(quarterWidth, ImGui.GetContentRegionAvail().Y), true,
                                             ImGuiWindowFlags.HorizontalScrollbar))
                        {
                            while (current != null)
                            {
                                if (ImGui.Selectable($"Point {++selectedIndex}"))
                                {
                                    _selectedPoint     = current;
                                    _selectedPathIndex = selectedIndex;
                                }

                                current = current.Child;
                            }

                            if (selectedIndex == -1)
                            {
                                ImGui.TextWrapped("Path is empty.");
                            }

                            ImGui.EndChild();
                        }

                        ImGui.SameLine();

                        ImGui.BeginGroup();

                        if (ImGui.Button("Add point"))
                        {
                            obstacle.Path.AddLast(new System.Numerics.Vector3[]
                            {
                                obstacle.Path.Last.Points[0] + System.Numerics.Vector3.UnitX
                            }, null);
                        }

                        ImGui.Separator();

                        if (_selectedPoint != null)
                        {
                            ImGui.Text($"Point {_selectedPathIndex}");

                            var point = _selectedPoint.Points[0];
                            ImGui.InputFloat3("", ref point);
                            obstacle.Path.ChangeNode(_selectedPoint, new System.Numerics.Vector3[] { point }, null);
                        }

                        ImGui.EndGroup();
                    }
                    else
                    {
                        ImGui.TextWrapped("A path can be set only for Kinematic obstacles (see Physics tab).");
                    }

                    ImGui.EndTabItem();
                }

                ImGui.EndTabBar();
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Raylib.SetTargetFPS(120);
            x = 0;
            Raylib.InitWindow(windowLength, windowHeight, "Flappy bird");
            int timer = 0;

            while (!Raylib.WindowShouldClose())
            {
                if (gameState == "Menu")
                {
                    try
                    {
                        highScore = int.Parse(System.IO.File.ReadAllText(@"highScore.txt"));
                    }
                    catch (System.Exception)
                    {
                        highScore = 0;
                    }
                    difficulty = 0;
                    score      = 0;
                    timer      = 0;
                    obstacles.Clear();
                    x    = 0;
                    p1.y = windowHeight / 2;
                    if (Raylib.IsKeyPressed(KeyboardKey.KEY_SPACE))
                    {
                        gameState = "Game";
                        SpawnObstacles();
                    }
                }
                if (gameState == "Game")
                {
                    x -= 2;
                    DespawnObstacles();
                    difficulty = score / 10;
                    if (difficulty == 11)
                    {
                        difficulty = 10;
                    }
                    if (obstacles.Count < 20)
                    {
                        timer++;
                        if (timer >= 360 - difficulty * 20)
                        {
                            SpawnObstacles();
                            timer = 0;
                        }
                    }
                    CheckKeyPresses();
                    UpdatePos();
                    CheckCollision();
                }
                if (gameState == "GameOver")
                {
                    if (Raylib.IsKeyPressed(KeyboardKey.KEY_SPACE))
                    {
                        gameState = "Menu";
                    }
                }
                Raylib.BeginDrawing();

                Raylib.ClearBackground(Color.WHITE);
                Raylib.DrawRectangle((int)p1.x, (int)p1.y, (int)p1.width, (int)p1.height, Color.RED);
                for (int i = 0; i < obstacles.Count; i++)
                {
                    Obstacle obstacle = obstacles[i];
                    Raylib.DrawRectangle((int)obstacle.x + (int)x, (int)obstacle.y, (int)obstacle.width, (int)obstacle.height, Color.GREEN);
                }
                if (gameState == "GameOver")
                {
                    Raylib.DrawText("You died", windowLength / 2 - 110, windowHeight / 2, 80, Color.RED);
                }
                Raylib.DrawText("Score: " + score, 10, 10, 30, Color.ORANGE);
                Raylib.DrawText("Highscore: " + highScore, windowLength - 230, 10, 30, Color.ORANGE);
                if (Raylib.IsKeyDown(KeyboardKey.KEY_RIGHT))
                {
                    Raylib.DrawText("Bruh", 15, windowHeight / 2, 400, Color.BLACK);
                }
                Raylib.EndDrawing();
            }
        }