hi again. i am a little confused with adding items to Lists.
I am writing a 2D Fortress game where the user controls a turret and fires bullets at incoming Sprites. at the moment I am trying to write the Game logic for bullets, here is an outline of what I want to do.
1/ Create a new bullet at the location of the barrel of the gun
2/ Set the Bullet shooting off in the direction the barrel is facing(i know the rotation)
seemed easier than it was for me;
here is what i am trying:
if(enough time has passed since you last fired)
{
create a new Bullet at the position of the barrel
get the rotation of the barrel and transform a vector to the currant rotation
set the bullet moving in the direction at a given speed.
!!** Add this bullet to the BulletList **!! //This is what I'm confused with
}
struct Bullet
{
public Vector2 Pos;
public Vector2 Dir;
public void Update()
{
Pos = new Vector2(Pos.X + Dir.X, Pos.Y + Dir.Y);
}
}
Bullet[] bullet;
List<Bullet[]> Bulletlist = new List<Bullet[]>();
private void FireBullet()
{
if (timeScinceFire > FireDelay)
{
bullet[BulletList.Count + 1].Position = //some code to get the position
bullet[BulletList.Count + 1].Direction= //Some code to get the vect & transform
BulletList.Add(bullet[BulletList.Count + 1]);
}
}
private void DrawBullets()
{
foreach(Bullet bullet in Bulletlist)
{
bullet.Update();
spriteBatch.Draw(tBullet, bullet.Pos, Color.White)
}
}
However this will not work as it think it should. Problems:
1/ Bullet does not Update() and move forward;
2/ first bullet draws at (1,1) ALWAYS
Can you guys see any problems?
bullet[BulletList.Count + 1]
I don't like this bit. Im not sure why I just don't think it looks right