static void Main(string[] args) { const int screenWidth = 1280; const int screenHeight = 720; Raylib.SetConfigFlags(ConfigFlag.FLAG_MSAA_4X_HINT | ConfigFlag.FLAG_VSYNC_HINT | ConfigFlag.FLAG_WINDOW_RESIZABLE); Raylib.InitWindow(screenWidth, screenHeight, "ImGui demo"); Raylib.SetTargetFPS(60); Random random = new Random(); _memoryEditorData = Enumerable.Range(0, 1024).Select(i => (byte)random.Next(255)).ToArray(); _controller.Load(screenWidth, screenHeight); // Main application loop while (!Raylib.WindowShouldClose()) { // Feed the input events to our ImGui controller, which passes them through to ImGui. _controller.Update(Raylib.GetFrameTime()); SubmitUI(); Raylib.BeginDrawing(); Raylib.ClearBackground(new Color((byte)(_clearColor.X * 255), (byte)(_clearColor.Y * 255), (byte)(_clearColor.Z * 255), (byte)255)); Raylib.DrawText("Hello, world!", 12, 12, 20, Color.BLACK); _controller.Draw(); Raylib.EndDrawing(); } _controller.Dispose(); Raylib.CloseWindow(); }
// The update function is the logical loop, here all logic goes. public override void Update() { // Loop through all of the buttons, and check what button is being pressed, // Act accordingly. for (int i = 0; i < uiElements.Length; i++) { if (uiElements[i].IsClicked()) { switch (uiElements[i].ID) { case 0: // New Game StageHandler.LoadStage(new MainGame("Game")); break; case 2: // Coop if (StageHandler.StageExists("Coop")) { StageHandler.SetCurrentStage("Coop"); } else { StageHandler.LoadStage(new CoopMenu("Coop")); } break; case 5: // Exit Raylib.CloseWindow(); Environment.Exit(1); break; } } } }
static (int, string) MenuTargetLogic(int mnTarget, string gState) { if (mnTarget == 1) { if (EnterOrSpaceCheck() == true) { gState = "game"; } } if (mnTarget == 2) { if (EnterOrSpaceCheck() == true) { gState = "options"; } } if (mnTarget == 3) { if (EnterOrSpaceCheck() == true) { Raylib.CloseWindow(); } } return(mnTarget, gState); }
static void Main(string[] args) { // Initializes the handlers that need initializing ScreenHandler.Init(CONFIG_SCREEN); GameHandler.Init(); // To allow the esc button to be used as a pause button, // F12 have been set as the exit key. Raylib.SetExitKey(key: KeyboardKey.KEY_F12); while (!Raylib.WindowShouldClose()) { Raylib.BeginDrawing(); // Default color if it is not overbidden by a background in any stage. Raylib.ClearBackground(Color.BLANK); // GameHandler is a static class. StageHandler.Run(); GameHandler.Run(); Raylib.EndDrawing(); } Raylib.CloseWindow(); // When the game closes, it saves the config. // ScreenHandler.SaveCurrentConfiguration(); }
public static void Game() { cardsLeft.AddRange(CreateAllCards()); Raylib.SetTargetFPS(120); Raylib.InitWindow(1200, 800, "31"); bool gameActive = true; CreateButtons(); ResetGame(); while (gameActive) { Raylib.SetExitKey(0); Raylib.BeginDrawing(); Raylib.ClearBackground(Color.WHITE); RenderButtons(); if (Raylib.IsKeyPressed(KeyboardKey.KEY_R)) { ResetGame(); } else if (Raylib.IsKeyPressed(KeyboardKey.KEY_Q)) { gameActive = false; } Raylib.EndDrawing(); } Raylib.CloseWindow(); }
private static void Main( ) { Raylib.SetConfigFlags(ConfigFlag.FLAG_WINDOW_TRANSPARENT); Raylib.InitWindow(ViewWindow.Width, ViewWindow.Height, "Mogol"); Raylib.SetTargetFPS(int.MaxValue); float tickTimer = 0f; while (!Raylib.WindowShouldClose( )) { Update( ); if (Playing) { float tickTime = 1f / TPS; tickTimer += Raylib.GetFrameTime( ); if (tickTimer >= tickTime) { FixedUpdate( ); tickTimer -= tickTime; } } Raylib.BeginDrawing( ); Draw( ); Raylib.EndDrawing( ); } Raylib.CloseWindow( ); }
void RunGame() { Raylib.InitWindow(windowWidth, windowHeight, windowTitle); Raylib.SetTargetFPS(60); LoadGame(); while Raylib.CloseWindow(); }
private void QuitGame() { GameData.ResetData(); PlayerData.ResetStats(); if (GameData.QuitGame) { GameData.ImageData.UnloadTextures(); GameData.AudioManager.CloseAudioDevice(); Raylib.CloseWindow(); // Close window and OpenGL context } }
void RunGame() { Raylib.InitWindow(windowWidth, windowHeight, windowTitle); LoadGame(); while (!Raylib.WindowShouldClose()) { Update(); Draw(); } Raylib.CloseWindow(); }
public void RunProgram() { Raylib.InitWindow(c.windowWidth, c.windowHeight, c.windowTitle); while (!Raylib.WindowShouldClose()) { LoadGame(); Update(); Draw(); s.Draw(); } Raylib.CloseWindow(); }
void RunGame() { Raylib.InitWindow(WindowWidth, WindowHeight, WindowTitle); Raylib.SetTargetFPS(60); loadGame(); while (!Raylib.WindowShouldClose()) { Update(); Draw(); } Raylib.CloseWindow(); }
void RunGame() { Raylib.InitWindow(windowWidth, windowHeight, windowTitle); Raylib.SetTargetFPS(60); // do on all projects LoadGame(); while (!Raylib.WindowShouldClose()) { Update(); Draw(); } Raylib.CloseWindow(); }
void RunGame() { Raylib.InitWindow(windowWidth, windowHeight, "Block Breaker"); Raylib.SetTargetFPS(60); LoadGame(); while (!Raylib.WindowShouldClose()) { Update(); Draw(); } Raylib.CloseWindow(); }
void RunProgram() { Raylib.InitWindow(windowWidth, windowHeight, "Pong"); Raylib.SetTargetFPS(60); LoadGame(); while (!Raylib.WindowShouldClose()) { Update(); Draw(); } Raylib.CloseWindow(); }
protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { // TODO: dispose managed state (managed objects) } // TODO: free unmanaged resources (unmanaged objects) and override finalizer // TODO: set large fields to null Raylib.CloseWindow(); disposedValue = true; } }
static void Main(string[] args) { Game game = new Game(); Raylib.InitWindow(game.windowWidth, game.windowHeight, game.windowTitle); Raylib.SetTargetFPS(60); game.LoadGame(); while (Raylib.WindowShouldClose() == false) { float frameTime = Raylib.GetFrameTime(); game.Update(frameTime); game.Draw(); } Raylib.CloseWindow(); }
public static void DrawGameInit(int tempCurrentUser) { Raylib.SetTargetFPS(120); Raylib.InitWindow(1900, 1000, "DrawGame"); bool gameActive = true; currentUser = tempCurrentUser; try { System.IO.Directory.CreateDirectory(@"dataStorage/" + currentUser + "/" + "DrawGameStorage"); } catch (SystemException) { throw; } FindLevels(); gameState = State.Menu; p1 = new Rectangle(Raylib.GetScreenWidth() / 4, (Raylib.GetScreenHeight() / 4) * 3, Raylib.GetScreenHeight() / 29, Raylib.GetScreenHeight() / 18); while (gameActive) { Raylib.SetExitKey(0); if (gameState == State.Game || gameState == State.Create) { CheckKeyPresses(); UpdatePos(); if (gameState == State.Game) { CheckCollision(); timer++; } } Raylib.BeginDrawing(); Raylib.ClearBackground(Color.WHITE); if (gameState == State.Game || gameState == State.Create || gameState == State.GamePause || gameState == State.CreatePause || gameState == State.Goal) { RenderScene(); StatusBar(); } if (gameState != State.Game && gameState != State.Create && gameState != State.Goal) { Menu(ref gameActive); } Raylib.EndDrawing(); } Raylib.CloseWindow(); }
static void Main(string[] args) { Game game = new Game(); Raylib.InitWindow(640, 480, "Hello World"); game.Init(); while (!Raylib.WindowShouldClose()) { game.Update(); game.Draw(); } game.Shutdown(); Raylib.CloseWindow(); }
static void Main(string[] args) { //Define global game variables string gameState = "intro"; const int windowX = 1200; const int windowY = 900; //Define Intro Screen Variables int playButtonRectX = windowX / 3; int playButtonRectY = (windowY / 3) * 2; int playButtonRectWidth = windowX / 3; int playButtonRectHeight = windowY / 6; Color buttonColor = Color.BROWN; Raylib.InitWindow(windowX, windowY, "Fighting Game"); while (!Raylib.WindowShouldClose()) { if (gameState == "intro") { //Logik if (Collide(playButtonRectX, playButtonRectY, playButtonRectWidth, playButtonRectHeight, Raylib.GetMouseX(), Raylib.GetMouseY(), 0, 0)) { buttonColor = Color.BEIGE; if (Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON)) { gameState = "shop"; } } else { buttonColor = Color.BROWN; } //Drawing Raylib.BeginDrawing(); Raylib.ClearBackground(Color.BLUE); Raylib.DrawText("ARENA BRAWLER", 20, windowY / 5, 135, Color.WHITE); Raylib.DrawRectangle(playButtonRectX, playButtonRectY, playButtonRectWidth, playButtonRectHeight, buttonColor); Raylib.DrawText("PLAY", playButtonRectX + 5, playButtonRectY, 150, Color.WHITE); Raylib.EndDrawing(); } else if (gameState == "shop") { Raylib.CloseWindow(); } }
static void Main(string[] args) { int width = 128; int height = 64; int cellSize = 12; Raylib.InitWindow(width * cellSize, height * cellSize, "Orzea"); Auton auton = new Auton(width, height); Color color; float elapsedTime = 0; //Raylib.SetTargetFPS(60); while (!Raylib.WindowShouldClose()) { Raylib.BeginDrawing(); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { if (auton.History[i, j]) { color = Color.WHITE; } else { color = Color.BLACK; } Raylib.DrawRectangle(i * cellSize, j * cellSize, cellSize, cellSize, color); } } elapsedTime += Raylib.GetFrameTime(); if (elapsedTime >= 0.2) { auton.Iterate(); elapsedTime = 0; } Raylib.EndDrawing(); } Raylib.CloseWindow(); }
static void Main(string[] args) { Raylib.InitWindow(1280, 720, "Game"); Raylib.SetWindowState(ConfigFlag.FLAG_WINDOW_RESIZABLE); Raylib.SetExitKey(KeyboardKey.KEY_END); scene = new World(); while (!Raylib.WindowShouldClose()) { var delta = Raylib.GetFrameTime(); if (delta != 0 && delta < 0.25) { scene.Update(); } Raylib.BeginDrawing(); Raylib.ClearBackground(Color.WHITE); scene.Draw(); Raylib.EndDrawing(); } Raylib.CloseWindow(); }
public void Run() { #if MACOS Raylib.SetConfigFlags(ConfigFlag.FLAG_WINDOW_HIGHDPI); #endif Initialize(); Raylib.InitWindow((int)WindowSize.X, (int)WindowSize.Y, Title); Raylib.SetExitKey((KeyboardKey)(-1)); LoadContent(); while (!Raylib.WindowShouldClose()) { Update(); Render(); } Unload(); Raylib.CloseWindow(); }
// we need to override the paperstart to decide whether to open OpenGL context or not public override void PaperStart() { if (Array.Exists <string>(arguments, element => element.Equals("--no-gui"))) { hasGui = false; Awake(); Console.WriteLine("PSDL: Ignoring OpenGL context"); Start(); while (true) { Update(); if (shouldClose) { break; } } Close(); } else { hasGui = true; Awake(); Raylib.InitWindow(width, height, title); Console.WriteLine("PSDL: OpenGL context opened"); WindowStart(); Start(); while (!Raylib.WindowShouldClose() && !shouldClose) { Update(); PaperDraw(); } Raylib.CloseWindow(); Close(); } }
private static void Main() { Canvas _canvas = new Canvas() { WindowWidth = MainWindowWidth, WindowHeight = MainWindowHeight }; int Middle = _canvas.WindowHeight / 2; int Center = _canvas.WindowWidth / 2; _canvas.AddBall(mass: 99, radius: 25, x: Center, y: Middle, vx: -0.0, vy: 0.0, Color.YELLOW, "Sun"); _canvas.AddBall(mass: 0.01, radius: 01, x: Center + 100 + 000, y: Middle, vx: -0.06, vy: +1.80, Color.DARKBROWN, "Mercury"); _canvas.AddBall(mass: 0.02, radius: 03, x: Center + 100 + 050, y: Middle, vx: -0.36, vy: +1.35, Color.GREEN, "Venus"); _canvas.AddBall(mass: 0.02, radius: 04, x: Center + 100 + 100, y: Middle, vx: -0.36, vy: +1.10, Color.BLUE, "Earth"); _canvas.AddBall(mass: 0.01, radius: 02, x: Center + 100 + 150, y: Middle, vx: -0.36, vy: +1.00, Color.RED, "Mars"); _canvas.AddBall(mass: 0.09, radius: 09, x: Center + 100 + 300, y: Middle, vx: -0.20, vy: +0.90, Color.MAROON, "Jupiter"); _canvas.AddBall(mass: 0.08, radius: 08, x: Center + 100 + 400, y: Middle, vx: -0.15, vy: +0.70, Color.SKYBLUE, "Saturn"); _canvas.AddBall(mass: 0.06, radius: 06, x: Center + 100 + 500, y: Middle, vx: -0.13, vy: +0.60, Color.BROWN, "Uranus"); _canvas.AddBall(mass: 0.05, radius: 05, x: Center + 100 + 600, y: Middle, vx: -0.08, vy: +0.48, Color.LIME, "Neptune"); //Pluto is no longer a planet! //_canvasManager.AddBall(mass: 0.01, radius: 01, x: Center + 100 + 900, y: Middle, vx: -0.07, vy:+0.07, Color.PURPLE); Raylib.InitWindow(_canvas.WindowWidth, _canvas.WindowHeight, "RLSolarSystem"); Raylib.SetTargetFPS(Defaults.FPS); //Comment/uncommet this line to get a less chaotic animation while (!Raylib.WindowShouldClose()) { Raylib.BeginDrawing(); Raylib.ClearBackground(Color.BLACK); _canvas.Render(); Raylib.EndDrawing(); } Raylib.CloseWindow(); }
static void Main() { Canvas _canvas = new Canvas(); _canvasManager = new CanvasManager(_canvas); int Middle = _canvas.Height / 2; int Center = _canvas.Width / 2; //Sun _canvasManager.AddBall(mass: 99, radius: 25, x: Center, y: Middle, vx: -0.0, vy: 0.0, Color.YELLOW); //Planets _canvasManager.AddBall(mass: 0.01, radius: 01, x: Center + 100 + 000, y: Middle, vx: -0.06, vy: +1.80, Color.DARKBROWN); _canvasManager.AddBall(mass: 0.02, radius: 03, x: Center + 100 + 050, y: Middle, vx: -0.36, vy: +1.35, Color.GREEN); _canvasManager.AddBall(mass: 0.02, radius: 04, x: Center + 100 + 100, y: Middle, vx: -0.36, vy: +1.10, Color.BLUE); _canvasManager.AddBall(mass: 0.01, radius: 02, x: Center + 100 + 150, y: Middle, vx: -0.36, vy: +1.00, Color.RED); _canvasManager.AddBall(mass: 0.09, radius: 09, x: Center + 100 + 300, y: Middle, vx: -0.20, vy: +0.90, Color.MAROON); _canvasManager.AddBall(mass: 0.08, radius: 08, x: Center + 100 + 400, y: Middle, vx: -0.15, vy: +0.70, Color.SKYBLUE); _canvasManager.AddBall(mass: 0.06, radius: 06, x: Center + 100 + 500, y: Middle, vx: -0.13, vy: +0.60, Color.BROWN); _canvasManager.AddBall(mass: 0.05, radius: 05, x: Center + 100 + 600, y: Middle, vx: -0.08, vy: +0.48, Color.LIME); //Pluto is no longer a planet! //_canvasManager.AddBall(mass: 0.01, radius: 01, x: Center + 100 + 900, y: Middle, vx: -0.07, vy:+0.07, Color.PURPLE); Raylib.InitWindow(_canvas.Width, _canvas.Height, "RLSolarSystem"); //Uncomment next line to get a less chaotic animation //Raylib.SetTargetFPS(60); while (!Raylib.WindowShouldClose()) { Raylib.BeginDrawing(); Raylib.ClearBackground(Color.BLACK); _canvasManager.Render(); Raylib.EndDrawing(); } Raylib.CloseWindow(); }
void RunGame() { InitWindow(windowWidth, windowHeight, windowTitle); SetTargetFPS(144); Camera3D camera = new Camera3D(); camera.position = new Vector3(4.0f, 2.0f, 4.0f); camera.target = new Vector3(0.0f, 1.8f, 0.0f); camera.up = new Vector3(0.0f, 1.0f, 0.0f); camera.fovy = 60.0f; camera.type = CAMERA_PERSPECTIVE; LoadGame(); while (!WindowShouldClose()) { Update(); Draw(); HideCursor(); } Raylib.CloseWindow(); }
public void Done() { drawScreen.Dispose(); Raylib.CloseWindow(); Raylib.UnloadRenderTexture(renderTexture); }
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(); }
static void Main(string[] args) { //Init Console.WriteLine("Enter the filename of the rom you want to load (from roms folder): "); string romName = Console.ReadLine(); Console.WriteLine("Enter target frame rate: "); int frameRate = Int32.Parse(Console.ReadLine()); Emu emu = new Emu(".\\roms\\" + romName); Raylib.InitWindow(640, 320, "My Chip-8 Emu - " + romName); Raylib.SetTargetFPS(frameRate); //Screen Texture Color[] pixelArray = new Color[64 * 32]; GCHandle pinnedArray = GCHandle.Alloc(pixelArray, GCHandleType.Pinned); IntPtr pixelPointer = pinnedArray.AddrOfPinnedObject(); Image screenImage = new Image { data = pixelPointer, width = 64, height = 32, format = (int)Raylib_cs.PixelFormat.UNCOMPRESSED_R8G8B8A8 }; Texture2D screenTexture = Raylib.LoadTextureFromImage(screenImage); pinnedArray.Free(); //Game Loop while (Raylib.WindowShouldClose() == false) { //Input emu.Keys[0] = Raylib.IsKeyDown(KeyboardKey.KEY_KP_0); emu.Keys[1] = Raylib.IsKeyDown(KeyboardKey.KEY_KP_1); emu.Keys[2] = Raylib.IsKeyDown(KeyboardKey.KEY_KP_2); emu.Keys[3] = Raylib.IsKeyDown(KeyboardKey.KEY_KP_3); emu.Keys[4] = Raylib.IsKeyDown(KeyboardKey.KEY_KP_4); emu.Keys[5] = Raylib.IsKeyDown(KeyboardKey.KEY_KP_5); emu.Keys[6] = Raylib.IsKeyDown(KeyboardKey.KEY_KP_6); emu.Keys[7] = Raylib.IsKeyDown(KeyboardKey.KEY_KP_7); emu.Keys[8] = Raylib.IsKeyDown(KeyboardKey.KEY_KP_8); emu.Keys[9] = Raylib.IsKeyDown(KeyboardKey.KEY_KP_9); emu.Keys[10] = Raylib.IsKeyDown(KeyboardKey.KEY_A); emu.Keys[11] = Raylib.IsKeyDown(KeyboardKey.KEY_B); emu.Keys[12] = Raylib.IsKeyDown(KeyboardKey.KEY_C); emu.Keys[13] = Raylib.IsKeyDown(KeyboardKey.KEY_D); emu.Keys[14] = Raylib.IsKeyDown(KeyboardKey.KEY_E); emu.Keys[15] = Raylib.IsKeyDown(KeyboardKey.KEY_F); //Update Emulator emu.Tick(); //Drawing Raylib.BeginDrawing(); Raylib.ClearBackground(Color.WHITE); for (int i = 0; i < emu.Screen.Length; i++) { int col = i % 64; int row = i / 64; if (emu.Screen[i] == 1) { Raylib.DrawRectangle(col * 10, row * 10, 10, 10, Color.WHITE); } else { Raylib.DrawRectangle(col * 10, row * 10, 10, 10, Color.BLACK); } } Raylib.EndDrawing(); } //End Game Raylib.UnloadTexture(screenTexture); Raylib.CloseWindow(); }
static void Menu() { //Create window Window.Initialize(); //Defines the position for the picker outside of the while loop so the value does not return to 0 every loop int picker = 0; while (!Raylib.WindowShouldClose()) { Raylib.BeginDrawing(); Raylib.ClearBackground(Window.backgroundColorMain); Raylib.DrawText("Racing game", 10, 10, 70, Color.WHITE); Raylib.DrawText(@" Contol scheme: Menu: W - Move up S - Move down E - Select ESC - Exit game In-game: Player one: W - Accelerate S - Reverse / Break A - Turn left D - Turn Right Player two: UP - Accelerate DOWN - Reverse / Break LEFT - Turn left RIGHT - Turn Right ESC - Return to menu ", 500, 10, 25, Color.WHITE); //PICK OPTIONS ARRAY string[] pickArray = new string[] { "Play", "Quit" }; //the text's y position is defined here since the same value is used further down in the code in the "picker" part int playTextY = 120; Raylib.DrawText(pickArray[0], 100, playTextY, 50, Color.WHITE); int exitTextY = 190; Raylib.DrawText(pickArray[1], 100, exitTextY, 50, Color.WHITE); if (Raylib.IsKeyPressed(KeyboardKey.KEY_S)) { picker++; } if (Raylib.IsKeyPressed(KeyboardKey.KEY_W)) { picker--; } //Lets player shift between play and exit, while also allowing picker to loop around selections if (picker == 0 || picker == 2) { picker = 0; Raylib.DrawText("-->", 10, playTextY, 50, Color.WHITE); } else if (picker == 1 || picker == -1) { picker = 1; Raylib.DrawText("-->", 10, exitTextY, 50, Color.WHITE); } if (picker == 0 && Raylib.IsKeyPressed(KeyboardKey.KEY_E)) { Raylib.CloseWindow(); Game(); } else if (picker == 1 && Raylib.IsKeyPressed(KeyboardKey.KEY_E)) { Raylib.CloseWindow(); Environment.Exit(0); } Raylib.EndDrawing(); } }