public void P1(float deltaTime) { if (IsKeyDown(KeyboardKey.KEY_A)) { Rotate(-deltaTime * tankSpeed); } if (IsKeyDown(KeyboardKey.KEY_D)) { Rotate(deltaTime * tankSpeed); } if (IsKeyDown(KeyboardKey.KEY_W)) { Vector2 facing = new Vector2(LocalTransform.m1, LocalTransform.m2) * deltaTime * 100 * tankSpeed; Translate(facing.x, facing.y); } if (IsKeyDown(KeyboardKey.KEY_S)) { Vector2 facing = new Vector2(LocalTransform.m1, LocalTransform.m2) * deltaTime * -100 * tankSpeed; Translate(facing.x, facing.y); } Update(deltaTime); if (IsKeyDown(KeyboardKey.KEY_Q)) { turretObject.Rotate(-deltaTime * turretSpeed); } if (IsKeyDown(KeyboardKey.KEY_E)) { turretObject.Rotate(deltaTime * turretSpeed); } bullet.Draw(); float xR = turretObject.GlobalTransform.m1; float yR = turretObject.GlobalTransform.m2; float rot = MathF.Atan2(xR, yR); if (IsKeyPressed(KeyboardKey.KEY_SPACE) && (reloadTime * deltaTime) >= 5) { turretObject.AddChild(bullet); bullet.SetPosition(65, -5.5f); float bulletX = bullet.GlobalTransform.m7; float bulletY = bullet.GlobalTransform.m8; turretObject.RemoveChild(bullet); reloadTime = 0; bullet.SetRotate(rot); bullet.bulletSpawn(turretObject, deltaTime); bullet.SetPosition(bulletX, bulletY); isbullet = true; } if (isbullet) { Vector2 facing = new Vector2(bullet.LocalTransform.m1, bullet.LocalTransform.m2) * deltaTime * 100 * bulletSpeed; bullet.Translate(facing.x, facing.y); } }
public void Draw() { BeginDrawing(); ClearBackground(Color.BEIGE); DrawText(fps.ToString(), 10, 10, 10, Color.LIME); foreach (SceneObject obstacle in obstacles) { if (obstacle.health > 0) { obstacle.Draw(); } } //tankObject.Draw(); p1.Draw(); p2.Draw(); explosionFX.Draw(); if (bullet.TimeLeft > 0) { bullet.Draw(); } explosionFX_.Draw(); if (bullet_.TimeLeft > 0) { bullet_.Draw(); } string p1wins = $"P1 wins: {p1.wins}"; int p1winM = MeasureText(p1wins, 20); string p1winstr = $"P1 win streak: {p1.winStreak}"; int p1winstrM = MeasureText(p1wins, 20); string p2wins = $"P2 wins: {p2.wins}"; int p2winM = MeasureText(p2wins, 20); string p2winstr = $"P1 win streak: {p2.winStreak}"; int p2winstrM = MeasureText(p2wins, 20); //P1 HUD DrawText("P1", 10, GetScreenHeight() - 30, 20, Color.BLUE); DrawRectangle(40, GetScreenHeight() - 192, 24, 128, Color.GRAY); DrawRectangle(40, GetScreenHeight() - 64 - (int)((p1.reload / p1.reloading) * 128), 24, (int)((p1.reload / p1.reloading) * 128), p1.loadColor); DrawText($"R\nE\nL\nO\nA\nD", 10, GetScreenHeight() - 224, 20, Color.WHITE); DrawRectangle(64, GetScreenHeight() - 64, 128, 24, Color.GRAY); DrawRectangle(64, GetScreenHeight() - 64, (int)((p1.armor / p1.maxArmor) * 128), 24, Color.SKYBLUE); DrawText($"A R M O R", 64, GetScreenHeight() - 30, 20, Color.WHITE); if (p1.winStreak > 0) { //DrawText(p1winstr,128, GetScreenHeight() - 96,20,Color.BLUE); } //P2 HUD DrawText("P2", GetScreenWidth() - 32, 10, 20, Color.RED); DrawRectangle(GetScreenWidth() - 64, 64, 24, 128, Color.GRAY); DrawRectangle(GetScreenWidth() - 64, 64, 24, (int)((p2.reload / p2.reloading) * 128), p2.loadColor); DrawText($"R\nE\nL\nO\nA\nD", GetScreenWidth() - 24, 48, 20, Color.WHITE); DrawRectangle(GetScreenWidth() - 192, 40, 128, 24, Color.GRAY); DrawRectangle(GetScreenWidth() - 192, 40, (int)((p2.armor / p2.maxArmor) * 128), 24, Color.SKYBLUE); DrawText($"A R M O R", GetScreenWidth() - 168, 10, 20, Color.WHITE); //DrawCircle((int)tankTL.GlobalTransform.m7, (int)tankTL.GlobalTransform.m8,3,Color.GREEN); if (p2.winStreak > 0) { //DrawText(p2winstr, GetScreenWidth() - 168, 42, 20, Color.RED); } if (paused) { if (p1.armor > 0 && p2.armor > 0) { Vector2 bodyWritePos = new Vector2((GetScreenWidth() / 5) - (((bodies.Count - 1) * 128) - 48), (GetScreenHeight() / 2) - ((barrels.Count - 1) * 64) + 32); Vector2 barrelWritePos = new Vector2(GetScreenWidth() / 5, (GetScreenHeight() / 2) - ((barrels.Count - 1) * 32)); Vector2 bodyWritePos_ = new Vector2((GetScreenWidth() / 5 * 4) - (((bodies.Count - 1) * 128) - 48), (GetScreenHeight() / 2) - ((barrels.Count - 1) * 64) + 32); Vector2 barrelWritePos_ = new Vector2((GetScreenWidth() / 5) * 4, (GetScreenHeight() / 2) - ((barrels.Count - 1) * 32)); int bottomTip = MeasureText(helper, 20); int debugTip = MeasureText(helper0, 10); for (int b = 0; b < bodies.Count; b++) { DrawText(helper, (GetScreenWidth() / 2) - (bottomTip / 2), GetScreenHeight() - 64, 20, Color.BROWN); DrawText(helper0, (GetScreenWidth() / 2) - (debugTip / 2), GetScreenHeight() - 128, 10, Color.BROWN); DrawText(helper1, (int)bodyWritePos.x, (int)bodyWritePos.y - 128, 20, Color.BLUE); DrawText(helper2, (int)bodyWritePos_.x, (int)bodyWritePos_.y - 128, 20, Color.RED); DrawRectangle((int)bodyWritePos.x + (b * 144), (int)bodyWritePos.y, 128, 32, (p1.bodyPick == b) ? Color.SKYBLUE : Color.LIGHTGRAY); DrawRectangleLines((int)bodyWritePos.x + (b * 144), (int)bodyWritePos.y, 128, 32, (p1.bodyPick == b) ? Color.BLUE : Color.GRAY); int tempM = MeasureText(bodies[b].Name, 10); DrawText(bodies[b].Name, (int)(bodyWritePos.x + (b * 144)) + 64 - (tempM / 2), (int)bodyWritePos.y, 10, Color.WHITE); DrawRectangle((int)bodyWritePos_.x + (b * 144), (int)bodyWritePos_.y, 128, 32, (p2.bodyPick == b) ? Color.SKYBLUE : Color.LIGHTGRAY); DrawRectangleLines((int)bodyWritePos_.x + (b * 144), (int)bodyWritePos_.y, 128, 32, (p2.bodyPick == b) ? Color.BLUE : Color.GRAY); DrawText(bodies[b].Name, (int)(bodyWritePos_.x + (b * 144)) + 64 - (tempM / 2), (int)bodyWritePos_.y, 10, Color.WHITE); } for (int b = 0; b < barrels.Count; b++) { DrawRectangle((int)barrelWritePos.x - 72, (int)barrelWritePos.y + b * 64 - 16, 144, 32, (p1.gunPick == b) ? Color.SKYBLUE : Color.LIGHTGRAY); DrawRectangleLines((int)barrelWritePos.x - 72, (int)barrelWritePos.y + b * 64 - 16, 144, 32, (p1.gunPick == b) ? Color.BLUE : Color.GRAY); int tempM = MeasureText(barrels[b].Name, 10); DrawText(barrels[b].Name, (int)barrelWritePos.x - (tempM / 2), (int)barrelWritePos.y + (b * 64), 10, Color.WHITE); DrawRectangle((int)barrelWritePos_.x - 72, (int)barrelWritePos_.y + b * 64 - 16, 144, 32, (p2.gunPick == b) ? Color.SKYBLUE : Color.LIGHTGRAY); DrawRectangleLines((int)barrelWritePos_.x - 72, (int)barrelWritePos_.y + b * 64 - 16, 144, 32, (p2.gunPick == b) ? Color.BLUE : Color.GRAY); DrawText(barrels[b].Name, (int)barrelWritePos_.x - (tempM / 2), (int)barrelWritePos_.y + (b * 64), 10, Color.WHITE); } } else { if (p1.armor <= 0) { int meas = MeasureText("PLAYER 2 WINS!!!", 40); int meas_ = MeasureText($"Win Streak: {p2.winStreak}", 20); DrawText($"PLAYER 2 WINS!!!", (GetScreenWidth() / 2) - (meas / 2), GetScreenHeight() / 2, 40, Color.RED); DrawText($"Win Streak: {p2.winStreak}", (GetScreenWidth() / 2) - (meas_ / 2), (GetScreenHeight() / 2) + 40, 20, Color.RED); } if (p2.armor <= 0) { int meas = MeasureText("PLAYER 1 WINS!!!", 40); int meas_ = MeasureText($"Win Streak: {p1.winStreak}", 20); DrawText($"PLAYER 1 WINS!!!", (GetScreenWidth() / 2) - (meas / 2), GetScreenHeight() / 2, 40, Color.BLUE); DrawText($"Win Streak: {p1.winStreak}", (GetScreenWidth() / 2) - (meas_ / 2), (GetScreenHeight() / 2) + 40, 20, Color.BLUE); } } } EndDrawing(); }