public void InitSpawner(CollidablePrimitiveObject obstacleToSpawn, Vector3 moveDir, float levelWidth, Vector3 spawnOffset = default) { this.obstacleArchetype = obstacleToSpawn; moveDirection = moveDir; this.spawnOffset = spawnOffset; destination = Transform3D.Translation + spawnOffset + moveDirection * levelWidth; }
/// <summary> /// Manually spawns an obstacle /// </summary> public void SpawnObstacle() { CollidablePrimitiveObject obstacle = obstacleArchetype.Clone() as CollidablePrimitiveObject; //obstacle.ID += count++; obstacle.ObjectManager.Add(obstacle); obstacle.Transform3D.Translation = Transform3D.Translation + spawnOffset; MoveObstacle(obstacle); }
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); }
private DrawnActor3D getObjectFromColor(Color color, Vector3 translation) { //if the pixel is red then draw a tall (stretched collidable unlit cube) if (color.Equals(new Color(255, 0, 0))) { PrimitiveObject archetype = archetypeDictionary["lit textured cube"] as PrimitiveObject; PrimitiveObject drawnActor3D = archetype.Clone() as PrimitiveObject; // PrimitiveObject drawnActor3D // = archetypeDictionary["lit textured pyramid"].Clone() as PrimitiveObject; //change it a bit drawnActor3D.ID = "cube " + count++; drawnActor3D.Transform3D.Scale = 10 * new Vector3(2, 3, 1); drawnActor3D.EffectParameters.Texture = textureDictionary["walls"]; drawnActor3D.EffectParameters.Alpha = 1; drawnActor3D.Transform3D.Translation = translation; drawnActor3D.Transform3D.RotationInDegrees = new Vector3(0, 0, 0); BoxCollisionPrimitive collisionPrimitive = new BoxCollisionPrimitive(drawnActor3D.Transform3D); //make a collidable object and pass in the primitive CollidablePrimitiveObject collidablePrimitiveObject = new CollidablePrimitiveObject( drawnActor3D.ID, ActorType.CollidableDecorator, StatusType.Update | StatusType.Drawn, drawnActor3D.Transform3D, drawnActor3D.EffectParameters, drawnActor3D.IVertexData, collisionPrimitive, objectManager); return(collidablePrimitiveObject); } else if (color.Equals(new Color(0, 0, 255))) { PrimitiveObject archetype = archetypeDictionary["lit textured pyramid"] as PrimitiveObject; PrimitiveObject drawnActor3D = archetype.Clone() as PrimitiveObject; //change it a bit drawnActor3D.ID = "Pyramid " + count++; drawnActor3D.Transform3D.Scale = 10 * new Vector3(1, 1, 1); drawnActor3D.EffectParameters.Texture = textureDictionary["Warning"]; drawnActor3D.EffectParameters.Alpha = 1; drawnActor3D.Transform3D.Translation = translation; drawnActor3D.Transform3D.RotationInDegrees = new Vector3(0, 0, 0); BoxCollisionPrimitive collisionPrimitive = new BoxCollisionPrimitive(drawnActor3D.Transform3D); //make a collidable object and pass in the primitive CollidablePrimitiveObject collidablePrimitiveObject = new CollidablePrimitiveObject( drawnActor3D.ID, ActorType.CollidableObstacle, StatusType.Update | StatusType.Drawn, drawnActor3D.Transform3D, drawnActor3D.EffectParameters, drawnActor3D.IVertexData, collisionPrimitive, objectManager); return(collidablePrimitiveObject); } return(null); }