public static bool CheckCollisionV1(Player _pl, Pickup _pu) { bool rtn = false; Rectangle PickUpColl; //= new Rectangle(_pu.Position.x - 10, _pu.Position.y - 10, 20, 20); float w = Pickup.MyTexture.width * 0.5f; float h = Pickup.MyTexture.height * 0.5f; PickUpColl = new Rectangle(_pu.Position.x - 0.5f * w, _pu.Position.y - 0.5f * h, w, h); Rectangle PlayerCol = new Rectangle(_pl.Position.x - 5, _pl.Position.y - 5, 10, 40); rtn = rl.CheckCollisionRecs(PlayerCol, PickUpColl); if (rtn) { _pu.Enabled = false; } return(rtn); }
public static bool checkCollision(Player pl, Pickup pu) { bool rtn = false; Random r = new Random(); Rectangle PickUpCol = new Rectangle(pu.pos.x, pu.pos.y, 10, 20); float w = Pickup.pickUpTex.width * .25f; float h = Pickup.pickUpTex.height * .25f; Rectangle PlayerCol = new Rectangle(pl.pos.x - 5, pl.pos.y, 10, 35); //Console.WriteLine(("Collision = " + PlayerCol + PickUpTest).ToString()); rtn = rl.CheckCollisionRecs(PickUpCol, PlayerCol); if (rtn) { //pu.enabled = false; pu.pos.x = r.Next(10, 750); pu.pos.y = r.Next(10, 400); } return(rtn); }
public static int Main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; int time = 20; int totalTime = time; int score = 0; Random rand = new Random(); rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window"); Pickup.myTexture = rl.LoadTexture("resources/platformPack_item007.png"); Player.p1 = rl.LoadTexture("resources/bat.png"); Player.p2 = rl.LoadTexture("resources/bat_fly.png"); Score.start(); //-------------------------------------------------------------------------------------- while (trial) { Player MyPlayer = new Player(); MyPlayer.vect.x = 50; MyPlayer.vect.y = 50; Enemy MyEnemy = new Enemy(); rl.SetTargetFPS(60); Pickup[] pickups = new Pickup[10]; for (int i = 0; i < 10; i++) { if (pickups[i] == null) { pickups[i] = new Pickup(); } pickups[i].fav = Color.DARKGRAY; pickups[i].pick.x = rand.Next(10, 750); pickups[i].pick.y = rand.Next(10, 400); for (int x = 0; x < i; x++) { while (CheckCollision(pickups[x], pickups[i]) || CheckCollision(MyPlayer, pickups[i], 1)) { Console.WriteLine($"Collision at {pickups[i].pick.x}, {pickups[i].pick.y}"); pickups[i].pick.x = rand.Next(10, 750); pickups[i].pick.y = rand.Next(10, 400); Console.WriteLine($"Moved to {pickups[i].pick.x}, {pickups[i].pick.y}"); } } } // Main game loop while (!rl.WindowShouldClose()) // Detect window close button or ESC key { // Update rl.BeginDrawing(); rl.ClearBackground(MyPlayer.MyColor); //---------------------------------------------------------------------------------- // TODO: Update your variables here foreach (Pickup pickup in pickups) { if (pickup.Enabled) { pickup.Draw(); score += CheckCollision(MyPlayer, pickup, 0) ? 1 : 0; } } if (rl.IsKeyPressed(KeyboardKey.KEY_R) && rl.IsKeyDown(KeyboardKey.KEY_LEFT_CONTROL)) { Score.reset(); } //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- if (score != 10 && totalTime > 0 && MyPlayer.health != 0) { MyPlayer.Draw(); MyPlayer.RunUpdate(); totalTime = (int)(time - rl.GetTime()); } else if (score == 10) { rl.DrawText("Congrats!", 350, 190, 20, Color.RAYWHITE); rl.DrawText("Press Enter to play again. Press Escape to close.", 140, 210, 20, Color.RAYWHITE); if (!done) { Score.add(totalTime); done = true; } Score.print(); if (rl.IsKeyPressed(KeyboardKey.KEY_ENTER)) { time = (int)rl.GetTime() + 20; totalTime = time; score = 0; for (int k = 0; k < pickups.Length; k++) { pickups[k] = null; } done = false; rl.EndDrawing(); break; } } else if (MyPlayer.health == 0) { rl.DrawText("You have no move lives.", 270, 190, 20, Color.RAYWHITE); rl.DrawText("Press Enter to play again. Press Escape to close.", 140, 210, 20, Color.RAYWHITE); if (rl.IsKeyPressed(KeyboardKey.KEY_ENTER)) { time = (int)(rl.GetTime() + 20); totalTime = time; score = 0; for (int k = 0; k < pickups.Length; k++) { pickups[k] = null; } rl.EndDrawing(); Score.print(); break; } } else if (totalTime <= 0) { rl.DrawText("You've ran out of time.", 300, 190, 20, Color.RAYWHITE); rl.DrawText("Press Enter to play again. Press Escape to close.", 140, 210, 20, Color.RAYWHITE); if (rl.IsKeyPressed(KeyboardKey.KEY_ENTER)) { time = (int)(rl.GetTime() + 20); totalTime = time; score = 0; for (int k = 0; k < pickups.Length; k++) { pickups[k] = null; } rl.EndDrawing(); Score.print(); break; } } rl.DrawText(score.ToString(), 775, 20, 20, Color.LIGHTGRAY); rl.DrawText(totalTime.ToString(), 385, 20, 20, Color.LIGHTGRAY); //---------------------------------------------------------------------------------- rl.EndDrawing(); } if (rl.WindowShouldClose()) { trial = false; } // De-Initialization //-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- } rl.CloseWindow(); // Close window and OpenGL context Score.textFile(); return(0); }
public static int Main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; bool gameOver = false; bool pause = false; int score = 0; int hiScore = 0; Player myPlayer = new Player(); myPlayer.Position.x = 50; myPlayer.Position.y = 125; Pickup[] Test = new Pickup[10]; int idx = 0; rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window"); Pickup.SetTexture("diamond.png"); rl.InitAudioDevice(); Pickup.SetSound("laser1.ogg"); Pickup.PlayClip(); Random rand = new Random(); int randInt = rand.Next(); for (int x = 100; x < 700 && idx < 10; x += 60) { Test[idx] = new Pickup(); Test[idx].Position.x = x; Test[idx].Position.y = rand.Next(75, 400); idx++; } rl.SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop while (!rl.WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- // TODO: Update your variables here //---------------------------------------------------------------------------------- myPlayer.RunUpdate(); // Draw //---------------------------------------------------------------------------------- rl.BeginDrawing(); rl.ClearBackground(Color.LIGHTGRAY); rl.DrawText($"Score: {score}", 50, 50, 30, Color.DARKBLUE); rl.DrawText($"Timer: {myPlayer.timer/60} / 30", 500, 50, 30, Color.DARKBLUE); if (myPlayer.timer >= 300) { rl.DrawText("You Lose ):", 250, 350, 50, Color.BLACK); myPlayer.playerEnabled = false; gameOver = true; pause = false; } myPlayer.Draw(); if (myPlayer.Position.x > 800) { myPlayer.Position.x = 5; } if (myPlayer.Position.x < 0) { myPlayer.Position.x = 795; } if (myPlayer.Position.y > 450) { myPlayer.Position.y = 5; } if (myPlayer.Position.y < 0) { myPlayer.Position.y = 445; } foreach (Pickup pickup in Test) { if (pickup.Enabled) { pickup.Draw(); if (CheckCollisionV1(myPlayer, pickup)) { score++; } } } if (!gameOver) { if (hiScore > score) { hiScore = score; } } else { if (rl.IsKeyPressed(KeyboardKey.KEY_ENTER)) { rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window"); gameOver = false; } } if (score == 10) { rl.DrawText("You Win!", 300, 250, 50, Color.MAROON); } //Console.WriteLine(CheckCollisionV1(myPlayer, Test)); rl.EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- rl.CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return(0); }
public static int Main() { // Initialization //-------------------------------------------------------------------------------------- void Restart() { if (rl.IsKeyDown(KeyboardKey.KEY_R)) { Init(); } } int screenWidth = 800; int screenHeight = 450; Tools tl = new Tools(); Player player = new Player(); Pickup[] pickup = new Pickup[10]; Enemy[] enemy = new Enemy[3]; int timer = 1800; int scoreToWin = 10; int score = 0; float i = 10f; bool condense = false; void Init() { timer = 1800; score = 0; player.pos.x = 20; player.pos.y = 20; player.enabled = true; player.hasWon = false; System.Array.Clear(pickup, 0, 9); int idx = 0; for (int j = 0; j < 10 && idx < 10; j++) { pickup[idx] = new Pickup(); pickup[idx].pos.x = Tools.rng.Next(100, 700); pickup[idx].pos.y = Tools.rng.Next(50, 400); idx++; } System.Array.Clear(enemy, 0, 2); idx = 0; for (int j = 0; j < 3 && idx < 3; j++) { enemy[idx] = new Enemy(); enemy[idx].pos.x = Tools.rng.Next(100, 700); enemy[idx].pos.y = Tools.rng.Next(50, 400); idx++; } } Init(); rl.InitWindow(screenWidth, screenHeight, "Raylib Playground"); rl.SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop while (!rl.WindowShouldClose()) // Detect window close button or ESC key { // Update - Where you update variables, run update functions, etc. //---------------------------------------------------------------------------------- player.PlayerUpdate(); if (timer > 0 && player.enabled && score < scoreToWin) { timer--; } if (condense == true) { i--; if (i == 10) { condense = false; } } else { i++; if (i > 250) { condense = true; } } //End Update ----------------------------------------------------------------------- // Draw - The top is drawn first, and is thusly on the bottom. //---------------------------------------------------------------------------------- rl.BeginDrawing(); rl.ClearBackground(Color.BLACK); rl.DrawCircleGradient(400, 225, i, Color.DARKBLUE, Color.BLACK); player.PlayerDraw(); foreach (Pickup p in pickup) { if (p.enabled) { p.PickupDraw(); score += tl.CheckCollisionPickup(player, p) ? 1 : 0; } } foreach (Enemy e in enemy) { e.EnemyUpdate(); e.EnemyDraw(); if (e.enabled) { tl.CheckCollisionEnemy(player, e); } if (score >= scoreToWin) { e.enabled = false; } } rl.DrawRectangleGradientV(320, -5, 155, 80, Color.DARKBLUE, Color.SKYBLUE); rl.DrawText($"Score: {score}", 335, 10, 30, Color.WHITE); rl.DrawText($"Timer: {timer / 60}", 330, 40, 30, Color.WHITE); if (score >= scoreToWin) { rl.DrawRectangleGradientV(280, 395, 250, 55, Color.SKYBLUE, Color.BLUE); rl.DrawText($"You Win!", 300, 400, 50, Color.WHITE); rl.DrawText("Press \"r\" to restart.", 195, 180, 40, Color.WHITE); player.hasWon = true; player.enabled = false; Restart(); } if (!player.enabled && timer > 0 && !player.hasWon) { rl.DrawRectangleGradientV(280, 395, 265, 55, Color.RED, Color.MAROON); rl.DrawText($"You Died.", 300, 400, 50, Color.WHITE); rl.DrawText("Press \"r\" to restart.", 195, 180, 40, Color.WHITE); Restart(); } if (timer == 0) { rl.DrawRectangleGradientV(280, 395, 250, 55, Color.RED, Color.MAROON); rl.DrawText($"Times up!", 300, 400, 50, Color.WHITE); rl.DrawText("Press \"r\" to restart.", 195, 180, 40, Color.WHITE); player.enabled = false; Restart(); } rl.EndDrawing(); //End Drawing ---------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- rl.CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return(0); }
public static int Main() { // Initialization //-------------------------------------------------------------------------------------- rl.InitAudioDevice(); Console.WriteLine($"INFO: Audio Device Status = {rl.IsAudioDeviceReady()}"); Sound pickUpS = rl.LoadSound("resources/AmmoPickup.ogg"); int screenWidth = 800; int screenHeight = 450; int score = 0, highScore = 0; int timer = 30 * 60; int trueTime = 0; string[] writeScore = new string[2]; bool restartBool = false; bool firstInc = true, secondInc = true, thirdInc = true, gameRunning = true; Random r = new Random(); Player myPlayer = new Player(); Pickup[] pickUp = new Pickup[10]; int idx = 0; rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window"); Pickup.SetTex("kenney_aie/items/platformPack_item002.png"); StreamReader reader; reader = new StreamReader("test.txt"); writeScore[0] = reader.ReadLine(); reader.Close(); StreamWriter writer; writer = new StreamWriter("test.txt"); //writer.WriteLine("Hello World!"); writer.Close(); for (int x = 100; x < 700 && idx < 10; x += 40) { pickUp[idx] = new Pickup(); pickUp[idx].pos.x = r.Next(10, 750); pickUp[idx].pos.y = r.Next(10, 400); idx++; } int radicalRadius = 0; if (radicalRadius > 100) { radicalRadius--; } else if (radicalRadius < 1) { radicalRadius++; } myPlayer.pos.x = 75; myPlayer.pos.y = 75; rl.SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop while (!rl.WindowShouldClose()) // Detect window close button or ESC key { timer--; trueTime = trueTime++ / 60; int temptime = timer / 60; // Update //---------------------------------------------------------------------------------- // TODO: Update your variables here //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- rl.BeginDrawing(); rl.ClearBackground(Color.RAYWHITE); if (score == 10 && firstInc) { timer += 5 * 60; firstInc = false; } else if (score == 20 && secondInc) { timer += 5 * 60; secondInc = false; } else if (score >= 30 && thirdInc) { writer = new StreamWriter("test.txt"); writer.WriteLine(writeScore[0] = $"{Convert.ToString(highScore)}, {Convert.ToString(trueTime)}"); writer.Close(); gameRunning = false; thirdInc = false; } else if (score >= 30) { rl.DrawText("Congratulations! You Win!\n\t\t\tPress R to Restart", 275, 200, 20, Color.LIGHTGRAY); restartBool = rl.IsKeyPressed(KeyboardKey.KEY_R); } myPlayer.RunUpdate(); myPlayer.Draw(); if (temptime <= 0 && score < 30) { rl.DrawText("Time is Up!\nPress R to Restart", 50, 60, 20, Color.LIGHTGRAY); restartBool = rl.IsKeyPressed(KeyboardKey.KEY_R); gameRunning = false; } else if (temptime > 0 & gameRunning) { rl.DrawText($"Time: {temptime}", 50, 60, 20, Color.LIGHTGRAY); foreach (Pickup p in pickUp) { p.Draw(); if (checkCollision(myPlayer, p)) { score++; rl.PlaySound(pickUpS); } } } if (restartBool) { score = 0; timer = 30 * 60; for (int x = 100; x < 700 && idx < 10; x += 40) { pickUp[idx] = new Pickup(); pickUp[idx].pos.x = r.Next(10, 750); pickUp[idx].pos.y = r.Next(10, 400); idx++; } gameRunning = true; restartBool = false; } if (highScore <= score) { highScore = score; } rl.DrawText($"Score: {score}", 50, 20, 20, Color.LIGHTGRAY); rl.DrawText($"High Score: {writeScore[0]}", 50, 40, 20, Color.LIGHTGRAY); //rl.DrawText("Congrats! You created your first window!", 190, 200, 20, Color.LIGHTGRAY); rl.EndDrawing(); //---------------------------------------------------------------------------------- } //System.IO.File.WriteAllText(@"C:\Users\s199009") // De-Initialization //-------------------------------------------------------------------------------------- rl.CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return(0); }
public static int Main() { // Initialization //-------------------------------------------------------------------------------------- Random rand = new Random(); Player player = new Player(); Pickup[] pickup = new Pickup[70]; Enemy[] enemies = new Enemy[50]; Enemy enemy = new Enemy(); Gun gun = new Gun(); int screenWidth = 1600; int screenHeight = 900; int health = player.health; int ammo = player.ammo; int score = player.score; int timer = 0; //bool winState = false; //rl.InitAudioDevice(); //var pick = rl.LoadAudioStream("powerUp1.oog"); rl.InitWindow(screenWidth, screenHeight, "Assessment"); //Create enemies Enemy.EnemyTexture("bat.png"); for (int Enidx = 0; Enidx < enemies.Length; Enidx++) { enemies[Enidx] = new Enemy(); enemies[Enidx].Position.x = rand.Next(20, screenWidth - 20); enemies[Enidx].Position.y = rand.Next(30, screenHeight - 20); } //Create pickups Ammo.SetTexture("platformPack_item001.png"); Health.SetTexture("platformPack_item017.png"); Score.SetTexture("platformPack_item009.png"); for (int idx = 0; idx < pickup.Length; idx++) { int pickChoice = rand.Next(0, 3); if (pickChoice == 0) { pickup[idx] = new Ammo(); pickup[idx].Position.x = rand.Next(20, screenWidth - 20); pickup[idx].Position.y = rand.Next(30, screenHeight - 20); } if (pickChoice == 1) { pickup[idx] = new Health(); pickup[idx].Position.x = rand.Next(20, screenWidth - 20); pickup[idx].Position.y = rand.Next(30, screenHeight - 20); } if (pickChoice == 2) { pickup[idx] = new Score(); pickup[idx].Position.x = rand.Next(20, screenWidth - 20); pickup[idx].Position.y = rand.Next(30, screenHeight - 20); } } player.Position.x = rand.Next(20, screenWidth - 20); player.Position.y = rand.Next(30, screenHeight - 20); rl.SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop while (!rl.WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- // TODO: Update your variables here //---------------------------------------------------------------------------------- player.RunUpdate(); timer++; // Draw //---------------------------------------------------------------------------------- rl.BeginDrawing(); rl.ClearBackground(Color.LIGHTGRAY); rl.DrawText("Score: " + score, 50, 50, 12, Color.WHITE); rl.DrawText("Health: " + health, 50, 75, 12, Color.WHITE); rl.DrawText("Time: " + timer / 60, screenWidth - 200, 50, 12, Color.WHITE); rl.DrawText("Ammo: " + ammo, screenWidth - 200, 80, 12, Color.WHITE); //if (timer/60 >= 30 && winState == false) //{ // rl.DrawText("Game Over", 250, 50, 20, Color.ORANGE); // rl.DrawText("BOI", 250, 75, 20, Color.ORANGE); // player.speed = 0; //} player.Draw(); foreach (Enemy en in enemies) { if (en.isEnabled) { en.Draw(); if (CheckCollisionV2(player, en)) { health--; score++; } //if (en.Position.x > player.Position.x) // en.Position.x-= 3; //if (en.Position.x < player.Position.x) // en.Position.x+= 3; //if (en.Position.y > player.Position.y) // en.Position.y-= 3; //if (en.Position.y < player.Position.y) // en.Position.y+= 3; if (health <= 0) { health = 0; rl.DrawText("Game Over", 250, 50, 20, Color.ORANGE); rl.DrawText("BOI", 250, 75, 20, Color.ORANGE); player.speed = 0; } } } foreach (Pickup pick in pickup) { if (pick.Enabled) { switch (pick.up) { case Pickup.PickupType.Ammo: ((Ammo)pick).Draw(); ammo += CheckCollisionV1(player, pick) ? 1 : 0; //adds one to variable break; case Pickup.PickupType.Health: ((Health)pick).Draw(); health += CheckCollisionV1(player, pick) ? 1 : 0; break; case Pickup.PickupType.Score: ((Score)pick).Draw(); if (CheckCollisionV1(player, pick)) { score += rand.Next(1, 11); } break; default: break; } //rl.PlayAudioStream(pick); //score.score += CheckCollisionV1(player, pick) ? 1 : 0; } } //Player screen Warps if (player.Position.x <= 0) { player.Position.x = screenWidth - 1; } if (player.Position.x >= screenWidth) { player.Position.x = 0; } if (player.Position.y <= 0) { player.Position.y = screenHeight - 1; } if (player.Position.y >= screenHeight) { player.Position.y = 0; } rl.EndDrawing(); //---------------------------------------------------------------------------------- //if (score.score >= 10) //{ // rl.DrawText("Oh goody, you survived", 250, 50, 20, Color.ORANGE); // //winState = true; // player.speed = 0; //} } // De-Initialization //-------------------------------------------------------------------------------------- rl.CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return(0); }
public static int Main() { // Initialization //-------------------------------------------------------------------------------------- Random rand = new Random(); Player player = new Player(); Bullet[] bullets = new Bullet[10]; Pickup[] pickup = new Pickup[70]; Enemy[] enemies = new Enemy[50]; string[] contents = File.LoadFile("GO.txt"); int screenWidth = 1000; int screenHeight = 900; int health = player.health; int ammo = player.ammo; int score = player.score; int timer = 0; int bulletpointer; int gameOverTimer = 0; bool winState = false; string username = ""; Console.WriteLine("What is your name?"); username = Console.ReadLine(); rl.InitWindow(screenWidth, screenHeight, "Assessment"); //Create enemies Enemy.EnemyTexture("bat.png"); for (int Enidx = 0; Enidx < enemies.Length; Enidx++) { enemies[Enidx] = new Enemy(); enemies[Enidx].Position.x = rand.Next(20, screenWidth - 20); enemies[Enidx].Position.y = rand.Next(30, screenHeight - 20); } //Create bullets for (int idx = 0; idx < bullets.Length; idx++) { bullets[idx] = new Bullet(); } //Create pickups Ammo.SetTexture("platformPack_item001.png"); Health.SetTexture("platformPack_item017.png"); Score.SetTexture("platformPack_item009.png"); for (int idx = 0; idx < pickup.Length; idx++) { int pickChoice = rand.Next(0, 3); if (pickChoice == 0) { pickup[idx] = new Ammo(); pickup[idx].Position.x = rand.Next(20, screenWidth - 20); pickup[idx].Position.y = rand.Next(30, screenHeight - 20); } if (pickChoice == 1) { pickup[idx] = new Health(); pickup[idx].Position.x = rand.Next(20, screenWidth - 20); pickup[idx].Position.y = rand.Next(30, screenHeight - 20); } if (pickChoice == 2) { pickup[idx] = new Score(); pickup[idx].Position.x = rand.Next(20, screenWidth - 20); pickup[idx].Position.y = rand.Next(30, screenHeight - 20); } } player.Position.x = rand.Next(20, screenWidth - 20); player.Position.y = rand.Next(30, screenHeight - 20); rl.SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop while (!rl.WindowShouldClose()) // Detect window close button or ESC key { // Update player.RunUpdate(); timer++; // Draw rl.BeginDrawing(); rl.ClearBackground(Color.LIGHTGRAY); rl.DrawText("Score: " + score, 50, 50, 12, Color.BLACK); rl.DrawText("Health: " + health, 50, 75, 12, Color.BLACK); rl.DrawText("Time: " + timer / 60, screenWidth - 200, 50, 12, Color.BLACK); rl.DrawText("Ammo: " + ammo, screenWidth - 200, 80, 12, Color.BLACK); if (timer / 60 >= 60 && winState == false) { rl.DrawText(contents[0], 250, 50, 20, Color.ORANGE); Console.WriteLine(gameOverTimer); player.speed = 0; ++gameOverTimer; if (gameOverTimer > 60 * 5) { File.SaveScore(username, score); return(0); } } player.Draw(); bool NotAllEnemiesDead = false; foreach (Enemy en in enemies) { if (en.Enabled) { NotAllEnemiesDead = true; en.Draw(); if (CheckCollisionV2(player, en)) { health--; } if (en.Position.x > player.Position.x) { en.Position.x -= 1 + rand.Next(0, 1); } if (en.Position.x < player.Position.x) { en.Position.x += 1 + rand.Next(0, 1); } if (en.Position.y > player.Position.y) { en.Position.y -= 1 + rand.Next(0, 1); } if (en.Position.y < player.Position.y) { en.Position.y += 1 + rand.Next(0, 1); } if (health <= 0) { health = 0; rl.DrawText(contents[0], 250, 50, 20, Color.ORANGE); player.speed = 0; ++gameOverTimer; if (gameOverTimer > 60 * 5) { File.SaveScore(username, score); return(0); } } } } if (NotAllEnemiesDead == false) { //Display win rl.DrawText("You won!", 250, 50, 20, Color.ORANGE); winState = true; ++gameOverTimer; if (gameOverTimer > 60 * 5) { File.SaveScore(username, score); return(0); } } if (rl.IsKeyPressed(KeyboardKey.KEY_SPACE) && ammo > 0) { bulletpointer = 1; //bullet.findDisableBullet(bullets); bullets[bulletpointer].Position.x = player.Position.x + 11; bullets[bulletpointer].Position.y = player.Position.y + 10; bullets[bulletpointer].bulletMove = true; bullets[bulletpointer].Enabled = true; ammo--; } foreach (Bullet bu in bullets) { if (bu.Enabled) { bu.Draw(); if (bu.bulletMove) { bu.Position.x += 5; } for (int i = 0; i < enemies.Length; ++i) { score += CheckCollisionV3(bu, enemies[i]) ? 1 : 0; } if (ammo <= 0) { ammo = 0; bu.Enabled = false; if (ammo > -1) { bu.Enabled = true; } } } } foreach (Pickup pick in pickup) { if (pick.Enabled) { switch (pick.up) { case Pickup.PickupType.Ammo: ((Ammo)pick).Draw(); ammo += CheckCollisionV1(player, pick) ? 1 : 0; //adds one to variable break; case Pickup.PickupType.Health: ((Health)pick).Draw(); health += CheckCollisionV1(player, pick) ? 1 : 0; break; case Pickup.PickupType.Score: ((Score)pick).Draw(); if (CheckCollisionV1(player, pick)) { score += rand.Next(1, 11); } break; default: break; } //rl.PlayAudioStream(pick); } } //Player screen Warps if (player.Position.x <= 0) { player.Position.x = screenWidth - 1; } if (player.Position.x >= screenWidth) { player.Position.x = 0; } if (player.Position.y <= 0) { player.Position.y = screenHeight - 1; } if (player.Position.y >= screenHeight) { player.Position.y = 0; } rl.EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- rl.CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return(0); }
public static int Main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; int time = 15; rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window"); string path = @"score.txt"; Player myPlayer = new Player(); myPlayer.texture = rl.LoadTexture($"frog1.png"); Pickup[] test = new Pickup[10]; int idx = 0; int framesCounter = 0; int frogCount = 1; Random random = new Random(); Audio laserOne = new Audio("laser1.ogg"); if (!File.Exists(path)) { StreamWriter sw = new StreamWriter(path); sw.Write(myPlayer.score); sw.Close(); } StreamReader srr = new StreamReader(path); string lines; lines = srr.ReadLine(); int temp; Int32.TryParse(lines, out temp); srr.Close(); myPlayer.highScore = temp; for (int i = 100; i < 700 && idx < 10; i += 40) { test[idx] = new Pickup(); test[idx].texture = rl.LoadTexture($"platformPack_item003.png"); test[idx].position.x = random.Next() % screenWidth - 10; test[idx].position.y = random.Next() % screenHeight - 10; idx++; } rl.SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop while (!rl.WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- // TODO: Update your variables here //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- rl.BeginDrawing(); rl.ClearBackground(Color.RAYWHITE); if (myPlayer.Enable) { myPlayer.RunUpdate(); } myPlayer.Draw(); foreach (Pickup pickup in test) { pickup.Draw(); Rectangle playerRec = new Rectangle(myPlayer.position.x, myPlayer.position.y, 10, 25); Rectangle pickupRec = new Rectangle(pickup.position.x, pickup.position.y, pickup.texture.width, pickup.texture.height); if (rl.CheckCollisionRecs(playerRec, pickupRec) && pickup.Enable) { StreamReader sr = new StreamReader(path); pickup.Enable = false; myPlayer.score++; string line; line = sr.ReadLine(); sr.Close(); int tmp; Int32.TryParse(line, out tmp); if (myPlayer.score > tmp) { StreamWriter sw = new StreamWriter(path); sw.Write(myPlayer.score); myPlayer.highScore = myPlayer.score; sw.Close(); } else { myPlayer.highScore = tmp; } } } if (rl.GetTime() > time) { rl.DrawText($"You ran out of time.", 100, 100, 18, Color.RED); myPlayer.Enable = false; } laserOne.Play(); rl.EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- rl.CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return(0); }
public static int Main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; //1280; int screenHeight = 450; //720; Player myPlayer = new Player(); Pickup[] myPickup = new Pickup[10]; int idx = 0; int score = 0; int timer = 600; for (int x = 100; x < 700 && idx < 10; x += 40) { myPickup[idx] = new Pickup(); myPickup[idx].position.x = x + (rnd.Next(0, 50) - 25); myPickup[idx].position.y = 150 + (rnd.Next(0, 100) - 50); idx++; } myPlayer.position.x = 75; myPlayer.position.y = 75; rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window"); rl.SetTargetFPS(60); //-------------------------------------------------------------------------------------- Texture2D frog1 = rl.LoadTexture("frog.png"); Texture2D frog2 = rl.LoadTexture("frog_leap.png"); Texture2D frog3 = rl.LoadTexture("frog_dead.png"); string[] gemTex = new string[4] { "Resources/items/platformPack_item001.png", "Resources/items/platformPack_item002.png", "Resources/items/platformPack_item003.png", "Resources/items/platformPack_item004.png" }; Texture2D[] test = new Texture2D[8] { rl.LoadTexture("Resources/items/platformPack_item001.png"), rl.LoadTexture("Resources/items/platformPack_item001.png"), rl.LoadTexture("Resources/items/platformPack_item002.png"), rl.LoadTexture("Resources/items/platformPack_item002.png"), rl.LoadTexture("Resources/items/platformPack_item003.png"), rl.LoadTexture("Resources/items/platformPack_item003.png"), rl.LoadTexture("Resources/items/platformPack_item004.png"), rl.LoadTexture("Resources/items/platformPack_item004.png") }; int g = 0; // Main game loop while (!rl.WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- // TODO: Update your variables here //---------------------------------------------------------------------------------- if (score < 10 && timer > 0) { myPlayer.RunUpdate(); timer--; } g++; if (g >= 8) { g = 0; } //myPlayer.rot += 12; // Draw //---------------------------------------------------------------------------------- rl.BeginDrawing(); rl.DrawText(g.ToString(), 50, 100, 1, Color.RAYWHITE); rl.ClearBackground(Color.SKYBLUE); //myPlayer.Draw(); if (score < 10 && timer > 0) { myPlayer.tex = frog1; myPlayer.Draw(); } else { if (score == 10) { myPlayer.tex = frog2; } myPlayer.Draw(); if (timer <= 10) { myPlayer.tex = frog3; } myPlayer.Draw(); } foreach (Pickup pickup in myPickup) { if (pickup.enabled) { pickup.tex = test[g]; pickup.Draw(); score += CheckCollisionV1(myPlayer, pickup) ? 1 : 0; } if (score == 10) { rl.DrawText("Bro nice job... ;)", 50, 100, 1, Color.RAYWHITE); rl.ClearBackground(Color.PINK); } } rl.DrawText("Time : " + (timer / 60), 320, 0, 20, Color.RAYWHITE); rl.DrawText("Score : " + score, 320, 400, 20, Color.RAYWHITE); //Console.WriteLine("buh:" + rl.CheckCollisionRecs(PlayerTest, PickupTest).ToString()); if (timer <= 0) { rl.ClearBackground(Color.RED); rl.DrawText("Certified Bruh Moment", 40, 100, 64, Color.RAYWHITE); //rl.CloseWindow(); } rl.EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- rl.CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return(0); }