public Brick(int posx, int posy, string NameSprite, int Score, Breakout breakout) : base(true) { // initial placement Transform.x = posx; Transform.y = posy; AddComponent(new Engine.System.Graphics.SpriteComponent(this, NameSprite, true)); AddComponent(new RuleComponent(this)); AddComponent(CollisionComponentBuilder.CreateNew() .Init(this, new Vector2(60, 30)) .SetBodyType(BodyType.Static) .SetCollidesWith(Category.Cat1) .SetCategoriesCollision(Category.Cat2) .SetFriction(0f) .AddOnCollisionEventHandler(delegate(Fixture sender, Fixture other, Contact contact) { other.Body.LinearVelocity = new Vector2(other.Body.LinearVelocity.X * 400, other.Body.LinearVelocity.Y * 400); return(true); }) .Build()); breakout.wall.Add(this); breakout.nbBrick += 1; Name = "Brick" + breakout.nbBrick; ScoreGiven = Score; var msg = new RuleManager.EngineMessage(); msg.entitybase = EntityManager.GetEntity("Ball"); msg.entityFocus = this; msg.Action = RuleManager.ActionEngine.Collision; GetComponent <RuleComponent>().WatcherActionEngine(msg, BreakBricks, "brick", this, "breakout"); }
public InvisibleWall(Vector2 pos, Vector2 size, bool destroyBallHandler = false) : base(true) { //Initial Placement Transform.x = pos.X; Transform.y = pos.Y; //Component AddComponent(new RuleComponent(this)); var builder = CollisionComponentBuilder.CreateNew(); builder.Init(this, size) .SetBodyType(BodyType.Static) .SetCategoriesCollision(Category.Cat2) .SetFriction(0f) .SetCollidesWith(Category.All); if (destroyBallHandler) { builder.AddOnCollisionEventHandler(delegate(Fixture sender, Fixture other, Contact contact) { EntityManager.GetAllEntities().Find(i => i.Guid == (Guid)other.Body.Tag).marked_for_deletion = true; ((Breakout)EntityManager.GetEntity("Breakout")).nbBall -= 1; return(true); }); } AddComponent(builder.Build()); }
public Ball() : base(true) { Name = "Ball"; // Initial placement Transform.x = 400; Transform.y = 300; // Components AddComponent(new Engine.System.Graphics.SpriteComponent(this, "Ball", true)); AddComponent(CollisionComponentBuilder.CreateNew() .Init(this, 25) .SetRestitution(1f) .SetCategoriesCollision(Category.Cat1) .SetCollidesWith(Category.All) .SetBodyType(BodyType.Dynamic) .SetFriction(0f) .Build()); var mvt = new MovementComponent(this, false); AddComponent(new RuleComponent(this)); AddComponent(mvt); //activation of the function to remove life /* var msg = new RuleManager.EngineMessage(); * msg.entitybase = this; * msg.entityFocus = borderscreen; * msg.Action = RuleManager.ActionEngine.Collision; * rulebrick.WatcherActionEngine(msg, removeLife, "Breakout", this, "nbBall");*/ }
private void CreateSantaCollisionComponent() { OnCollisionEventHandler print_collide = (sender, other, contact) => { Debug.WriteLine("entity controlled:" + sender.Body.Tag + " entity collide:" + other.Body.Tag); Debug.WriteLine("res" + contact.FixtureA.Restitution); //TODO Fix missing/wrong code // var tmp = new RuleManager.EngineMessage(); // tmp.Action = RuleManager.ActionEngine.Collision; // tmp.entitybase = EntityManager.GetAllEntities().Find(i => i.Guid == (Guid)sender.Tag); //tmp.entityFocus = EntityManager.GetAllEntities().Find(i => i.Guid == (Guid)other.Tag); // RuleManager.EngineAction.Enqueue(tmp); return(true); }; santaEnt.AddComponent(CollisionComponentBuilder.CreateNew() .Init(santaEnt, 25) .SetBodyType(BodyType.Dynamic) .SetCollidesWith(Category.All) .SetCategoriesCollision(Category.Cat1) // .SetMass(1f) // .SetInertia(1f) .SetLinearVelocity(new Vector2(300, 0)) .SetRestitution(1f) // .SetIgnoreCCD(true) // .SetForce(100f) .AddOnCollisionEventHandler(print_collide) .Build()); }
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 }
private static Entity CreateBricks(int x, int y, bool vert, BodyType bodyType, Category collidesWith, Category collision, Vector2 force = default(Vector2), Vector2 linearVelocity = default(Vector2), float mass = 2, bool gravity = false, float restitution = 1f) { var entity = new Entity(true); entity.Transform.x = x; entity.Transform.y = y; // entity.Name = "brick" + nbNameBrick; Debug.WriteLine(entity.Name); // nbNameBrick += 1; Vector2 hitbox; if (vert) { entity.AddComponent(new SpriteComponent(entity, "BrickVert", true)); hitbox = new Vector2(30, 60); } else { entity.AddComponent(new SpriteComponent(entity, "Brick", true)); hitbox = new Vector2(60, 30); } var fixtureCollisionEventHandlers = new List <OnCollisionEventHandler>(); fixtureCollisionEventHandlers.Add(delegate(Fixture sender, Fixture other, Contact contact) { other.Body.LinearVelocity = new Vector2(-100, -70); return(true); }); fixtureCollisionEventHandlers.Add(delegate(Fixture sender, Fixture other, Contact contact) { other.Body.LinearVelocity = new Vector2(0, -170); return(true); }); fixtureCollisionEventHandlers.Add(delegate(Fixture sender, Fixture other, Contact contact) { other.Body.LinearVelocity = new Vector2(100, -70); return(true); }); CollisionComponent component = CollisionComponentBuilder.CreateNew() .Init(entity, hitbox) .SetBodyType(BodyType.Dynamic) .SetCollidesWith(collidesWith) .SetCategoriesCollision(collision) .SetIgnoreGravity(gravity) // .SetIgnoreCCD(true) //.ApplyForce(force) // .SetMass(mass) // .SetInertia(0) // .SetLinearVelocity(linearVelocity) .SetHitBoxDivide(3) .SetRestitution(restitution) .SetFixtureOnCollisionEventHandlers(fixtureCollisionEventHandlers) .Build(); entity.AddComponent(component); return(entity); }