public override void Update(List <Component> components) { foreach (FrogEnemyComponent frog in components) { frog.LogicStateMachine.Update(); frog.AttackDelay.Update(); var actor = frog.Owner.GetComponent <StackableActorComponent>(); // Damaging the player. if ( !actor.Crouching && actor.LogicStateMachine.CurrentState == ActorStates.InAir && actor.StackedNext == null ) { var players = SceneMgr.CurrentScene.GetEntityListByComponent <PlayerComponent>(); var physics = frog.Owner.GetComponent <PhysicsComponent>(); foreach (var playerEntity in players) { var player = playerEntity.GetComponent <PlayerComponent>(); var playerActor = playerEntity.GetComponent <StackableActorComponent>(); if (playerActor.Crouching && actor.LogicStateMachine.CurrentState != ActorStates.Stacked) { continue; } var position = frog.Owner.GetComponent <PositionComponent>(); var playerPosition = playerEntity.GetComponent <PositionComponent>(); var playerPhysics = playerEntity.GetComponent <PhysicsComponent>(); // Setting up colliders. physics.Collider.Position = position.Position; physics.Collider.PreviousPosition = position.PreviousPosition; playerPhysics.Collider.Position = playerPosition.Position; playerPhysics.Collider.PreviousPosition = playerPosition.PreviousPosition; // Seting up colliders. if (CollisionDetector.CheckCollision(physics.Collider, playerPhysics.Collider)) { StackableActorSystem.Damage(playerEntity.GetComponent <StackableActorComponent>()); } } } // Damaging the player. } }
public Entity Make(TiledObject obj, Layer layer, MapBuilder map) { var gato = ActorBaseFactory.Make(obj, layer, map, Tag); var master = gato; for (var i = 0; i < int.Parse(obj.Properties["stack"]); i += 1) { var slave = Entity.CreateFromTemplate(layer, Tag); var slaveActor = slave.GetComponent <StackableActorComponent>(); slaveActor.Silent = true; StackableActorSystem.StackEntity(master.GetComponent <StackableActorComponent>(), slaveActor); master = slave; slave.GetComponent <PositionComponent>().Position = obj.Position - Vector2.UnitY * 32; // Fixes cats colliding with the ground. slave.GetComponent <PositionComponent>().PreviousPosition = obj.Position - Vector2.UnitY * 32; } return(gato); }
public override void Update(List <Component> components) { foreach (CatEnemyComponent gato in components) { var physics = gato.Owner.GetComponent <PhysicsComponent>(); var actor = gato.Owner.GetComponent <StackableActorComponent>(); actor.LeftAction = (gato.Direction == -1); actor.RightAction = (gato.Direction == 1); if (actor.LogicStateMachine.CurrentState == ActorStates.OnGround) { var position = gato.Owner.GetComponent <PositionComponent>(); // Checking if there is a wall next to us. physics.Collider.Position = position.Position + Vector2.UnitX * gato.Direction * (physics.Collider.Size.X / 2 + 1); if (physics.CollisionH == gato.Direction) { gato.Direction *= -1; actor.Orientation = gato.Direction; } // Checking if there is a wall next to us. else { // Checking if there is a pit below us. var collider = new RectangleCollider(); collider.Size = Vector2.One; collider.Position = position.Position + (physics.Collider.Size / 2 + Vector2.One) * new Vector2(gato.Direction, 1); if (PhysicsSystem.CheckCollision(gato.Owner, collider) == null) { gato.Direction *= -1; actor.Orientation = gato.Direction; } // Checking if there is a pit below us. } } // Damaging the player. if ( ( actor.StackOwner == null || ( actor.StackOwner != null && !actor.StackOwner.HasComponent <PlayerComponent>() ) ) && actor.LogicStateMachine.CurrentState != ActorStates.Dead ) { var players = SceneMgr.CurrentScene.GetEntityListByComponent <PlayerComponent>(); foreach (var playerEntity in players) { var player = playerEntity.GetComponent <PlayerComponent>(); var playerActor = playerEntity.GetComponent <StackableActorComponent>(); if (playerActor.Crouching && actor.LogicStateMachine.CurrentState != ActorStates.Stacked) { continue; } var position = gato.Owner.GetComponent <PositionComponent>(); var playerPosition = playerEntity.GetComponent <PositionComponent>(); var playerPhysics = playerEntity.GetComponent <PhysicsComponent>(); // Setting up colliders. physics.Collider.Position = position.Position; physics.Collider.PreviousPosition = position.PreviousPosition; playerPhysics.Collider.Position = playerPosition.Position; playerPhysics.Collider.PreviousPosition = playerPosition.PreviousPosition; // Seting up colliders. if (CollisionDetector.CheckCollision(physics.Collider, playerPhysics.Collider)) { StackableActorSystem.Damage(playerEntity.GetComponent <StackableActorComponent>()); } } } // Damaging the player. } }