public override void Update(GameTime gameTime) { player = (CollidablePlayerObject)this.ObjectManager.GetActorByID("collidable player1"); Vector3 movement = new Vector3(0, 1, 0); //enemy movement towards player, player has to be a certain distance away if ((this.Transform3D.Translation - player.Transform3D.Translation).Length() <= 60) { if (this.Transform3D.Translation.X <= player.Transform3D.Translation.X) { this.Transform3D.TranslateBy(new Vector3(0.2f, 0, 0)); } else if (this.Transform3D.Translation.X >= player.Transform3D.Translation.X) { this.Transform3D.TranslateBy(new Vector3(-0.2f, 0, 0)); } if (this.Transform3D.Translation.Z <= player.Transform3D.Translation.Z) { this.Transform3D.TranslateBy(new Vector3(0, 0, 0.2f)); } else if (this.Transform3D.Translation.Z >= player.Transform3D.Translation.Z) { this.Transform3D.TranslateBy(new Vector3(0, 0, -0.2f)); } } //reset translate and rotate and update primitive base.Update(gameTime); }
public CollidableEnemy(string id, ActorType actorType, StatusType statusType, Transform3D transform, EffectParameters effectParameters, IVertexData vertexData, ICollisionPrimitive collisionPrimitive, ObjectManager objectManager, float speed, float range, CollidablePlayerObject player) : base(id, actorType, statusType, transform, effectParameters, vertexData, collisionPrimitive, objectManager) { this.speed = speed; this.range = range; this.player = player; }
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); }