void RunGame() { Raylib.InitWindow(windowWidth, windowHeight, windowTitle); Raylib.SetTargetFPS(60); LoadGame(); while (!Raylib.WindowShouldClose()) { Update(); Draw(); } Raylib.CloseWindow(); }
private static void Selection() { int keypress = Raylib.GetKeyPressed(); if (Raylib.IsKeyPressed(KeyboardKey.KEY_BACKSPACE)) { keypress = 9000; } else if (Raylib.IsKeyReleased(KeyboardKey.KEY_ENTER)) { switch (selection) { case "1": AvoidMeteorMiniGame.avoidMeteorState = "Game"; break; case "2": MainWindow.settings.userStats.currentTime = MainWindow.settings.userStats.currentTime.AddDays(1); mainTrail.UseFood(3); mainTrail.CheckHealth(); MainWindow.settings.currentScreen = "Main Trail"; mainTrail.StartAnimation = true; break; } selection = ""; } switch (keypress) { case '1': selection = "1"; break; case '2': selection = "2"; break; case 9000: selection = String.Empty; break; default: break; } Raylib.DrawText("What is your choice? " + selection + "_", 100, 450, 30, WHITE); }
public static Sound Audio(string path) { if (audio == null) { audio = new Dictionary <string, Sound>(); } if (!audio.ContainsKey(path)) { if (!LoadPath(path, out string audioPath)) { Program.LoadingMessage($"No sound, bud. {audioPath}"); } var newAudio = Raylib.LoadSound(audioPath); audio.Add(path, newAudio); } return(audio[path]); }
static void Main(string[] args) { Raylib.InitWindow(800, 600, "Raylib base"); Raylib.SetTargetFPS(60); Raylib.SetExitKey(0); // Disable ESC key exit while (!Raylib.WindowShouldClose()) { // Logic // Drawing Raylib.BeginDrawing(); Raylib.ClearBackground(Color.GRAY); Raylib.EndDrawing(); } }
//Handles all of the main game logic including the main game loop. public void Run() { Start(); while (!_gameOver && !Raylib.WindowShouldClose()) { float deltaTime = Raylib.GetFrameTime(); Update(deltaTime); Draw(); while (Console.KeyAvailable) { Console.ReadKey(true); } } End(); }
//Called when the game begins. Use this for initialization. public void Start() { //Creates a new window for raylib Raylib.InitWindow(1024, 760, "Math For Games"); Raylib.SetTargetFPS(60); //Set up console window Console.CursorVisible = false; Console.Title = "Math For Games"; //Create a two new scenes for our actors to exist in and add them. Scene scene1 = new Scene(); Scene scene2 = new Scene(); //Create the actors to add to our scene Enemy enemyHigh = new Enemy(0, 5, Color.GREEN, new Vector2(0, 5), new Vector2(30, 5), '■', ConsoleColor.Green); Enemy enemyMid = new Enemy(10, 10, Color.GREEN, new Vector2(0, 10), new Vector2(30, 10), '■', ConsoleColor.Green); Enemy enemyLow = new Enemy(3, 20, Color.GREEN, new Vector2(0, 20), new Vector2(30, 20), '■', ConsoleColor.Green); Player player = new Player(0, 1, Color.BLUE, '@', ConsoleColor.Red); Goal goal = new Goal(30, 20, Color.GREEN, player, 'G', ConsoleColor.Green); //Initialize the enemies starting values enemyHigh.Speed = 1; enemyMid.Speed = 1; enemyLow.Target = player; //Set player's starting speed player.Speed = 5; //Add actors to the scenes scene1.AddActor(player); scene1.AddActor(enemyHigh); scene1.AddActor(enemyMid); scene1.AddActor(enemyLow); scene1.AddActor(goal); scene2.AddActor(player); //Sets the starting scene index and adds the scenes to the scenes array int startingSceneIndex = 0; startingSceneIndex = AddScene(scene1); AddScene(scene2); //Sets the current scene to be the starting scene index SetCurrentScene(startingSceneIndex); }
public static Music Music(string path) { if (music == null) { music = new Dictionary <string, Music>(); } if (!music.ContainsKey(path)) { if (!LoadPath(path, out string audioPath)) { Program.LoadingMessage($"No music, bud. {audioPath}"); } var newAudio = Raylib.LoadMusicStream(audioPath); music.Add(path, newAudio); } return(music[path]); }
static void Main(string[] args) { Raylib.InitWindow(300, 300, "DVD"); Raylib.ToggleFullscreen(); Raylib.ClearBackground(color Color); while (!Raylib.WindowShouldClose()) { Raylib.BeginDrawing(); Raylib.EndDrawing(); } }
public override void Display() { MainTrailMainDisplay(); //Confirmation(); if (!MainWindow.settings.userStats.ShipWorking) { ShipBroke(); } else if (StartAnimation == false && MainWindow.settings.userStats.milesTraveled == 0 && String.IsNullOrEmpty(tempPopUpMessage)) { LargePopUp(popUpMessages[MainWindow.settings.userStats.currentLocation].Item1, popUpMessages[MainWindow.settings.userStats.currentLocation].Item2, popUpMessages[MainWindow.settings.userStats.currentLocation].Item3); } else if (StartAnimation == false && String.IsNullOrEmpty(tempPopUpMessage)) { if (Raylib.IsKeyReleased(KeyboardKey.KEY_ENTER)) { StartAnimation = true; } } else { if (!String.IsNullOrEmpty(tempPopUpMessage)) { LargePopUp(tempPopUpMessage, tempPromptBool, tempNextScreen); } else { PressEnterToSizeUp(); Tuple <int, int> foodAndFuel = GetFoodAndFuelMod(); CheckHealth(); CheckOxygen(); CalamityChance(); CheckForDeadPlayers(); Travel(foodAndFuel.Item1); foodCounter++; if (foodCounter > 400) { foodCounter = 0; UseFood(foodAndFuel.Item2); } } } }
public static Model Model(string path) { if (models == null) { models = new Dictionary <string, Model>(); } if (!models.ContainsKey(path)) { if (!LoadPath(path, out string modelPath)) { Program.LoadingMessage($"No model, bud. {modelPath}"); } Console.WriteLine($"loading: {modelPath}"); var model = Raylib.LoadModel(modelPath); models.Add(path, model); } return(models[path]); }
//Handles all of the main game logic including the main game loop. public void Run() { Start(); while (!_gameOver && !Raylib.WindowShouldClose()) { GetKeyPressed(65); Update(); Draw(); while (Console.KeyAvailable) { Console.ReadKey(true); } Thread.Sleep(135); } End(); }
private void Update() { rectangleColorInt = ButtonSeries.GetSelectedColor(colorInt); if (ButtonSeries.GetSelectedButtonID(3) == 0) { textColor = Color.BLACK; } if (Raylib.IsKeyDown(key)) { highlightKey = true; } else { highlightKey = false; } }
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(); }
private void Draw() { Raylib.BeginDrawing(); Raylib.ClearBackground(BLACK); _gameBackground.draw(); GameData.EnemyManager.draw(); GameData.AlliedMissileManager.draw(); GameData.ExplosionManager.draw(); player.draw(); DrawUI(); _crosshair.draw(); Raylib.EndDrawing(); }
private static void DisplayMessage(int Progress) { List <string> messages = missionControlMessages[Progress]; if (choosenMessage == 99) { choosenMessage = r.Next(0, messages.Count); } string message = messages[choosenMessage]; //message = missionControlMessages[8][2]; // For debugging, force a specific message. string[] messageArray = message.Split("\n"); Raylib.DrawText("Mission Control:", (Raylib.GetScreenWidth() - 225) / 2, Raylib.GetScreenHeight() / 5, 30, WHITE); for (int i = 0; i < messageArray.Length; i++) { Raylib.DrawText(messageArray[i], Raylib.GetScreenWidth() / 32, Raylib.GetScreenHeight() / 4 + +30 + (50 * i), 30, WHITE); } }
public void Draw() { // Draws the ouline of UI Raylib.DrawRectangle(pos.X, pos.Y, width, height, Color.BROWN); // if white turn draw text with white font if (board.Turn % 2 == 0) { Raylib.DrawText("White turn", pos.X + 5, 50, 40, Color.WHITE); } // if black turn draw text with black font else { Raylib.DrawText("Black turn", pos.X + 5, 50, 40, Color.BLACK); } // draws the turn the game is on Raylib.DrawText(((board.Turn + 2) / 2).ToString(), pos.X + 5, 100, 30, Color.WHITE); }
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"; } } }
public override void Display() { ClearBackground(Colors.space); starscape(); Moon(); Menuline(Raylib.GetScreenWidth() / 128, Raylib.GetScreenHeight() / 6); Menuline(Raylib.GetScreenWidth() / 128, Raylib.GetScreenHeight() / 24 * 20); MoonshotLogo(); Message(); if (loopCount > 5) { Confirmation(); } else { loopCount++; } }
} //End public void Run() { Start(); //Loops the game until either the game is set to be over or the window closes while (!_gameOver && !Raylib.WindowShouldClose()) { float deltaTime = Raylib.GetFrameTime(); Update(deltaTime); Draw(); while (Console.KeyAvailable) Console.ReadKey(true); } //While game isn't over and Window shouldn't close End(); } //Run
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(); } }
private void LiveChat() { try { /*this while loop uses stream.Read to get data from the server, the stream we are using is the server and by reading it * we can get the bytes coming from the stream and then we can use the GetString to convert bytes to a string, which we then * print to the user */ NetworkStream stream = client.GetStream(); byte[] data2 = new byte[512]; while (liveChat || !Raylib.WindowShouldClose()) { string responeseData = string.Empty; int bytes = stream.Read(data2, 0, data2.Length); responeseData = System.Text.Encoding.UTF8.GetString(data2, 0, bytes); System.Console.WriteLine(responeseData); Message newMessage = JsonConvert.DeserializeObject <Message>(responeseData); if (newMessage.header == "MESSAGELENGTH") { data2 = new byte[newMessage.length + 256]; } if (newMessage.image != string.Empty) { byte[] imageData = Convert.FromBase64String(newMessage.image); string imageDataRaw = Encoding.UTF8.GetString(imageData); using (MemoryStream imageStream = new MemoryStream(imageData)) { System.Drawing.Image image = System.Drawing.Image.FromStream(imageStream, true, true); image.Save("file.png", ImageFormat.Png); img = Raylib.LoadImage("file.png"); File.Delete("file.png"); } } messages.Add(newMessage); } //if the server closes down for some reason, it will deliver this message to you and return you to the start. } catch (Exception) { stream.Close(); System.Console.WriteLine("Connection with the server broke!"); return; } }
public void Draw() { if (texture.height != 0) { if (IsHovered()) { Raylib.DrawTextureRec(texture, new Rectangle(0, 0, size.X, size.Y), position, Color.GRAY); } else { Raylib.DrawTextureRec(texture, new Rectangle(0, 0, size.X, size.Y), position, Color.WHITE); } } else { // if the user has defined a texture it will not use this. // Depending on the IsHovered, it will change the background. if (IsHovered()) { Raylib.DrawRectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y, Color.GRAY); } else { Raylib.DrawRectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y, backgroundColor); } } // Draws the text in the center of the box, no matter what. using the formula: /* * w2 = // whatever you want the width to be * h2 = // whatever you want the height to be * x2 = x1 + ((w1 - w2) / 2); * y2 = y1 + ((h1 - h2) / 2); */ Raylib.DrawText( text, (int)position.X + ((int)size.X - Raylib.MeasureText(text, (int)fontSize)) / 2, (int)position.Y + ((int)size.Y - (int)fontSize) / 2, (int)fontSize, textColor ); }
public void Update() { if (Raylib.IsKeyDown(KeyboardKey.KEY_A)) { rotation -= rotationSpeed; } if (Raylib.IsKeyDown(KeyboardKey.KEY_D)) { rotation += rotationSpeed; } if (Raylib.IsKeyDown(KeyboardKey.KEY_W)) { var dir = GetFacingDirection(); velocity += dir * accelerationSpeed; } if (Raylib.IsKeyDown(KeyboardKey.KEY_S)) { var dir = GetFacingDirection(); velocity -= dir * accelerationSpeed; } pos += velocity; if (pos.X < 0) { pos.X = program.windowWidth; } if (pos.X > program.windowWidth) { pos.X = 0; } if (pos.Y < 0) { pos.Y = program.windowHeight; } if (pos.Y > program.windowHeight) { pos.Y = 0; } }
public void PlatformerMovement(List <IBody> bodies) { var delta = Raylib.GetFrameTime(); var xdir = 0; if (Raylib.IsKeyDown(KeyboardKey.KEY_D)) { xdir = 1; } if (Raylib.IsKeyDown(KeyboardKey.KEY_A)) { xdir = -1; } velocity.X = xdir * speed; velocity.Y += gravity * delta; if (Raylib.IsKeyPressed(KeyboardKey.KEY_W) && currentJumps < maxJumps) { velocity.Y = -jumpForce; currentJumps += 1; } velocity.Y = Math.Clamp(velocity.Y, -1000, 1000); var nextVel = velocity * delta; var collision = Body.Collides(nextVel, bodies); if (collision.direction.X != 0) { nextVel.X = 0; } if (collision.direction.Y != 0) { nextVel.Y = 0; velocity.Y = 0; } Body.position += nextVel; if (collision.direction.Y == 1) { velocity.Y = 0; currentJumps = 0; } }
public void Execute() { // // Make sure you are in the correct scene! // var MyScene = (Scene)Global.CurrentScene; if (MyScene.GetType().Name != "PlayScene") { return; } var ActiveScene = (PlayScene)Global.CurrentScene; // new API for getting group with all matched entities from context var entities = Context <Default> .AllOf <TurretComponent>().GetEntities(); foreach (var entity in entities) { Transform tr = entity.Get <Transform>(); //if (Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON)) //{ // tr.LookAt(Raylib.GetMousePosition()); //} float rot = Global.LookAt(Raylib.GetMousePosition(), entity.Get <Transform>().Position); entity.Get <Transform>().Rotation = rot; //entity.Modify<Transform>().LookAt(Global.GetMousePosition()) ; // // shot fired // if (Raylib.IsKeyPressed(KeyboardKey.KEY_SPACE)) { var tComp = entity.Get <TurretComponent>(); ActiveScene.FireMissile(Raylib.GetMousePosition(), entity.Get <Transform>().Position, tr.Rotation); //ActiveScene.FireMissile(Raylib.GetMousePosition(), // tComp.BulletPlaceHolder.Get<Transform>().Position, // tr.Rotation); } } }
static void Main(string[] args) { Raylib.InitWindow(1800, 1000, "Hello TE!"); Image xWing = Raylib.LoadImage(@"XWing.png"); Texture2D xWingTexture = Raylib.LoadTextureFromImage(xWing); float x = 0; float y = 0; while (!Raylib.WindowShouldClose()) { if (Raylib.IsKeyDown(KeyboardKey.KEY_D)) { x += 1f; } if (Raylib.IsKeyDown(KeyboardKey.KEY_A)) { x -= 1f; } if (Raylib.IsKeyDown(KeyboardKey.KEY_S)) { y += 1f; } if (Raylib.IsKeyDown(KeyboardKey.KEY_W)) { y -= 1f; } Raylib.BeginDrawing(); Raylib.ClearBackground(Color.BLACK); Raylib.DrawCircle(400, 300, 100, Color.GRAY); Raylib.DrawCircle(400, 300, 50, Color.DARKGRAY); Raylib.DrawTexture(xWingTexture, (int)x, (int)y, Color.WHITE); Raylib.EndDrawing(); } }
public override void Update(Editor arg) { if (!arg.Simulator.TryGetJunctionFromPosition(arg.GetWorldMousePos(), out JunctionWireNode? jwn, out Wire? w)) { this.GoToState <ESNone>(0); return; } if (Raylib.IsMouseButtonPressed(MouseButton.MOUSE_BUTTON_LEFT)) { if (!arg.Simulator.IsPositionOnSelected(arg.GetWorldMousePos())) { arg.Simulator.Selection.Clear(); arg.Simulator.Select(node !); } this.GoToState <ESMovingSelection>(1); return; } }
//Called when the game begins. Use this for initialization. public void Start() { //Creates a new window for raylib Raylib.InitWindow(1024, 760, "Math For Games"); Raylib.SetTargetFPS(60); //Set up console window Console.CursorVisible = false; Console.Title = "Math For Games"; //Create a new scene for our actors to exist in Scene scene1 = new Scene(); Scene scene2 = new Scene(); //Creates two actors to add to our scene Goal goal = new Goal(5, 5, Color.GREEN, '■', ConsoleColor.Green); Enemy enemy = new Enemy(2, 1, scene1, Color.GREEN, '■', ConsoleColor.Green); Player player = new Player(0, 1, scene1, Color.BLUE, '@', ConsoleColor.Red); enemy.Target = player; scene1.AddActor(player); scene1.AddActor(goal); scene1.AddActor(enemy); scene2.AddActor(player); player.Speed = 5; int startingSceneIndex = 0; startingSceneIndex = AddScene(scene1); AddScene(scene2); SetCurrentScene(startingSceneIndex); player.SetScale(1, 2); player.SetRotation(0.5f); player.SetTranslate(new Vector2(10, 10)); goal.SetTranslate(new Vector2(5, 5)); goal.SetScale(3.5f, 3.5f); player.AddChild(enemy); }
//Called when the game begins. Use this for initialization. public void Start() { //Creates a new window for raylib Raylib.InitWindow(1024, 760, "Math For Games"); //Sets the framerate Raylib.SetTargetFPS(60); //Set up console window Console.CursorVisible = false; Console.Title = "Math For Games"; //Create a new scene for our actors to exist in Scene scene1 = new Scene(); Scene scene2 = new Scene(); //Creates two actors to add to our scene Actor actor = new Actor(0, 0, Color.GREEN, '■', ConsoleColor.Green); actor.Velocity.X = 1; Enemy enemy = new Enemy(0, 1, Color.GREEN, '■', ConsoleColor.Green); Player player = new Player(0, 1, Color.RED, '@', ConsoleColor.Red); actor.Velocity.X = 1; enemy.Target = player; enemy.SetTranslation(new Vector2(5, 0)); player.SetTranslation(new Vector2(10, 10)); player.AddChild(enemy); player.SetScale(1, 6); //Player player3 = new Player() scene1.AddActor(actor); scene1.AddActor(player); scene1.AddActor(enemy); scene2.AddActor(player); player.Speed = 5; int startingSceneIndex = 0; startingSceneIndex = AddScene(scene1); AddScene(scene2); SetCurrentScene(startingSceneIndex); }
public void Draw() { Raylib.DrawCircle( (int)Position.X, (int)Position.Y, Size, this.GetColor() ); if (Selected) { Raylib.DrawCircleLines( (int)Position.X, (int)Position.Y, Size + 2, this.GetHighlightColor() ); } }