public override IEnumerable<Barebones.Dependencies.IDependency> GetDependencies() { yield return new Dependency<PhysicsComponent>(item => m_Physics = item); yield return new Dependency<Recrutable>(item => m_Recrutable = item); yield return new Dependency<JointComponent>(item => m_Joint = item); yield return new Dependency<GameplayManager>(item => m_GM = item); }
public PhysicsComponent(MyVoxelDebugInputComponent comp) { m_comp = comp; Static = this; AddShortcut(MyKeys.NumPad8, true, false, false, false, () => "Clear boxes", () => { m_list.ClearList(); return false; }); }
public PhysDuck(Path res) { Shape shape = new BoxShape(new Vector(1.0, 1.0, 1.0)); RigidBody body = new RigidBody(shape); Texture txt = Texture.Load(res["Textures"]["texture.bmp"]); body.Position = new Vector(0.0, 0.0, 5.0); this._Phys = new PhysicsComponent(body); this._Duck = new ModelComponent(Model.LoadFile(res, "candle.obj"), this._Phys, txt); this._Duck.Model.Color = Color.RGB(1.0, 0.0, 0.0); }
public TestOldMan(int playerNumber = 0) { mPlayerNumber = playerNumber; mPosition = new PositionComponent(this, 100, 100); mRotation = new RotationComponent(this); //mRenderable = new RenderableComponent(this); mPhysics = new PhysicsComponent(this); mAnimated = new AnimatedComponent(this); mInput = new InputComponent(this); mController = new PlayerControllerComponent(this); mHealth = new HealthComponent(this, 100.0f); }
public Player(Jitter.World World) { this.Position = new Vector(0.0, 0.0, 0.0); this._Body = new RigidBody(new BoxShape(0.5f, 1.7f, 0.5f)); //this._Body.UseUserMassProperties(new JMatrix(), 1.0f); this._Body.Restitution = 0.0f; this._Body.Position = new Vector(0.0, 0.0, 0.0); //this._Controller = new CharacterController(World, this._Body); //this._Controller.Position = new Vector(0.0, 0.0, 10.0); this._Phys = new PhysicsComponent(this._Body); //World.AddConstraint(this._Controller); }
public GroundTest(Path res, Vector2d Size) { Shape shape = new BoxShape(new Vector(Size.X, Size.Y, 1.0)); RigidBody body = new RigidBody(shape); body.Mass = 99999f; body.IsStatic = true; body.Position = new Vector(0.0, 0.0, 0.0); this._Phys = new PhysicsComponent(body); this._Phys.Scale = new Vector(Size.X, Size.Y, 1.0); Texture txt = Texture.Load(res["Textures"]["texture.bmp"]); this._Duck = new ModelComponent(Model.LoadFile(res, "cube.obj"), this._Phys, txt); this._Duck.Model.Color = Color.RGB(1.0, 1.0, 1.0); }
private static void CreateEntitiesInArray() { for (int i = 0; i < numberOfEntities; i++) { PhysicsComponent p = new PhysicsComponent(); AIComponent ai = new AIComponent(); RenderComponent r = new RenderComponent(); _physicsComponents[i] = p; _aiComponents[i] = ai; _renderComponents[i] = r; GameEntity g = new GameEntity(p, ai, r); _entities[i] = g; } }
public PhysicsElementInfo(PhysicsComponent component, SkeletonUpdater skeleton) { shape = component.ColliderShape; var rigidbodyComponent = component as RigidbodyComponent; isKinematic = rigidbodyComponent != null && rigidbodyComponent.IsKinematic; colliderShapes = component.ColliderShapes != null?CloneDescs(component.ColliderShapes) : null; var componentBase = component as PhysicsSkinnedComponentBase; boneName = componentBase?.NodeName; this.skeleton = skeleton; boneIndex = componentBase?.BoneIndex ?? -1; var triggerBase = component as PhysicsTriggerComponentBase; isTrigger = triggerBase != null && triggerBase.IsTrigger; }
/// <summary> /// Applies the velocity of a moving object onto the player if the player is standing on it. /// </summary> /// <param name="collideObject"></param> /// <param name="normalForce"></param> private void InheritVelocity(Transform collideObject, ref Vector3 normalForce) { otherPhysics = collideObject.GetComponent <PhysicsComponent>(); if (otherPhysics == null) { return; } normalForce = normalForce.normalized * (normalForce.magnitude + Vector3.Project(otherPhysics.GetVelocity(), normalForce.normalized).magnitude); Vector3 forceInDirection = Vector3.ProjectOnPlane(velocity - otherPhysics.GetVelocity(), normalForce.normalized); Vector3 friction = -forceInDirection.normalized * normalForce.magnitude; if (friction.magnitude > forceInDirection.magnitude) { friction = friction.normalized * forceInDirection.magnitude; } velocity += friction; }
public Entity CreateDebugEntity(PhysicsComponent component, bool alwaysAddOffset = false) { if (component?.ColliderShape == null) { return(null); } if (component.DebugEntity != null) { return(null); } var debugEntity = new Entity(); var skinnedElement = component as PhysicsSkinnedComponentBase; if (skinnedElement != null && skinnedElement.BoneIndex != -1) { Vector3 scale, pos; Quaternion rot; skinnedElement.BoneWorldMatrixOut.Decompose(out scale, out rot, out pos); debugEntity.Transform.Position = pos; debugEntity.Transform.Rotation = rot; } else { Vector3 scale, pos; Quaternion rot; component.Entity.Transform.WorldMatrix.Decompose(out scale, out rot, out pos); debugEntity.Transform.Position = pos; debugEntity.Transform.Rotation = rot; } var shouldNotAddOffset = component is RigidbodyComponent || component is CharacterComponent; //don't add offset for non bone dynamic and kinematic as it is added already in the updates var colliderEntity = CreateChildEntity(component, component.ColliderShape, alwaysAddOffset || !shouldNotAddOffset); if (colliderEntity != null) { debugEntity.AddChild(colliderEntity); } return(debugEntity); }
private void MoveSingulo(SingularityComponent singularity, PhysicsComponent physics) { if (singularity.Level <= 1) { return; } // TODO: Could try gradual changes instead but for now just try to replicate var pushVector = new Vector2(_robustRandom.Next(-10, 10), _robustRandom.Next(-10, 10)); if (pushVector == Vector2.Zero) { return; } physics.LinearVelocity = Vector2.Zero; physics.LinearVelocity = pushVector.Normalized * 2; }
private void MoveSingulo(ServerSingularityComponent singularity, PhysicsComponent physics) { // TODO: Need to make this events instead. if (singularity.Level <= 1) { physics.BodyStatus = BodyStatus.OnGround; return; } // TODO: Could try gradual changes instead var pushAngle = _robustRandom.NextAngle(); var pushStrength = _robustRandom.NextFloat(0.75f, 1.0f); physics.LinearVelocity = Vector2.Zero; physics.BodyStatus = BodyStatus.InAir; physics.ApplyLinearImpulse(pushAngle.ToVec() * (pushStrength + 10f / Math.Min(singularity.Level, 4) * physics.Mass)); // TODO: Speedcap it probably? }
public override async Task Execute() { Trigger.ProcessCollisions = true; while (Game.IsRunning) { Collision firstCollision = await Trigger.NewCollision(); PhysicsComponent otherCollider = Trigger == firstCollision.ColliderA ? firstCollision.ColliderB : firstCollision.ColliderA; CockroachScript isCockroach = otherCollider.Entity.Get <CockroachScript>(); if (isCockroach != null) { CollisionStarted(isCockroach); } } }
public void controlNamedPair(PhysicsComponent @object, string name, float relative) { IList <ThrusterResponsibility.ThrusterBinding> thrusterBindings; if (!thrusterResponsibility.physicsObjectIdToThrusters.TryGetValue(@object.id, out thrusterBindings)) { return; } foreach (var iThrusterBinding in thrusterBindings.Where(v => v.tag == name + "+")) { iThrusterBinding.relative += relative; } foreach (var iThrusterBinding in thrusterBindings.Where(v => v.tag == name + "-")) { iThrusterBinding.relative -= relative; } }
void Uncrouch(PositionComponent position, PhysicsComponent physics, StackableActorComponent actor) { var colliderSize = physics.Collider.Size; var oldH = colliderSize.Y; colliderSize.Y = actor.Height; physics.Collider.Size = colliderSize; position.Position.Y -= (colliderSize.Y - oldH) / 2; actor.Crouching = false; if (actor.StackedPrevious == null) { SoundController.PlaySound(Resources.Sounds.Crouch); } }
public void ConnectObject(JointConnectionComponent attachmentComponent, Vector3 connectionPoint) { GameObject target = attachmentComponent.gameObject; PhysicsComponent targetPhysics = attachmentComponent.Physics; if (connectedGameObjects.Contains(target) || targetPhysics.IsConnectedToJoint) { return; } Joint joint = CreateJoint(); SetJointAnchorPoints(joint, attachmentComponent, connectionPoint); OverrideRigidbodySettings(targetPhysics.Rigidbody); joint.connectedBody = targetPhysics.Rigidbody; RegisterConnectedObject(target, joint, targetPhysics); }
public Projectile(Entity source, Vector location, Vector velocity, int power, int maxDistance) { this.sprite = Services.Sprites["projectile"]; this.source = source; this.Power = power; this.maxDistance = maxDistance; this.creationLocation = location; Physics = Services.Game.Physics.CreateComponent(this); Physics.Velocity = velocity; Physics.applyGravity = false; Physics.checkType = CollisionCheckType.BlocksProjectiles; CreateTrailEmitter(); Location = location; Size = new Vector(8, 8); }
private Entity CreateFireball() { Entity entity = new Entity(); entity.SetName("Fireball"); PhysicsComponent pc = new PhysicsComponent { _forces = new List <Vector2>(), airFrictionTweaker = 0.5f, useAirFriction = true, useGravity = true, masse = 1 }; entity.AddComponent(pc); entity.AddComponent(new RenderComponent { image = "fireball.png", size = new Vector2(fireballX, fireballY) }); int random = new Random().Next(10, 40); entity.AddComponent(new VelocityComponent { maxVelocity = 10000, velocity = new Vector2(-20 * random, -20 * random) }); entity.AddComponent(new BoxCollisionComponent { isTrigger = false, size = new Vector2(fireballX, fireballY) }); entity.AddComponent(new PositionComponent { orientation = 0f, position = new Vector2(bowserX - fireballX - 10, bowserY - 10 - fireballY) }); entity.AddComponent(new ScriptComponent { Script = new FireballScript() }); return(entity); }
private void ContactRemoval(ContactPoint contact, PhysicsComponent component0, PhysicsComponent component1) { Collision existingPair = null; foreach (var x in component0.Collisions) { if (x.InternalEquals(component0, component1)) { existingPair = x; break; } } if (existingPair == null) { #if DEBUG //should not happen? throw new Exception("Pair not present."); #else return; #endif } if (existingPair.Contacts.Contains(contact)) { existingPair.Contacts.Remove(contact); removedContactsCache.Add(contact); contactToCollision.Remove(contact); if (existingPair.Contacts.Count == 0) { component0.Collisions.Remove(existingPair); component1.Collisions.Remove(existingPair); removedCollisionsCache.Add(existingPair); } } else { #if DEBUG //should not happen? throw new Exception("Contact not in pair."); #endif } }
//--------------------------------------------------------------------------- public void AddRect(int x, int y, int width, int height) { PhysicsComponent physics = GetComponent <PhysicsComponent>(); if (physics != null) { Fixture fixture = FixtureFactory.AttachRectangle(width * 64.0f / Unit, height * 64.0f / Unit, 0, new Vector2((x + width / 2.0f) * 64.0f / Unit, (y + height / 2.0f) * 64.0f / Unit), physics.Body, Entity); fixture.CollisionCategories = m_CategoryMapping[CollisionCategory]; fixture.CollidesWith = m_CategoryMapping[CollidesWith]; fixture.IsSensor = true; fixture.OnCollision += OnCollision; fixture.OnSeparation += OnSeparation; Fixtures.Add(fixture); Rects.Add(new Rectangle(x * 64, y * 64, width * 64, height * 64)); AreaManager.Get().AddAreaRect(Entity, x, y, width, height); } }
public void InitComponent(int entityID, float accelerationX, float accelerationY, float gravityX, float gravityY, float mass, float velocityX, float velocityY) { // Arrange. PhysicsComponent component; // Act. component = new PhysicsComponent(entityID, accelerationX, accelerationY, gravityX, gravityY, mass, velocityX, velocityY); // Assert. Assert.IsTrue(entityID == component.EntityID && Math.Abs(accelerationX - component.AccelerationX) < float.Epsilon && Math.Abs(accelerationY - component.AccelerationY) < float.Epsilon && Math.Abs(gravityX - component.GravityX) < float.Epsilon && Math.Abs(gravityY - component.GravityY) < float.Epsilon && Math.Abs(mass - component.Mass) < float.Epsilon && Math.Abs(velocityX - component.VelocityX) < float.Epsilon && Math.Abs(velocityY - component.VelocityY) < float.Epsilon); }
private void MoveSingulo(ServerSingularityComponent singularity, PhysicsComponent physics) { // To prevent getting stuck, ServerSingularityComponent will zero the velocity of a singularity when it goes to a level <= 1 (see here). if (singularity.Level <= 1) { return; } // TODO: Could try gradual changes instead but for now just try to replicate var pushVector = new Vector2(_robustRandom.Next(-10, 10), _robustRandom.Next(-10, 10)); if (pushVector == Vector2.Zero) { return; } physics.LinearVelocity = Vector2.Zero; physics.LinearVelocity = pushVector.Normalized * 2; }
public Box2 GetWorldAABB(PhysicsComponent body, TransformComponent xform, EntityQuery <TransformComponent> xforms, EntityQuery <FixturesComponent> fixtures) { var(worldPos, worldRot) = xform.GetWorldPositionRotation(xforms); var transform = new Transform(worldPos, (float)worldRot.Theta); var bounds = new Box2(transform.Position, transform.Position); foreach (var fixture in fixtures.GetComponent(body.Owner).Fixtures.Values) { for (var i = 0; i < fixture.Shape.ChildCount; i++) { var boundy = fixture.Shape.ComputeAABB(transform, i); bounds = bounds.Union(boundy); } } return(bounds); }
private Entity CreateFireball() { Entity entity = new Entity(); entity.SetName("Fireball"); PhysicsComponent pc = new PhysicsComponent { _forces = new List <Vector2>(), airFrictionTweaker = 0.5f, useAirFriction = true, useGravity = true, masse = 1 }; pc._forces.Add(new Vector2(0, -1500000)); entity.AddComponent(pc); entity.AddComponent(new RenderComponent { image = "fireball.png", size = new Vector2(fireballX, fireballY) }); entity.AddComponent(new VelocityComponent { maxVelocity = 700 }); entity.AddComponent(new BoxCollisionComponent { isTrigger = false, size = new Vector2(fireballX, fireballY) }); entity.AddComponent(new PositionComponent { orientation = 0f, position = new Vector2(lavaMiddleX - fireballX / 2, lavaY - 10 - fireballY) }); entity.AddComponent(new ScriptComponent { Script = new FireballScript() }); return(entity); }
protected void HandleMobMovement(IMoverComponent mover, PhysicsComponent physicsComponent, IMobMoverComponent mobMover) { // TODO: Look at https://gameworksdocs.nvidia.com/PhysX/4.1/documentation/physxguide/Manual/CharacterControllers.html?highlight=controller as it has some adviceo n kinematic controllersx if (!UseMobMovement(_broadPhaseSystem, physicsComponent, _physicsManager)) { return; } var transform = mover.Owner.Transform; var(walkDir, sprintDir) = mover.VelocityDir; var weightless = transform.Owner.IsWeightless(_physicsManager); // Handle wall-pushes. if (weightless) { // No gravity: is our entity touching anything? var touching = IsAroundCollider(_broadPhaseSystem, transform, mobMover, physicsComponent); if (!touching) { transform.LocalRotation = physicsComponent.LinearVelocity.GetDir().ToAngle(); return; } } // Regular movement. // Target velocity. var total = (walkDir * mover.CurrentWalkSpeed + sprintDir * mover.CurrentSprintSpeed); if (total != Vector2.Zero) { // This should have its event run during island solver soooo transform.DeferUpdates = true; transform.LocalRotation = total.GetDir().ToAngle(); transform.DeferUpdates = false; HandleFootsteps(mover, mobMover); } physicsComponent.LinearVelocity = total; }
private void UpdateEntity(Entity entity) { PhysicsComponent entityPhysics = null; for (int i = 0; i < entity.components.Count; i++) { if (typeof(PhysicsComponent) == entity.components.ElementAt(i).GetType()) { entityPhysics = (PhysicsComponent)entity.components.ElementAt(i); } } //Il faut que l'entité possède un composant de physique if (entityPhysics != null) { entityPhysics.Move(deltaTime); CheckForCollisions(entityPhysics, entity.id); } }
public void recalcAngularAccelerationOfThrustersForObjectId(PhysicsEngine physicsEngine, ulong objectId) { Trace.Assert(physicsObjectIdToThrusters.ContainsKey(objectId)); if (!physicsObjectIdToThrusters.ContainsKey(objectId)) { // indicates a bug in some code because we expect this to be the case but it is not fatal // TODO< log > return; } IList <ThrusterBinding> thrusterBindings = physicsObjectIdToThrusters[objectId]; foreach (ThrusterBinding iThrusterBinding in thrusterBindings) { PhysicsComponent objectPhysicsComponent = physicsEngine.getObjectById(objectId); iThrusterBinding.additionalInformation.cachedAngularAccelerationOnObject = objectPhysicsComponent.calcAngularAccelerationOfRigidBodyForAppliedForce(iThrusterBinding.attachedForce.objectLocalPosition, iThrusterBinding.localDirection.scale(iThrusterBinding.maximalForce)); } }
public void SetLinearVelocity(PhysicsComponent body, Vector2 velocity) { if (body.BodyType == BodyType.Static) { return; } if (Vector2.Dot(velocity, velocity) > 0.0f) { body.Awake = true; } if (body._linearVelocity.EqualsApprox(velocity, 0.0001f)) { return; } body._linearVelocity = velocity; body.Dirty(EntityManager); }
private void DummyLoadHero(Vector2 pos) { // Load the Hero Hero hero = new Hero(GameSession.NextID); PhysicsComponent pc = new PhysicsComponent(hero.Id); pc.Type = PhysicsComponent.PhysicsType.NONE; pc.Hitbox = MathUtils.GetRectangleHitbox(new Vector2(0, 1), 1, 1); pc.Position = pos; _gs.PhysicsManager.Add(pc); RenderComponent rc = new RenderComponent(hero.Id); rc.SpriteID = 0; _gs.RenderManager.Add(rc); _gs.EntityManager.Add(hero); _gs.EntityManager.PlayerId = hero.Id; }
void OnTriggerEnter(Collider other) { collidingPhysComp = other.GetComponent <PhysicsComponent>(); if (collidingPhysComp.GetVelocity().magnitude >= destructionVelocity * Time.deltaTime) { //Particlescript start var obj = Instantiate(explosionEffects, destructibleObject.GetComponent <Transform>().position, Quaternion.identity); obj.AddComponent <ParticleSplash>(); //Particlescript stop //spawnDebris(); Object.Destroy(destructibleObject); //destructibleObject.GetComponent<Renderer>().enabled = false; } else { destructibleObject.layer = LayerMask.NameToLayer("Scoop"); } }
//--------------------------------------------------------------------------- public void Init() { IEntity parent = GetParent(); if (parent != null) { TransformComponent parentTransform = parent.GetComponent <TransformComponent>(); if (parentTransform != null) { parentTransform.OrientationChanged += OnParentOrientationChanged; } PhysicsComponent parentPhysics = parent.GetComponent <PhysicsComponent>(); PhysicsComponent physics = GetComponent <PhysicsComponent>(); if (parentPhysics != null) { parentPhysics.AddJoint(physics); } } }
public MainBase() { Health = 100; Size = 8; ProceduralCube shape = new ProceduralCube(); shape.Scale(Size); shape.SetColor(Color.Blue); AddComponent(new RenderGeometryComponent(BufferBuilder.VertexBufferBuild(shape), BufferBuilder.IndexBufferBuild(shape), shape.PrimitiveCount)); AddComponent(new EffectRenderComponent(EffectLoader.LoadSM5Effect("flatshaded"))); AddComponent(new ShadowCasterComponent()); var physicsComponent = new PhysicsComponent(false, false, PhysicsMeshType.box); AddComponent(physicsComponent); SystemCore.GameObjectManager.AddAndInitialiseGameObject(this); GetComponent <PhysicsComponent>().PhysicsEntity.CollisionInformation.Events.DetectingInitialCollision += Events_DetectingInitialCollision; }
public PlayerMovementScript(Camera camera, PhysicsComponent physics, float speed = 3f, float jump = 0.14f, float mouseSensitivity = 0.25f) { _camera = camera; _mouseSensitivity = mouseSensitivity; _speed = speed; Actions.Add(Key.W, delta => _moveDirection += Vector3.UnitZ); Actions.Add(Key.S, delta => _moveDirection -= Vector3.UnitZ); Actions.Add(Key.A, delta => _moveDirection -= Vector3.UnitX); Actions.Add(Key.D, delta => _moveDirection += Vector3.UnitX); Actions.Add(Key.Space, delta => { if (physics.IsPlatformCollision) { physics.AddImpulse(Vector3.UnitY * jump); } }); _inputController = InputController.GetInstance(); }
public MobEntity(Game game, string model) : base(game) { StepSize = 0.5f; SetModel(model); interp = new LocalInterpComponent(game, this); collisions = new CollisionsComponent(game, this); physics = new PhysicsComponent(game, this); physics.hacks = hacks; physics.collisions = collisions; if (Utils.CaselessEq(model, "pig") || Utils.CaselessEq(model, "sheep")) { ai = new FleeAI(game, this); } else { ai = new HostileAI(game, this); } }
private void OnPhysicsInit(EntityUid uid, PhysicsComponent component, ComponentInit args) { if (component.BodyType == BodyType.Static) { component._awake = false; } var xform = Transform(uid); // TODO: Ordering fuckery need a new PR to fix some of this stuff if (xform.MapID != MapId.Nullspace) { component.PhysicsMap = EntityManager.GetComponent <SharedPhysicsMapComponent>(_mapManager.GetMapEntityId(xform.MapID)); } Dirty(uid); // Yeah yeah TODO Combine these // Implicitly assume that stuff doesn't cover if a non-collidable is initialized. if (component.CanCollide) { if (component.Awake) { EntityManager.EventBus.RaiseEvent(EventSource.Local, new PhysicsWakeMessage(component)); } if (!_containerSystem.IsEntityInContainer(uid, xform)) { // TODO: Probably a bad idea but ehh future sloth's problem; namely that we have to duplicate code between here and CanCollide. EntityManager.EventBus.RaiseLocalEvent(uid, new CollisionChangeMessage(component, uid, component._canCollide)); } } else { component._awake = false; } var startup = new PhysicsInitializedEvent(uid); EntityManager.EventBus.RaiseLocalEvent(uid, ref startup); }
// Handle dialogue private void handleDialogue(string levelUid, PhysicsComponent playerPhysicsComponent, bool inDialogue) { DialogueSystem dialogueSystem = _systemManager.getSystem(SystemType.Dialogue) as DialogueSystem; List <int> dialogueEntities = _entityManager.getEntitiesPosessing(levelUid, ComponentType.CharacterDialogue); for (int i = 0; i < dialogueEntities.Count; i++) { PhysicsComponent otherPhysicsComponent = _entityManager.getComponent(levelUid, dialogueEntities[i], ComponentType.Physics) as PhysicsComponent; Vector2 relative = playerPhysicsComponent.body.Position - otherPhysicsComponent.body.Position; float distanceSq = relative.LengthSquared(); if (_newKeyState.IsKeyDown(Keys.E) && _oldKeyState.IsKeyUp(Keys.E)) { if (!inDialogue && distanceSq <= 1f) { CharacterDialogueComponent dialogueComponent = _entityManager.getComponent(levelUid, dialogueEntities[i], ComponentType.CharacterDialogue) as CharacterDialogueComponent; dialogueSystem.beginDialogue(levelUid, PlayerSystem.PLAYER_ID, dialogueEntities[i], dialogueComponent); } } else { TooltipComponent tooltipComponent = _entityManager.getComponent(levelUid, dialogueEntities[i], ComponentType.Tooltip) as TooltipComponent; if (tooltipComponent == null) { if (!inDialogue && distanceSq <= 1f) { _entityManager.addComponent(levelUid, dialogueEntities[i], new TooltipComponent("[Use] Talk", otherPhysicsComponent.body, 1f)); } } else { if (inDialogue || distanceSq > 1f) { _entityManager.removeComponent(levelUid, dialogueEntities[i], ComponentType.Tooltip); } } } } }
public bool HasChanged(PhysicsComponent component, SkeletonUpdater skeletonUpdater) { var componentBase = component as PhysicsSkinnedComponentBase; var triggerBase = component as PhysicsTriggerComponentBase; var newBoneName = componentBase?.NodeName; var newIndex = componentBase?.BoneIndex ?? -1; var rb = component as RigidbodyComponent; return(shape != component.ColliderShape || (colliderShapes == null && component.ColliderShapes != null) || (colliderShapes != null && component.ColliderShapes == null) || DescsAreDifferent(colliderShapes, component.ColliderShapes) || component.ColliderShapeChanged || (rb != null && isKinematic != rb.IsKinematic) || skeleton != skeletonUpdater || boneIndex != newIndex || boneIndex == -1 && skeletonUpdater != null && !string.IsNullOrEmpty(boneName) || //force recreation if we have a skeleton?.. wrong name tho is also possible... triggerBase != null && triggerBase.IsTrigger != isTrigger || shape != null && component.DebugEntity == null || //force recreation in this case as well boneName != newBoneName); }
public TestNess(int playerNumber = 0) { mPlayerNumber = playerNumber; mPosition = new PositionComponent(this, 100, 100); mRotation = new RotationComponent(this); //mRenderable = new RenderableComponent(this); mPhysics = new PhysicsComponent(this); mAnimated = new AnimatedComponent(this); mInput = new InputComponent(this); mController = new PlayerControllerComponent(this); //switch (mPlayerNumber) //{ // case 0: // // Player 0 means no human control. // break; // case 1: // mInput.PlayerIndex = PlayerIndex.One; // break; // case 2: // mInput.PlayerIndex = PlayerIndex.Two; // break; // case 3: // mInput.PlayerIndex = PlayerIndex.Three; // break; // case 4: // mInput.PlayerIndex = PlayerIndex.Four; // break; //} mHealth = new HealthComponent(this, 100.0f); }
protected override void ApplyPhysics(PhysicsComponent component) { component.YVelocity += _currentElapsedTime * ConfigSettings.GRAVITY_PPS; component.XVelocity = CheckMaxVelocity(component.XVelocity, ConfigSettings.MAX_X_VELOCITY); component.YVelocity = CheckMaxVelocity(component.YVelocity, ConfigSettings.MAX_Y_VELOCITY); }
public override IEnumerable<Barebones.Dependencies.IDependency> GetDependencies() { yield return new Dependency<PhysicsComponent>(item => m_Physics = item); yield return new Dependency<Recrutable>(item => m_Recrutable = item); }
private void CreatePhysicsComponent(string motionType) { switch (motionType) { case "None": break; case "Pendulum": Point pivotPoint = new Point((int)Math.Round(Position.X), (int)Math.Round(Position.Y - 200)); Point weightPoint = new Point((int)Math.Round(Position.X + 200), (int)Math.Round(Position.Y)); PhysicsComponent = new PendulumPhysicsComponent(Engine, pivotPoint, weightPoint); break; default: throw new Exception("Physics component type not recognized"); } }
private bool isCollidingWithPlayer(PhysicsComponent phys) { return player.physComp.hitBox.isTouching(phys.hitBox); }
public void addStaticObject(PhysicsComponent newComponent) { staticObjects.Add(newComponent); }
public void addDoorObject(PhysicsComponent newComponent) { door = newComponent; }
private void StopPlayerMotionOnCollision(PhysicsComponent phys) { HitboxHit result = player.physComp.hitBox.Intersects(phys.hitBox); Vector2 offset = Vector2.Zero; switch (result) { case HitboxHit.Bottom: offset.Y -= player.physComp.hitBox.overall.Bottom - phys.hitBox.overall.Top; player.physComp.velocity.Y = 0; player.IsJumping = false; break; case HitboxHit.Right: offset.X -= player.physComp.hitBox.overall.Right - phys.hitBox.overall.Left; player.physComp.velocity.X = 0; break; case HitboxHit.Left: offset.X += phys.hitBox.overall.Right - player.physComp.hitBox.overall.Left; player.physComp.velocity.X = 0; break; case HitboxHit.Top: offset.Y += phys.hitBox.overall.Bottom - player.physComp.hitBox.overall.Top; player.physComp.velocity.Y = 0; break; case HitboxHit.None: return; } player.Location += offset; }
private bool isComponentCloseEnoughToPlayer(PhysicsComponent phys) { if (phys == null) return false; Vector2 diffVector = phys.hitBox.overall.Center.ToVector2() - player.physComp.hitBox.overall.Center.ToVector2(); if (player.physComp.hitBox.isNearby(phys.hitBox)) return true; else return false; }
public override void Dispose(bool disposing) { if (enemySound != null) { enemySound.Stop(AudioStopOptions.Immediate); enemySound.Dispose(); enemySound = null; } if (animation != null) { animation.Dispose(disposing); animation = null; } if (deathAnimation != null) { deathAnimation.Dispose(disposing); deathAnimation = null; } if (deathLight != null) { deathLight.Dispose(disposing); deathLight = null; } enemyPhysicsComponent.Dispose(true); enemyPhysicsComponent = null; base.Dispose(disposing); }
// for this to work, the components should be passed as pointers // this is NOT possible in C# // can use pass by reference or unsafe context ... but still not the same as in C++ public GameEntity(PhysicsComponent physics, AIComponent ai, RenderComponent render) { Physics = physics; Ai = ai; Render = render; }
public void ClearStage() { door = null; staticObjects.Clear(); mechanicsObjects.Clear(); }