void OnPrimitiveContacted(CollisionPrimitive primitive) { if (primitive is AmmoRound) { AmmoRound ammo = (AmmoRound)primitive; this.TakeDamage(ammo.ShotType, ammo.Position); } }
/// <summary> /// Inicialización /// </summary> protected override void Initialize() { // Actualizar la proyección GlobalMatrices.UpdateProjection(this.GraphicsDevice); // Cámara CameraGameComponent camera = new CameraGameComponent(this); camera.Position = new Vector3(50.0f, 80.0f, 50.0f); camera.KeyBoardSensibility = 50; this.Components.Add(camera); // Suelo float size = _TerrainSize * 0.5f; Vector3 NO = new Vector3(-size, 40, size); Vector3 NE = new Vector3(size, 20, size); Vector3 SO = new Vector3(-size, 20, -size); Vector3 SE = new Vector3(size, 30, -size); Triangle tr1 = new Triangle(NO, SO, NE); Triangle tr2 = new Triangle(NE, SO, SE); this.Physics.RegisterTerrain(new CollisionTriangleSoup(new Triangle[] { tr1, tr2 }, float.PositiveInfinity)); FloorGameComponent floor = new FloorGameComponent(this, new Vector3[] { NO, NE, SO, SE }, @"floor"); floor.Position = new Vector3(0f, 0f, 0f); this.Components.Add(floor); // Inicializa las balas List <AmmoRound> roundList = new List <AmmoRound>(); for (int i = 0; i < _AmmoRounds; i++) { AmmoRound round = new AmmoRound(ShotType.UnUsed, 0f, 0f); this.Physics.RegisterAmmoData(round); roundList.Add(round); } AmmoDrawer ammoDrawer = new AmmoDrawer(this); ammoDrawer.Rounds = roundList.ToArray(); this.Components.Add(ammoDrawer); // Inicializa las cajas Random rnd = new Random(DateTime.Now.Millisecond); for (int i = 0; i < _Boxes; i++) { // Inicializa los componentes gráficos de las cajas float hsX = 0.5f + ((float)rnd.NextDouble() * 1.5f); float hsY = 0.5f + ((float)rnd.NextDouble() * 1.5f); float hsZ = 0.5f + ((float)rnd.NextDouble() * 1.5f); Vector3 min = new Vector3(-hsX, -hsY, -hsZ); Vector3 max = new Vector3(hsX, hsY, hsZ); CubeGameComponent cube = new CubeGameComponent(this, min, max); cube.Register(this.Physics); this.m_Cubes.Add(cube); this.Components.Add(cube); } // El tanque del jugador 1 m_Tank_1 = new Tank(this); this.Components.Add(m_Tank_1); // El tanque del jugador 2 m_Tank_2 = new Tank(this); this.Components.Add(m_Tank_2); base.Initialize(); m_Tank_1.Register(this.Physics); m_Tank_2.Register(this.Physics); this.Reset(); }
/// <summary> /// Registra una bala /// </summary> /// <param name="ammo">Bala</param> public void RegisterAmmoData(AmmoRound ammo) { this.m_AmmoData.Add(ammo); }