void Draw() { //DRAWING Logic Raylib.BeginDrawing(); Raylib.ClearBackground(Color.DARKGRAY); Raylib.DrawCircle((int)ball.pos.X, (int)ball.pos.Y, ball.radius, Color.RAYWHITE); Raylib.DrawFPS(10, 10); Raylib.EndDrawing(); }
void Draw() { Raylib.BeginDrawing(); Raylib.ClearBackground(Color.BLACK); if (currentGameState != null) { currentGameState.Draw(); } Raylib.EndDrawing(); Raylib.DrawFPS(10, windowHeight - 30); }
void Draw() { Raylib.BeginDrawing(); Raylib.ClearBackground(Color.BLACK); if (tile != null) { tile.Draw(); } Raylib.DrawFPS(windowWidth - 100, 20); Raylib.EndDrawing(); }
void Draw() { Raylib.BeginDrawing(); Raylib.ClearBackground(Color.RAYWHITE); if (currentGameState != null) { currentGameState.Draw(); } Raylib.DrawFPS(windowWidth - 70, 10); Raylib.EndDrawing(); }
//Used to display objects and other info on the screen. public void Draw() { Raylib.BeginDrawing(); Raylib.ClearBackground(Color.BLACK); Console.Clear(); _scenes[_currentSceneIndex].Draw(); Raylib.DrawText("SPACE SHOT", 465, 10, 50, Color.VIOLET); Raylib.DrawFPS(1, 1); if (_gameOver) { DrawLooseText(); } Raylib.EndDrawing(); }
/// <summary> /// Runs every frame. Used for drawing to the screen /// </summary> private void Draw() { // Begin Raylib Drawing Raylib.BeginDrawing(); // Clear the screen Raylib.ClearBackground(Color.RAYWHITE); // Draw the current scene to the screen GetCurrentScene().Draw(); // Draw Debug info Raylib.DrawFPS(Raylib.GetScreenWidth() - 100, 10); Raylib.DrawText("Actors: " + GetCurrentScene().NumActors.ToString(), 10, 10, 16, Color.GREEN); // End Raylib Drawing Raylib.EndDrawing(); }
static void Main(string[] args) { Vector2 mousePos = Raylib.GetMousePosition(); int time = 0; int Cvalue = 220; int set = 0; int min = 0; int hour = 14; int days = 0; int width = 1200; int height = 1000; string[] gameState = { "intro", "main", "info", "settings", "win" }; string select = gameState[0]; Color timeOfDay = new Color(Cvalue, Cvalue, Cvalue - 60, 150); Track Traintrack = new Track() { name = "Tomoul track" }; Traintrack.OrderAdd(100, 200); Traintrack.OrderAdd(950, 700); Train Cooltrain = new Train() { name = "Tomoul Train", storage = new int[5], speed = 2f, cost = 500, xy = new Vector2(Traintrack.stopOrder[0].xy.X - 25, Traintrack.stopOrder[0].xy.Y - 10) }; Raylib.InitWindow(width, height, "Trainline"); Raylib.SetTargetFPS(30); while (!Raylib.WindowShouldClose()) { switch (select) { case "intro": Raylib.BeginDrawing(); Raylib.ClearBackground(timeOfDay); Raylib.DrawText("Trainline", width / 2 - 300, 50, 120, Color.BLACK); Raylib.DrawRectangle(width / 2 - 120, height / 2 - 120, 220, 100, Color.BLACK); Raylib.DrawText("Start", width / 2 - 100, height / 2 - 100, 60, Color.WHITE); Raylib.DrawRectangle(width / 2 - 150, height / 2, 300, 100, Color.BLACK); Raylib.DrawText("Settings", width / 2 - 130, height / 2 + 20, 60, Color.WHITE); mousePos = Raylib.GetMousePosition(); Vector2 startPosMin = new Vector2(width / 2 - 120, height / 2 - 120); Vector2 startPosMax = new Vector2(width / 2 + 100, height / 2 - 20); Vector2 settingsPosMin = new Vector2(width / 2 - 150, height / 2); Vector2 settingsPosMax = new Vector2(width / 2 + 150, height / 2 + 120); if (Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON) == true && mousePos.X >= startPosMin.X && mousePos.Y >= startPosMin.Y && mousePos.X <= startPosMax.X && mousePos.Y <= startPosMax.Y) { select = gameState[1]; } else if (Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON) == true && mousePos.X >= settingsPosMin.X && mousePos.Y >= settingsPosMin.Y && mousePos.X <= settingsPosMax.X && mousePos.Y <= settingsPosMax.Y) { select = gameState[3]; } Raylib.EndDrawing(); break; case "main": timeOfDay = new Color(Cvalue, Cvalue, Cvalue - 60, 150); Raylib.BeginDrawing(); if (time < 720) { if (set == 5) { Cvalue--; set = 0; } Raylib.ClearBackground(timeOfDay); } else if (time >= 720 && time < 1440) { if (set == 5) { Cvalue++; set = 0; } Raylib.ClearBackground(timeOfDay); } if (time > 1440) { time = 0; set = 0; } List <string> Namn = new List <string>(); Raylib.DrawRectangle(0, 900, 1200, 100, Color.BLACK); set++; time++; if (set == 5) { min = min + 5; } if (min > 55) { min = 0; hour++; } if (hour > 23) { hour = 0; days++; } if (min == 0 || min == 5) { if (hour <= 9) { Raylib.DrawText("Day " + days + ", Clock 0" + hour + ":0" + min, 800, 900, 40, Color.GREEN); } else { Raylib.DrawText("Day " + days + ", Clock " + hour + ":0" + min, 800, 900, 40, Color.GREEN); } } else if (hour <= 9) { Raylib.DrawText("Day " + days + ", Clock 0" + hour + ":" + min, 800, 900, 40, Color.GREEN); } else { Raylib.DrawText("Day " + days + ", Clock " + hour + ":" + min, 800, 900, 40, Color.GREEN); } Raylib.DrawFPS(50, 50); Raylib.EndDrawing(); trainmove(Cooltrain, Traintrack); break; case "info": Raylib.BeginDrawing(); Raylib.ClearBackground(Color.WHITE); Raylib.DrawCircle(100, 100, 100, Color.BLUE); Raylib.EndDrawing(); break; case "settings": Raylib.BeginDrawing(); Raylib.ClearBackground(Color.WHITE); Raylib.DrawCircle(100, 100, 100, Color.BLUE); Raylib.EndDrawing(); break; } } }
static void Main(string[] args) { //World Rules bool open = true; int width = 600; //Width of the window int height = 600; //Height of the window int worldX = 0; //Where the world 0 is - X axis int worldY = 0; //Where the world 0 is - Y axis int gameState = 0; //What part of the game is active 0 = Main Menu 1 = Game 2 = Death int gravity = 0; //The force of gravity int cayTimeOri = 10; //How long the cayote Time should be int cayTime = 0; //Current Cayote Time //Player Rules int size = 20; //Size of the player squere int playerX = width / 2 - size / 2; //Where the player is on the screen - X axis int playerY = height / 2 - size / 2; //Where the player is on the screen - Y axis int playerWorldX; //Where the player is Worldwise - X axis int playerWorldY; //Where the player is Worldwise - Y axis bool fall; //If the player should fall int jump = 0; //Force upwards - Warning should not be tinkered with as the player would start by jumping int speed = 16; //How fast the player is int coins = 0; //Normal Platforms int platformLength = 2; //How many platforms are integrated, Flawed system as it needs to be changed as well when adding new platforms int[] platformX = new int[platformLength]; //Where each platform is related to world 0 - X axis int[] platformY = new int[platformLength]; //Where each platform is related to world 0 - Y axis int[] platformWidth = new int[platformLength]; //The width of each platform int[] platformHeight = new int[platformLength]; //The length of each platform platformX[0] = -500; platformY[0] = 500; platformWidth[0] = 2000; platformHeight[0] = 25; //Platform 0 platformX[1] = -200; platformY[1] = 301; platformWidth[1] = 200; platformHeight[1] = 25; //Platform 1 //Should possibley be changed to a class format //Coin int coinLength = 1; //How many coins are integrated, Flawed system as it needs to be changed as well when adding new coins int coinSize = 10; //The size of coins int[] coinX = new int[coinLength]; //Where each coin is related to world 0 - X axis int[] coinY = new int[coinLength]; //Where each coin is related to world 0 - Y axis bool[] coinHidden = new bool[coinLength]; //Hide coins picked up coinX[0] = 100; coinY[0] = 480; //Coin 0 for (int i = 0; i < coinHidden.Length; i++) { coinHidden[i] = false; } //File Creation bool fileCreation = false; string fileName = ""; int fileCreationStep = 0; //Map creation int mapCreationStep = 0; //checkPoint creation string checkPointString = ""; Color checkPointColor = new Color(0, 255, 0, 130); int checkPointSize = 30; List <int> buildingcheckPointX = new List <int>(); List <int> buildingcheckPointY = new List <int>(); //Platform creation string platformString = ""; Color platformColor = new Color(255, 255, 255, 130); List <int> buildingPlatformX = new List <int>(); List <int> buildingPlatformY = new List <int>(); List <int> buildingPlatformWidth = new List <int>(); List <int> buildingPlatformHigth = new List <int>(); int currentPlatformX = 0; int currentPlatformY = 0; int currentPlatformW = 0; int currentPlatformH = 0; //Coin creation string coinString = ""; Color coinColor = new Color(0, 255, 0, 130); List <int> buildingCoinX = new List <int>(); List <int> buildingCoinY = new List <int>(); //Load int loadStep = 0; int loadButWidth = 400; int loadButHight = 100; int loadY = 0; string[] existingDirectories = Directory.GetDirectories(@"maps"); Color[] mapColBack = new Color[existingDirectories.Length]; Color[] mapColFront = new Color[existingDirectories.Length]; // Raylib.InitWindow(width, height, "Platformer"); //Creates Window Raylib.SetTargetFPS(60); //Target Framerate Raylib.SetExitKey(0); while (!Raylib.WindowShouldClose() && open == true) //Reapeats every Frame, The Game { if (gameState == 0) //Main Menu { menu(); } else if (gameState == 1) //Game { game(); } else if (gameState == 2) //Death { death(); } else if (gameState == 3) //Create Map File { fileCreate(); } else if (gameState == 4) //Make Level { mapCreate(); } else if (gameState == 5) //Choose Map { mapLoad(); } else { gameState = 0; } if (Raylib.IsKeyPressed(KeyboardKey.KEY_ESCAPE) && gameState != 3 && gameState != 4) { gameState = 0; } } void menu() //Gamestate 0 { int mouseX = Raylib.GetMouseX(); int mouseY = Raylib.GetMouseY(); Color but1ColBack = new Color(30, 30, 30, 255); Color but2ColBack = new Color(30, 30, 30, 255); Color but3ColBack = new Color(30, 30, 30, 255); Color but1ColFront = new Color(255, 255, 255, 255); Color but2ColFront = new Color(255, 255, 255, 255); Color but3ColFront = new Color(255, 255, 255, 255); if ((mouseX > 20 && mouseX < 320) && (mouseY > 200 && mouseY < 270)) { but1ColBack = new Color(255, 255, 255, 255); but1ColFront = new Color(10, 10, 10, 255); } if ((mouseX > 20 && mouseX < 320) && (mouseY > 270 && mouseY < 320)) { but2ColBack = new Color(255, 255, 255, 255); but2ColFront = new Color(10, 10, 10, 255); } if ((mouseX > 20 && mouseX < 320) && (mouseY > 340 && mouseY < 390)) { but3ColBack = new Color(255, 255, 255, 255); but3ColFront = new Color(10, 10, 10, 255); } if ((mouseX > 20 && mouseX < 320) && (mouseY > 200 && mouseY < 270) && Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON) == true) { gameState = 1; } if ((mouseX > 20 && mouseX < 320) && (mouseY > 270 && mouseY < 320) && Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON) == true) { gameState = 3; } if ((mouseX > 20 && mouseX < 320) && (mouseY > 340 && mouseY < 390) && Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON) == true) { gameState = 5; } //Graphics Raylib.BeginDrawing(); //Begin Draw Raylib.ClearBackground(Color.BLACK); //Background Raylib.DrawText("A Small Platformer", 20, 20, 60, Color.WHITE); Raylib.DrawRectangle(20, 200, 300, 50, but1ColBack); Raylib.DrawText("Play Game", 30, 210, 30, but1ColFront); Raylib.DrawRectangle(20, 270, 300, 50, but2ColBack); Raylib.DrawText("Make Level", 30, 280, 30, but2ColFront); Raylib.DrawRectangle(20, 340, 300, 50, but3ColBack); Raylib.DrawText("LOREM IPSUM", 30, 350, 30, but3ColFront); Raylib.EndDrawing(); //End Draw if (Raylib.IsKeyPressed(KeyboardKey.KEY_ESCAPE) && gameState == 0) { open = false; } } //GAME void game() //Gamestate 1 { playerWorldX = playerX - worldX; playerWorldY = playerY - worldY; fall = true; movement(); //Player Movement logic(); //Platform and Gravity Logic + Jump //Graphics Raylib.BeginDrawing(); //Begin Draw Raylib.ClearBackground(Color.BLACK); //Background Raylib.DrawRectangle(playerX, playerY, size, size, Color.GREEN); //Player for (int i = 0; i < platformX.Length; i++) //Platforms loop { Raylib.DrawRectangle(worldX + platformX[i], worldY + platformY[i], platformWidth[i], platformHeight[i], Color.WHITE); //Induvidual Platforms } for (int i = 0; i < coinX.Length; i++) //Platforms loop { if (coinHidden[i] == false) { Raylib.DrawRectangle(worldX + coinX[i], worldY + coinY[i], coinSize, coinSize, Color.YELLOW); //Induvidual Platforms } } Raylib.DrawFPS(10, 10); Raylib.DrawText("Coins: " + coins, 10, 40, 10, Color.YELLOW); Raylib.EndDrawing(); //End Draw } void movement() //Prt of GS 1 { if (Raylib.IsKeyDown(KeyboardKey.KEY_A) || Raylib.IsKeyDown(KeyboardKey.KEY_LEFT)) //Go Left { if (width / 2 - 100 < playerX) //Move player within boundary { playerX -= speed; } else //Otherwise move world { worldX += speed; } } if (Raylib.IsKeyDown(KeyboardKey.KEY_D) || Raylib.IsKeyDown(KeyboardKey.KEY_RIGHT)) //Go Right { if (width / 2 + 100 > playerX) //Move player within boundary { playerX += speed; } else //Otherwise move world { worldX -= speed; } } } void logic() //Prt of GS 1 { for (int i = 0; i < platformLength; i++) //Platform Logic { //Make not fall if on platform if ((playerWorldY + size - gravity <= platformY[i]) && (playerWorldY + size >= platformY[i]) && (playerWorldX + size > platformX[i]) && (playerWorldX < platformX[i] + platformWidth[i])) { if (playerWorldY + size - gravity <= platformY[i]) { playerY = platformY[i] - size; } fall = false; } } //Create the possibility to jump if cayote Time hasent gone to 0 if ((Raylib.IsKeyPressed(KeyboardKey.KEY_W) || Raylib.IsKeyPressed(KeyboardKey.KEY_UP)) && cayTime > 0) { jump = 40; cayTime = 0; } if (fall == true) //If nothing stoped it from falling it will fall { playerY += gravity; gravity++; if (cayTime > 0) { cayTime--; } } if (fall == false) //If the player isnt falling { gravity = 0; cayTime = cayTimeOri; } if (jump != 0) //Gravity implementation { playerY -= jump; //Affect player jump -= 2; //Deceases jumpforce until 0 } if (playerY > height) //Fall death { gameState = 2; } //Coins for (int i = 0; i < coinLength; i++) { if (((playerWorldX < coinX[i] && playerWorldX + size > coinX[i]) || (playerWorldX <coinX[i] + coinSize && playerWorldX + size> coinX[i] + coinSize)) && ((playerWorldY <coinY[i] && playerWorldY + size> coinY[i]) || (playerWorldY <coinY[i] + coinSize && playerWorldY + size> coinY[i] + coinSize)) && coinHidden[i] == false) { coins++; coinHidden[i] = true; } } } void death() //Gamestate 2 { if (Raylib.IsKeyPressed(KeyboardKey.KEY_R)) { worldX = 0; worldY = 0; playerX = 300; playerY = 300; gameState = 1; } //Graphics Raylib.BeginDrawing(); //Begin Draw Raylib.ClearBackground(Color.BLACK); //Background Raylib.DrawText("You Died", width / 2 - 90, height / 2 - 20, 40, Color.RED); //Death Text Raylib.DrawText("Press [R] to restart", width / 2 - 210, height / 2 + 60, 40, Color.RED); Raylib.EndDrawing(); //End Draw } void fileCreate() //Gamestate 3 { if (fileCreationStep == 0) { fileCreation = true; keyBoard(); fileCreation = false; if (Raylib.IsKeyPressed(KeyboardKey.KEY_ENTER)) { fileCreationStep = 1; } //Graphics Raylib.BeginDrawing(); Raylib.ClearBackground(Color.BLACK); Raylib.DrawText("Make a new File", 10, 10, 20, Color.WHITE); Raylib.DrawText(fileName, 20, 110, 20, Color.WHITE); Raylib.EndDrawing(); } if (fileCreationStep == 1) { Directory.CreateDirectory(@"maps\" + fileName); File.Create(@"maps\" + fileName + @"\platform.txt").Close(); System.Console.WriteLine("File Created: " + fileName + @"\platform.txt"); File.Create(@"maps\" + fileName + @"\checkPoint.txt").Close(); System.Console.WriteLine("File Created: " + fileName + @"\checkPoint.txt"); File.Create(@"maps\" + fileName + @"\coin.txt").Close(); System.Console.WriteLine("File Created: " + fileName + @"\coin.txt"); fileCreationStep = 2; } if (fileCreationStep == 2) { Raylib.BeginDrawing(); Raylib.ClearBackground(Color.BLACK); Raylib.DrawText("New File Created", 10, 10, 20, Color.WHITE); Raylib.EndDrawing(); gameState = 4; } } void mapCreate() //Gamestate 4 { if (Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON)) { if (mapCreationStep == 5) //Coins { coinString += (Raylib.GetMouseX() - worldX).ToString(); coinString += "," + (Raylib.GetMouseY() - worldY).ToString(); buildingCoinX.Add(Raylib.GetMouseX() - worldX - coinSize / 2); buildingCoinY.Add(Raylib.GetMouseY() - worldY - coinSize / 2); coinString += Environment.NewLine; } if (mapCreationStep == 2) //X, Y for platform { platformString += (Raylib.GetMouseX() + worldX).ToString(); platformString += "," + (Raylib.GetMouseY() + worldY).ToString(); buildingPlatformX.Add(Raylib.GetMouseX() - worldX); buildingPlatformY.Add(Raylib.GetMouseY() - worldY); currentPlatformX = Raylib.GetMouseX() - worldX; currentPlatformY = Raylib.GetMouseY() - worldY; mapCreationStep = -1; } if (mapCreationStep == 3) //Width and Heigth for platforms { currentPlatformW = currentPlatformX - (Raylib.GetMouseX() - worldX); currentPlatformH = currentPlatformY - (Raylib.GetMouseY() - worldY); if (currentPlatformW < 0) { currentPlatformW = currentPlatformW * -1; } if (currentPlatformH < 0) { currentPlatformH = currentPlatformH * -1; } platformString += "," + (currentPlatformW).ToString(); platformString += "," + (currentPlatformH).ToString(); buildingPlatformWidth.Add(currentPlatformW); buildingPlatformHigth.Add(currentPlatformH); platformString += Environment.NewLine; mapCreationStep = 2; } if (mapCreationStep == 1) //checkPoints { checkPointString += Environment.NewLine; checkPointString += (Raylib.GetMouseX() - worldX).ToString(); checkPointString += "," + (Raylib.GetMouseY() - worldY).ToString(); buildingcheckPointX.Add(Raylib.GetMouseX() - worldX); buildingcheckPointY.Add(Raylib.GetMouseY() - worldY); } if (mapCreationStep == 0) //Initial spawn { System.Console.WriteLine("ACTIVE FILE = " + fileName); checkPointString = (Raylib.GetMouseX() - worldX).ToString(); checkPointString += "," + (Raylib.GetMouseY() - worldY).ToString(); buildingcheckPointX.Add(Raylib.GetMouseX() - worldX - checkPointSize / 2); buildingcheckPointY.Add(Raylib.GetMouseY() - worldY - checkPointSize / 2); mapCreationStep = 1; } if (mapCreationStep == -1) { mapCreationStep = 3; } } if (Raylib.IsKeyDown(KeyboardKey.KEY_W) || Raylib.IsKeyDown(KeyboardKey.KEY_UP)) { worldY += speed; } if (Raylib.IsKeyDown(KeyboardKey.KEY_A) || Raylib.IsKeyDown(KeyboardKey.KEY_LEFT)) { worldX += speed; } if (Raylib.IsKeyDown(KeyboardKey.KEY_S) || Raylib.IsKeyDown(KeyboardKey.KEY_DOWN)) { worldY -= speed; } if (Raylib.IsKeyDown(KeyboardKey.KEY_D) || Raylib.IsKeyDown(KeyboardKey.KEY_RIGHT)) { worldX -= speed; } if (Raylib.IsKeyPressed(KeyboardKey.KEY_ENTER)) { if (mapCreationStep == 5) { File.WriteAllText(@"maps\" + fileName + @"\coin.txt", coinString); gameState = 0; } if (mapCreationStep == 2) { File.WriteAllText(@"maps\" + fileName + @"\platform.txt", platformString); mapCreationStep = 5; } if (mapCreationStep == 1) { File.WriteAllText(@"maps\" + fileName + @"\checkPoint.txt", checkPointString); mapCreationStep = 2; } } Raylib.BeginDrawing(); Raylib.ClearBackground(Color.BLACK); if (mapCreationStep == 0) { Raylib.DrawText("Choose a place for player spawn", 10, 10, 20, Color.WHITE); } if (mapCreationStep == 1) { Raylib.DrawText("Choose a place for the next checkPoint", 10, 10, 20, Color.WHITE); } if (mapCreationStep == 2) { Raylib.DrawText("Choose a place for the next platform", 10, 10, 20, Color.WHITE); } if (mapCreationStep == 3) { Raylib.DrawText("Choose a place for the other end of the platform", 10, 10, 20, Color.WHITE); } if (mapCreationStep == 5) { Raylib.DrawText("Choose a place to place coins", 10, 10, 20, Color.WHITE); } for (int i = 0; i < buildingcheckPointX.Count; i++) { Raylib.DrawRectangle(buildingcheckPointX[i] + worldX, buildingcheckPointY[i] + worldY, checkPointSize, checkPointSize, checkPointColor); } for (int i = 0; i < buildingPlatformHigth.Count; i++) { Raylib.DrawRectangle(buildingPlatformX[i] + worldX, buildingPlatformY[i] + worldY, buildingPlatformWidth[i], buildingPlatformHigth[i], platformColor); } for (int i = 0; i < buildingCoinX.Count; i++) { Raylib.DrawRectangle(buildingCoinX[i] + worldX, buildingCoinY[i] + worldY, coinSize, coinSize, Color.YELLOW); } Raylib.EndDrawing(); } void mapLoad() //Gamestate 5 { if (loadStep == 0) { loadY = 0; string[] existingDirectories = Directory.GetDirectories(@"maps"); loadStep = 1; } else if (loadStep == 1) { initialLoad(); } else if (loadStep == 3) { } } void initialLoad() { if (existingDirectories.Length > 0) { Raylib.BeginDrawing(); //Begin Draw Raylib.ClearBackground(Color.BLACK); //Background for (int i = 0; i < existingDirectories.Length; i++) { string directoryName = new DirectoryInfo(existingDirectories[i]).Name; mapColBack[i] = new Color(20, 20, 20, 255); mapColFront[i] = new Color(255, 255, 255, 255); if (Raylib.GetMouseX() > 20 && Raylib.GetMouseX() < 20 + loadButWidth && Raylib.GetMouseY() > 20 + i * 20 + i * loadButHight && Raylib.GetMouseY() < 20 + i * 20 + i * loadButHight + loadButHight) { mapColBack[i] = new Color(255, 255, 255, 255); mapColFront[i] = new Color(20, 20, 20, 255); } if (Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON)) { if (Raylib.GetMouseX() > 20 && Raylib.GetMouseX() < 20 + loadButWidth && Raylib.GetMouseY() > 20 + i * 20 + i * loadButHight && Raylib.GetMouseY() < 20 + i * 20 + i * loadButHight + loadButHight) { char[] loadSeperator = { '\n' }; string loadPlatform = File.ReadAllText(existingDirectories[i] + @"\platform.txt"); string[] loadPlatformSplit = loadPlatform.Split(loadSeperator); for (int g = 0; g < loadPlatformSplit.Length; g++) { System.Console.WriteLine(loadPlatformSplit[g]); } string[] loadCoin = File.ReadAllLines(existingDirectories[i] + @"\coin.txt"); string[] loadCheckPoint = File.ReadAllLines(existingDirectories[i] + @"\checkPoint.txt"); } } //Graphics Raylib.DrawRectangle(20, 20 + loadY + i * (loadButHight + 20), loadButWidth, loadButHight, mapColBack[i]); Raylib.DrawText(directoryName, 30, 30 + i * 20 + i * loadButHight, 30, mapColFront[i]); } Raylib.EndDrawing(); } else { System.Console.WriteLine("No files found"); gameState = 0; } } void keyBoard() //When the Player should write text { if (Raylib.IsKeyPressed(KeyboardKey.KEY_A)) { if (fileCreation == true) { fileName += "a"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_B)) { if (fileCreation == true) { fileName += "b"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_C)) { if (fileCreation == true) { fileName += "c"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_D)) { if (fileCreation == true) { fileName += "d"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_E)) { if (fileCreation == true) { fileName += "e"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_F)) { if (fileCreation == true) { fileName += "f"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_G)) { if (fileCreation == true) { fileName += "g"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_H)) { if (fileCreation == true) { fileName += "h"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_I)) { if (fileCreation == true) { fileName += "i"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_J)) { if (fileCreation == true) { fileName += "j"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_K)) { if (fileCreation == true) { fileName += "k"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_L)) { if (fileCreation == true) { fileName += "l"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_M)) { if (fileCreation == true) { fileName += "m"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_N)) { if (fileCreation == true) { fileName += "n"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_O)) { if (fileCreation == true) { fileName += "o"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_P)) { if (fileCreation == true) { fileName += "p"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_Q)) { if (fileCreation == true) { fileName += "q"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_R)) { if (fileCreation == true) { fileName += "r"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_S)) { if (fileCreation == true) { fileName += "s"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_T)) { if (fileCreation == true) { fileName += "t"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_U)) { if (fileCreation == true) { fileName += "u"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_V)) { if (fileCreation == true) { fileName += "v"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_W)) { if (fileCreation == true) { fileName += "w"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_X)) { if (fileCreation == true) { fileName += "x"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_Y)) { if (fileCreation == true) { fileName += "y"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_Z)) { if (fileCreation == true) { fileName += "z"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_ONE)) { if (fileCreation == true) { fileName += "1"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_TWO)) { if (fileCreation == true) { fileName += "2"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_THREE)) { if (fileCreation == true) { fileName += "3"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_FOUR)) { if (fileCreation == true) { fileName += "4"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_FIVE)) { if (fileCreation == true) { fileName += "5"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_SIX)) { if (fileCreation == true) { fileName += "6"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_SEVEN)) { if (fileCreation == true) { fileName += "7"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_EIGHT)) { if (fileCreation == true) { fileName += "8"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_NINE)) { if (fileCreation == true) { fileName += "9"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_ZERO)) { if (fileCreation == true) { fileName += "0"; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_SPACE)) { if (fileCreation == true) { fileName += " "; } } if (Raylib.IsKeyPressed(KeyboardKey.KEY_BACKSPACE)) { if (fileCreation == true) { try{ fileName = fileName.Remove(fileName.Length - 1, 1); } catch {} } } } }
public void Update() { if (Raylib.IsMouseButtonDown(MouseButton.MOUSE_LEFT_BUTTON)) { changeCellAtMouse(Cell.Water); } if (Raylib.IsMouseButtonDown(MouseButton.MOUSE_RIGHT_BUTTON)) { changeCellAtMouse(Cell.Empty); } if (Raylib.IsKeyPressed(KeyboardKey.KEY_SPACE)) { updateGrid = !updateGrid; } if (Raylib.IsKeyPressed(KeyboardKey.KEY_RIGHT)) { speed += 5; } if (Raylib.IsKeyPressed(KeyboardKey.KEY_LEFT)) { speed -= 5; } speed = (int)Math.Clamp(speed, 0, 100); if (updateGrid) { UpdateGrid(); } //rendering for (var y = 0; y < gridY; y++) { for (var x = 0; x < gridX; x++) { var cell = state[y * gridX + x]; var color = cell == Cell.Empty ? Color.GRAY : cell == Cell.Water ? Color.BLUE : cell == Cell.Sand ? Color.YELLOW : Color.BLACK; Raylib.DrawRectangle(x * cellSize, y * cellSize, cellSize, cellSize, color); } } Raylib.DrawFPS(1200, 0); var t = Raylib.MeasureText("PAUSED", 50); Raylib.DrawText(updateGrid ? "" : "PAUSED", Raylib.GetScreenWidth() / 2 - t / 2, Raylib.GetScreenHeight() / 2, 50, Color.WHITE); Raylib.DrawText($"speed: {speed}", 1, 1, 20, Color.WHITE); void changeCellAtMouse(Cell cell) { var m = Raylib.GetMousePosition(); var x = (int)(m.X / cellSize); var y = (int)(m.Y / cellSize); if (x > 0 && y > 0 && x < gridX && y < gridY) { state[y * gridX + x] = cell; } } }
/// <summary> /// Display all Entities that are Visible using thier RenderLayer order /// </summary> public virtual void Render() { //------------------------------------------------------------------------------- // Get all RenderComponent, sort them, low -> high //------------------------------------------------------------------------------- List <RenderComponent> ComponentsToRender = new List <RenderComponent>(); // // Find all Entities (in case some were removed/added) // GameEntities = EntityContext.GetEntities().Where(e => e.EntityType == 0).ToList(); SceneEntities = EntityContext.GetEntities().Where(e => e.EntityType == 1).ToList(); foreach (Entity ent in GameEntities) { if (!(ent.Get <Transform>().Enabled&& ent.Get <Transform>().Visiable)) { continue; } // // Ask Entitas for all components attached to "ent" entity // Entitas.IComponent[] allComp = ent.GetComponents(); //this entity's component foreach (Entitas.IComponent comp in allComp) //get the renderable ones { if (comp is IRenderable) { RenderComponent myComp = (RenderComponent)comp; ComponentsToRender.Add(myComp); } } } //------------------------------------------------------------------------------- // CAMERA DISPLAY BeginMode2D //------------------------------------------------------------------------------- if (CameraEnabled && CameraEntityToFollow != null) { // need to get the entity that is target of camera -> target Get<Transform>().Position // Any component that is in view of the camera, is drawn first switch (CameraType2D) { case Camera2DType.FollowPlayer: UpdateCameraCenter(); break; case Camera2DType.FollowInsideMap: UpdateCameraInsideMap(); break; case Camera2DType.FollowCenterSmooth: UpdateCameraCenterSmoothFollow(); break; } Raylib.BeginMode2D(Camera); } //------------------------------------------------------------------------------- // RENDER ORDER sorting (low to high) then render //------------------------------------------------------------------------------- foreach (RenderComponent myComp in ComponentsToRender.OrderBy(e => e.RenderLayer)) { myComp.Render(); //call draw method } //------------------------------------------------------------------------------- // CAMERA DISPLAY EndMode2D //------------------------------------------------------------------------------- if (CameraEnabled && CameraEntityToFollow != null) { if (Global.DebugRenderEnabled) { // // display camera position // int screenHeight = Global.SceneHeight; int screenWidth = Global.SceneWidth; int tx = (int)CameraEntityToFollow.Get <Transform>().Position.X; int ty = (int)CameraEntityToFollow.Get <Transform>().Position.Y; Raylib.DrawLine(tx, -screenHeight * 10, tx, screenHeight * 10, Color.GREEN); //Verticval Raylib.DrawLine(-screenWidth * 10, ty, screenWidth * 10, ty, Color.GREEN); //Horizontal //tx = (int)Global.WindowCenter.X; //ty = (int)Global.WindowCenter.Y; //Raylib.DrawLine(tx, -screenHeight * 10, tx, screenHeight * 10, Color.RED); //Verticval //Raylib.DrawLine(-screenWidth * 10, ty, screenWidth * 10, ty, Color.RED); //Horizontal } Raylib.EndMode2D(); } //------------------------------------------------------------------------------- // U I ENTITIES , they are drawn on top of all other game entities //------------------------------------------------------------------------------- foreach (Entity ent in SceneEntities) { if (!ent.Get <Transform>().Enabled) { continue; } if (!ent.Get <Transform>().Visiable) { continue; } Entitas.IComponent[] allComp = ent.GetComponents(); //this entity's component foreach (Entitas.IComponent comp in allComp) { if (comp is IRenderable) { RenderComponent myComp = (RenderComponent)comp; myComp.Render(); //call draw method } } } //----------------- // Scene debug //----------------- if (Global.DebugRenderEnabled) { Raylib.DrawText(Raylib.GetMousePosition().ToString(), 10, 10, 20, Color.WHITE); if (CameraEnabled && CameraEntityToFollow != null) { Raylib.DrawFPS(10, 30); Raylib.DrawText("Zoom" + Camera.zoom.ToString(), 10, 50, 20, Color.WHITE); } else { Raylib.DrawFPS(10, 30); } } }
static void Main(string[] args) { Raylib.InitWindow(1366, 768, "Foam Test"); Raylib.SetTargetFPS(60); //args = new string[] { "C:/Projekti/Foam/bin/mapfoam/sample/test.mapfoam" }; //args = new[] { "C:/Projekti/Ray/build/bin/sample/light_test.mapfoam" }; Cam3D = new Camera3D(new Vector3(1, 1, 1), Vector3.Zero, Vector3.UnitY); Raylib.SetCameraMode(Cam3D, CameraMode.CAMERA_FREE); Model[] Models = null; FoamModel FoamModel = null; bool DrawText = true; bool DrawWireframe = false; bool DrawSkeleton = true; bool UpdateAnimation = true; while (!Raylib.WindowShouldClose()) { if (Raylib.IsKeyPressed(KeyboardKey.KEY_F1)) { DrawText = !DrawText; } if (Raylib.IsKeyPressed(KeyboardKey.KEY_F2)) { DrawWireframe = !DrawWireframe; } if (Raylib.IsKeyPressed(KeyboardKey.KEY_F3)) { DrawSkeleton = !DrawSkeleton; } if (Raylib.IsKeyPressed(KeyboardKey.KEY_F4)) { UpdateAnimation = !UpdateAnimation; } if (Raylib.IsFileDropped() || (args != null && args.Length > 0)) { string DroppedFile = null; if (args != null && args.Length > 0) { DroppedFile = args[0]; args = null; } else { DroppedFile = Raylib.GetDroppedFiles()[0]; } Model[] NewModels = LoadModels(DroppedFile, out float Scale, out FoamModel NewFoamModel); if (NewModels != null && NewFoamModel != null) { if (NewModels.Length == 0 && NewFoamModel.Animations != null && FoamModel != null) { foreach (var NewAnim in NewFoamModel.Animations) { Utils.Append(ref FoamModel.Animations, NewAnim); } } else { if (Models != null) { foreach (var M in Models) { Raylib.UnloadModel(M); } } Models = NewModels; FoamModel = NewFoamModel; //Cam3D.position = new Vector3(0.5f, 0.25f, 0.5f) * Scale; //Cam3D.target = new Vector3(0, 0.25f, 0) * Scale; } } Raylib.ClearDroppedFiles(); } /*if (Models != null) * UpdateModel(FoamModel, FrameIndex);*/ Raylib.BeginDrawing(); Raylib.ClearBackground(new Color(50, 50, 50)); //Raylib.ClearBackground(new Color(0, 0, 0)); if (Models != null) { Raylib.UpdateCamera(ref Cam3D); Raylib.BeginMode3D(Cam3D); for (int i = 0; i < Models.Length; i++) { if (DrawWireframe) { Raylib.DrawModelWires(Models[i], Vector3.Zero, 1, Color.White); } else { Raylib.DrawModel(Models[i], Vector3.Zero, 1, Color.White); } } if (UpdateAnimation) { UpdateModelAnimation(FoamModel); } if (FoamModel != null && DrawSkeleton) { DrawBones(FoamModel); } Raylib.EndMode3D(); if (DrawText) { if (WorldTexts != null) { foreach (var KV in WorldTexts) { Raylib.DrawText(KV.Value, (int)KV.Key.X, (int)KV.Key.Y, 10, Color.White); } } } } DrawTextLine("F1 - Toggle bone names", 0); DrawTextLine("F2 - Toggle wireframe", 1); DrawTextLine("F3 - Toggle skeleton", 2); DrawTextLine("F4 - Toggle animations", 3); Raylib.DrawFPS(5, 5); Raylib.EndDrawing(); } }
static void Main(string[] args) { #region setup och listor int screenY = 900; int screenX = 1400; string scene = "intro"; int score = 0; int miss = 0; Raylib.InitWindow(screenX, screenY, "Carnival Shooter"); Raylib.SetTargetFPS(60); bool exitGame = false; // Gör enemies till listan Rectangle e1 = new Rectangle(-300, 125, 90, 90); Rectangle e2 = new Rectangle(screenX + 300, 360, 110, 110); Rectangle e3 = new Rectangle(-300, 650, 120, 120); //Lista till struct List <EnemyStruct> enemyList = new List <EnemyStruct>(); enemyList.Add(new EnemyStruct(e1, 15)); List <EnemyStruct> enemyList1 = new List <EnemyStruct>(); enemyList1.Add(new EnemyStruct(e2, -10)); List <EnemyStruct> enemyList2 = new List <EnemyStruct>(); enemyList2.Add(new EnemyStruct(e3, 5)); /* * // Lista till speed som läggs till * List<int> speed = new List<int>(); * speed.Add(15); * speed.Add(-10); * speed.Add(5); */ #endregion // main loop while (!Raylib.WindowShouldClose() && !exitGame) { Raylib.BeginDrawing(); #region intro if (scene == "intro") { introScreen(screenX, screenY); if (Raylib.IsKeyPressed(KeyboardKey.KEY_SPACE)) { scene = "game"; } else if (Raylib.IsKeyPressed(KeyboardKey.KEY_Q)) { //Raylib.CloseWindow(); exitGame = true; } } #endregion #region backgrund och structförsök (game skärmen) else if (scene == "game") { Raylib.ClearBackground(Color.GREEN); Texture2D bg = Raylib.LoadTexture("bg_vatten1.png"); Raylib.DrawTexture(bg, 0, 0, Color.WHITE); Raylib.DrawFPS(40, 40); // försök till att använda structurer for (int i = 0; i < enemyList.Count; i++) { EnemyStruct e = enemyList[i]; e.Update(); Raylib.DrawRectangle((int)e.rect.x, (int)e.rect.y, (int)e.rect.width, (int)e.rect.height, Color.WHITE); } for (int i = 0; i < enemyList1.Count; i++) { EnemyStruct e = enemyList1[i]; e.Update(); Raylib.DrawRectangle((int)e.rect.x, (int)e.rect.y, (int)e.rect.width, (int)e.rect.height, Color.WHITE); } for (int i = 0; i < enemyList2.Count; i++) { EnemyStruct e = enemyList2[i]; e.Update(); Raylib.DrawRectangle((int)e.rect.x, (int)e.rect.y, (int)e.rect.width, (int)e.rect.height, Color.WHITE); } #endregion #region enemy spawn //detta ska spawna en till enemy if (enemyList.Last().rect.x > 0) { enemyList.Add(new EnemyStruct(new Rectangle(-300, 125, 90, 90), 15)); // speed.Add(15); } if (enemyList1.Last().rect.x < screenX) { enemyList1.Add(new EnemyStruct(new Rectangle((screenX + 300), 360, 110, 110), -15)); // speed.Add(-15); } if (enemyList2.Last().rect.x > 0) { enemyList2.Add(new EnemyStruct(new Rectangle(-300, 650, 120, 120), 5)); // speed.Add(5); } #endregion //metoder score = enemy(screenX, screenY, score, miss, enemyList, enemyList1, enemyList2); crossHair(); Score(screenX, score); Miss(screenX, screenY, miss); //(används inte än) } Raylib.EndDrawing(); } }
public static int Init(bool debugging = true, bool resetProgress = false, bool raylibLogging = false, bool displayFPS = false) { // Initialization //-------------------------------------------------------------------------------------- bool firstRun = true; // Count the amount of cycles to track when to run GC.Collect int cleanupCounter = 0; // Count the amount of times tab was pressed in a certain period of time. int tabCounter = 0; if (debugging) { Raylib.SetTraceLogLevel(TraceLogType.LOG_ALL); } else { Raylib.SetTraceLogLevel(TraceLogType.LOG_ERROR); } // Custom Logging if (raylibLogging) { Raylib.SetTraceLogLevel(TraceLogType.LOG_ALL); Raylib.SetTraceLogCallback(LogCustom); } // Reset to defaults if (resetProgress) { settings = new Settings(true); } // Create Window // 800x600 is the games internal resolution. InitWindow(800, 600, "M O O N S H O T"); Image icon = LoadImage(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Images/moon.png")); Raylib.ImageResize(ref icon, 100, 100); Raylib.SetWindowIcon(icon); // Enable Sound InitAudioDevice(); // Switch to Full Screen if setting is set. if (!Raylib.IsWindowFullscreen() && settings.StartFullscreen) { Raylib.ToggleFullscreen(); Raylib.HideCursor(); } // Set the Exit Key to something invalid. To disable it... Raylib.SetExitKey(KeyboardKey.KEY_LEFT_CONTROL | KeyboardKey.KEY_RIGHT_CONTROL); // Set FPS Target SetTargetFPS(60); // Set currentScreenTempStore to the currentScreen if savedProgress is true if (settings.savedProgress) { currentScreenTempStore = settings.currentScreen; } //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button { if (displayFPS) { Raylib.DrawFPS(0, 0); } // Check if tab key is pressed and if so launch save menu if (!settings.nonGameScreens.Contains(settings.currentScreen.ToLower())) { tabCounter = SavetoMenu(tabCounter, cleanupCounter); } // Toggle FullScreen on Escape key ToggleFS(); // Draw //---------------------------------------------------------------------------------- BeginDrawing(); // Splash Screen on initial launch if (firstRun) { (new splashScreen()).Display(); if (cleanupCounter > 150) { firstRun = false; } } else if (Raylib.GetScreenWidth() > 800) { Raylib.ClearBackground(BLACK); Raylib.DrawText("Screen resize not working!\nPlease change resolution to 800x600 manually.", 30, 30, 30, WHITE); } else { // Go through each screen and check if screen name matches the currentScreen. // This is how we track the game state. Not sure if this is how other's would create games but it works. bool foundScreen = false; foreach (screen scrn in settings.screensList) { if (settings.savedProgress == true) { if (settings.nonGameScreens.Contains(scrn.Name.ToLower()) && settings.nonGameScreens.Contains(settings.currentScreen.ToLower())) { if (settings.currentScreen.ToLower() == "avoid meteor game") { } else if (settings.currentScreen.ToLower() == "collect rocks game") { } else if (settings.currentScreen.ToLower() == scrn.Name.ToLower()) { ((screen)scrn).Display(); // Display screen foundScreen = true; } } } else { if (scrn.Name.ToLower() == settings.currentScreen.ToLower()) { ((screen)scrn).Display(); // Display screen foundScreen = true; } } } if (!foundScreen) { settings.currentScreen = "welcome"; } } EndDrawing(); // Count loops cleanupCounter++; // .NET Garbage collection every 10000 cycles // Probably not needed but why not? if (cleanupCounter > 10000) { GC.Collect(); GC.WaitForPendingFinalizers(); cleanupCounter = 0; } // Exit if Running is false; if (!settings.Running) { break; } //---------------------------------------------------------------------------------- //Console.WriteLine(settings.userStats.ToString()); } // Save settings if (settings.nonGameScreens.Contains(settings.currentScreen.ToLower())) { if (!string.IsNullOrEmpty(currentScreenTempStore)) { settings.currentScreen = currentScreenTempStore; } else if (settings.currentScreen.ToLower() == "avoid meteor game") { } else if (settings.currentScreen.ToLower() == "collect rocks game") { } else if (settings.currentScreen.ToLower() == "repair ship") { settings.currentScreen = "main trail"; } else { settings.currentScreen = ""; } } settings.SaveSettings(); // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return(0); }