// Removes object from map: void RemoveObjectFromMap(CGameObject o) { int x, y, width, height; GetDimensionsOnMap(o, out x, out y, out width, out height); // Put our tank on the map: for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { mapMain[x + j, y + i] = null; } } }
public CMenuMode(int playersCount, int hiscore, int hiscoreP1, int hiscoreP2) { var backgroudImage = playersCount > 1 ? Properties.Resources.Menu_2p : Properties.Resources.Menu_1p; this.hiscore = hiscore; this.hiscoreP1 = hiscoreP1; this.hiscoreP2 = hiscoreP2; this.playersCount = playersCount; mainMenu = new CGameObject(backgroudImage, 0, 448, 512, 448); menuCursor = new CMainMenuCursor(135, 695, Properties.Resources.Player1tank_right1, Properties.Resources.Player1tank_right2); ProcessableObjects.Add(menuCursor); }
// ********************************* // Methods: // ********************************* // - - - - - - - - - - // Managing objects : // - - - - - - - - - - // This method sets object on a map: protected override void AddObject(CGameObject o) { // Adding to all objects: AllGameObjects.Add(o); // if it is processable then add it to corresponding list: if (o is IProcessable) { ProcessableObjects.Add((IProcessable)o); } if ((o is CIconEnemy) || (o is ClevelFlag) || (o is CPlayerIcon)) { StatisticObjects.Add(o); } // Set event handlers: SetEventHandlers(o); //Add to map: CGameObject[,] map; // Choosing the right map: map = (o is CProjectile) ? mapProjectiles : mapMain; // check if transparent: if (!o.Transparent) { int x, y, width, height; GetDimensionsOnMap(o, out x, out y, out width, out height); // Put on the map: for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { map[x + j, y + i] = o; } } } }
// This method removes object from map: protected override void RemoveObject(CGameObject o) { // Removing from all objects: AllGameObjects.Remove(o); // if (o is IProcessable) { ProcessableObjects.Remove((IProcessable)o); } if ((o is CIconEnemy) || (o is ClevelFlag) || (o is CPlayerIcon)) { StatisticObjects.Remove(o); } // Removing from map: CGameObject[,] map; // Choosing the right map: map = (o is CProjectile) ? mapProjectiles : mapMain; // if object is not transparent then removing it: if (!o.Transparent) { int x, y, width, height; GetDimensionsOnMap(o, out x, out y, out width, out height); // Removing from map: for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { map[x + j, y + i] = null; } } } }
public CExplotion(CGameObject exploded, int explotionLevel) : base() { this.ExplodedObject = exploded; this.ExplotionLevel = explotionLevel; this.Width = 64; this.Height = 64; this.X = exploded.X - (int)(this.Width / 2) + (int)(exploded.Width / 2); this.Y = exploded.Y - (int)(this.Height / 2) + (int)(exploded.Height / 2); this.images = new List <Image> { Properties.Resources.explotion_1, Properties.Resources.explotion_2, Properties.Resources.explotion_3, Properties.Resources.explotion_4, Properties.Resources.explotion_5, Properties.Resources.explotion_3, Properties.Resources.explotion_2 }; this.DrawPriority = 10; // image changing interval: imageChangeInterval = explotionLevel > 2 ? 6 : 3; }
protected override void RemoveObject(CGameObject o) { AllGameObjects.Remove(o); //if (o is IProcessable) ProcessableObjects.Remove((IProcessable)o); }
protected override void AddObject(CGameObject o) { AllGameObjects.Add(o); //if (o is IProcessable) ProcessableObjects.Add((IProcessable)o); }
// ********************************* // Methods: // ********************************* private void SetBlock(Blocks block, float x, float y) { int blockmap = 0; StaticObjects object_id = StaticObjects.Brick; int mapX = (int)(x / 16) - 1; int mapY = (int)(y / 16) - 1;; switch (block) { case Blocks.WallFull: blockmap = 0x0F; object_id = StaticObjects.Brick; break; case Blocks.WallUp: blockmap = 0x0C; object_id = StaticObjects.Brick; break; case Blocks.WallDown: blockmap = 0x03; object_id = StaticObjects.Brick; break; case Blocks.WallLeft: blockmap = 0x0A; object_id = StaticObjects.Brick; break; case Blocks.WallRight: blockmap = 0x05; object_id = StaticObjects.Brick; break; case Blocks.IronFull: blockmap = 0x0F; object_id = StaticObjects.Iron; break; case Blocks.IronUp: blockmap = 0x0C; object_id = StaticObjects.Iron; break; case Blocks.IronDown: blockmap = 0x03; object_id = StaticObjects.Iron; break; case Blocks.IronLeft: blockmap = 0x0A; object_id = StaticObjects.Iron; break; case Blocks.IronRight: blockmap = 0x05; object_id = StaticObjects.Iron; break; case Blocks.Garden: blockmap = 0x0F; object_id = StaticObjects.Garden; break; case Blocks.Ice: blockmap = 0x0F; object_id = StaticObjects.Ice; break; case Blocks.Water: blockmap = 0x0F; object_id = StaticObjects.Water; break; default: blockmap = 0x00; object_id = StaticObjects.Empty; break; } int comparator = 0x08; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { if (tileMap[mapX + j, mapY + i] != null) { RemoveObject(tileMap[mapX + j, mapY + i]); } if ((comparator & blockmap) != 0) { CGameObject new_object = (CGameObject)CObjectCreator.CreateStaticObject(object_id, (float)((x + (j * 16))), (float)((y + (i * 16)))); AddObject(new_object); tileMap[mapX + j, mapY + i] = new_object; mapBuffer[mapY + j + (mapX + i) * 26] = (int)object_id; } else { tileMap[mapX + j, mapY + i] = null; } comparator >>= 1; } } }
protected abstract void RemoveObject(CGameObject o);
protected abstract void AddObject(CGameObject o);
// - - - - - - - - - // Configurators: // - - - - - - - - - // Sets event handlers for object: void SetEventHandlers(CGameObject o) { // - - - if (o is CBrick) { o.onHit += OnHit_Object; o.onDestroy += OnDestroy_Object; } if (o is CIron) { o.onDestroy += OnDestroy_Object; } // - - - if (o is CTank) { // Setting events: (o as CTank).onCheckMoveForward += OnCheck_CanMoveForward; (o as CTank).onDestroy += OnDestroy_Tank; (o as CTank).onMove += OnMove_Object; (o as CTank).onShoot += OnShoot_Tank; (o as CTank).onInvinsible += this.OnActivate_ForceField; } if (o is CTankEnemy) { (o as CTankEnemy).OnCreateBonus += OnBonusCreate; } // if (o is CTankPlayer) { (o as CTankPlayer).onDirectionChange += OnMove_Object; //(o as CTankPlayer).onDestroy += OnPlayerTankDestroy; } // if (o is CTankPortal) { (o as CTankPortal).onDestroy += OnDestroy_Portal; } if (o is CExplotion) { (o as CExplotion).onDestroy += OnDestroy_Object; (o as CExplotion).onDestroy += OnDestroy_Explotion; } // if (o is CProjectile) { // Setting event handlers: (o as CProjectile).onDestroy += OnDestroy_Projectile; (o as CProjectile).onMove += OnMove_Projectile; (o as CProjectile).onCheckTargetHit += OnCheck_IsTargetHit; } // if (o is CGameOverMessage) { o.onDestroy += this.OnComplete_Level; } // if (o is CEagle) { o.onDestroy += this.OnHit_HQ; } if (o is CPoints) { o.onDestroy += this.OnDestroy_Object; } if (o is CForceField) { o.onDestroy += this.OnDestroy_Object; } if (o is CBonus) { o.onDestroy += this.OnDestroy_Object; (o as CBonus).CheckBonusTake = this.OnCheck_IsBonusTaken; (o as CBonus).OnBonusTake += this.OnBonusTake; if (o is CBonusSpade) { (o as CBonusSpade).OnBonusTake += this.OnBonusTake_Spade; (o as CBonusSpade).OnBonusExpire += this.OnBonusExpire_Spade; } if (o is CBonusGranade) { (o as CBonusGranade).OnBonusTake += this.OnBonusTake_Granade; } if (o is CBonusLife) { (o as CBonusLife).OnBonusTake += this.OnBonusTake_Life; } if (o is CBonusClock) { (o as CBonusClock).OnBonusTake += this.OnBonusTake_Clock; (o as CBonusClock).OnBonusExpire += this.OnBonusExpire_Clock; } if (o is CBonusHelmet) { (o as CBonusHelmet).OnBonusTake += this.OnBonusTake_Helmet; } if (o is CBonusStar) { (o as CBonusStar).OnBonusTake += this.OnBonusTake_Star; } } }