public void DrawExplosions(GameState gameState) { base.DrawTroop(gameState,false); for (int i = 0; i < stateGame.explosions.Count; i++) { StateGameLayer.Explosion exp = stateGame.explosions[i]; Vector3 nearPoint = new Vector3(exp.Position.X, exp.Position.Y, exp.Position.Z); nearPoint = spriteBatch.GraphicsDevice.Viewport.Project(nearPoint, Projection, View, World); Vector2 explosionPosition = new Vector2(nearPoint.X - (explosionTexture.Width / 4) * 0.5f, nearPoint.Y - (explosionTexture.Width / 4) * 0.5f); spriteBatch.Begin(); spriteBatch.Draw(explosionTexture, explosionPosition, new Rectangle(exp.ExplosionCurrentFrame.X * exp.ExplosionFrameSize.X, exp.ExplosionCurrentFrame.Y * exp.ExplosionCurrentFrame.Y, exp.ExplosionFrameSize.X, exp.ExplosionFrameSize.Y), Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 1); spriteBatch.End(); } }
public RenderingFactory(ContentManager Content) : base(Content) { planet = Content.Load<Model>("ModelTroops/Planet"); gs = Content.ServiceProvider.GetService(typeof(GameState)) as GameState; spriteBatch = Content.ServiceProvider.GetService(typeof(SpriteBatch)) as SpriteBatch; stateGame = Content.ServiceProvider.GetService(typeof(StateGame)) as StateGame; factories = stateGame.getFactories(); for (int i = 0; i < factories.Count; i++) { if (factories[i].ObjectType == 1) { TranslateX((float)factories[i].CurrentPos.X); TranslateZ((float)factories[i].CurrentPos.Z); break; } } /* * setting up the new texture when planet is clicked */ textureList.Add(Content.Load<Texture2D>("ModelTroops/marsTexture")); textureList.Add(Content.Load<Texture2D>("ModelTroops/earthTexture")); textureList.Add(Content.Load<Texture2D>("ModelTroops/venusTexture")); textureList.Add(Content.Load<Texture2D>("ModelTroops/planetTexture3")); textureList.Add(Content.Load<Texture2D>("ModelTroops/planetTexture4")); textureList.Add(Content.Load<Texture2D>("ModelTroops/planetTexture1")); textureList.Add(Content.Load<Texture2D>("ModelTroops/planetTexture2")); boundingSpherePlanet = new BoundingSphere(); foreach (ModelMesh mesh in planet.Meshes) { if (boundingSpherePlanet.Radius == 0) boundingSpherePlanet = mesh.BoundingSphere; else boundingSpherePlanet = BoundingSphere.CreateMerged(boundingSpherePlanet, mesh.BoundingSphere); } }
public void DrawFactory(GameState gameState, bool map) { base.DrawBackground(); for (int i = 0; i < factories.Count; i++) { StateGameLayer.Factory factory = factories[i]; foreach (ModelMesh mesh in planet.Meshes) { foreach (BasicEffect effect in mesh.Effects) { if (factories[i].Selected == true) { effect.AmbientLightColor = new Vector3(1.0f, 1.0f, 1.0f); } else { effect.EnableDefaultLighting(); } switch (factories[i].ObjectType) { case 1: effect.AmbientLightColor = new Vector3(0.0f, 0.0f, 1.0f); effect.SpecularColor = new Vector3(0.0f, 0.0f, 1.0f); break; case 2: effect.AmbientLightColor = new Vector3(1.0f, 0.0f, 0.0f); effect.SpecularColor = new Vector3(1.0f, 0.0f, 0.0f); break; default: effect.AmbientLightColor = new Vector3(0.0f, 0.0f, 0.0f); effect.SpecularColor = new Vector3(0.0f, 0.0f, 0.0f); break; } effect.Texture = textureList.ElementAt(factories[i].textureType); effect.World = Matrix.CreateRotationX(MathHelper.ToRadians(-70)); effect.World *= Matrix.CreateRotationY(MathHelper.ToRadians(factories[i].axisRotation())); effect.World *= Matrix.CreateScale(factories[i].scaleFactor) * Matrix.CreateTranslation(factory.CurrentPos.X, factory.CurrentPos.Y, factory.CurrentPos.Z); if (map) { effect.View = ViewMap; } else { effect.View = View; } effect.Projection = Projection; } mesh.Draw(); } } }
public void DrawTroop(GameState gameState, bool map) { if (map == false) { base.DrawLasers(gameState); } else { base.DrawFactory(gameState, map); } List<StateGameLayer.Troop> troops = gameState.getTroops(); ModelMeshCollection modelMesh = null; for (int i = 0; i < troops.Count; i++) { StateGameLayer.Troop troop = troops[i]; if (troop.Fighting) { Vector2 troopOrigin = new Vector2(battle.Width * 0.5f, battle.Height * 0.5f); } switch (troop.ObjectType) { case 1: modelMesh = blue_tank.Meshes; break; case 2: modelMesh = red_tank.Meshes; break; } int spaceSeparationTroop = 100; for (int numElement = 0; numElement < troop.Elements / 3 + 1; numElement++) { foreach (ModelMesh mesh in modelMesh) { // This is where the mesh orientation is set, as well // as our camera and projection. foreach (BasicEffect effect in mesh.Effects) { effect.EnableDefaultLighting(); effect.World = World; effect.World *= Matrix.CreateRotationY((float)-troop.Rotation); switch (numElement) { case 0: effect.World *= Matrix.CreateTranslation(/*-3200*/troop.CurrentPos.X/*COORD TROOP X*/, troop.CurrentPos.Y/*COORD TROOP Y*/, /*-4500*/troop.CurrentPos.Z/*COORD TROOP Z*/); break; case 1: effect.World *= Matrix.CreateTranslation(/*-3200*/troop.CurrentPos.X - spaceSeparationTroop/*COORD TROOP X*/, troop.CurrentPos.Y/*COORD TROOP Y*/, /*-4500*/troop.CurrentPos.Z + spaceSeparationTroop/*COORD TROOP Z*/); break; case 2: effect.World *= Matrix.CreateTranslation(/*-3200*/troop.CurrentPos.X + spaceSeparationTroop/*COORD TROOP X*/, troop.CurrentPos.Y/*COORD TROOP Y*/, /*-4500*/troop.CurrentPos.Z + spaceSeparationTroop/*COORD TROOP Z*/); break; case 3: effect.World *= Matrix.CreateTranslation(/*-3200*/troop.CurrentPos.X + spaceSeparationTroop * 2/*COORD TROOP X*/, troop.CurrentPos.Y/*COORD TROOP Y*/, /*-4500*/troop.CurrentPos.Z + spaceSeparationTroop * 2/*COORD TROOP Z*/); break; case 4: effect.World *= Matrix.CreateTranslation(/*-3200*/troop.CurrentPos.X - spaceSeparationTroop * 2/*COORD TROOP X*/, troop.CurrentPos.Y/*COORD TROOP Y*/, /*-4500*/troop.CurrentPos.Z + spaceSeparationTroop * 2/*COORD TROOP Z*/); break; case 5: effect.World *= Matrix.CreateTranslation(/*-3200*/troop.CurrentPos.X/*COORD TROOP X*/, troop.CurrentPos.Y/*COORD TROOP Y*/, /*-4500*/troop.CurrentPos.Z + spaceSeparationTroop * 2/*COORD TROOP Z*/); break; case 6: effect.World *= Matrix.CreateTranslation(/*-3200*/troop.CurrentPos.X/*COORD TROOP X*/, troop.CurrentPos.Y/*COORD TROOP Y*/, /*-4500*/troop.CurrentPos.Z + spaceSeparationTroop * 3/*COORD TROOP Z*/); break; } if (map) { effect.View = ViewMap; } else { effect.View = View; } effect.Projection = Projection; // Draw the mesh, using the effects set above. mesh.Draw(); effect.Projection = Projection; mesh.Draw(); } } } } }