Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region Using Statements
- using System;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- #endregion
- namespace Application
- {
- public class Enemy
- {
- protected Vector2 position = Vector2.Zero;
- protected Texture2D texture = null;
- protected float speed = 150.0f;
- float shootTimer = 0;
- protected bool isDead = true;
- public bool IsDead {
- get { return isDead; }
- set { isDead = value; }
- }
- public Texture2D Texture {
- get { return texture; }
- set { texture = value; }
- }
- public Vector2 Position {
- get { return position; }
- set { position = value; }
- }
- public Rectangle Bounds {
- get { return new Rectangle ((int)position.X, (int)position.Y, texture.Bounds.Width, texture.Bounds.Height); }
- }
- public Enemy ()
- {
- }
- public void Update( float deltaTime )
- {
- if (isDead == true)
- return;
- position.Y += speed * deltaTime;
- if (shootTimer < 0)
- shootTimer -= deltaTime;
- if (Game1.player.Position.X < position.X + texture.Width && Game1.player.Position.X > position.X) {
- if (shootTimer <= 0) {
- foreach (Bullet b in Game1.bullets) {
- if (b.IsDead == true) {
- b.IsDead = false;
- b.Position = Position;
- b.isFromPlayer = false;
- break;
- }
- }
- shootTimer = 0.5f;
- }
- }
- if( CheckCollisions () == true)
- {
- isDead = true;
- }
- }
- public bool CheckCollisions()
- {
- Rectangle bounds = Bounds;
- //check all bullets
- foreach (Bullet b in Game1.bullets) {
- if (b.IsDead == false && b.isFromPlayer == true && bounds.Intersects (b.Bounds) == true) {
- b.IsDead = true;
- return true;
- }
- }
- return false;
- }
- public void Draw(SpriteBatch spritebatch)
- {
- if (isDead == true)
- return;
- if (texture == null)
- return;
- spritebatch.Draw (texture, position, Color.White);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement