public static Entity GetMouth(Color color) { float radius = 10f; var mouthEntity = new Entity("mouth"); var transform = new TransformComponent(mouthEntity) { LocalPosition = Vector2.Zero, LocalRotation = new Rotation(0), LocalDepth = 0.09f, Scale = new Vector2(1, 1) }; var graphics = new GraphicsComponent(mouthEntity) { TexturePath = TextureAtlas.MouthPath, Dimensions = new Point((int)(radius * 2), (int)(radius * 2)), Color = color }; var mouthComp = new MouthComponent(mouthEntity) { }; var collider = new CircleColliderComponent(mouthEntity) { Radius = radius, }; mouthEntity.AddComponents(transform, graphics, mouthComp, collider); return(mouthEntity); }
public SimpleTestEnemy(string name, Guid parent) : base(name, parent) { Animation.Init(AssetManager.Get().Find <Texture2D>(ESpriteAssets.WalkingAnimation3), Vector2.One); Animation.AddSetting((int)Tag.MoveLeft, new AnimationSetting(8, 2, 8, 15, true, true)); Animation.AddSetting((int)Tag.MoveRight, new AnimationSetting(8, 2, 0, 7, true)); Animation.Stop(); AddComponent <ShadowComponent>().Init(AssetManager.Get().Find <Texture2D>(ESpriteAssets.RedOrb), new Vector2(6.0f, 2.0f), new Vector2(0.0f, 10.0f)); CircleColliderComponent collider = AddComponent <CircleColliderComponent>(); collider.Init(22, BodyType.Dynamic); }
public void SerializeAndDeserialize() { // Arrange var component = new CircleColliderComponent { Radius = 123.456 }; // Act var actual = SerializeAndDeserialize(component); // Assert Assert.That(actual.Radius, Is.EqualTo(component.Radius)); Assert.That(actual.IsColliding, Is.False); Assert.That(actual.CollidingEntities, Is.Empty); }
public static Entity GetFoodPellet(Color color) { float radius = 10f; var foodEntity = new Entity("food"); var transform = new TransformComponent(foodEntity) { LocalPosition = Vector2.Zero, LocalRotation = new Rotation(0), LocalDepth = 0.09f, Scale = new Vector2(1, 1) }; var graphics = new GraphicsComponent(foodEntity) { TexturePath = TextureAtlas.SoupPath, Dimensions = new Point((int)(radius * 2), (int)(radius * 2)), Color = color }; var colourComp = new VisibleColourComponent(foodEntity) { RealR = 0.9f, RealB = 0.05f, RealG = 0.05f, }; var energy = new EnergyComponent(foodEntity) { Energy = 3 }; var edible = new EdibleComponent(foodEntity) { }; var collider = new CircleColliderComponent(foodEntity) { Radius = radius, }; foodEntity.AddComponents(transform, graphics, energy, edible, collider, colourComp); return(foodEntity); }
//--------------------------------------------------------------------------- public Bullet(string name, Guid parent) : base(name, parent) { AddComponent <TransformComponent>(); AddComponent <BulletPhysicsComponent>(); AddComponent <SpriteComponent>().Init(AssetManager.Get().Find <Texture2D>(ESpriteAssets.RedOrb)); AddComponent <LightingComponent>().Init(AssetManager.Get().Find <Texture2D>(ESpriteAssets.RedOrb), Vector2.Zero, Vector2.One * 2, Color.White, 0.5f); CircleColliderComponent collider = AddComponent <CircleColliderComponent>(); collider.Init(4, BodyType.Dynamic); collider.SetSensor(true); collider.SetCollisionCategory(ECollisionCategory.Bullet); collider.SetCollidesWith(ECollisionCategory.Stage); collider.Enter += OnHit; AddComponent <DespawnComponent>(); }
public void Radius_ShouldUpdateCircleColliderComponentRadius() { // Arrange var circleColliderComponent = new CircleColliderComponent { Radius = 123 }; var circleColliderComponentModel = new CircleColliderComponentModel(circleColliderComponent); // Assume Assume.That(circleColliderComponentModel.Radius, Is.EqualTo(123)); // Act circleColliderComponentModel.Radius = 456; // Assert Assert.That(circleColliderComponentModel.Radius, Is.EqualTo(456)); Assert.That(circleColliderComponent.Radius, Is.EqualTo(456)); }
public static Entity GetWeapon(Color color) { float radius = 8f; var weaponEntity = new Entity("weapon"); var transform = new TransformComponent(weaponEntity) { LocalPosition = Vector2.Zero, LocalRotation = new Rotation(0), LocalDepth = 0.09f, Scale = new Vector2(1, 1) }; var graphics = new GraphicsComponent(weaponEntity) { TexturePath = TextureAtlas.BoxingGloveRetractedPath, Dimensions = new Point((int)(radius * 2), (int)(radius * 2)), Color = color }; var collider = new CircleColliderComponent(weaponEntity) { Radius = radius, }; var weaponComp = new WeaponComponent(weaponEntity) { ActivateThreshold = 0.75f, AttackCost = 0.1f, AttackTimeSeconds = 0.1f, CooldownTimeSeconds = 1.2f, Damage = 34f }; weaponEntity.AddComponents(transform, graphics, weaponComp, collider); return(weaponEntity); }
//--------------------------------------------------------------------------- private static Pickup Create(string name, Vector3 location, Vector3 force) { Pickup pickup = EntityFactory.Create <Pickup>(string.Format("{0}Pickup", name)); pickup.AddComponent <TransformComponent>().Init(location); PhysicsComponent physics = pickup.AddComponent <PhysicsComponent>(); physics.Init(BodyType.Dynamic, 0.97f, 2.0f); CircleColliderComponent collider = pickup.AddComponent <CircleColliderComponent>(); collider.Init(25, BodyType.Dynamic); collider.SetCollidesWith(ECollisionCategory.Stage); collider.SetCollisionCategory(ECollisionCategory.Pickup); collider.SetRestitution(0.3f); //collider.SetSensor(true); physics.ApplyForce(force, true); pickup.AddComponent <DespawnComponent>(); return(pickup); }
public CircleColliderComponentModel(CircleColliderComponent component) { _component = component; }
private void DrawCircle(CircleColliderComponent circleColliderComponent, in Matrix3x3 transform)
public void GetCollisions() { RemoveDeletedEntities(); // Sort all entities by their minimum X extent Compatible.Sort((e1, e2) => e1.GetComponent <CircleColliderComponent>().MinX() .CompareTo( e2.GetComponent <CircleColliderComponent>().MinX() ) ); // Reset collision info for (int i = 0; i < Compatible.Count; i++) { CircleColliderComponent collider = Compatible[i].GetComponent <CircleColliderComponent>(); TransformComponent transform = Compatible[i].GetComponent <TransformComponent>(); collider.UpdatePosition(transform); collider.ClearCollisions(); } Collisions.Clear(); for (int i = 0; i < Compatible.Count; i++) { CircleColliderComponent collider = Compatible[i].GetComponent <CircleColliderComponent>(); float maxX = collider.MaxX(); for (int j = i + 1; j < Compatible.Count; j++) { CircleColliderComponent otherCollider = Compatible[j].GetComponent <CircleColliderComponent>(); // If the other collider has a minimum x span that is greater than our max x, // Then we no longer need to keep checking. This collider and all other colliders after it cannot be intersecting this collider. if (otherCollider.MinX() > maxX) { break; } if (collider.Intersects(otherCollider)) { if (!_shouldDetectCollision(Compatible[i], Compatible[j])) { continue; } //Calculatye the collison normal var collNormal = otherCollider.Position - collider.Position; if (collNormal != Vector2.Zero) { collNormal.Normalize(); } else { collNormal = Vector2.One; } Collisions.Add(new Collision() { Normal = collNormal, E1 = Compatible[i], E2 = Compatible[j] }); } } } }
//--------------------------------------------------------------------------- public Player(string name, Guid parent) : base(name, parent) { Index = (PlayerIndex)PlayerCount++; AddComponent <TransformComponent>().Init(new Vector3(Index == PlayerIndex.One ? 340 : 420, 400, 0)); AddComponent <PlayerAttributesComponent>().Init(500.0f, 250.0f, 125.0f, 2.0f, 1.0f); AddComponent <InventoryComponent>(); MovementAnimationComponent animation = AddComponent <MovementAnimationComponent>(); if (Index == PlayerIndex.One) { animation.Init(AssetManager.Get().Find <Texture2D>(ESpriteAssets.WalkingAnimation), Vector2.One); } else { animation.Init(AssetManager.Get().Find <Texture2D>(ESpriteAssets.WalkingAnimation2), Vector2.One); } animation.AddSetting((int)Tag.MoveLeft, new AnimationSetting(8, 2, 8, 15, true, true)); animation.AddSetting((int)Tag.MoveRight, new AnimationSetting(8, 2, 0, 7, true)); AddComponent <ShadowComponent>().Init(AssetManager.Get().Find <Texture2D>(ESpriteAssets.RedOrb), new Vector2(6.0f, 2.0f), new Vector2(0.0f, 10.0f)); AddComponent <ActorPhysicsComponent>().Init(BodyType.Dynamic, 0.8f, 1.0f, true); CircleColliderComponent collider = AddComponent <CircleColliderComponent>(); collider.Init(44, BodyType.Dynamic); //collider.SetCollisionCategory(ECollisionCategory.Player); AddComponent <LightingComponent>().Init(AssetManager.Get().Find <Texture2D>(ELightAssets.CircleLight), Vector2.Zero, new Vector2(5.0f, 5.0f), Color.White, 0.6f); InputComponent input = AddComponent <InputComponent>(); if (input != null) { input.Init(Index); input.ClearActions(); switch (Index) { case PlayerIndex.One: input.MapAction(EGameAction.MOVE_LEFT, EInput.KEYBOARD_LEFT, EInput.GAMEPAD_THUMBSTICK_LEFT_LEFT); input.MapAction(EGameAction.MOVE_RIGHT, EInput.KEYBOARD_RIGHT, EInput.GAMEPAD_THUMBSTICK_LEFT_RIGHT); input.MapAction(EGameAction.MOVE_UP, EInput.KEYBOARD_UP, EInput.GAMEPAD_THUMBSTICK_LEFT_UP); input.MapAction(EGameAction.MOVE_DOWN, EInput.KEYBOARD_DOWN, EInput.GAMEPAD_THUMBSTICK_LEFT_DOWN); input.MapAction(EGameAction.LOOK_LEFT, EInput.GAMEPAD_THUMBSTICK_RIGHT_LEFT); input.MapAction(EGameAction.LOOK_RIGHT, EInput.GAMEPAD_THUMBSTICK_RIGHT_RIGHT); input.MapAction(EGameAction.LOOK_UP, EInput.GAMEPAD_THUMBSTICK_RIGHT_UP); input.MapAction(EGameAction.LOOK_DOWN, EInput.GAMEPAD_THUMBSTICK_RIGHT_DOWN); input.MapAction(EGameAction.INVENTORY_NEXT_ITEM, EInput.KEYBOARD_E, EInput.GAMEPAD_DPAD_DOWN); input.MapAction(EGameAction.INVENTORY_PREVIOUS_ITEM, EInput.KEYBOARD_Q, EInput.GAMEPAD_DPAD_UP); input.MapAction(EGameAction.INVENTORY_USE_ITEM, EInput.GAMEPAD_X); input.MapAction(EGameAction.INVENTORY_DROP_ITEM, EInput.GAMEPAD_TRIGGER_RIGHT); input.MapAction(EGameAction.PLAYER_ATTACK, EInput.GAMEPAD_TRIGGER_LEFT); break; case PlayerIndex.Two: input.MapAction(EGameAction.MOVE_LEFT, EInput.KEYBOARD_A, EInput.GAMEPAD_THUMBSTICK_LEFT_LEFT); input.MapAction(EGameAction.MOVE_RIGHT, EInput.KEYBOARD_D, EInput.GAMEPAD_THUMBSTICK_LEFT_RIGHT); input.MapAction(EGameAction.MOVE_UP, EInput.KEYBOARD_W, EInput.GAMEPAD_THUMBSTICK_LEFT_UP); input.MapAction(EGameAction.MOVE_DOWN, EInput.KEYBOARD_S, EInput.GAMEPAD_THUMBSTICK_LEFT_DOWN); input.MapAction(EGameAction.LOOK_LEFT, EInput.GAMEPAD_THUMBSTICK_RIGHT_LEFT); input.MapAction(EGameAction.LOOK_RIGHT, EInput.GAMEPAD_THUMBSTICK_RIGHT_RIGHT); input.MapAction(EGameAction.LOOK_UP, EInput.GAMEPAD_THUMBSTICK_RIGHT_UP); input.MapAction(EGameAction.LOOK_DOWN, EInput.GAMEPAD_THUMBSTICK_RIGHT_DOWN); input.MapAction(EGameAction.INVENTORY_NEXT_ITEM, EInput.KEYBOARD_E, EInput.GAMEPAD_DPAD_DOWN); input.MapAction(EGameAction.INVENTORY_PREVIOUS_ITEM, EInput.KEYBOARD_Q, EInput.GAMEPAD_DPAD_UP); input.MapAction(EGameAction.INVENTORY_USE_ITEM, EInput.GAMEPAD_X); input.MapAction(EGameAction.INVENTORY_DROP_ITEM, EInput.GAMEPAD_TRIGGER_RIGHT); input.MapAction(EGameAction.PLAYER_ATTACK, EInput.GAMEPAD_TRIGGER_LEFT); break; } } //playerIndicatorP1 = EntityFactory.Create<Entity>(GUID, "PlayerIndicatorP1"); //playerIndicatorP1.AddComponent<TransformComponent>().Init(new Vector3(0, -65, 0)); //piAnimationP1 = playerIndicatorP1.AddComponent<AnimationComponent>(); //piAnimationP1.Init(AssetManager.Get().Find<Texture2D>("PlayerIndicatorAnimationP1"), new Vector2(0.4f, 0.4f)); //piAnimationP1.AddSetting(0, new AnimationSetting(8, 1, 0, 7, false)); //playerIndicatorP1.Disable(); //RangeWeapon weapon = EntityFactory.Create<RangeWeapon>(GUID, "Primary Weapon P1"); //weapon.Init(); //if (Index == PlayerIndex.One) //{ // //GetComponent<ActorPhysicsComponent>().AddJoint(weapon.GetComponent<PhysicsComponent>()); //} MeleeWeapon weapon = EntityFactory.Create <MeleeWeapon>(GUID, "Primary Weapon P1"); if (Index == PlayerIndex.One) { GetComponent <ActorPhysicsComponent>().AddJoint(weapon.GetComponent <PhysicsComponent>()); } }
public static Entity GetCritter(Color color) { float radius = 10f; var critter = new Entity(); var pos = new Vector2(0, 0); var transform = new TransformComponent(critter) { LocalPosition = pos, LocalRotation = new Rotation(MathHelper.PiOver4), LocalDepth = 0.1f, Scale = new Vector2(1, 1) }; var graphics = new GraphicsComponent(critter) { TexturePath = TextureAtlas.CirclePath, Dimensions = new Point((int)(radius * 2), (int)(radius * 2)), Color = color }; var velocity = new VelocityComponent(critter) { RotationalVelocity = 0, Velocity = Vector2.Zero }; var circleCollider = new CircleColliderComponent(critter) { Radius = radius }; var rigidbody = new RigidBodyComponent(critter) { Mass = 0.05f, Restitution = 0.1f }; var drag = new DragComponent(critter) { MovementDragCoefficient = 0.1f, RotationDragCoefficient = 10f }; var movementControl = new MovementControlComponent(critter) { MaxMovementForceNewtons = 10.0f, MaxRotationForceNewtons = 10.0f, MovementMode = MovementMode.TwoWheels, }; var colour = new VisibleColourComponent(critter) { }; var energy = new EnergyComponent(critter) { Energy = 4f }; var reproduction = new ReproductionComponent(critter) { Efficency = 0.7f, ReproductionEnergyCost = 8f, Reproduce = 0, ReproductionThreshold = 0.5f, RequiredRemainingEnergy = 1f, ChildDefinitionId = "Soupling" }; var health = new HealthComponent(critter) { Health = 100, MaxHealth = 100, }; var age = new OldAgeComponent(critter) { MaxAge = 5 * 60 }; var brain = new BrainComponent(critter) { InputMap = new Dictionary <string, string> { { "eye1R", "eye1.EyeComponent.ActivationR" }, { "eye1G", "eye1.EyeComponent.ActivationG" }, { "eye1B", "eye1.EyeComponent.ActivationB" }, { "eye2R", "eye2.EyeComponent.ActivationR" }, { "eye2G", "eye2.EyeComponent.ActivationG" }, { "eye2B", "eye2.EyeComponent.ActivationB" }, { "eye3R", "eye3.EyeComponent.ActivationR" }, { "eye3G", "eye3.EyeComponent.ActivationG" }, { "eye3B", "eye3.EyeComponent.ActivationB" }, { "eye4R", "eye4.EyeComponent.ActivationR" }, { "eye4G", "eye4.EyeComponent.ActivationG" }, { "eye4B", "eye4.EyeComponent.ActivationB" }, { "mouth", "mouth.MouthComponent.Eating" }, { "nosecos", "nose.NoseComponent.CosActivation" }, { "nosesin", "nose.NoseComponent.SinActivation" }, { "health", "HealthComponent.HealthPercent" }, { "myRed", "VisibleColourComponent.RealR" }, { "myGreen", "VisibleColourComponent.RealG" }, { "myBlue", "VisibleColourComponent.RealB" }, { "Random", "Random" }, { "Bias", "Bias" }, }, //OutputMap = new Dictionary<string, string> // { // {"forwardback", "MovementControlComponent.WishForceForward" }, // {"rotation", "MovementControlComponent.WishRotForce" }, // {"reproduce", "ReproductionComponent.Reproduce" }, // {"red", "VisibleColourComponent.R" }, // {"green", "VisibleColourComponent.G" }, // {"blue", "VisibleColourComponent.B" }, // {"attack", "weapon.WeaponComponent.Activation" } // } OutputMap = new Dictionary <string, string> { { "wheelLeft", "MovementControlComponent.WishWheelLeftForce" }, { "wheelRight", "MovementControlComponent.WishWheelRightForce" }, { "reproduce", "ReproductionComponent.Reproduce" }, { "red", "VisibleColourComponent.R" }, { "green", "VisibleColourComponent.G" }, { "blue", "VisibleColourComponent.B" }, { "attack", "weapon.WeaponComponent.Activation" } } }; critter.AddComponents(transform, graphics, velocity, circleCollider, rigidbody, drag, movementControl, reproduction, colour, energy, health, age, brain); var eye1 = Eye.GetEye(Color.White, MathHelper.ToRadians(30)); eye1.Tag = "eye1"; critter.AddChild(eye1); var eye2 = Eye.GetEye(Color.White, MathHelper.ToRadians(-30)); eye2.Tag = "eye2"; critter.AddChild(eye2); var eye3 = Eye.GetEye(Color.White, MathHelper.ToRadians(90)); eye3.Tag = "eye3"; critter.AddChild(eye3); var eye4 = Eye.GetEye(Color.White, MathHelper.ToRadians(-90)); eye4.Tag = "eye4"; critter.AddChild(eye4); var mouth = Mouth.GetMouth(Color.White); critter.AddChild(mouth); mouth.GetComponent <TransformComponent>().LocalPosition = new Vector2(15, 0); var nose = Nose.GetNose(Color.White, 0, 10); nose.Tag = "nose"; critter.AddChild(nose); var weapon = Weapon.GetWeapon(Color.White); weapon.Tag = "weapon"; critter.AddChild(weapon); weapon.GetComponent <TransformComponent>().LocalPosition = new Vector2(30, 0); return(critter); }