/// <summary> /// Create a new Planet instance. /// </summary> /// <param name="imageFilename">The filename of the planet image to load.</param> /// <param name="bitmap_TransparentColor">The color in the image to treat as transparent.</param> /// <param name="position">The screen location of the center of the planet.</param> /// <param name="scale">The scale (size multiplier) of the image.</param> public Planet(string imageFilename, Color bitmap_TransparentColor, Point position, float scale) : base(GetPlanetSprite(imageFilename, bitmap_TransparentColor, scale)) { //Surface surface = this.Sprite.Surface; this.X = position.X - this.Width / 2; this.Y = position.Y - this.Height / 2; this.Velocity = new Vector(); this.Life = -1; this.Static = true; if (Configuration.Planet.ShowPlanetaryHalo) { // Prepare the planetary "halo" surface. Circle circle = new Circle(Configuration.Planet.GravityWellRadius, Configuration.Planet.GravityWellRadius, Configuration.Planet.GravityWellRadius); this.haloSurface = new Surface(Configuration.Planet.GravityWellRadius * 2, Configuration.Planet.GravityWellRadius * 2); this.haloSurface.Alpha = Configuration.Planet.PlanetaryHaloAlpha; this.haloSurface.AlphaBlending = true; this.haloSurface.Draw(circle, Configuration.Planet.PlanetaryRimFillColor, true, false); this.haloSurface.Draw(circle, Configuration.Planet.PlanetaryHaloFillColor, true, true); // Convert it for display. this.haloSurface = this.haloSurface.Convert(Video.Screen, true, false); } else { this.haloSurface = null; } }
protected virtual void renderKeyboard(Surface s) { if (_keyboardSurface == null) { _keyboardSurface = new Surface(_keyRect.Size); foreach (KeyValuePair<Rectangle, string> kv in _whiteKeys) { Box box = new Box(kv.Key.Location, kv.Key.Size); _keyboardSurface.Draw(box, _backColor, true, true); _keyboardSurface.Draw(box, _foreColor, true, false); } foreach (KeyValuePair<Rectangle, string> kv in _blackKeys) { Box box = new Box(kv.Key.Location, kv.Key.Size); _keyboardSurface.Draw(box, _foreColor, true, true); } } s.Blit(_keyboardSurface, _keyRect.Location); bool black = false; Rectangle cr = Rectangle.Empty; foreach (KeyValuePair<Rectangle, string> kv in _blackKeys) { if (kv.Key.Top <= _parent.Player.Y - _view.Y && _parent.Player.Y - _view.Y <= kv.Key.Bottom) { cr = new Rectangle(kv.Key.Location, kv.Key.Size); black = true; break; } } if (!black) { foreach (KeyValuePair<Rectangle, string> kv in _whiteKeys) { if (kv.Key.Top <= _parent.Player.Y - _view.Y && _parent.Player.Y - _view.Y <= kv.Key.Bottom) { cr = new Rectangle(kv.Key.Location, kv.Key.Size); break; } } } if (!cr.IsEmpty) { cr.Offset(_keyRect.Location); Circle cir = new Circle(new Point(cr.Right - 22, (int)(cr.Y + cr.Height / 2.0)), 10); s.Draw(cir, _strongColor, true, true); s.Draw(cir, _strongColor, true, false); } }
public override void Tick(object sender, TickEventArgs args) { //Game Logic Tick GameObj.GameTick(); //HUD Update LabelScore.Caption = "Score : " + GameObj.Score; LabelWave.Caption = "Wave : " + GameObj.Wave; LabelCrystal.Caption = "Crystals Left : " + GameObj.Crystal; LabelGold.Caption = "Gold : " + GameObj.Gold; LabelFps.Caption = "Fps : " + args.Fps; NextWaveBox.CurrentWave = GameObj.Wave - 1; CleanGarbage(); //Normal GUI Render foreach (GuiItem Item in Container) { Surface RenderedItem = RenderItem(Item); Screen.Blit(RenderedItem, Item.GetRect()); } //Game Graphics Render //Surface GameSurface = MapRender.Render(); Surface GameSurface = new Surface(MapBackground); //GameSurface.Blit(MapBackground, new Point(0, 0)); //Surface GameSurface = new Surface(MapRenderer.MAP_WIDTH_PX, MapRenderer.MAP_HEIGHT_PX); if (GameObj.State == GameState.CreepAttack) { isNewWave = true; Surface CreepsLayer = CreepRender.Render(GameObj.Creeps,GameObj.map); GameSurface.Blit(CreepsLayer, new Point(0, 0)); } else if (GameObj.State == GameState.NoAttack) { if (isNewWave) { LastAttackInfo = 0; isNewWave = false; WaveBox.Wave = GameObj.GetNextWaveInfo(); WaveBox.UpdateCaption(); CreepRender.Clean(); CreepRender = new CreepRenderer(CreepTextures.GetEntry(GameObj.CurrentWave.GfxName)); TopLevelContainer.Add(WaveBox); } if (UnitClassesChooserBox.ChoosenClass != UnitClasses.None) { if (GameRectangle.Contains(MousePos)) { Point relpoint = new Point(MousePos.X - GameStartP.X, MousePos.Y - GameStartP.Y); MapCoord Coord = new MapCoord(relpoint); PlayerUnit tmpUnit = PlayerUnit.CreateUnit(UnitClassesChooserBox.ChoosenClass); UnitInfoBox.ChangeUnit(tmpUnit); Surface UnitGfx = PlayerUnitRenderer.Render(tmpUnit); if (GameObj.map.Tiles[Coord.Row][Coord.Column].Type == TileType.Normal) { GameSurface.Blit(UnitGfx, new Rectangle(new Point(Coord.ToPoint().X + (Tile.TILE_WIDTH - UnitGfx.Width) / 2, Coord.ToPoint().Y + (Tile.TILE_HEIGHT - UnitGfx.Height) / 2), new Size(UnitGfx.Width, UnitGfx.Height))); DrawUnitRange(GameSurface, Coord, tmpUnit); } } } } else if (GameObj.State == GameState.GameOver && TopLevelContainer.Count == 0) { if (!AskedPlayerName) { PlayerNameDialog.TextEntry = PlayerName; TopLevelContainer.Add(PlayerNameDialog); PlayerNameDialog.SetEvents(); AskedPlayerName = true; } else { GameOverBox box = new GameOverBox(GameObj, Garbage); box.SetEvents(); box.X = (Width - box.Width) / 2; box.Y = (Height - box.Height) / 2; TopLevelContainer.Add(box); //Saving Score , must ask for name before GameObj.SaveScore(PlayerName); LastAttackInfo = 0; AskedPlayerName = false; } } else if (GameObj.State == GameState.Complete && TopLevelContainer.Count == 0) { if (!AskedPlayerName) { PlayerNameDialog.TextEntry = PlayerName; TopLevelContainer.Add(PlayerNameDialog); PlayerNameDialog.SetEvents(); AskedPlayerName = true; } else { GameCompleteBox box = new GameCompleteBox(GameObj, Garbage); box.SetEvents(); box.X = (Width - box.Width) / 2; box.Y = (Height - box.Height) / 2; TopLevelContainer.Add(box); //Saving Score , must ask for name before GameObj.SaveScore(PlayerName); LastAttackInfo = 0; AskedPlayerName = false; } } foreach (MapCoord Coord in GameObj.PlayerUnits.Keys) { Surface Unit = PlayerUnitRenderer.Render(GameObj.PlayerUnits[Coord]); Point Dest = new Point(Coord.ToPoint().X + ((Tile.TILE_WIDTH - Unit.Width) / 2), Coord.ToPoint().Y + ((Tile.TILE_HEIGHT - Unit.Height) / 2)); Rectangle Clip = new Rectangle(Dest, Unit.Size); GameSurface.Blit(Unit, Clip); if (!SelectedTile.isEmpty && Coord.SameCoord(SelectedTile)) { DrawUnitRange(GameSurface, Coord, GameObj.PlayerUnits[Coord]); } } if (!SelectedTile.isEmpty && GameObj.map.Tiles[SelectedTile.Row][SelectedTile.Column].Type == TileType.Normal) { Surface Sqr = new Surface(Tile.TILE_WIDTH, Tile.TILE_HEIGHT); Sqr.Alpha = 100; Sqr.AlphaBlending = true; Sqr.Fill(Color.LightBlue); Box Border = new Box(new Point(0, 0), new Size(Sqr.Width-1, Sqr.Height-1)); Sqr.Draw(Border, Color.Black); Rectangle Clip = new Rectangle(SelectedTile.ToPoint(), new Size(Tile.TILE_WIDTH, Tile.TILE_HEIGHT)); GameSurface.Blit(Sqr, Clip); } UpdateAttackSpriteCollection(); MageSprites.Update(args); if (GameObj.State == GameState.CreepAttack) { foreach (TextSprite Spr in CritSprites) { GameSurface.Blit(Spr, new Rectangle(Spr.Position, Spr.Size)); } foreach (MageAttackSprite Spr in MageSprites.Sprites) { GameSurface.Blit(Spr); } foreach (Projectile pro in GameObj.Projectiles) { Circle c = new Circle(pro.Position, 3); Circle d = new Circle(pro.Position, 2); GameSurface.Draw(c, Color.Blue); GameSurface.Draw(d, Color.BlueViolet); } } Screen.Blit(GameSurface, GameRectangle); //Top Level gui Render (Menu to Add Tower and Upgrade Tower) foreach (GuiItem Item in TopLevelContainer) { Surface RenderedItem = RenderItem(Item); Screen.Blit(RenderedItem, Item.GetRect()); } Screen.Update(); }
public void DrawUnitRange(Surface GameSurface, MapCoord Coord, PlayerUnit Unit) { Circle MaxRange = new Circle(Coord.ToPointMiddle(), (short)Unit.Range); GameSurface.Draw(MaxRange, Color.Aqua, true); if (Unit.MinusRange != 0) { Circle MinusRange = new Circle(Coord.ToPointMiddle(), (short)Unit.MinusRange); GameSurface.Draw(MinusRange, Color.Red, true); } }
private void Tick(object sender, TickEventArgs e) { while (times < MAXCOUNT) { circle = new Circle( (short)rand.Next(0, width), (short)rand.Next(0, height), (short)rand.Next(20, 100)); surf.Draw(circle, Color.FromArgb( rand.Next(255), rand.Next(255), rand.Next(255), rand.Next(255)), false, true); circle = new Circle( (short)rand.Next(0, width), (short)rand.Next(0, height), (short)rand.Next(20, 100)); surf.Draw(circle, Color.FromArgb( rand.Next(255), rand.Next(255), rand.Next(255), rand.Next(255))); times++; screen.Update(); screen.Blit(surf, new Rectangle(new Point(0, 0), screen.Size)); Thread.Sleep(SLEEPTIME); } times = 0; surf.Fill(new Rectangle(new Point(0, 0), surf.Size), Color.Black); while (times < MAXCOUNT) { ellipse = new Ellipse( (short)rand.Next(0, width), (short)rand.Next(0, height), (short)rand.Next(20, 100), (short)rand.Next(20, 100)); surf.Draw(ellipse, Color.FromArgb( rand.Next(255), rand.Next(255), rand.Next(255), rand.Next(255))); ellipse = new Ellipse( (short)rand.Next(0, width), (short)rand.Next(0, height), (short)rand.Next(20, 100), (short)rand.Next(20, 100)); surf.Draw(ellipse, Color.FromArgb(rand.Next(255), rand.Next(255), rand.Next(255), rand.Next(255)), false, true); times++; screen.Update(); screen.Blit(surf, new Rectangle(new Point(0, 0), screen.Size)); Thread.Sleep(SLEEPTIME); } Thread.Sleep(SLEEPTIME); times = 0; surf.Fill(new Rectangle(new Point(0, 0), surf.Size), Color.Black); while (times < MAXCOUNT) { line = new Line( (short)rand.Next(0, width), (short)rand.Next(0, height), (short)rand.Next(0, width), (short)rand.Next(0, height)); surf.Draw(line, Color.FromArgb( rand.Next(255), rand.Next(255), rand.Next(255), rand.Next(255))); times++; screen.Update(); screen.Blit(surf, new Rectangle(new Point(0, 0), screen.Size)); Thread.Sleep(SLEEPTIME); } Thread.Sleep(SLEEPTIME); times = 0; surf.Fill(new Rectangle(new Point(0, 0), surf.Size), Color.Black); while (times < MAXCOUNT) { triangle = new Triangle( (short)rand.Next(0, width / 2), (short)rand.Next(0, height / 2), (short)rand.Next(0, width / 2), (short)rand.Next(0, height / 2), (short)rand.Next(0, width / 2), (short)rand.Next(0, height / 2)); surf.Draw(triangle, Color.FromArgb( rand.Next(255), rand.Next(255), rand.Next(255) , rand.Next(255))); triangle = new Triangle( (short)rand.Next(0, width / 2), (short)rand.Next(0, height / 2), (short)rand.Next(0, width / 2), (short)rand.Next(0, height / 2), (short)rand.Next(0, width / 2), (short)rand.Next(0, height / 2)); surf.Draw(triangle, Color.FromArgb( rand.Next(255), rand.Next(255), rand.Next(255), rand.Next(255)), false, true); times++; screen.Update(); screen.Blit(surf, new Rectangle(new Point(0, 0), screen.Size)); Thread.Sleep(SLEEPTIME); } Thread.Sleep(SLEEPTIME); times = 0; surf.Fill(new Rectangle(new Point(0, 0), surf.Size), Color.Black); while (times < MAXCOUNT) { short[] x = { (short)rand.Next(0, width), (short)rand.Next(0, width), (short)rand.Next(0, width), (short)rand.Next(0, width), (short)rand.Next(0, width) }; short[] y = { (short)rand.Next(0, height), (short)rand.Next(0, height), (short)rand.Next(0, height), (short)rand.Next(0, height), (short)rand.Next(0, height) }; polygon = new Polygon(x, y); surf.Draw(polygon, Color.FromArgb( rand.Next(255), rand.Next(255), rand.Next(255), rand.Next(255))); short[] a = { (short)rand.Next(0, width), (short)rand.Next(0, width), (short)rand.Next(0, width), (short)rand.Next(0, width), (short)rand.Next(0, width) }; short[] b = { (short)rand.Next(0, height), (short)rand.Next(0, height), (short)rand.Next(0, height), (short)rand.Next(0, height), (short)rand.Next(0, height) }; polygon = new Polygon(a, b); surf.Draw(polygon, Color.FromArgb( rand.Next(255), rand.Next(255), rand.Next(255), rand.Next(255)), false, true); times++; screen.Update(); screen.Blit(surf, new Rectangle(new Point(0, 0), screen.Size)); Thread.Sleep(SLEEPTIME); } Thread.Sleep(SLEEPTIME); times = 0; surf.Fill(new Rectangle(new Point(0, 0), surf.Size), Color.Black); try { while (times < MAXCOUNT) { short[] x = { (short)rand.Next(0, width), (short)rand.Next(0, width), (short)rand.Next(0, width), (short)rand.Next(0, width), (short)rand.Next(0, width) }; short[] y = { (short)rand.Next(0, height), (short)rand.Next(0, height), (short)rand.Next(0, height), (short)rand.Next(0, height), (short)rand.Next(0, height) }; texturedPolygon = new TexturedPolygon(new Surface(file), x, y, 10, 10); surf.Draw(texturedPolygon, Color.FromArgb( rand.Next(255), rand.Next(255), rand.Next(255), rand.Next(255))); short[] a = { (short)rand.Next(0, width), (short)rand.Next(0, width), (short)rand.Next(0, width), (short)rand.Next(0, width), (short)rand.Next(0, width) }; short[] b = { (short)rand.Next(0, height), (short)rand.Next(0, height), (short)rand.Next(0, height), (short)rand.Next(0, height), (short)rand.Next(0, height) }; //short[] a = { // 0, 200, 200, 0 // }; //short[] b = { // 0, 0, 200, 200 // }; texturedPolygon = new TexturedPolygon(new Surface(file), a, b, 10, 20); surf.Draw(texturedPolygon, Color.FromArgb( rand.Next(255), rand.Next(255), rand.Next(255), rand.Next(255)), false, true); times++; screen.Update(); screen.Blit(surf, new Rectangle(new Point(0, 0), screen.Size)); Thread.Sleep(SLEEPTIME); } } catch (EntryPointNotFoundException ex) { Console.WriteLine("Using old version of SDL_gfx. Please upgrade to >=2.0.16"); Console.WriteLine(ex); } Thread.Sleep(SLEEPTIME); times = 0; surf.Fill(new Rectangle(new Point(0, 0), surf.Size), Color.Black); while (times < MAXCOUNT) { pie = new Pie((short)rand.Next(0, width), (short)rand.Next(0, height), (short)rand.Next(20, 100), (short)rand.Next(0, 360), (short)rand.Next(0, 360)); surf.Draw(pie, Color.FromArgb( rand.Next(255), rand.Next(255), rand.Next(255), rand.Next(255))); pie = new Pie((short)rand.Next(0, width), (short)rand.Next(0, height), (short)rand.Next(20, 100), (short)rand.Next(0, 360), (short)rand.Next(0, 360)); surf.Draw(pie, Color.FromArgb(rand.Next(255), rand.Next(255), rand.Next(255), rand.Next(255)), false, true); times++; screen.Update(); screen.Blit(surf, new Rectangle(new Point(0, 0), screen.Size)); Thread.Sleep(SLEEPTIME); } Thread.Sleep(SLEEPTIME); times = 0; surf.Fill(new Rectangle(new Point(0, 0), surf.Size), Color.Black); while (Events.Poll()) { // handle events till the queue is empty } while (times < MAXCOUNT) { short[] c = {(short)rand.Next(0, width), (short)rand.Next(0, width), (short)rand.Next(0, width), (short)rand.Next(0, width), (short)rand.Next(0, width)}; short[] d = {(short)rand.Next(0, height), (short)rand.Next(0, height), (short)rand.Next(0, height), (short)rand.Next(0, height), (short)rand.Next(0, height)}; bezier = new Bezier(c, d, 0); surf.Draw(bezier, Color.FromArgb(rand.Next(255), rand.Next(255), rand.Next(255), rand.Next(255))); times++; screen.Update(); screen.Blit(surf, new Rectangle(new Point(0, 0), screen.Size)); Thread.Sleep(SLEEPTIME); } Thread.Sleep(SLEEPTIME); times = 0; surf.Fill(new Rectangle(new Point(0, 0), surf.Size), Color.Black); while (times < MAXCOUNT) { box = new Box( (short)rand.Next(0, width), (short)rand.Next(0, height), (short)rand.Next(0, width), (short)rand.Next(0, height)); surf.Draw(box, Color.FromArgb( rand.Next(255), rand.Next(255), rand.Next(255), rand.Next(255))); box = new Box( (short)rand.Next(0, width), (short)rand.Next(0, height), (short)rand.Next(0, width), (short)rand.Next(0, height)); surf.Draw(box, Color.FromArgb( rand.Next(255), rand.Next(255), rand.Next(255), rand.Next(255)), false, true); times++; screen.Update(); screen.Blit(surf, new Rectangle(new Point(0, 0), screen.Size)); Thread.Sleep(SLEEPTIME); } Thread.Sleep(SLEEPTIME); times = 0; surf.Fill(new Rectangle(new Point(0, 0), surf.Size), Color.Black); int xpixel; int ypixel; int rpixel; int gpixel; int bpixel; while (times < 100) { xpixel = rand.Next(10, width); ypixel = rand.Next(10, height); rpixel = rand.Next(255); gpixel = rand.Next(255); bpixel = rand.Next(255); surf.GetColorValue(Color.FromArgb(rpixel, gpixel, bpixel)); //colorValue = screen.MapColor(Color.FromArgb(254, 0, 0)); //screen.DrawPixel(x, y, Color.Red); //Console.WriteLine("colorValue: " + colorValue.ToString(CultureInfo.CurrentCulture)); surf.Draw(new Point(xpixel, ypixel), Color.FromArgb(rpixel, gpixel, bpixel)); //screen.DrawPixel(x, y, Color.Red); //Console.WriteLine("GetPixel: " + screen.GetPixel(xpixel, ypixel).ToString()); //Console.WriteLine("GetPixel: " + screen.GetColorValue(screen.GetPixel(xpixel, ypixel)).ToString(CultureInfo.CurrentCulture)); times++; screen.Update(); screen.Blit(surf, new Rectangle(new Point(0, 0), screen.Size)); } }