/* * This constructer initializes the defense tower. It takes the bouding box of the defense tower * that user wants to place and the type of the defense tower as its argument. */ public DefenseTower(RectangleF boundingBoxInput, DefenseTowerType defenseTowerTypeInput) { //store the type of the defense tower type = defenseTowerTypeInput; //initialize the projectile depending on the type of the projectile switch (type) { case DefenseTowerType.Normal: range = NORMAL_TOWER_RANGE; cost = NORMAL_COST; defenseTowerImage = Properties.Resources.NormalTower; break; case DefenseTowerType.LongRange: range = LONG_RANGE_TOWER_RANGE; cost = LONG_COST; defenseTowerImage = Properties.Resources.LongRangeTower; break; case DefenseTowerType.Missile: range = MISSILE_TOWER_RANGE; cost = MISSILE_COST; defenseTowerImage = Properties.Resources.MissileTowerWithProjectile; break; default: break; } //set the bouding box for the defense tower boundingBox = boundingBoxInput; //set the actual image of the defense tower paintDefenseTowerImage = defenseTowerImage; }
/* * This is a constructer that record all the information for the projectile from the user. It takes the bounding box * of the defenseTower, the range of the defense tower, the type of the defense tower as its argument. */ public Projectile(RectangleF defenseTowerBBInput, float rangeInput, DefenseTowerType defenseTowerTypeInput) { //create the constants for each proprotities of the defense TOWER const float NORMAL_PROJECTILE_SPEED = 1000, LONG_RANGE_PROJECTILE_SPEED = 2000, MISSILE_PROJECTILE_SPEED = 200; const int NORMAL_PROJECTILE_DAMAGE = 50, LONG_RANGE_PROJECTILE_DAMAGE = 150, MISSILE_PROJECTILE_DAMAGE = 150; const float NORMAL_PROJECTILE_GAPTIME = 0.3f, LONG_RANGE_PROJECTILE_GAPTIME = 1.0f, MISSILE_PROJECTILE_GAPTIME = 1.5f; //assign values to all private variables centerPoint = Graphic.CalculateCenterPoint(defenseTowerBBInput); rangeRadius = rangeInput; defenseTowerType = defenseTowerTypeInput; rangeBB = CalculateRangeBoundingBox(defenseTowerBBInput, rangeInput); timeCounter = new Stopwatch(); //set up the projectile depeding the type of the defenseTower switch (defenseTowerType) { case DefenseTowerType.Normal: speed = NORMAL_PROJECTILE_SPEED; projectileDamage = NORMAL_PROJECTILE_DAMAGE; gapTime = NORMAL_PROJECTILE_GAPTIME; projectileSize = new SizeF(15, 15); //start the projectile from the center of the tower initialXLocation = centerPoint.X - projectileSize.Width / 2; initialYLocation = centerPoint.Y - projectileSize.Height / 2; break; case DefenseTowerType.LongRange: speed = LONG_RANGE_PROJECTILE_SPEED; projectileDamage = LONG_RANGE_PROJECTILE_DAMAGE; gapTime = LONG_RANGE_PROJECTILE_GAPTIME; projectileSize = new SizeF(20, 20); //start the projectile from the center of the tower initialXLocation = centerPoint.X - projectileSize.Width / 2; initialYLocation = centerPoint.Y - projectileSize.Height / 2; break; case DefenseTowerType.Missile: speed = MISSILE_PROJECTILE_SPEED; projectileDamage = MISSILE_PROJECTILE_DAMAGE; gapTime = MISSILE_PROJECTILE_GAPTIME; projectileSize = new SizeF(50, 50); initialXLocation = defenseTowerBBInput.X + defenseTowerBBInput.Width / 2 - projectileSize.Width / 2; initialYLocation = defenseTowerBBInput.Y; break; default: break; } }