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 Init() { TextureIndex Textures = TextureIndex.LoadTextureIndex("../../../../assets/Textures/MapTiles.xml"); CreepTextures = CreepTextureIndex.LoadIndex("../../../../assets/GameData/CreepSpriteIndex.xml"); MapTiles = Textures.LoadTextures(); GameStartP = new Point(200, 100); CritSprites = new TextSpriteList(); MapRender = new MapRenderer(GameObj.map, MapTiles); CreepRender = new CreepRenderer(CreepTextures.GetEntry(GameObj.CurrentWave.GfxName)); GameRectangle = new Rectangle(GameStartP,new Size(GameObj.map.Columns*Tile.TILE_WIDTH,GameObj.map.Rows*Tile.TILE_HEIGHT)); SelectedTile = new MapCoord(); MageSprites = new MageAttackSprites(); TopLevelContainer = new List<GuiItem>(); MapBackground = MapRender.Render(); Background = new BackgroundItem(Color.WhiteSmoke); Background.X = 0; Background.Y = 0; Background.Width = Width; Background.Height = Height; ButtonPanel = new BackgroundItem(Color.LightGray); ButtonPanel.X = 0; ButtonPanel.Y = 0; ButtonPanel.Width = Width; ButtonPanel.Height = 80; HudPanel = new BackgroundItem(Color.SteelBlue); HudPanel.X = 0; HudPanel.Y = 640; HudPanel.Width = Width; HudPanel.Height = 120; CloseButton = new ButtonItem("Close",120,22,"Quit"); CloseButton.X = 10; CloseButton.Y = 20; PauseButton = new ButtonItem("Pause", 120, 22, "Pause"); PauseButton.X = 140; PauseButton.Y = 20; StartWaveButton = new ButtonItem("StartWave", 120, 22, "Start Wave"); StartWaveButton.X = 270; StartWaveButton.Y = 20; CombatLogButton = new ButtonItem("CombatLog", 120, 22, "View Combat Log"); CombatLogButton.X = 10; CombatLogButton.Y = 50; BuyUnitButton = new ButtonItem("BuyUnit", 120, 22, "Buy a Unit"); BuyUnitButton.X = 140; BuyUnitButton.Y = 50; ResetButton = new ButtonItem("Reset", 120, 22, "Restart"); ResetButton.X = 270; ResetButton.Y = 50; LabelScore = new LabelItem("Score : 0"); LabelScore.X = 10; LabelScore.Y = 650; LabelScore.Foreground = Color.White; LabelWave = new LabelItem("Wave : " + GameObj.Wave); LabelWave.X = 350; LabelWave.Y = 650; LabelWave.Foreground = Color.White; LabelCrystal = new LabelItem("Crystal Left : " + GameObj.Crystal); LabelCrystal.X = 10; LabelCrystal.Y = 680; LabelCrystal.Foreground = Color.White; LabelGold = new LabelItem("Gold : " + GameObj.Gold); LabelGold.X = 350; LabelGold.Y = 680; LabelGold.Foreground = Color.White; LabelFps = new LabelItem("Fps : 30"); LabelFps.X = Width - 70; LabelFps.Y = 4; LogBox = new CombatLogBox(GameObj.LastCombatLog, Garbage); UnitInfoBox = new PlayerUnitInfoBox(new Point(GameStartP.X + GameRectangle.Width + 10,GameStartP.Y)); CreepBox = new CreepInfoBox(); CreepBox.FromPoint(new Point(GameStartP.X + GameRectangle.Width + 10, GameStartP.Y + UnitInfoBox.Height + 10)); UnitClassesChooserBox = new UnitClassesChooser(Garbage); UnitClassesChooserBox.X = GameStartP.X + ((GameRectangle.Width - UnitClassesChooserBox.Width) / 2); ; UnitClassesChooserBox.Y = GameStartP.Y + ((GameRectangle.Height - UnitClassesChooserBox.Height) / 2); ; WaveBox = new WaveInfoBox(GameObj.GetNextWaveInfo(),Garbage); WaveBox.X = GameStartP.X + ((GameRectangle.Width - WaveBox.Width) / 2); WaveBox.Y = GameStartP.Y + ((GameRectangle.Height - WaveBox.Height) / 2); NextWaveBox = new CreepNextWaveBox(GameObj.CreepWaves); NextWaveBox.X = 10; NextWaveBox.Y = GameStartP.Y; PlayerNameDialog = new TextInputDialogBox("Highscore Entry", "Player Name : "); PlayerNameDialog.X = (Width - PlayerNameDialog.Width) / 2; PlayerNameDialog.Y = (Height - PlayerNameDialog.Height) / 2; PlayerNameDialog.TextEntry = PlayerName; Container.Add(Background); Container.Add(ButtonPanel); Container.Add(HudPanel); Container.Add(CloseButton); Container.Add(PauseButton); Container.Add(StartWaveButton); Container.Add(CombatLogButton); Container.Add(BuyUnitButton); Container.Add(ResetButton); Container.Add(LabelScore); Container.Add(LabelCrystal); Container.Add(LabelWave); Container.Add(LabelGold); Container.Add(LabelFps); Container.Add(NextWaveBox); Container.Add(UnitInfoBox); Container.Add(CreepBox); }