public PlayerObject(Game1 game, int playerNum, SpriteType type) : base(game) { Transform2DComponent transformComponent = new Transform2DComponent( this, new Vector2(300,100), 0.0f, new Vector2(1.0f)); this.AddComponent(transformComponent); this.AddComponent(new PlayerComponent(this, playerNum)); this.AddComponent(new CurrentActionComponent( this, new ActionComponent(DirectionalAction.Left, SecondaryAction.Stand, PrimaryAction.None), new Dictionary<ActionDefinition, ActionInfo>() )); this.AddComponent(new SpriteComponent(this, type, game)); }
public GameObject BuildStaticRectangularObstacle( Vector2 translation, Rectangle rect, float friction, Color color) { GameObject obstacle = new GameObject(this._game); List<Vector2> vertices = new List<Vector2>(); vertices.Add(new Vector2(rect.Left, rect.Top)); vertices.Add(new Vector2(rect.Right, rect.Top)); vertices.Add(new Vector2(rect.Right, rect.Bottom)); vertices.Add(new Vector2(rect.Left, rect.Bottom)); Transform2DComponent transformComponent = new Transform2DComponent( obstacle, translation, 0.0f, new Vector2(1.0f, 1.0f)); MeshComponent meshComponent = new MeshComponent(obstacle, vertices); ColorComponent colorComponent = new ColorComponent(obstacle, color); BoundingBoxComponent boundingBoxComponent = new BoundingBoxComponent( obstacle, new List<Shape>{ new Shape(vertices) }, false); PhysicalPropertiesComponent physicsPropertiesComponent = new PhysicalPropertiesComponent(obstacle, friction); IsPhysicalComponent isPhysicalComponent = new IsPhysicalComponent(obstacle, false); obstacle.AddComponent(transformComponent); obstacle.AddComponent(meshComponent); obstacle.AddComponent(colorComponent); obstacle.AddComponent(boundingBoxComponent); obstacle.AddComponent(physicsPropertiesComponent); obstacle.AddComponent(isPhysicalComponent); return obstacle; }
public static GameObject BuildActionProjectile( Game1 game, GameObject parent, ActionInfo actInfo, Vector2 position, Vector2 velocity, int lifetime, List<Shape> boundingBoxes) { GameObject entity = new GameObject(game); entity.SetParent(parent); Transform2DComponent transformComponent = new Transform2DComponent( entity, position, 0.0f, Vector2.One); BoundingBoxComponent bbComponent = new BoundingBoxComponent(entity, boundingBoxes, true); CurrentActionComponent caComponent = new CurrentActionComponent( entity, new ActionComponent(DirectionalAction.Left, SecondaryAction.Stand, PrimaryAction.None), new Dictionary<ActionDefinition, ActionInfo>()); LifetimeComponent lifetimeComponent = new LifetimeComponent(entity, lifetime); IsActionComponent isActionComponent = new IsActionComponent(entity, actInfo); MotionPropertiesComponent motionComponent = new MotionPropertiesComponent(entity, 1.0f); motionComponent.SetVelocity(velocity); entity.AddComponent(transformComponent); entity.AddComponent(bbComponent); entity.AddComponent(caComponent); entity.AddComponent(motionComponent); entity.AddComponent(lifetimeComponent); entity.AddComponent(isActionComponent); return entity; }
public static GameObject BuildDynamicEntity( Game1 game, Vector2 position, float rotation, Vector2 scale, float maxGroundSpeed, float maxAirSpeed, SpriteType spriteType, List<Shape> boundingBoxes) { GameObject entity = new GameObject(game); Transform2DComponent transformComponent = new Transform2DComponent( entity, position, rotation, scale); SpriteComponent sprite = new SpriteComponent(entity, spriteType, game); BoundingBoxComponent bbComponent = new BoundingBoxComponent(entity, boundingBoxes, true); CurrentActionComponent caComponent = new CurrentActionComponent( entity, new ActionComponent(DirectionalAction.Left, SecondaryAction.Stand, PrimaryAction.None), new Dictionary<ActionDefinition, ActionInfo>()); GravityComponent gravComponent = new GravityComponent(entity, 1.0f); MotionPropertiesComponent motionComponent = new MotionPropertiesComponent( entity, 1.0f, maxGroundSpeed, maxAirSpeed); IsPhysicalComponent isPhysicalComponent = new IsPhysicalComponent(entity, true); IsCharacterComponent isCharComponent = new IsCharacterComponent(entity); SoundComponent soundComponent = new SoundComponent(entity); entity.AddComponent(transformComponent); entity.AddComponent(sprite); entity.AddComponent(bbComponent); entity.AddComponent(caComponent); entity.AddComponent(gravComponent); entity.AddComponent(motionComponent); entity.AddComponent(isPhysicalComponent); entity.AddComponent(isCharComponent); entity.AddComponent(soundComponent); return entity; }