Jump to content
  • Advertisement

zoogy1983

Member
  • Content Count

    6
  • Joined

  • Last visited

Community Reputation

110 Neutral

About zoogy1983

  • Rank
    Newbie
  1. Buckeye,   I was wrong... I was calling bulletPosition = position; in the wrong place. I am calling it in my Update method when I want to show the bullet. All works now! Thanks for the help!!   GO BUCKEYES!!
  2. Thanks for the reply!   When I do this: new public void Draw()         {             if (bulletIsVisible)             {                 SpriteBatch.Draw(bullet, bulletPosition, Color.White);                 bulletPosition.X -= 1.0f;             }             SpriteBatch.Draw(texture, position, Color.White);         } The bullet gets drawn at the location of where the ships spawn. What I am trying to do is give it the ships position and shoot it from where the ship is currently on the screen instead of the place where it spawned from. When step through the code bullet position has the same coordinates as enemy position so to me this should work but it doesn't. Is there another way I should be approaching this?
  3. Hello,   I am having a small issue, I have two ships spawning on the screen at one time and I want to have them shoot every few seconds.   I am able to pass the bullets to the enemies position but when I want it to shoot it doesn't. Posted below is my code. Any help on this matter would be great.   public class Enemy : GameObject     {         Random random = new Random();         public Texture2D texture;         Texture2D bullet;         Vector2 bulletPosition;         bool isVisible = true;         bool bulletIsVisible = false;         int randX, randY;         int bulletTimer;         public Enemy(Texture2D newTexture, Vector2 newPosition)             : base()         {             texture = newTexture;             position = newPosition;             //Controls the speed of enemy ships             randY = random.Next(-3, 2);             randX = random.Next(-4, -2);             bullet = gameManager.Game.Content.Load<Texture2D>("bullet");             velocity = new Vector2(randX, randY);         }         new public void Update()         {             position += velocity;             if (position.Y <= 0 || position.Y >= gameManager.Game.GraphicsDevice.Viewport.Height - texture.Height)                 velocity.Y = -velocity.Y;             if (position.X < 0 - texture.Width)                 isVisible = false;             bulletTimer += 1;             if (bulletTimer == 100)             {                 bulletIsVisible = true;             }         }         new public void Draw()         {             if (bulletIsVisible)             {                 SpriteBatch.Draw(bullet, position, Color.White);                 bulletPosition = position;                 bulletPosition.X -= 1.0f;             }             SpriteBatch.Draw(texture, position, Color.White);         }     }
  4. zoogy1983

    Shooting multiple bullets

      You are correct, my naming convention is weird, but perhaps I should have a bullet manager as well. Which in reallity I can rework this class into that. I will look into this. Thanks!   My ship is always in the middle of the screen by design. I know that I can give it the ships position at all times and I will although the actual ship never moves.   As far as the movement of my bullet it is in the Update method:   [source] Position += direction * speed * (float)gameManager.GameSpeed;[/source]   I have the variables in the ShootBullet in a for loop hoping that it would go through my list of bullets and do that for every bullet. So I guess my big problem is getting the bullets into a list. Like I said I am able to shoot one bullet but getting the bullets in the list and shoot every time the button is pressed is where I am having the issue.   Thanks
  5. zoogy1983

    Shooting multiple bullets

    Thank you for your response.   A bullet always shoots from the middle of the screen - where the ship is   To answer your question:   This class is actually inherited from a weapons manager class (I changed the name of the class to better represent the kind of weapon I am making) I am not creating a new ship I am giving the bullets start position where the ship is. Shoot bullets makes the bullet visible gives it speed and also gives the direction of the bullet. base.Draw calls the inherrited classes draw method which hought was good since it works just fine.   I know that my probem is in where I press the space key because I need it to update the bullet in the same location and give it the same movement.
  6. Hello,   Below is my bullet class and what I am trying to accomplish is putting bullets in a list so I can shoot multiple bullets. I am having a really hard time trying to figure this out. When my code is running I hit the spacebar and only one bullet shoots. Can someone please let me know what I am doing wrong or at least point me in the right direction, thanks!   [source]using System; using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Storage; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; namespace OptimusOrbis.GameObjects { public class DefaultBullet : WeaponsManager { public Ship Ship { get; set; } public DefaultBullet defaultBullet { get; set; } List bullets; KeyboardState mPreviousKeyboardState; public DefaultBullet() : base() { Ship = new Ship(); LoadImage("bullet"); rateOfFire = 1; Damage = 1; distance = 0; maxDistance = 500; bullets = new List(); //bullet will be the same position as the ship //Ship always stays in the middle so does the bullet //until it is fired off Position = Ship.Position; } new public void Update() { base.Update(); //Allows to use the keyboard KeyboardState aCurrentKeyboardState = Keyboard.GetState(); mPreviousKeyboardState = aCurrentKeyboardState; Position += direction * speed * (float)gameManager.GameSpeed; if (aCurrentKeyboardState.IsKeyDown(Keys.Space)) { bullets.Add(Position); for (int i = 0; i < bullets.Count; i++) { ShootBullet(); } } } ///   /// Shoots the default bullets /// public void ShootBullet() { for (int i = 0; i < bullets.Count; i++) { Visible = true; speed = 10.0f; direction.X = 1; } } new public void Draw() { if (Visible == true) { for (int i = 0; i < bullets.Count; i++) { base.Draw(); } } } } } [/source]    
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!