/********************************************************************************************/ //this is where you write the application specific CDCR response for your game protected override void HandleCollisionResponse(Actor collidee) { if (collidee is CollidableZoneObject) { CollidableZoneObject simpleZoneObject = collidee as CollidableZoneObject; //do something based on the zone type - see Main::InitializeCollidableZones() for ID if (simpleZoneObject.ID.Equals("sound and camera trigger zone 1")) { //publish an event e.g sound, health progress object[] parameters = { "smokealarm" }; EventDispatcher.Publish(new EventData(EventCategoryType.Sound, EventActionType.OnPlay2D, parameters)); } //IMPORTANT - setting this to null means that the ApplyInput() method will get called and the player can move through the zone. Collidee = null; } else if (collidee is CollidablePrimitiveObject) { //the octahedron at the end of the level if (collidee.ActorType == ActorType.CollidablePickup) { object[] parameters = { "win" }; EventDispatcher.Publish(new EventData(EventCategoryType.Sound, EventActionType.OnPlay2D, parameters)); object[] parameters2 = new object[] { "end" }; EventDispatcher.Publish(new EventData(EventCategoryType.Player, EventActionType.OnGameOver, parameters2)); object[] parameters3 = new object[] { 2 }; EventDispatcher.Publish(new EventData(EventCategoryType.Player, EventActionType.OnWin, parameters3)); } //the enemy collision that resets the player else if (collidee.ActorType == ActorType.Enemy) { object[] parameters = { "lose" }; EventDispatcher.Publish(new EventData(EventCategoryType.Sound, EventActionType.OnPlay2D, parameters)); (collidee as DrawnActor3D).EffectParameters.DiffuseColor = Color.Yellow; Transform3D.Translation = new Vector3(150, 2.5f, 500); } if (collidee.ActorType == ActorType.CollidableObstacle) { object[] parameters = { "lose" }; EventDispatcher.Publish(new EventData(EventCategoryType.Sound, EventActionType.OnPlay2D, parameters)); (collidee as DrawnActor3D).EffectParameters.DiffuseColor = Color.Yellow; Transform3D.Translation = new Vector3(150, 2.5f, 500); object[] parameters2 = new object[] { 1 }; EventDispatcher.Publish(new EventData(EventCategoryType.UI, EventActionType.OnDeathCountChange, parameters2)); } } }
private DrawnActor3D GetObjectFromColor(Color color, Vector3 translation, Texture2D texture, int x) { //add an else if for each type of object that you want to load... if (color.Equals(new Color(255, 0, 0))) { #region Player CollidablePlayerObject archetype = archetypeDictionary[GameConstants.Player] as CollidablePlayerObject; CollidablePlayerObject drawnActor3D = archetype.Clone() as CollidablePlayerObject; drawnActor3D.ID = "Player " + count++; drawnActor3D.Transform3D.Translation = translation + new Vector3(0, -0.1f, 0); drawnActor3D.Initialize(); return(drawnActor3D); #endregion } if (color.Equals(new Color(0, 0, 255))) { #region Water Tile //Water Tile CollidablePrimitiveObject archetype = archetypeDictionary[GameConstants.Water] as CollidablePrimitiveObject; CollidablePrimitiveObject drawnActor3D = archetype.Clone() as CollidablePrimitiveObject; drawnActor3D.ID = "Water " + count++; drawnActor3D.Transform3D.Translation = translation; return(drawnActor3D); #endregion } if (color.Equals(new Color(0, 255, 0))) { #region Grass Tile //Grass Tile CollidablePrimitiveObject archetype = archetypeDictionary[GameConstants.Grass] as CollidablePrimitiveObject; CollidablePrimitiveObject drawnActor3D = archetype.Clone() as CollidablePrimitiveObject; drawnActor3D.ID = "Grass " + count++; drawnActor3D.Transform3D.Translation = translation; drawnActor3D.Transform3D.RotationInDegrees = new Vector3(0, 0, 0); return(drawnActor3D); #endregion } if (color.Equals(new Color(0, 0, 0))) { #region Road Tile //Road Tile CollidablePrimitiveObject archetype = archetypeDictionary[GameConstants.Road] as CollidablePrimitiveObject; CollidablePrimitiveObject drawnActor3D = archetype.Clone() as CollidablePrimitiveObject; drawnActor3D.ID = "Road " + count++; drawnActor3D.Transform3D.Translation = translation; drawnActor3D.Transform3D.RotationInDegrees = Vector3.Zero; return(drawnActor3D); #endregion } if (color.Equals(new Color(255, 255, 0))) { #region Obstacle Spawner //Obstacle Spawner MovingObstacleSpawner archetype = archetypeDictionary["Obstacle Spawner"] as MovingObstacleSpawner; MovingObstacleSpawner drawnActor3D = archetype.Clone() as MovingObstacleSpawner; drawnActor3D.ID = "Obstacle Spawner " + count++; drawnActor3D.Transform3D.Translation = translation; Vector3 moveDir = (x < texture.Width / 2) ? Vector3.UnitX : -Vector3.UnitX; drawnActor3D.InitSpawner(archetypeDictionary["Obstacle"] as CollidablePrimitiveObject, moveDir, texture.Width, new Vector3(0, -0.25f, 0)); obstacleSpawner = drawnActor3D; return(drawnActor3D); #endregion } if (color.Equals(new Color(100, 100, 100))) { #region Water Platform Spawner //Water Platform Spawner MovingObstacleSpawner archetype = archetypeDictionary["Obstacle Spawner"] as MovingObstacleSpawner; MovingObstacleSpawner drawnActor3D = archetype.Clone() as MovingObstacleSpawner; drawnActor3D.ID = "Water Platform Spawner " + count++; drawnActor3D.Transform3D.Translation = translation; Vector3 moveDir = (x < texture.Width / 2) ? Vector3.UnitX : -Vector3.UnitX; drawnActor3D.InitSpawner(archetypeDictionary["Water Platform"] as CollidablePrimitiveObject, moveDir, texture.Width, new Vector3(0, -1f, 0)); obstacleSpawner = drawnActor3D; return(drawnActor3D); #endregion } if (color.Equals(new Color(200, 200, 200))) { #region Win Zone Transform3D transform3D = new Transform3D(translation, Vector3.Zero, new Vector3(texture.Width, 1f, 1f), Vector3.UnitZ, Vector3.UnitY); CollidableZoneObject winZone = new CollidableZoneObject( "Win Zone", ActorType.WinZone, StatusType.Update, transform3D, new BoxCollisionPrimitive(transform3D) ); return(winZone); #endregion } if (color.Equals(new Color(100, 70, 0))) { #region Water Platform CollidablePrimitiveObject archetype = archetypeDictionary["Water Platform"] as CollidablePrimitiveObject; CollidablePrimitiveObject drawnActor3D = archetype.Clone() as CollidablePrimitiveObject; drawnActor3D.ID = "Water Platform " + count++; drawnActor3D.Transform3D.Translation = translation; movingObstacles.Add(drawnActor3D); return(drawnActor3D); #endregion } if (color.Equals(new Color(100, 0, 255))) { #region Moving Obstacle (Car) CollidablePrimitiveObject archetype = archetypeDictionary["Obstacle"] as CollidablePrimitiveObject; CollidablePrimitiveObject drawnActor3D = archetype.Clone() as CollidablePrimitiveObject; drawnActor3D.ID = "Obstacle " + count++; drawnActor3D.Transform3D.Translation = translation; //Apply Random color drawnActor3D.EffectParameters.DiffuseColor = new Color(rand.Next(256), rand.Next(256), rand.Next(256)); movingObstacles.Add(drawnActor3D); return(drawnActor3D); #endregion } if (color.Equals(new Color(0, 255, 255))) { #region Blocking Obstacle CollidablePrimitiveObject archetype = archetypeDictionary["Blocking Obstacle"] as CollidablePrimitiveObject; CollidablePrimitiveObject drawnActor3D = archetype.Clone() as CollidablePrimitiveObject; drawnActor3D.ID = "Blocking Obstacle " + count++; drawnActor3D.Transform3D.Translation = translation + new Vector3(0, -0.25f, 0); return(drawnActor3D); #endregion } if (color.Equals(new Color(255, 50, 255))) { #region Shooter CollidablePrimitiveObject archetype = archetypeDictionary["Shooter"] as CollidablePrimitiveObject; CollidablePrimitiveObject drawnActor3D = archetype.Clone() as CollidablePrimitiveObject; drawnActor3D.ID = "Shooter " + count++; drawnActor3D.Transform3D.Translation = translation; drawnActor3D.EffectParameters.DiffuseColor = Color.Gray; drawnActor3D.ControllerList.Add(new ShootingController("Shooting Controller", ControllerType.ShootingController, archetypeDictionary["Projectile"] as CollidableProjectile, 5f, GameConstants.Projectile_UnitMoveTimeInMs)); return(drawnActor3D); #endregion } if (color.Equals(new Color(255, 150, 0))) { #region Star Pickup CollidablePrimitiveObject archetype = archetypeDictionary["Star Pickup"] as CollidablePrimitiveObject; CollidablePrimitiveObject drawnActor3D = archetype.Clone() as CollidablePrimitiveObject; drawnActor3D.ID = "Star Pickup " + count++; drawnActor3D.Transform3D.Translation = translation; EventDispatcher.Publish(new EventData(EventCategoryType.Tween, EventActionType.OnAdd, new object[] { new RotationTween(drawnActor3D, 1000, new Vector3(0, 90, 0), true, null, LoopType.Repeat), new TranslationTween(drawnActor3D, 1000, Vector3.Up * 0.25f, true, null, LoopType.ReverseAndRepeat, EasingType.easeOut) })); return(drawnActor3D); #endregion } return(null); }