public void Enemy_Shoot(HeroSprite Hero, List<Bullet> Enemy_Bullets) { if (this.isEnemyActive == true) { //isAttacking = true; Enemy_Rof_Cooldown++; this.Enemy_Aim(Hero); if (Enemy_Rof_Cooldown >= this.getEnemy_Current_Rof) { Update_Enemy = false; if (this.getEnemy_Current_Picture == this.getEnemy_Current_StandRight) { this.setEnemy_Current_Picture = this.getEnemy_Current_ShootRight; } else if (this.getEnemy_Current_Picture == this.getEnemy_Current_StandLeft) { this.setEnemy_Current_Picture = this.getEnemy_Current_ShootLeft; } for (int i = 0; i < Enemy_Bullets.Count; i++) { if (Enemy_Bullets[i].isBulletActive == false) { Enemy_Middle = new Vector2(this.getEnemy_Current_Position.X + this.getEnemy_Current_Width / 2, this.getEnemy_Current_Position.Y + this.getEnemy_Current_Height / 2); Hero_Middle = new Vector2(Hero.getHero_Position.X + 20, Hero.getHero_Position.Y + 30); Enemy_Bullets[i].ActivateBullet(Hero_Middle, Enemy_Middle, Enemy_Current_Bullet, Enemy_Current_Bullet_Speed); Enemy_Rof_Cooldown = 0; break; } } Enemy_Rof_Cooldown = 0; } if (Enemy_Rof_Cooldown == 10) { this.Revert(); } } }
public void Update(GameTime gameTime, HeroSprite Hero) { }
public void Enemy_Aim(HeroSprite Hero) { if (Update_Enemy == true) { if (Hero.getHero_Position.X > this.getEnemy_Current_Position.X) { if (this.getEnemy_Current_Picture == this.getEnemy_Current_ShootRight || this.getEnemy_Current_Picture == this.getEnemy_Current_ShootLeft) { this.setEnemy_Current_Picture = this.getEnemy_Current_ShootRight; } else if (this.getEnemy_Current_Picture == this.getEnemy_Current_StandRight || this.getEnemy_Current_Picture == this.getEnemy_Current_StandLeft) { this.setEnemy_Current_Picture = this.getEnemy_Current_StandRight; } } else if (Hero.getHero_Position.X < this.getEnemy_Current_Position.X) { if (this.getEnemy_Current_Picture == this.getEnemy_Current_ShootRight || this.getEnemy_Current_Picture == this.getEnemy_Current_ShootLeft) { this.setEnemy_Current_Picture = this.getEnemy_Current_ShootLeft; } else if (this.getEnemy_Current_Picture == this.getEnemy_Current_StandRight || this.getEnemy_Current_Picture == this.getEnemy_Current_StandLeft) { this.setEnemy_Current_Picture = this.getEnemy_Current_StandLeft; } } } }
public bool Enemy_Attack(HeroSprite Hero, int Hero_Width, int Hero_Height, int Enemy_Charger_Width, int Enemy_Charger_Height) { if (Enemy_Rof_Cooldown <= this.getEnemy_Current_Rof) { Enemy_Rof_Cooldown++; } if (this.getEnemy_Current_Position.X > Hero.getHero_Position.X - Enemy_Charger_Width && this.getEnemy_Current_Position.X < Hero.getHero_Position.X + Hero_Width + Enemy_Charger_Width - 20) { if (this.getEnemy_Current_Position.Y > Hero.getHero_Position.Y - Enemy_Charger_Height && this.getEnemy_Current_Position.Y < Hero.getHero_Position.Y + Hero_Height + Enemy_Charger_Height) { if (Enemy_Rof_Cooldown >= this.getEnemy_Current_Rof) { Update_Enemy = false; if (this.getEnemy_Current_Picture == this.getEnemy_Current_StandRight) { this.setEnemy_Current_Picture = this.getEnemy_Current_ShootRight; } else if (this.getEnemy_Current_Picture == this.getEnemy_Current_StandLeft) { this.setEnemy_Current_Picture = this.getEnemy_Current_ShootLeft; } Enemy_Rof_Cooldown = 0; return true; } } } if (Enemy_Rof_Cooldown == 30) { this.Revert(); } return false; }
public void Update(GameTime gameTime, HeroSprite Hero, int inMaxWidth, int inMaxHeight) { if (Update_Enemy == true) { float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds; Vector2 Move_Towards = -(this.getEnemy_Current_Position - Hero.getHero_Position); Move_Towards.Normalize(); this.setEnemy_Current_Position = this.getEnemy_Current_Position + (Move_Towards * this.getEnemy_Current_MoveSpeed * elapsedTime); } }
public void ActivateEnemy(String inEnemy_Type, Texture2D inEnemy_Bullet, Texture2D inEnemy_Picture, Texture2D inEnemy_StandRight, Texture2D inEnemy_ShootRight, Texture2D inEnemy_StandLeft, Texture2D inEnemy_ShootLeft, int inEnemy_Lives, int inEnemy_MoveSpeed, int inEnemy_Current_Bullet_Speed, int inEnemy_Rof, int inMaxWidth, int inMaxHeight, int inEnemy_Width, int inEnemy_Height, HeroSprite Hero) { isEnemyActive = true; Enemy_Current_Type = inEnemy_Type; Enemy_Current_Bullet = inEnemy_Bullet; Enemy_Current_Picture = inEnemy_Picture; Enemy_Current_StandRight = inEnemy_StandRight; Enemy_Current_ShootRight = inEnemy_ShootRight; Enemy_Current_StandLeft = inEnemy_StandLeft; Enemy_Current_ShootLeft = inEnemy_ShootLeft; Enemy_Current_Lives = inEnemy_Lives; Enemy_Current_Rof = inEnemy_Rof; Enemy_Current_MoveSpeed = inEnemy_MoveSpeed; Enemy_Current_Bullet_Speed = inEnemy_Current_Bullet_Speed; Enemy_Current_Width = inEnemy_Width; Enemy_Current_Height = inEnemy_Height; inMaxHeight = inMaxHeight - inEnemy_Height; inMaxWidth = inMaxWidth - inEnemy_Width; //if (Hero.getHero_Position.X > Enemy_Tanks[i].getEnemy_Current_Position.X - 45 && Hero.getHero_Position.X < Enemy_Tanks[i].getEnemy_Current_Position.X + 185) // { // if (Hero.getHero_Position.Y > Enemy_Tanks[i].getEnemy_Current_Position.Y - 85 && Hero.getHero_Position.Y < Enemy_Tanks[i].getEnemy_Current_Position.Y + 225) Random Generate_Position = new Random(); int Which_Wall = Generate_Position.Next(4); if (Which_Wall == Old_Wall) { Which_Wall = Generate_Position.Next(4); } Old_Wall = Which_Wall; if (Which_Wall == 0) //Left wall { Enemy_Current_Position.X = 0; Enemy_Current_Position.Y = Generate_Position.Next(0, inMaxHeight - 50); while (Hero.getHero_Position.X > Enemy_Current_Position.X - 45 && Hero.getHero_Position.X < Enemy_Current_Position.X + 185 && Hero.getHero_Position.Y > Enemy_Current_Position.Y - 85 && Hero.getHero_Position.Y < Enemy_Current_Position.Y + 225) { Enemy_Current_Position.X = inMaxWidth - 50; Enemy_Current_Position.Y = Generate_Position.Next(inMaxHeight - 50); } Enemy_Current_Picture = Enemy_Current_StandRight; } else if (Which_Wall == 1) //Right wall { Enemy_Current_Position.X = inMaxWidth - 50; Enemy_Current_Position.Y = Generate_Position.Next(0, inMaxHeight - 50); while (Hero.getHero_Position.X > Enemy_Current_Position.X - 45 && Hero.getHero_Position.X < Enemy_Current_Position.X + 185 && Hero.getHero_Position.Y > Enemy_Current_Position.Y - 85 && Hero.getHero_Position.Y < Enemy_Current_Position.Y + 225) { Enemy_Current_Position.X = 0; Enemy_Current_Position.Y = Generate_Position.Next(inMaxHeight - 50); } Enemy_Current_Picture = Enemy_Current_StandLeft; } else if (Which_Wall == 2) //Top wall { Enemy_Current_Position.Y = 0; Enemy_Current_Position.X = Generate_Position.Next(0, inMaxWidth - 50); while (Hero.getHero_Position.X > Enemy_Current_Position.X - 45 && Hero.getHero_Position.X < Enemy_Current_Position.X + 185 && Hero.getHero_Position.Y > Enemy_Current_Position.Y - 85 && Hero.getHero_Position.Y < Enemy_Current_Position.Y + 225) { Enemy_Current_Position.Y = inMaxHeight - 50; Enemy_Current_Position.X = Generate_Position.Next(inMaxWidth - 50); } Enemy_Current_Picture = Enemy_Current_StandRight; } else if (Which_Wall == 3) //Bottom wall { Enemy_Current_Position.Y = inMaxHeight - 50; Enemy_Current_Position.X = Generate_Position.Next(0, inMaxWidth - 50); while (Hero.getHero_Position.X > Enemy_Current_Position.X - 45 && Hero.getHero_Position.X < Enemy_Current_Position.X + 185 && Hero.getHero_Position.Y > Enemy_Current_Position.Y - 85 && Hero.getHero_Position.Y < Enemy_Current_Position.Y + 225) { Enemy_Current_Position.Y = 0; Enemy_Current_Position.X = Generate_Position.Next(inMaxHeight - 50); } Enemy_Current_Picture = Enemy_Current_StandLeft; } }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); Screen_Width = graphics.GraphicsDevice.Viewport.Width; Screen_Height = graphics.GraphicsDevice.Viewport.Height; if (Draw_Background == true) { Background_Texture = Content.Load<Texture2D>("Grass_Background2"); } Screen_Rectangle = new Rectangle(0, 0, Screen_Width, Screen_Height); Hud = new HUD(); Hud.Font = Content.Load<SpriteFont>("gameFont"); Hud.Lives = 3; Hud.Score = 0; Hud.Wave = 0; Tree1 = Content.Load<Texture2D>("Tree1"); Random Generate_Tree_Position = new Random(); int Tree_Position1_X = Generate_Tree_Position.Next(100, Screen_Width / 2 - 80), Tree_Position1_Y = Generate_Tree_Position.Next(100, Screen_Height / 2 - 105); int Tree_Position2_X = Generate_Tree_Position.Next(100, Screen_Width / 2 - 80), Tree_Position2_Y = Generate_Tree_Position.Next(Screen_Height / 2 + 105, Screen_Height - 215); int Tree_Position3_X = Generate_Tree_Position.Next(Screen_Width / 2 + 80, Screen_Width - 165), Tree_Position3_Y = Generate_Tree_Position.Next(100, Screen_Height / 2 - 105); int Tree_Position4_X = Generate_Tree_Position.Next(Screen_Width / 2 + 80, Screen_Width - 165), Tree_Position4_Y = Generate_Tree_Position.Next(Screen_Height / 2 + 105, Screen_Height - 215); //int Tree_Position5_X = Generate_Tree_Position.Next(800, 1100), Tree_Position5_Y = Generate_Tree_Position.Next(50, 400); //int Tree_Position6_X = Generate_Tree_Position.Next(800, 1100), Tree_Position6_Y = Generate_Tree_Position.Next(500, 800); Tree_Position1 = new Vector2(Tree_Position1_X, Tree_Position1_Y); Tree_Position2 = new Vector2(Tree_Position2_X, Tree_Position2_Y); Tree_Position3 = new Vector2(Tree_Position3_X, Tree_Position3_Y); Tree_Position4 = new Vector2(Tree_Position4_X, Tree_Position4_Y); //Tree_Position5 = new Vector2(Tree_Position5_X, Tree_Position5_Y); //Tree_Position6 = new Vector2(Tree_Position6_X, Tree_Position6_Y); Hero_Bullet = Content.Load<Texture2D>("Hero_Bullet"); for (int i = 0; i < 10; i++) { Hero_Bullets.Add(new Bullet()); } Hero_Grenade = Content.Load<Texture2D>("Hero_Grenade"); for (int i = 0; i < 4; i++) { Hero_Grenades.Add(new Grenade()); } Explosion = Content.Load<Texture2D>("Explosion"); Hero_Stand_Right = Content.Load<Texture2D>("Hero_Stand_Right"); Hero_Move_Right = Content.Load<Texture2D>("Hero_Move_Right"); Hero_Stand_Left = Content.Load<Texture2D>("Hero_Stand_Left"); Hero_Move_Left = Content.Load<Texture2D>("Hero_Move_Left"); Hero_Stand_Up = Content.Load<Texture2D>("Hero_Stand_Up"); Hero_Move_Up = Content.Load<Texture2D>("Hero_Move_Up"); Hero_Stand_Down = Content.Load<Texture2D>("Hero_Stand_Down"); Hero_Move_Down = Content.Load<Texture2D>("Hero_Move_Down"); Hero_Heart = Content.Load<Texture2D>("Hero_Heart"); Crosshair_Final = Content.Load<Texture2D>("Crosshair_Final"); Shield_Final = Content.Load<Texture2D>("Shield_Final"); Hero_Start_Position = new Vector2(Screen_Width / 2, Screen_Height / 2); Hero = new HeroSprite(Hero_Stand_Right, Hero_Move_Right, Hero_Stand_Left, Hero_Move_Left, Hero_Stand_Up, Hero_Move_Up, Hero_Stand_Down, Hero_Move_Down, Shield_Final, Hero_Start_Position); Powerup_Godmode = Content.Load<Texture2D>("Powerup_Godmode"); Powerup_Gun = Content.Load<Texture2D>("Powerup_Gun"); Powerup_Speed = Content.Load<Texture2D>("Powerup_Speed"); Powerup_Heart = Content.Load<Texture2D>("Powerup_Heart"); Powerup_Spawn_Rate = 400; for (int i = 0; i < 4; i++) { Powerups.Add(new Powerup()); } Enemy_Tank_ShootRight = Content.Load<Texture2D>("Enemy_Tank_ShootRight"); Enemy_Tank_StandRight = Content.Load<Texture2D>("Enemy_Tank_StandRight"); Enemy_Tank_ShootLeft = Content.Load<Texture2D>("Enemy_Tank_ShootLeft"); Enemy_Tank_StandLeft = Content.Load<Texture2D>("Enemy_Tank_StandLeft"); Enemy_Tank_Bullet = Content.Load<Texture2D>("Enemy_Tank_Bullet"); for (int i = 0; i < 4; i++) { Enemy_Tanks.Add(new EnemySprite()); } for (int i = 0; i < 20; i++) { Enemy_Tank_Bullets.Add(new Bullet()); } Enemy_Grunt_ShootRight = Content.Load<Texture2D>("Enemy_Grunt_ShootRight"); Enemy_Grunt_StandRight = Content.Load<Texture2D>("Enemy_Grunt_StandRight"); Enemy_Grunt_ShootLeft = Content.Load<Texture2D>("Enemy_Grunt_ShootLeft"); Enemy_Grunt_StandLeft = Content.Load<Texture2D>("Enemy_Grunt_StandLeft"); Enemy_Grunt_Bullet = Content.Load<Texture2D>("Hero_Bullet"); for (int i = 0; i < 4; i++) { Enemy_Grunts.Add(new EnemySprite()); } for (int i = 0; i < 20; i++) { Enemy_Grunt_Bullets.Add(new Bullet()); } Enemy_Charger_AttackRight = Content.Load<Texture2D>("Enemy_Charger_AttackRight"); Enemy_Charger_RunRight = Content.Load<Texture2D>("Enemy_Charger_RunRight"); Enemy_Charger_AttackLeft = Content.Load<Texture2D>("Enemy_Charger_AttackLeft"); Enemy_Charger_RunLeft = Content.Load<Texture2D>("Enemy_Charger_RunLeft"); for (int i = 0; i < 4; i++) { Enemy_Chargers.Add(new EnemySprite()); } //Menu_Background = Content.Load<Texture2D>("Menu_Background"); Menu_Background = Content.Load<Texture2D>("Grass_Background2"); Texture2D Help = Content.Load<Texture2D>("Help"); Menu = new Menu(Content.Load<SpriteFont>("gameFont"), graphics.GraphicsDevice.Viewport.Width, graphics.GraphicsDevice.Viewport.Height, Crosshair_Final, Help); GameOver_Background = Content.Load<Texture2D>("Game_Over_Screen"); }