/// <summary> /// Define the area in which the camera will freely chase the player /// inset of the play area by the camera offset /// </summary> /// <returns>Rectangle</returns> private Rectangle BuildChaseArea() { Point2D TopLeft = playArea.TopLeft.Add(camOffset); Point2D BottomRight = playArea.BottomRight.Subtract(camOffset); return(SwinGame.CreateRectangle(TopLeft, BottomRight)); }
public Menu(string id, string title, List <MenuElement> elements) { Id = id; this.title = title; this.elements = elements; bounds = SwinGame.CreateRectangle(0, 0, SwinGame.ScreenWidth(), SwinGame.ScreenHeight()); }
private Rectangle CreateElementBounds(JObject obj) { Point2D pos = obj["pos"].ToObject <Point2D>(); Size2D <float> size = obj["size"].ToObject <Size2D <float> >(); int w = SwinGame.ScreenWidth(); int h = SwinGame.ScreenHeight(); return(SwinGame.CreateRectangle(pos.X * w, pos.Y * h, size.W * w, size.H * h)); }
private void DrawOverlay() { Rectangle screenRect = SwinGame.CreateRectangle(Camera.CameraPos().X, Camera.CameraPos().Y, SwinGame.ScreenWidth(), SwinGame.ScreenHeight()); SwinGame.FillRectangle(SwinGame.RGBAColor(255, 0, 0, 80), screenRect); Rectangle textRect = SwinGame.CreateRectangle(0, SwinGame.ScreenHeight() * 0.85f, SwinGame.ScreenWidth(), 100); SwinGame.DrawText("UNDOING COMMANDS", Color.White, Color.Transparent, "MenuTitle", FontAlignment.AlignCenter, textRect); }
private void DrawUI() { float w = SwinGame.ScreenWidth(); float h = SwinGame.ScreenHeight(); Rectangle rect = SwinGame.CreateRectangle(SwinGame.ToWorldX(w * 0.3f), SwinGame.ToWorldY(h * 0.92f), w * 0.4f, h * 0.02f); SwinGame.FillRectangle(Color.Red, rect.X, rect.Y, rect.Width * commandHistory.Count / 200, rect.Height); SwinGame.DrawRectangle(Color.White, rect); }
/// <summary> /// Build the side areas of the play area /// </summary> /// <returns>List of rectangles</returns> private List <Rectangle> BuildSideAreas() { return(new List <Rectangle>() { SwinGame.CreateRectangle(cornerAreas[0].TopRight, chaseArea.TopRight), //top SwinGame.CreateRectangle(cornerAreas[1].BottomLeft, cornerAreas[2].TopRight), //right SwinGame.CreateRectangle(chaseArea.BottomLeft, cornerAreas[2].BottomLeft), //bottom SwinGame.CreateRectangle(cornerAreas[0].BottomLeft, chaseArea.BottomLeft) //left }); }
public void Draw() { Level.Draw(); entityHandler.Draw(cameraHandler.Viewport); //draw points Rectangle scoreRect = SwinGame.CreateRectangle(0, 0, SwinGame.ScreenWidth(), SwinGame.ScreenHeight() * 0.1f); SwinGame.DrawText(scoresheet.FetchTeamScore(Team.Team1).ToString(), Color.Yellow, Color.Transparent, "MenuTitle", FontAlignment.AlignCenter, scoreRect); }
// <summary> // Read the user's name for their highsSwinGame. // </summary> // <param name="value">the player's sSwinGame.</param> // <remarks> // This verifies if the score is a highsSwinGame. // </remarks> public static void ReadHighScore(int value) { const int ENTRY_TOP = 500; if (_Scores.Count == 0) { LoadScores(); } // Is it a high score if (value > _Scores[_Scores.Count - 1].Value) { Score s = new Score(); s.Value = value; GameController.AddNewState(GameState.ViewingHighScores); int x = 0; x = ScoresLeft + SwinGame.TextWidth(GameResources.GameFont("Courier"), "Name: "); // Creates area for user to enter their name Rectangle rect = SwinGame.CreateRectangle(x, ENTRY_TOP - 80, 50, 50); // Reads text within the rectangles area SwinGame.StartReadingText(Color.White, NameWidth, GameResources.GameFont("Courier"), rect); // Read the text from the user while (SwinGame.ReadingText()) { SwinGame.ProcessEvents(); UtilityFunctions.DrawBackground(); DrawHighScores(); SwinGame.DrawText("Name: ", Color.White, GameResources.GameFont("Courier"), ScoresLeft, ENTRY_TOP - 80); SwinGame.RefreshScreen(); } s.Name = SwinGame.TextReadAsASCII(); // Makes all highscore entries captialised s.Name = s.Name.ToUpper(); if (s.Name.Length < 3) { s.Name = s.Name + new string(Convert.ToChar(" "), 3 - s.Name.Length); } _Scores.RemoveAt(_Scores.Count - 1); _Scores.Add(s); _Scores.Sort(); SaveScores(); GameController.EndCurrentState(); } }
/// <summary> /// Split current grid into 4 children grids /// </summary> /// <returns>4 rectangles</returns> private Rectangle[] CreateGrids() { Point2D gridCenter = SwinGame.PointAt(grid.X + (grid.Width / 2), grid.Y + (grid.Height / 2)); return(new Rectangle[4] { SwinGame.CreateRectangle(grid.TopLeft, gridCenter), //top left SwinGame.CreateRectangle(grid.CenterTop, grid.CenterRight), //top right SwinGame.CreateRectangle(gridCenter, grid.BottomRight), //bottom right SwinGame.CreateRectangle(grid.CenterLeft, grid.CenterBottom) //bottom left }); }
/// <summary> /// Define the corner areas of the play area /// </summary> /// <returns>List of rectangles</returns> private List <Rectangle> BuildCornerAreas() { //now that we know the chase cam rectangle return(new List <Rectangle>() { SwinGame.CreateRectangle(playArea.TopLeft, chaseArea.TopLeft), SwinGame.CreateRectangle(chaseArea.Right, playArea.Top, playArea.Right, chaseArea.Top), SwinGame.CreateRectangle(chaseArea.BottomRight, playArea.BottomRight), SwinGame.CreateRectangle(playArea.Left, chaseArea.Bottom, chaseArea.Left, playArea.Bottom) }); }
private void DrawCooldown() { Point2D offset1 = SwinGame.PointAt(-8, 5); Point2D offset2 = SwinGame.PointAt(8, 12); Rectangle cdBar = SwinGame.CreateRectangle(RealPos.Add(offset1), RealPos.Add(offset2)); Rectangle cdProg = SwinGame.CreateRectangle(cdBar.TopLeft, cdBar.Width * cdHandler.cdPercentage, cdBar.Height); Color progClr = cdProg.Width < cdBar.Width ? SwinGame.RGBAColor(255, 120, 0, 190) : SwinGame.RGBAColor(0, 255, 0, 140); SwinGame.FillRectangle(progClr, cdProg); SwinGame.DrawRectangle(SwinGame.RGBAColor(0, 255, 0, 255), cdBar); }
private void DrawHealthBar() { float yOffset = SwinGame.PointLineDistance(RealPos, BoundingBox[0]); Point2D offset1 = SwinGame.PointAt(-20, yOffset + 10); Point2D offset2 = SwinGame.PointAt(20, yOffset + 15); Rectangle healthBar = SwinGame.CreateRectangle(RealPos.Add(offset1), RealPos.Add(offset2)); Rectangle health = SwinGame.CreateRectangle(healthBar.TopLeft, Math.Max(healthBar.Width * Condition, 0), healthBar.Height); Color healthClr = health.Width < healthBar.Width ? SwinGame.RGBAColor(255, 120, 0, 190) : SwinGame.RGBAColor(0, 255, 0, 190); SwinGame.FillRectangle(healthClr, health); SwinGame.DrawRectangle(SwinGame.RGBAColor(255, 255, 255, 255), healthBar); }
private List <Rectangle> CreateSelectionBounds(float xStart, float yStart, float xPadding, float yPadding, float width, float height) { List <Rectangle> result = new List <Rectangle>(); for (int y = 0; y < 2; ++y) { for (int x = 0; x < 4; ++x) { float rectX = xStart + (x * (width + xPadding)); float rectY = yStart + (y * (height + yPadding)); Rectangle bounds = SwinGame.CreateRectangle(rectX, rectY, width, height); result.Add(bounds); } } return(result); }
public Tile(TileType type, int x, int y, int size) : base(x, y, size) { _type = type; if (_type == TileType.EMPTY) { _colour = Color.Black; } else { _colour = Color.Gray; } _original_colour = _colour; _hitBox = SwinGame.CreateRectangle((Single)_position.X, (Single)_position.Y, _size, _size); }
public void RegisterLevels() { levelList.Clear(); fileList = Directory.GetFiles(dirPath); foreach (string file in fileList) { try { JObject obj = Util.Deserialize(file); if (obj == null) { continue; } string id = obj.Value <string>("id"); bool playable = obj.Value <bool>("playable"); string json = JsonConvert.SerializeObject(obj.GetValue("ships")); List <string> shipsToSpawn = JsonConvert.DeserializeObject <List <string> >(json); int asteroidsToSpawn = obj.Value <int>("asteroids"); Size2D <int> size = obj["size"].ToObject <Size2D <int> >(); Rectangle playArea = SwinGame.CreateRectangle(SwinGame.PointAt(0, 0), size.W, size.H); //List<EnvMod> EnvMods = obj["environMods"].ToObject<List<EnvMod>>(); //Most likely will not work JObject bkgdObj = obj.Value <JObject>("background"); BackgroundFactory backgroundFac = new BackgroundFactory(); Background bkgd = backgroundFac.Create(bkgdObj, playArea); levelList.Add(id, new Level(id, null, shipsToSpawn, asteroidsToSpawn, playable, playArea, bkgd)); } catch (Exception e) { Console.WriteLine($"Cannot read level: {file}"); Console.WriteLine(e); } } }
/// <summary> /// Draw the end of the game screen, shows the win/lose state /// </summary> public static void DrawEndOfGame() { UtilityFunctions.DrawField(GameController.ComputerPlayer.PlayerGrid, GameController.ComputerPlayer, true); UtilityFunctions.DrawSmallField(GameController.HumanPlayer.PlayerGrid, GameController.HumanPlayer); if (GameController.HumanPlayer.IsDestroyed) { SwinGame.DrawText("YOU LOSE!", Color.White, Color.Transparent, GameResources.GameFont("ArialLarge"), FontAlignment.AlignCenter, SwinGame.CreateRectangle(0, 250, SwinGame.ScreenWidth(), SwinGame.ScreenHeight())); } else { SwinGame.DrawText("-- WINNER --", Color.White, Color.Transparent, GameResources.GameFont("ArialLarge"), FontAlignment.AlignCenter, SwinGame.CreateRectangle(0, 250, SwinGame.ScreenWidth(), SwinGame.ScreenHeight())); } }
/// <summary> /// Draws the menu at the indicated level. /// </summary> /// <param name="menu">the menu to draw</param> /// <param name="level">the level (height) of the menu</param> /// <param name="xOffset">the offset of the menu</param> /// <remarks> /// The menu text comes from the _menuStructure field. The level indicates the height /// of the menu, to enable sub menus. The xOffset repositions the menu horizontally /// to allow the submenus to be positioned correctly. /// </remarks> private static void DrawButtons(int menu, int level, int xOffset) { int buttonTop = 0; buttonTop = _menuTop - (_menuGap + _buttonHeight) * level; int i = 0; for (i = 0; i <= _menuStructure[menu].Length - 1; i++) { int buttonLeft = 0; buttonLeft = _menuLeft + _buttonSeparation * (i + xOffset); //The below commeted code makes the buttons look ugly //SwinGame.FillRectangle(Color.White, buttonLeft, buttonTop, _buttonWidth, _buttonHeight); SwinGame.DrawText(_menuStructure[menu][i], _MenuColor, Color.Black, GameResources.GameFont("Menu"), FontAlignment.AlignCenter, SwinGame.CreateRectangle(buttonLeft + _TextOffset, buttonTop + _TextOffset, _buttonWidth, _buttonHeight)); if (SwinGame.MouseDown(MouseButton.LeftButton) & IsMouseOverMenu(i, level, xOffset)) { SwinGame.DrawRectangle(_HighlightColor, buttonLeft, buttonTop, _buttonWidth, _buttonHeight); } } }
/// <summary> /// Returns whether the object is on the screen or not /// </summary> protected bool IsOnScreen() { Rectangle cameraBox = SwinGame.CreateRectangle(Camera.CameraPos(), SwinGame.ScreenWidth(), SwinGame.ScreenHeight()); return(SwinGame.PointInRect(RealPos, cameraBox)); }
public override bool IsAt(Point2D pt) { return(SwinGame.PointInRect(pt, SwinGame.CreateRectangle(this.X, this.Y, this.X + _length, this.Y))); }
private static void ShowMessage(string message, int number) { const int _tx = 310; const int _ty = 493; const int _tw = 200; const int _th = 25; const int _steps = 5; const int _bgX = 279; const int _bgY = 453; int _fullW = 0; _fullW = 260 * number / _steps; SwinGame.DrawBitmap(_loaderEmpty, _bgX, _bgY); SwinGame.DrawBitmap(_loaderFull, 0, 0); SwinGame.DrawText(message, Color.White, Color.Transparent, _loadingFont, FontAlignment.AlignCenter, SwinGame.CreateRectangle(_tx, _ty, _tw, _th)); SwinGame.RefreshScreen(); SwinGame.ProcessEvents(); }
public override bool IsAt(Point2D pt) { return(SwinGame.PointInRect(pt, SwinGame.CreateRectangle(this.X, this.Y, _width, _height))); }
/// <summary> /// Draws the menu at the indicated level. /// </summary> /// <param name="menu">the menu to draw</param> /// <param name="level">the level (height) of the menu</param> /// <param name="xOffset">the offset of the menu</param> /// <remarks> /// The menu text comes from the _menuStructure field. The level indicates the height /// of the menu, to enable sub menus. The xOffset repositions the menu horizontally /// to allow the submenus to be positioned correctly. /// </remarks> private static void DrawButtons(int menu, int level, int xOffset) { int btnTop = 0; btnTop = MENU_TOP - (MENU_GAP + BUTTON_HEIGHT) * level; int i = 0; for (i = 0; i <= _menuStructure[menu].Length - 1; i++) { int btnLeft = 0; btnLeft = MENU_LEFT + BUTTON_SEP * (i + xOffset); //The below commeted code makes the buttons look ugly //SwinGame.FillRectangle(Color.White, btnLeft, btnTop, BUTTON_WIDTH, BUTTON_HEIGHT); SwinGame.DrawText(_menuStructure[menu][i], MENU_COLOR, Color.Black, GameResources.GameFont("Menu"), FontAlignment.AlignCenter, SwinGame.CreateRectangle(btnLeft + TEXT_OFFSET, btnTop + TEXT_OFFSET, BUTTON_WIDTH, BUTTON_HEIGHT)); if (SwinGame.MouseDown(MouseButton.LeftButton) & IsMouseOverMenu(i, level, xOffset)) { SwinGame.DrawRectangle(HIGHLIGHT_COLOR, btnLeft, btnTop, BUTTON_WIDTH, BUTTON_HEIGHT); } } }
private static Rectangle ParseRectangle(string rect) { string[] xywh = rect.Trim('(', ')', ' ').Split(','); return(SwinGame.CreateRectangle(int.Parse(xywh[0]), int.Parse(xywh[1]), int.Parse(xywh[2]), int.Parse(xywh[3]))); }