/// <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(); }
// Ne fonctionne pas correctement public void Detect(Enemy enemy) { Vector2 distance; distance.X = game.player.Hitbox.X - enemy.enemy_rec.X; distance.Y = game.player.Hitbox.Y - enemy.enemy_rec.Y; if (Math.Abs(distance.X) < 50 || Math.Abs(distance.Y) > 50) { is_aware = true; float rotationangle = (float)Math.Atan2(distance.X, distance.Y); enemy.velocity = new Vector2((float)Math.Cos(rotationangle), (float)Math.Sin(rotationangle)) * 1f; } enemy.position += enemy.velocity; enemy.enemy_rec.X = (int)enemy.position.X; enemy.enemy_rec.Y = (int)enemy.position.Y; }
//METHODS public void SpawnEnemies(int enemy_number) { Enemy new_enemy; Random random_pos = new Random(); int rand_x, rand_y; while (enemy_number > 0) { new_enemy = new Enemy(game); rand_x = random_pos.Next(0, game.screenwidth-enemy_rec.X); rand_y = random_pos.Next(0, game.screenheight-enemy_rec.Y); new_enemy.position = new Vector2(rand_x, rand_y); new_enemy.enemy_rec = new Rectangle(rand_x, rand_y, 32, 32); new_enemy.is_alive = true; game.Enemy_List.Add(new_enemy); enemy_number--; } }
// Ne fonctionne pas correctement public void Track(Enemy enemy) { if (enemy.is_aware) { Vector2 distance; distance.X = game.player.Hitbox.X - enemy.enemy_rec.X; distance.Y = game.player.Hitbox.Y - enemy.enemy_rec.Y; float rotationangle = (float)Math.Atan2(distance.X, distance.Y); enemy.velocity = new Vector2((float)Math.Cos(rotationangle), (float)Math.Sin(rotationangle)) * 1f; enemy.position += enemy.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); 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); }