private void CreateSantaInputComponent() { var santaInput = new InputComponent(santaEnt); ActionDelegate walk_up_down = (entity, dict) => { entity.GetComponent <MovementComponent>().MoveToUp(); }; ActionDelegate walk_down_down = (entity, dict) => { entity.GetComponent <MovementComponent>().MoveToDown(); }; ActionDelegate walk_right_down = (entity, dict) => { entity.GetComponent <MovementComponent>().MoveToRight(); }; ActionDelegate walk_left_down = (entity, dict) => { entity.GetComponent <MovementComponent>().MoveToLeft(); }; ActionDelegate walk_up_up = (entity, dict) => { entity.GetComponent <MovementComponent>().StopMoveToDirection(MovementComponent.DirectionMovement.UP); }; ActionDelegate walk_down_up = (entity, dict) => { entity.GetComponent <MovementComponent>().StopMoveToDirection(MovementComponent.DirectionMovement.DOWN); }; ActionDelegate walk_left_up = (entity, dict) => { entity.GetComponent <MovementComponent>().StopMoveToDirection(MovementComponent.DirectionMovement.LEFT); }; ActionDelegate walk_right_up = (entity, dict) => { entity.GetComponent <MovementComponent>().StopMoveToDirection(MovementComponent.DirectionMovement.RIGHT); }; ActionDelegate debug_hitbox = (entity, dict) => { GraphicManager.DebugHitbox(); }; santaInput.AddAction("walk_up", OnKey.DOWN, Key.Up, null, walk_up_down); // santaInput.AddAction("walk_up", OnKey.UP, Key.Up, null, walk_up_up); santaInput.AddAction("walk_down", OnKey.DOWN, Key.Down, null, walk_down_down); // santaInput.AddAction("walk_down", OnKey.UP, Key.Down, null, walk_down_up); santaInput.AddAction("walk_left", OnKey.DOWN, Key.Left, null, walk_left_down); // santaInput.AddAction("walk_left", OnKey.UP, Key.Left, null, walk_left_up); santaInput.AddAction("walk_right", OnKey.DOWN, Key.Right, null, walk_right_down); // santaInput.AddAction("walk_right", OnKey.UP, Key.Right, null, walk_right_up); santaInput.AddAction("debug_hitbox", OnKey.PRESSED, Key.F1, null, debug_hitbox); santaEnt.AddComponent(santaInput); }
public Bat() : base(true) { // Initial placement Transform.x = 400; Transform.y = 150; // Main Components AddComponent(new RuleComponent(this)); // var input = new InputComponent(this); AddComponent(MovementComponentBuilder.CreateNew().Init(this).SetForceAmount(3000).Build()); AddComponent(new SpriteComponent(this, "Bat", true)); List <OnCollisionEventHandler> fixtureOnCollisionEventHandlers = new List <OnCollisionEventHandler>(); fixtureOnCollisionEventHandlers.Add(delegate(Fixture sender, Fixture other, Contact contact) { Vector2 linear = other.Body.LinearVelocity; if (linear.Y >= 0) { other.Body.LinearVelocity = new Vector2(-100, -70); } else { other.Body.LinearVelocity = new Vector2(-100, 70); } return(true); }); fixtureOnCollisionEventHandlers.Add(delegate(Fixture sender, Fixture other, Contact contact) { Vector2 linear = other.Body.LinearVelocity; if (linear.Y >= 0) { other.Body.LinearVelocity = new Vector2(0, -170); } else { other.Body.LinearVelocity = new Vector2(0, 170); } return(true); }); fixtureOnCollisionEventHandlers.Add(delegate(Fixture sender, Fixture other, Contact contact) { Vector2 linear = other.Body.LinearVelocity; if (linear.Y >= 0) { other.Body.LinearVelocity = new Vector2(100, -70); } else { other.Body.LinearVelocity = new Vector2(100, 70); } return(true); }); AddComponent(CollisionComponentBuilder.CreateNew() .Init(this, new Vector2(153, 40)) .SetBodyType(BodyType.Dynamic) .SetCollidesWith(Category.All) .SetCategoriesCollision(Category.Cat3) .SetHitBoxDivide(3) .SetFixtureOnCollisionEventHandlers(fixtureOnCollisionEventHandlers) .SetFriction(0f) .Build()); var input = new InputComponent(this); ActionDelegate move_up_down = (entity, dict) => { GetComponent <MovementComponent>().MoveToUp(); }; ActionDelegate move_up_up = (entity, dict) => { GetComponent <MovementComponent>().StopMoveToDirection(MovementComponent.DirectionMovement.UP); }; ActionDelegate move_down_down = (entity, dict) => { GetComponent <MovementComponent>().MoveToDown(); }; ActionDelegate move_down_up = (entity, dict) => { GetComponent <MovementComponent>().StopMoveToDirection(MovementComponent.DirectionMovement.DOWN); }; ActionDelegate move_right_down = (entity, dict) => { GetComponent <MovementComponent>().MoveToRight(); }; ActionDelegate move_right_up = (entity, dict) => { GetComponent <MovementComponent>().StopMoveToDirection(MovementComponent.DirectionMovement.RIGHT); }; ActionDelegate move_left_down = (entity, dict) => { GetComponent <MovementComponent>().MoveToLeft(); }; ActionDelegate move_left_up = (entity, dict) => { GetComponent <MovementComponent>().StopMoveToDirection(MovementComponent.DirectionMovement.LEFT); }; ActionDelegate launch_ball = (entity, dict) => { EntityManager.GetEntity("Breakout").GetComponent <RuleComponent>().WatcherVarEntity("score", 0, "Breakout", SpawnBall, "Ball", this, "none"); }; ActionDelegate exit = (entity, dict) => Engine.Core.Game.Instance.Exit(); input.AddAction("move_right", OnKey.DOWN, Ultraviolet.Input.Key.Right, null, move_right_down); input.AddAction("move_right", OnKey.UP, Ultraviolet.Input.Key.Right, null, move_right_up); input.AddAction("move_left", OnKey.DOWN, Ultraviolet.Input.Key.Left, null, move_left_down); input.AddAction("move_left", OnKey.UP, Ultraviolet.Input.Key.Left, null, move_left_up); input.AddAction("exit", OnKey.PRESSED, Ultraviolet.Input.Key.Escape, null, exit); input.AddAction("launch_ball", OnKey.PRESSED, Ultraviolet.Input.Key.Space, null, launch_ball); AddComponent(input); // Mouvement mechanics not implemented yet. // Waiting for update from physics part before tweaking it }