public override void Init(string tag, GameObject unit) { base.Init(tag, unit); projectile = Instantiate(projectileRef, this.transform); projectile.tag = tag; projectile.transform.position = new Vector3(unit.transform.position.x, 1f, unit.transform.position.z); projectile.Initialize(unit.transform.forward, tag); }
public void CreateProjectile(string tag, Vector3 position, Vector3 direction) { projectile = Instantiate(projectileRef); projectile.tag = tag; projectile.transform.position = position; projectile.transform.position = new Vector3(projectile.transform.position.x, 1f, projectile.transform.position.z); projectile.Initialize(direction, tag); }
//private void UpdateCollision() //{ // // Use the Rectangle's built-in intersect function to // // determine if two objects are overlapping // Rectangle rectangle1; // Rectangle rectangle2; // // Only create the rectangle once for the player // rectangle1 = new Rectangle((int)Character.bounds.X, (int)Character.bounds.Y, Character.bounds.Width, Character.bounds.Height); // // Do the collision between the player and the enemies // for (int i = 0; i < currentlevel.enemies.Count; i++) // { // rectangle2 = new Rectangle((int)enemies[i].Position.X, // (int)enemies[i].Position.Y, // enemies[i].Width, // enemies[i].Height); // // Determine if the two objects collided with each // // other // if (rectangle1.Intersects(rectangle2)) // { // // Subtract the health from the player based on // // the enemy damage // player.Health -= enemies[i].Damage; // // Since the enemy collided with the player // // destroy it // enemies[i].Health = 0; // // If the player health is less than zero we died // if (player.Health <= 0) // { // player.Active = false; // alive = false; // } // } // } // // Projectile vs Enemy Collision // for (int i = 0; i < projectiles.Count; i++) // { // for (int j = 0; j < enemies.Count; j++) // { // // Create the rectangles we need to determine if we collided with each other // rectangle1 = new Rectangle((int)projectiles[i].Position.X - // projectiles[i].Width / 2, (int)projectiles[i].Position.Y - // projectiles[i].Height / 2, projectiles[i].Width, projectiles[i].Height); // rectangle2 = new Rectangle((int)enemies[j].Position.X - enemies[j].Width / 2, // (int)enemies[j].Position.Y - enemies[j].Height / 2, // enemies[j].Width, enemies[j].Height); // // Determine if the two objects collided with each other // if (rectangle1.Intersects(rectangle2)) // { // enemies[j].Health -= projectiles[i].Damage; // projectiles[i].Active = false; // } // } // } //} public static void AddProjectile(Vector2 position) { Projectile projectile = new Projectile(); projectile.Initialize(projectileTexture, position); if (Character.currentFacing == Character.facing.right) projectile.projectileMoveSpeed = 6; else projectile.projectileMoveSpeed = -6; projectiles.Add(projectile); laserSound.Play(); }