/// <summary> /// Causes the Hero to create a projectile and fire it in the direction /// he is facing; Hero is then responsible for updating and drawing this projectile /// </summary> public void shoot() { if (canShoot) { int x = 0; int y = 0; if (this.getDirection().Equals(Direction.North)) y = -this.getHeight() / 2; if (this.getDirection().Equals(Direction.South)) y = this.getHeight() / 2; if (this.getDirection().Equals(Direction.East)) x = this.getWidth() / 2; if (this.getDirection().Equals(Direction.West)) x = -this.getWidth() / 2; Projectile bullet = new Projectile(this.getX() + x, this.getY() + y, 300.0f, this.getDirection()); bullet.setImage(Sprite.getCommonImage(PROJECTILE_IMAGE_NAME)); bullet.addCollideEvent(new ProjectileCollideEvent(heroBulletCollideEvent)); WorldManager.enqueueObjectToCurrentRoom(bullet); canShoot = false; shootTimer = 0.0f; } }
public override void update(float elapsed) { base.update(elapsed); if (isAggressive) { switch (attackPattern) { case 0: //star burst attackTimer1 += elapsed; if (attackTimer1 > 0.5) { for (float angle = 0; angle < 2 * Math.PI; angle += (float)Math.PI / 4) { Projectile proj = new Projectile(this.getXCenter() + (int)(this.getWidth() / 2 * Math.Cos(angle)), this.getYCenter() - (int)(this.getHeight() / 2 * Math.Sin(angle)), 300f, angle); proj.setImage(Sprite.getCommonImage(Directories.SPRITES + "projectile")); proj.setCollideEvent(new ProjectileCollideEvent(braceBulletCollideEvent)); WorldManager.enqueueObjectToCurrentRoom(proj); } attackTimer1 = 0.0f; } break; case 1: //spiral attackTimer2 += elapsed; if (attackTimer2 > 0.15) { attackAngleCounter2 += 0.35f; Projectile proj = new Projectile(this.getXCenter() + (int)(this.getWidth() / 2 * Math.Cos(attackAngleCounter2)), this.getYCenter() - (int)(this.getHeight() / 2 * Math.Sin(attackAngleCounter2)), 300f, attackAngleCounter2); proj.setImage(Sprite.getCommonImage(Directories.SPRITES + "projectile")); proj.setCollideEvent(new ProjectileCollideEvent(braceBulletCollideEvent)); WorldManager.enqueueObjectToCurrentRoom(proj); attackTimer2 = 0.0f; } break; case 2: //snipe attackTimer3 += elapsed; if (attackTimer3 > 0.40) { int dx = Hero.instance.getXCenter() - this.getXCenter(); int dy = -(Hero.instance.getYCenter() - this.getYCenter()); float angle = (float)Math.Atan2(dy, dx); Projectile proj = new Projectile(this.getXCenter() + (int)(this.getWidth() / 2 * Math.Cos(angle)), this.getYCenter() - (int)(this.getHeight() / 2 * Math.Sin(angle)), 300f, angle); proj.setImage(Sprite.getCommonImage(Directories.SPRITES + "projectile")); proj.setCollideEvent(new ProjectileCollideEvent(braceBulletCollideEvent)); WorldManager.enqueueObjectToCurrentRoom(proj); attackTimer3 = 0.0f; } break; case 3: //firing squad if (!initializeFire) { Vector2[] chooseLoc = new Vector2[4]; //list for four corners chooseLoc[0] = new Vector2(ROOM_MARGIN/2, ROOM_MARGIN/2); chooseLoc[1] = new Vector2(WorldManager.m_currentRoom.background.Width * Room.TILE_SIZE - ROOM_MARGIN, ROOM_MARGIN/2); chooseLoc[3] = new Vector2(ROOM_MARGIN/2, WorldManager.m_currentRoom.background.Height * Room.TILE_SIZE - ROOM_MARGIN); chooseLoc[2] = new Vector2(WorldManager.m_currentRoom.background.Width * Room.TILE_SIZE - ROOM_MARGIN, WorldManager.m_currentRoom.background.Height * Room.TILE_SIZE - ROOM_MARGIN); int choose = rand.Next(4); nextDestFiring = chooseLoc[(choose + 1) % 4]; if (choose == 0) fireDirection = Direction.South; else if (choose == 1) fireDirection = Direction.West; else if (choose == 2) fireDirection = Direction.North; else fireDirection = Direction.East; this.moveToDestination((int)chooseLoc[choose].X, (int)chooseLoc[choose].Y, delegate() { readyToFire = true; }); initializeFire = true; } if (readyToFire) { if (!initializeFire2) { this.moveToDestination((int)nextDestFiring.X, (int)nextDestFiring.Y, delegate() { initializeFire = false; initializeFire2 = false; readyToFire = false; attackPattern = 0; }); initializeFire2 = true; } attackTimer4 += elapsed; if (attackTimer4 > 0.2f) { float angle = SunsetUtils.convertDirectionToAngle(fireDirection); Projectile proj = new Projectile(this.getXCenter() + (int)(this.getWidth() / 2 * Math.Cos(angle)), this.getYCenter() - (int)(this.getHeight() / 2 * Math.Sin(angle)), 300f, angle); proj.setImage(Sprite.getCommonImage(Directories.SPRITES + "projectile")); proj.setCollideEvent(new ProjectileCollideEvent(braceBulletCollideEvent)); WorldManager.enqueueObjectToCurrentRoom(proj); attackTimer4 = 0.0f; } } break; } if (isMovingRandomly && attackPattern != 3) { moveRandomTimer += elapsed; if (moveRandomTimer > 0.30) { int xbound = WorldManager.m_currentRoom.background.Width * Room.TILE_SIZE; int ybound = WorldManager.m_currentRoom.background.Height * Room.TILE_SIZE; this.moveToDestination(rand.Next(xbound), rand.Next(ybound), null); moveRandomTimer = 0.0f; } } attackPatternSwitchTimer += elapsed; if (attackPatternSwitchTimer > 5.0f && attackPattern != 3) { attackPatternSwitchTimer = 0.0f; attackPattern = (attackPattern + 1) % 4; isMovingRandomly = rand.Next(2) == 1; //attackPattern = 3; this.cancelMoveToDestination(); } } }
public override void update(float elapsed) { base.update(elapsed); if (isFoodFight) { FC1timer += elapsed; FC2timer += elapsed; FC3timer += elapsed; FC4timer += elapsed; if (FC1timer > 2.5) { foodType++; FC1timer = 0; Projectile food = new Projectile(5 * 32, 17 * 32, 180f, Direction.North); food.setCollideEvent(new ProjectileCollideEvent(foodCollideEvent)); if (foodType % 3 == 0) { if (foodFightDifficulty == 0) food.setImage(hamburger); else { food.setImage(cow); food.setSpeed(250f); food.setXCenter(5 * 32); } } if (foodType % 3 != 0) food.setImage(apple); if (foodFightDifficulty == 3) food.setSpeed(350f); this.addObject(food); if (foodFightDifficulty > 0) { FC1acounter++; if (FC1acounter % 2 == 0) { Projectile food2 = new Projectile(4 * 32, 17 * 32, 275f, Direction.North); food2.setCollideEvent(new ProjectileCollideEvent(foodCollideEvent)); food2.setImage(hamburger); this.addObject(food2); } } } if (FC2timer > .5) { FC2counter++; FC2timer = 0; if (FC2counter >= 0 && FC2counter <= 5) { Projectile food = new Projectile(10 * 32, 4 * 32, 90f, Direction.South); food.setCollideEvent(new ProjectileCollideEvent(foodCollideEvent)); if (foodType % 3 == 0) food.setImage(hamburger); if (foodType % 3 != 0) food.setImage(apple); this.addObject(food); } if (FC2counter > 7) FC2counter = 0; if (foodFightDifficulty > 0) { FC2acounter++; if (FC2acounter >= 0 && FC2acounter <= 13) { Projectile food2 = new Projectile(11 * 32, 4 * 32, 120f, Direction.South); food2.setCollideEvent(new ProjectileCollideEvent(foodCollideEvent)); if (foodType % 2 == 0) food2.setImage(hamburger); else food2.setImage(apple); this.addObject(food2); } if (FC2acounter > 19) FC2acounter = 0; } } if (FC3timer > .35) { FC3timer = 0; FC3counter++; if (FC3counter <= 11 + foodFightDifficulty && FC3counter >= 0) { Projectile food = new Projectile(15 * 32, 17 * 32, 120f, Direction.North); food.setCollideEvent(new ProjectileCollideEvent(foodCollideEvent)); if (foodType % 3 == 0) food.setImage(hamburger); if (foodType % 3 != 0) food.setImage(apple); this.addObject(food); } if (FC3counter > 18) FC3counter = 0; if (foodFightDifficulty > 1) { FC3acounter++; if (FC3acounter >= 0 && FC3acounter <= 19) { Projectile food2 = new Projectile(14 * 32, 17 * 32, 150f, Direction.North); food2.setCollideEvent(new ProjectileCollideEvent(foodCollideEvent)); if (foodType % 2 == 0) food2.setImage(hamburger); else food2.setImage(apple); this.addObject(food2); } if (FC3acounter > 25) FC3acounter = 0; } } if (FC4timer > .65) { FC4counter++; FC4timer = 0; if (FC4counter >= 0 && FC4counter <= 13) { Projectile food = new Projectile(20 * 32, 4 * 32, 130f - (5f * foodFightDifficulty), Direction.South); food.setCollideEvent(new ProjectileCollideEvent(foodCollideEvent)); if (FC4counter == 13) { food.setImage(cow); food.setXCenter(20 * 32); } else if (foodType % 3 == 0) food.setImage(hamburger); else if (foodType % 3 != 0) food.setImage(apple); this.addObject(food); } if (FC4counter >= 16) FC4counter = 0; if (foodFightDifficulty > 2) { FC4acounter++; if (FC4acounter >= 0 && FC4acounter <= 13 && foodFightDifficulty > 0) { Projectile food2 = new Projectile(21 * 32, 4 * 32, 100f, Direction.South); food2.setCollideEvent(new ProjectileCollideEvent(foodCollideEvent)); if (foodType % 2 == 0) food2.setImage(hamburger); else food2.setImage(apple); this.addObject(food2); } if (FC4acounter > 12) FC4acounter = 0; } } } }