Exemple #1
0
 //enemy constructor
 public Enemy(Game1 game)
 {
     this.game = game;
     //creates a new collision box for the enemy |location|size X,Y,Z|is dynamic or not|
     enemyColBox = new Box(getNewLocation(), 1, 1, 1, 0.1f);
     //is enemy affected by gravity
     enemyColBox.IsAffectedByGravity = false;
     // Model transforms
     Matrix transform = Matrix.CreateScale(enemyColBox.Width, enemyColBox.Height, enemyColBox.Length);
     //Loads the enemy model and places it an the correct position then scales, rotates
     EntityModel enemyModel = new EntityModel(enemyColBox, game.Content.Load<Model>("Models/enemyShip1"), Matrix.Identity * Matrix.CreateScale(0.03f) * Matrix.CreateRotationX(30f), game);
     //adds enemy collision box to the game
     game.space.Add(enemyColBox);
     //adds enemy moddel to the game
     game.Components.Add(enemyModel);
     enemyColBox.Tag = enemyModel;
     //sets the enemy positon at a new random location
     targetLocation = getNewLocation();
 }
Exemple #2
0
 //Player Constructor
 public Player(Game1 game)
 {
     this.game = game;
     //creates a new collision box for the player |location|size X,Y,Z|
     shipColBox = new Box(shipPos, 1f, 1f, 1f);
     //sets its mass
     shipColBox.Mass = 2.0f;
     // sets if its affected by gravity
     shipColBox.IsAffectedByGravity = false;
     //add collision box to game
     game.space.Add(shipColBox);
     //Loads the ship model and applys transforms
     shipModel = new EntityModel(shipColBox, game.Content.Load<Model>("Models/Ship"), Matrix.Identity * Matrix.CreateScale(0.0005f), game);
     //load laser sound
     laser = game.Content.Load<SoundEffect>("Audio/Laser");
     //add ship model to game
     game.Components.Add(shipModel);
     shipColBox.Tag = shipModel;
     //resets position of player in world space
     //collision rule to prevent the bullet colliding  with the player ship
     //CollisionRules.AddRule(shipColBox, game.bullet, CollisionRule.NoBroadPhase);
     //set bullet collision information with game objects
     shipColBox.CollisionInformation.Events.InitialCollisionDetected += ShipCollision;
 }
Exemple #3
0
 //create and fire bullet
 public void Firebullet()
 {
     //if sound fx value is true the play laser sound
     if (soundFx == true)
     {
         laser.Play();
     }
     //instantiate bullet collision box
     bullet = new Box(player.shipColBox.Position, 0.2f, 0.2f, 0.2f, 1f);
     //set the bullets LinearVelocity
     bullet.LinearVelocity = player.shipColBox.OrientationMatrix.Forward * 150;
     //set the bullets orientation to the players orientation
     bullet.Orientation = player.shipColBox.Orientation;
     //and the bullet to the game space
     space.Add(bullet);
     //load bullet model and carry out its transforms
     EntityModel model = new EntityModel(bullet, Content.Load<Model>("Models/rocket"), Matrix.Identity * Matrix.CreateScale(0.1f) * Matrix.CreateRotationY(34.6f), this);
     //add bullets model to the game space
     Components.Add(model);
     bullet.Tag = model;
     //collision rule to prevent the bullet coliding with the player ship
     CollisionRules.AddRule(player.shipColBox, bullet, CollisionRule.NoBroadPhase);
     //set bullet collision information with game objects
     bullet.CollisionInformation.Events.InitialCollisionDetected += BulletCollision;
 }
        public void DrawTurrets(Game1 game)
        {
            turretColBox = new Box(turretPos, 2f, 2f, 2f);
            turretModel = new EntityModel(turretColBox, game.Content.Load<Model>("Models/turret"), (Matrix.CreateScale(0.020f) * Matrix.CreateRotationX(30f) * Matrix.CreateTranslation(0f,0f,-7f)), game);
            game.space.Add(turretColBox);
            game.Components.Add(turretModel);
            turretColBox.Tag = turretModel;

            turretColBox1 = new Box(turretPos1, 2f, 2f, 2f);
            turretModel = new EntityModel(turretColBox1, game.Content.Load<Model>("Models/turret"), (Matrix.CreateScale(0.020f) * Matrix.CreateRotationX(30f) * Matrix.CreateTranslation(0f, 0f, -7f)), game);
            game.space.Add(turretColBox1);
            game.Components.Add(turretModel);
            turretColBox1.Tag = turretModel;

            turretColBox2 = new Box(turretPos2, 2f, 2f, 2f);
            turretModel = new EntityModel(turretColBox2, game.Content.Load<Model>("Models/turret"), (Matrix.CreateScale(0.020f) * Matrix.CreateRotationX(30f) * Matrix.CreateTranslation(0f, 0f, -7f)), game);
            game.space.Add(turretColBox2);
            game.Components.Add(turretModel);
            turretColBox2.Tag = turretModel;

            turretColBox3 = new Box(turretPos3, 2f, 2f, 2f);
            turretModel = new EntityModel(turretColBox3, game.Content.Load<Model>("Models/turret"), (Matrix.CreateScale(0.020f) * Matrix.CreateRotationX(30f) * Matrix.CreateTranslation(0f, 0f, -7f)), game);
            game.space.Add(turretColBox3);
            game.Components.Add(turretModel);
            turretColBox3.Tag = turretModel;
        }
 public void DrawBuidlings(Game1 game)
 {
     buildingColBox = new Box(buildingPos, 6f, 3f, 3f);
     buildingModel = new EntityModel(buildingColBox, game.Content.Load<Model>("Models/shack"), Matrix.Identity * (Matrix.CreateScale(0.05f)*Matrix.CreateRotationX(30.0f)), game);
     game.space.Add(buildingColBox);
     game.Components.Add(buildingModel);
     buildingColBox.Tag = buildingModel;
 }