public ColBox(int x, int y, int width, int height, bool addCollider = true, bool showBounds = false, string name = "wall") { if (addCollider == false) { return; } col = new EasyDraw(width, height, addCollider); col.name = name; col.NoFill(); col.Stroke(245, 66, 66); if (name == "WinBox") { col.Stroke(19, 252, 3); } if (showBounds) { col.StrokeWeight(1); } else { col.NoStroke(); } col.ShapeAlign(CenterMode.Min, CenterMode.Min); col.Rect(0, 0, col.width - 1, col.height - 1); col.x = x; col.y = y; AddChild(col); }
public MyGame() : base(800, 600, false, false) { _ball = new Ball(30, new Vec2(width / 2, height / 2)); AddChild(_ball); _text = new EasyDraw(250, 25); _text.TextAlign(CenterMode.Min, CenterMode.Min); AddChild(_text); lines = new List <NLineSegment>(); _lineSegment1 = new NLineSegment(new Vec2(500, 500), new Vec2(100, 200), 0xff00ff00, 3); _lineSegment2 = new NLineSegment(new Vec2(800, 100), new Vec2(500, 600), 0xff00ff00, 3); _lineSegment3 = new NLineSegment(new Vec2(50, 250), new Vec2(800, 100), 0xff00ff00, 3); AddChild(_lineSegment1); AddChild(_lineSegment2); AddChild(_lineSegment3); lines.Add(_lineSegment1); lines.Add(_lineSegment2); lines.Add(_lineSegment3); Vec2 testVelocity = new Vec2(2, -11); Vec2 testNormal = new Vec2(0.8f, 0.6f); testVelocity.Reflect(1, testNormal); Console.WriteLine(testVelocity.x == 10f && testVelocity.y == -5f); }
public HistoricImageHud(string historyFileName) : base("data/White Texture.png", true, false) { var bg = new EasyDraw(game.width, game.height, false); bg.Clear(Color.FromArgb(0, Color.Black)); AddChild(bg); _mainImage = new Sprite(historyFileName, true, false); AddChild(_mainImage); //_mainImage.scale = 0.5f; _mainImage.SetOriginToCenter(); _mainImage.SetXY(MyGame.HALF_SCREEN_WIDTH, MyGame.HALF_SCREEN_HEIGHT); DrawableTweener.TweenSpriteAlpha(_mainImage, 0, 1, 400, Easing.Equation.CubicEaseOut); var textBg = new EasyDraw(game.width, 30, false); textBg.Clear(Color.Black); AddChild(textBg); textBg.SetXY(0, game.height - 30); var pressToContinueText = new DebugTextBox("Press Esc to continue", game.width, 30, 0xffffff, 0x00010101, CenterMode.Center, CenterMode.Center); AddChild(pressToContinueText); pressToContinueText.SetXY(0, game.height - 30); DrawableTweener.Blink(pressToContinueText, 1, 0, 400); }
public MyGame() : base(800, 600, false, false) { ball = new Ball(30, new Vec2(width / 2, height / 2), new Vec2(-2, 1)); AddChild(ball); text = new EasyDraw(250, 25); text.TextAlign(CenterMode.Min, CenterMode.Min); AddChild(text); lineSegment = new NLineSegment(new Vec2(500, 500), new Vec2(100, 200), 0xff00ff00, 3); lineSegment2 = new NLineSegment(new Vec2(100, 200), new Vec2(500, 500), 0xff00ff00, 3); wallLeft = new NLineSegment(new Vec2(0, height), new Vec2(0, 0), pLineWidth: 2); wallRight = new NLineSegment(new Vec2(width, 0), new Vec2(width, height), pLineWidth: 2); wallTop = new NLineSegment(new Vec2(0, 0), new Vec2(width, 0), pLineWidth: 2); wallBottom = new NLineSegment(new Vec2(width, height), new Vec2(0, height), pLineWidth: 2); AddChild(lineSegment); AddChild(lineSegment2); AddChild(wallLeft); AddChild(wallRight); AddChild(wallTop); AddChild(wallBottom); Lines = new List <NLineSegment> { lineSegment, lineSegment2, wallLeft, wallRight, wallTop, wallBottom }; Restart(); PrintInfo(); }
public ClickablePiece(string fileName, Vec2 position, int ID) : base(fileName, position, 9, 1) { _id = ID; _selection = new EasyDraw(width + _selectionStrokeWidth * 2, height + _selectionStrokeWidth * 2); AddChild(_selection); _selection.SetOrigin(width / 2, height / 2); _selection.SetXY(-_selectionStrokeWidth / 2, -_selectionStrokeWidth / 2); }
public MyGame() : base(800, 600, false, false) { _ball = new Ball(30, new Vec2(width / 2, height / 2)); AddChild(_ball); _text = new EasyDraw(200, 25); _text.TextAlign(CenterMode.Min, CenterMode.Min); AddChild(_text); }
public TextBoard(int width, int height) { riffic = new Font("RifficFree - Bold.ttf", 17); _easyDraw = new EasyDraw(width, height, false); _easyDraw.TextFont(riffic); _easyDraw.TextAlign(CenterMode.Center, CenterMode.Center); AddChild(_easyDraw); }
public HUD() : base() { /* shared lives - on main level screen? centered? * individual HP - position? * ammo * pickups (energy cells) * ability cooldowns */ text_elements = new EasyDraw(game.width, game.height, false); }
public Rope() { this.AddChild(new OnRopeTigger(0, ropeLength)); _easyDraw = new EasyDraw(10, (int)ropeLength, false); _easyDraw.StrokeWeight(3); _easyDraw.Stroke(255); this.AddChild(_easyDraw); //ropeObject.SetXY(120,120); }
public Button(string bText, int bX = 0, int bY = 0) : base() { text = new EasyDraw(700, 25, false); text.x = bX; text.y = bY; text.TextFont(new Font("bahnschrift", 16)); text.TextAlign(CenterMode.Min, CenterMode.Min); AddChild(text); buttonText = bText; }
/*----------------------------------------- * createText() * ----------------------------------------*/ private void createText() { _scoreHud = new EasyDraw(150, 50); _scoreHud.TextAlign(CenterMode.Min, CenterMode.Min); AddChild(_scoreHud); _deathScreen = new EasyDraw(1280, 720); _deathScreen.TextAlign(CenterMode.Min, CenterMode.Min); AddChild(_deathScreen); _livesHud = new EasyDraw(150, 330); _livesHud.TextAlign(CenterMode.Min, CenterMode.Min); AddChild(_livesHud); }
public MyGame() : base(800, 600, false, false) { _ball = new Ball(30, new Vec2(width / 2 - 80, height / 6)); AddChild(_ball); _text = new EasyDraw(250, 25); _text.TextAlign(CenterMode.Min, CenterMode.Min); AddChild(_text); _lineSegment = new NLineSegment(new Vec2(500, 500), new Vec2(100, 200), 0xff00ff00, 3); AddChild(_lineSegment); }
public MyGame() : base(800, 600, false, false) { timer = new Timer(); AddChild(timer); _ball = new Ball(30, new Vec2(width / 2, height / 2)); AddChild(_ball); _text = new EasyDraw(500, 25); _text.TextAlign(CenterMode.Min, CenterMode.Min); AddChild(_text); TestVectorFunction test = new TestVectorFunction(); }
public StartScreen() : base(Settings.StartScreen_Bg_Image, false, false) { GameSoundManager.Instance.PlayMusic(Settings.StartScreen_Music); _fader = new EasyDraw(game.width, game.height, false); _fader.Clear(Color.Black); AddChild(_fader); DrawableTweener.TweenSpriteAlpha(_fader, 1, 0, Settings.Default_AlphaTween_Duration, () => { _lockStart = false; }); }
/// <summary> /// Draws a given textstring to an EasyDraw, following Tiled's text alignment conventions. /// (It uses the text alignment settings of the textCanvas) /// </summary> /// <param name="textCanvas">the EasyDraw for displaying text, for instance as created by CreateTextField</param> /// <param name="text">The text to display. Note that text is not automatically wrapped, so include /// manual newline symbols (\n)</param> public static void DrawText(EasyDraw textCanvas, string text) { float pixelWidth = textCanvas.width / textCanvas.scaleX; float pixelHeight = textCanvas.height / textCanvas.scaleY; // Set Text alignment: float textX = textCanvas.HorizontalTextAlign == CenterMode.Min ? 0 : (textCanvas.HorizontalTextAlign == CenterMode.Max ? pixelWidth : pixelWidth / 2f); float textY = textCanvas.VerticalTextAlign == CenterMode.Min ? 0 : (textCanvas.VerticalTextAlign == CenterMode.Max ? pixelHeight : pixelHeight / 2f); textCanvas.Text(text, textX, textY); }
public Dialog() { Bitmap Bmp = new Bitmap(800, 100); Graphics gfx = Graphics.FromImage(Bmp); SolidBrush brush = new SolidBrush(System.Drawing.ColorTranslator.FromHtml("#A57300")); gfx.FillRectangle(brush, 0, 0, 800, 100); Sprite _background = new Sprite(Bmp) { width = 800, height = 100, y = 8 }; AddChild(_background); _player = ((MyGame)game).GetPlayer(); for (int i = 0; i < 8; i++) { Sprite _concon = new Sprite("Data/Sprites/concon.png"); if (i > 3) { _concon.y = 100; _concon.x = (i - 4) * 240; } else { _concon.x = i * 240; } AddChild(_concon); } _easyDraw = new EasyDraw(800, 100); AddChild(_easyDraw); PrivateFontCollection pfc = new PrivateFontCollection(); pfc.AddFontFile("Data/Font/LCD Solid.ttf"); _font = new Font(new FontFamily(pfc.Families[0].Name), 15, FontStyle.Regular); }
public Menu() : base() { Sprite _menuSprite = new Sprite("Data/HUD/mm1.png"); Bitmap Bmp = new Bitmap(100, 100); Graphics gfx = Graphics.FromImage(Bmp); SolidBrush brush = new SolidBrush(Color.Yellow); gfx.FillRectangle(brush, 0, 0, 100, 100); _buttonSelectedSprite = new Sprite(Bmp) { width = 100, height = 12, x = 300 + (_menuSprite.width / 2) }; if (Data.Default.level == 1) { _buttonSelectedSprite.y = 200 + 5; } else { _buttonSelectedSprite.y = 200 + 5 + 24; _indexButton++; } AddChild(_buttonSelectedSprite); _menuSprite.x = 300 + (_menuSprite.width / 2); _menuSprite.y = 200; AddChild(_menuSprite); _easyDraw = new EasyDraw(800, 600); AddChild(_easyDraw); PrivateFontCollection pfc = new PrivateFontCollection(); pfc.AddFontFile("Data/Font/LCD Solid.ttf"); _font = new Font(new FontFamily(pfc.Families[0].Name), 8, FontStyle.Regular); _easyDraw.graphics.DrawString("Game Programming Assigment", _font, new SolidBrush(Color.White), new PointF(615, 575)); _easyDraw.graphics.DrawString("by Filippo Maria Leonardi", _font, new SolidBrush(Color.White), new PointF(622, 585)); _easyDraw.graphics.DrawString("Controls", _font, new SolidBrush(Color.White), new PointF(0, 555)); _easyDraw.graphics.DrawString("Press 1 to use health postions", _font, new SolidBrush(Color.White), new PointF(0, 565)); _easyDraw.graphics.DrawString("Press 2 to use mana postions", _font, new SolidBrush(Color.White), new PointF(0, 575)); _easyDraw.graphics.DrawString("Press 3 to use the special attack", _font, new SolidBrush(Color.White), new PointF(0, 585)); }
public TextBox(string pText, int pWidth, int pHeight, uint pTextColor = 0xffffffff, uint pBgColor = 0xff050505, uint pBorderColor = 0xffffffff, float pBorderWeight = 1, bool addCollider = false) : base(pWidth, pHeight, addCollider) { _bgColor = Color.FromArgb((int)pBgColor); _textColor = Color.FromArgb((int)pTextColor); _borderColor = Color.FromArgb((int)pBorderColor); _borderWeight = pBorderWeight; _easy = new EasyDraw(pWidth, pHeight); AddChild(_easy); _easy.TextFont(Settings.Textbox_Font, 12); this.Text = pText; }
public FishStand(float givenX, float givenY, float givenRotation) : base(givenX, givenY, "fishShop.png", givenRotation) { _buyMenu = new Sprite("buyScreen.png"); _buyMenu2 = new Sprite("buyScreen2.png"); _exitButton = new Sprite("exitCross.png"); _buyMenu.SetOrigin(_buyMenu.width / 2, _buyMenu.height / 2); _buyMenu.SetXY(game.width - _buyMenu.width + 150, game.height - _buyMenu.height + 150); _buyMenu2.SetOrigin(_buyMenu.width / 2, _buyMenu.height / 2); _buyMenu2.SetXY(game.width - _buyMenu.width + 150, game.height - _buyMenu.height + 150); _exitButton.SetXY(_buyMenu.x + 500, _buyMenu.y - 325); _menuShown = false; scale = 0.85f; _boughtItem = new EasyDraw(1920, 1080); _boughtItem.TextSize(16); _boughtItem.SetColor(0, 0, 0); }
public PreGameStartScreen(string fileName, string musicFilename, OnFinished onFinished = null) : base(fileName, false, false) { if (!string.IsNullOrWhiteSpace(musicFilename)) { GameSoundManager.Instance.FadeOutCurrentMusic(); GameSoundManager.Instance.PlayMusic(musicFilename); } _fader = new EasyDraw(game.width, game.height, false); _fader.Clear(Color.Black); AddChild(_fader); _onFinished = onFinished; _lockKey = false; DrawableTweener.TweenSpriteAlpha(_fader, 1, 0, Settings.Default_AlphaTween_Duration, () => { //_lockKey = false; }); }
//-------------------------------------------------------------------------------------------- // REGION: public static utility methods, related to creating and placing GXPEngine objects // based on data from Tiled Objects. //-------------------------------------------------------------------------------------------- /// <summary> /// Creates an EasyDraw for displaying text, based on the configuration parameters of a /// Tiled object. (Including font, text alignment, color) /// </summary> /// <param name="obj">The Tiled (text) object</param> /// <returns></returns> public static EasyDraw CreateTextField(TiledObject obj, bool addCollider = true, bool highQualityText = true) { float scaleMultiplier = highQualityText ? 2 : 1; // 1=as is. 2=better antialiasing, but 4 x size EasyDraw message = new EasyDraw((int)Mathf.Ceiling(obj.Width * scaleMultiplier), (int)Mathf.Ceiling(obj.Height * scaleMultiplier), addCollider); // TODO: Cache fonts? // Set Font: FontStyle f = FontStyle.Regular; if (obj.textField.bold == 1 && obj.textField.italic == 1) { f = FontStyle.Bold | FontStyle.Italic; } else if (obj.textField.bold == 0 && obj.textField.italic == 1) { f = FontStyle.Italic; } else if (obj.textField.bold == 1 && obj.textField.italic == 0) { f = FontStyle.Bold; } message.TextFont(new Font(obj.textField.font, Mathf.Round(obj.textField.fontSize * scaleMultiplier), f, GraphicsUnit.Pixel)); message.graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; //AntiAlias; // Set text alignment: message.TextAlign( obj.textField.horizontalAlign == "left" ? CenterMode.Min : (obj.textField.horizontalAlign == "right" ? CenterMode.Max : CenterMode.Center), obj.textField.verticalAlign == "top" ? CenterMode.Min : (obj.textField.verticalAlign == "bottom" ? CenterMode.Max : CenterMode.Center) ); // Set color: uint col = obj.textField.Color; message.Fill(Color.FromArgb((int)(col & 255), (int)((col >> 24) & 255), (int)((col >> 16) & 255), (int)((col >> 8) & 255)), (int)(col & 255)); return(message); }
public MyGame() : base(800, 600, false, false, pPixelArt: true) { Sound _sound = new Sound("Data/Sounds/theme.mp3", true, true); _soundChannel = _sound.Play(); Menu _mainMenu = new Menu(); AddChild(_mainMenu); _level = new Level(); Bitmap Bmp = new Bitmap(800, 200); Graphics gfx = Graphics.FromImage(Bmp); SolidBrush brush = new SolidBrush(Color.Black); gfx.FillRectangle(brush, 0, 0, 800, 200); _gameOverRectangleUp = new Sprite(Bmp) { y = -200 }; _gameOverRectangleDown = new Sprite(Bmp) { y = 600 }; _slideVelocity = 1; _easyDraw = new EasyDraw(800, 600); AddChild(_easyDraw); PrivateFontCollection pfc = new PrivateFontCollection(); pfc.AddFontFile("Data/Font/LCD Solid.ttf"); _font = new Font(new FontFamily(pfc.Families[0].Name), 12, FontStyle.Regular); }
public Shop(float x, float y) : base("Data/HUD/shop.png") { SetScaleXY(2f); this.x = x; this.y = y; _player = ((MyGame)game).GetPlayer(); _hud = ((MyGame)game).GetHud(); Bitmap Bmp = new Bitmap(100, 100); Graphics gfx = Graphics.FromImage(Bmp); SolidBrush brush = new SolidBrush(Color.White); gfx.FillRectangle(brush, 0, 0, 100, 100); _itemSelectedSprite = new Sprite(Bmp) { width = 26, height = 26, x = 41, y = 131 }; AddChild(_itemSelectedSprite); _actionSelectedSprite = new Sprite("Data/HUD/shop_rect.png"); _actionSelectedSprite.SetXY(164, 46); AddChild(_actionSelectedSprite); //Filling items for (int i = 0; i < 5; i++) { Sprite _itemSprite = new Sprite("Data/Sprites/item" + i + ".png"); if (i > 2) { _itemSprite.SetXY(41 + 1 + (i * 32), 133); } else { _itemSprite.SetXY(41 + 3 + (i * 32), 134); } AddChild(_itemSprite); } string path = "Data/Items.xml"; XmlSerializer serializer = new XmlSerializer(typeof(Items)); StreamReader reader = new StreamReader(path); _items = (Items)serializer.Deserialize(reader); reader.Close(); _easyDraw = new EasyDraw(300, 300); AddChild(_easyDraw); PrivateFontCollection pfc = new PrivateFontCollection(); pfc.AddFontFile("Data/Font/LCD Solid.ttf"); _font = new Font(new FontFamily(pfc.Families[0].Name), 10, FontStyle.Regular); }
public HUD() { Sprite stats = new Sprite("Data/HUD/hud_frame.png"); AddChild(stats); _player = ((MyGame)game).GetPlayer(); Bitmap Bmp = new Bitmap(100, 100); Graphics gfx = Graphics.FromImage(Bmp); //Life bar color 1 SolidBrush brush = new SolidBrush(System.Drawing.ColorTranslator.FromHtml("#FF969F")); gfx.FillRectangle(brush, 0, 0, 100, 100); _life1 = new Sprite(Bmp); _life1.x = 97; _life1.y = 14.5f; _life1.width = 46; _life1.height = 3; AddChild(_life1); //Life bar color 2 brush = new SolidBrush(System.Drawing.ColorTranslator.FromHtml("#E70052")); gfx.FillRectangle(brush, 0, 0, 100, 100); _life2 = new Sprite(Bmp); _life2.x = 97; _life2.y = 17.5f; _life2.width = 46; _life2.height = 3; AddChild(_life2); //Mana bar color 1 brush = new SolidBrush(System.Drawing.ColorTranslator.FromHtml("#6DCFF6")); gfx.FillRectangle(brush, 0, 0, 100, 100); _mana1 = new Sprite(Bmp); _mana1.x = 176; _mana1.y = 14.5f; _mana1.width = 0; _mana1.height = 3; AddChild(_mana1); //Mana bar color 2 brush = new SolidBrush(System.Drawing.ColorTranslator.FromHtml("#0080FF")); gfx.FillRectangle(brush, 0, 0, 100, 100); _mana2 = new Sprite(Bmp); _mana2.x = 176; _mana2.y = 17.5f; _mana2.width = 0; _mana2.height = 3; AddChild(_mana2); _easyDraw = new EasyDraw(100, 100); AddChild(_easyDraw); PrivateFontCollection pfc = new PrivateFontCollection(); pfc.AddFontFile("Data/Font/LCD Solid.ttf"); _font = new Font(new FontFamily(pfc.Families[0].Name), 10, FontStyle.Regular); _notchArray = new Sprite[3]; _health_potion_number = Data.Default.healthpotions; _mana_potion_number = Data.Default.manapotions; updatePotionsValueOnScreen(); UpdateLifeBar(Data.Default.lifepoints); UpdateManaBar(Data.Default.manapoints); }
//-------------------------------------------------------------------------------------------- // REGION: private methods (for reading single layers from the Tiled file). //-------------------------------------------------------------------------------------------- void LoadObjectGroup(int index, bool autoInstance = false) { if (map.ObjectGroups.Length <= index) { return; } ObjectGroup group = map.ObjectGroups[index]; if (group.Objects == null) { return; } foreach (TiledObject obj in group.Objects) { obj.Initialize(); Sprite newSprite = null; if (_manualObjects.Contains(obj.Type)) { // Don't create an object, just fire the event and let the user create something. //Console.WriteLine("Skipping object because type is in manual list: "+obj); } else if (obj.ImageID >= 0) // Create an AnimationSprite { TileSet tileSet = map.GetTileSet(obj.ImageID); if (tileSet == null || tileSet.Image == null) { throw new Exception("The Tiled map contains unembedded tilesets (.tsx files) - please embed them in the map"); } int frame = obj.ImageID - tileSet.FirstGId; //Console.WriteLine("Creating image object: "+obj); AnimationSprite anim = null; if (autoInstance && obj.Type != null) { try { anim = (AnimationSprite)Activator.CreateInstance(Type.GetType(obj.Type), new object[] { Path.Combine(_foldername, tileSet.Image.FileName), tileSet.Columns, tileSet.Rows, obj }); } catch (Exception error) { Console.WriteLine("Couldn't automatically create an AnimationSprite object from the Tiled (image) object with ID {0} and type {1}.\n Error: {2}", obj.ID, obj.Type, error.Message); } } if (anim == null) { anim = new AnimationSprite(Path.Combine(_foldername, tileSet.Image.FileName), tileSet.Columns, tileSet.Rows, -1, false, addColliders); } anim.Mirror(obj.MirrorX, obj.MirrorY); anim.SetFrame(frame); newSprite = anim; } else if (obj.textField != null) { //Console.WriteLine("Creating text object: "+obj); EasyDraw message = CreateTextField(obj, addColliders, highQualityText); DrawText(message, obj.textField.text); newSprite = message; } else { //Console.WriteLine("Skipping non-graphical object: "+obj); if (autoInstance && obj.Type != "") { try { newSprite = (Sprite)Activator.CreateInstance(Type.GetType(obj.Type), new object[] { obj }); } catch (Exception error) { Console.WriteLine("Couldn't automatically create a sprite object from the Tiled (shape) object with ID {0} and type {1}.\n Error: {2}", obj.ID, obj.Type, error.Message); } } } if (newSprite != null) { SetPositionRotationScaleOrigin(newSprite, obj, defaultOriginX, defaultOriginY); rootObject.AddChild(newSprite); } if (OnObjectCreated != null) { OnObjectCreated(newSprite, obj); } } }