public Vector2 Bullet_Speed(Vector2 distance, MouseState mouse, Bullet bullet) { distance.X = mouse.X - game.player.Rec_Player.X; distance.Y = mouse.Y - game.player.Rec_Player.Y; float Rotationangle = (float)Math.Atan2(distance.Y, distance.X); bullet.velocity = new Vector2((float)Math.Cos(Rotationangle), (float)Math.Sin(Rotationangle)) * 10f; return bullet.velocity; }
/// <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() { // TODO: Add your initialization logic here base.Initialize(); player = new Player(this); bullet = new Bullet(this); weapon = new Weapons(this); Enemy_List = new List<Enemy>(); enemy = new Enemy(this); player.Initialize(); bullet.Initialize(); enemy.Initialize(); }
public void Shoot(MouseState mouse, GameTime gameTime) { if (x < 0.1f) { x = x + (float)gameTime.ElapsedGameTime.TotalSeconds; } if (x >= 0.1f) { can_shoot = true; } player = game.player; if (mouse.LeftButton == ButtonState.Pressed && can_shoot) { Bullet new_bullet ; Vector2 position = new Vector2(player.Rec_Player.X, player.Rec_Player.Y); Vector2 distance; mouse = Mouse.GetState(); if (player.Bullet_Number != 0) { new_bullet = new Bullet(game); player.Bullet_Number--; distance.X = mouse.X - new_bullet.Rec_ball.X; distance.Y = mouse.Y - new_bullet.Rec_ball.Y; new_bullet.Position = position; new_bullet.Velocity = new_bullet.Bullet_Speed(distance, mouse, new_bullet); new_bullet.Position = position + new_bullet.Velocity; new_bullet.Is_Visible = true; player.Bullet_List.Add(new_bullet); x = 0f; can_shoot = false; } } Reload(player.P_Weapon); }
/// <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() { // TODO: Add your initialization logic here base.Initialize(); player = new Player(this); bullet = new Bullet(this); weapon = new Weapons(this); particle = new Particle(this); Enemy_List = new List<Enemy>(); Particle_list = new List<Particle>(); enemy = new Enemy(this); player.Initialize(); bullet.Initialize(); enemy.Initialize(); camera = new Camera(GraphicsDevice.Viewport, this); map1 = new Map(); map1.Generate(map1.Create_Map(0), 32); }