public void Update(float deltaTime, KeyboardState keyboardState, MouseState mouseState, Point windowSize) { if (alive) { scale = new Vector2(0.2f, 0.2f); if (keyboardState.IsKeyDown(Keys.W)) { speed = 5; moveDir.Y = -5; } else { moveDir.Y = 5; } if (position.Y <= 0) { speed = 5; moveDir.Y = 5; } else if (position.Y >= 500 - (texture.Height * scale.Y)) { speed = 5; moveDir.Y = -5; } if (moveDir != Vector2.Zero) { moveDir.Normalize(); position += (moveDir * speed); rectangle.Location = position.ToPoint(); } attackTimer += deltaTime; if (attackTimer <= attackSpeed) { attackTimer += deltaTime; } if (keyboardState.IsKeyDown(Keys.Space) == true && attackTimer >= attackSpeed) { BulletManager.AddBullet(TextureLibrary.GetTexture("Bullet"), position, new Vector2(1, 0), 100, new Vector2(0.05f, 0.05f), Bullet.Owner.Player, color); attackTimer = 0; } } else { color = Color.Black; } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); bulletTexture = Content.Load <Texture2D>("Bullet"); playerTexture = Content.Load <Texture2D>("PlayerTexture"); groundTexture = Content.Load <Texture2D>("Ground"); scrolling1 = new Scrolling(Content.Load <Texture2D>("Background"), new Rectangle(0, 0, 800, 485)); scrolling2 = new Scrolling(Content.Load <Texture2D>("Background"), new Rectangle(800, 0, 800, 485)); TextureLibrary.LoadTexture(Content, "Enemy"); TextureLibrary.LoadTexture(Content, "PlayerTexture"); TextureLibrary.LoadTexture(Content, "Bullet"); // TODO: use this.Content to load your game content here }
public void Update(float deltaTime, Player player, int windowHeight) { if (alive == true) { attackTimer += deltaTime; if (attackTimer <= attackSpeed) { attackTimer += deltaTime; } if (Vector2.Distance(position, new Vector2(1, 0)) <= attackRange && attackTimer >= attackSpeed) { BulletManager.AddBullet(TextureLibrary.GetTexture("Bullet"), position, new Vector2(-1, 0) - position, 400, new Vector2(0.05f, 0.05f), Bullet.Owner.Enemy, color); attackTimer = 0; } } }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { random = new Random(); enemys = new List <Enemy>(); textures = new Dictionary <string, Texture2D>(); numEnemys = 1; // TODO: Add your initialization logic here base.Initialize(); player = new Player(TextureLibrary.GetTexture("PlayerTexture"), new Vector2(20, 1), 5, new Vector2(1, 1), Color.White, 1000, 1); enemy = new Enemy(TextureLibrary.GetTexture("Enemy"), new Vector2(100, 1), 5, new Vector2(1, 1), Color.White, 1000, 10000, 1); for (int i = 0; i < numEnemys; i++) { float randomY = random.Next(Window.ClientBounds.Height); enemys.Add(new Enemy(TextureLibrary.GetTexture("Enemy"), new Vector2(Window.ClientBounds.Width / 2, randomY), 100, Vector2.One, Color.White, 1000, 5000, 1)); } ground = new Ground(groundTexture, new Vector2(20, 0), new Vector2(20, 1), Color.White); position = new Vector2(20, 1); scale = new Vector2(0.15f, 0.15f); offset = (playerTexture.Bounds.Size.ToVector2() / 2f) * scale; playerRectangle = new Rectangle((position - offset).ToPoint(), (playerTexture.Bounds.Size.ToVector2() * scale).ToPoint()); groundRectangle = groundTexture.Bounds; groundRectangle.Location = ground.AccessPosition.ToPoint(); }