コード例 #1
0
 // Constructor based on hit-collision intersection
 private HitInformation(HitInformation info, ModelReference entityId)
 {
     this.hitData      = info.hitData;
     this.intersection = info.intersection;
     this.collisionId  = info.collisionId;
     this.entityId     = entityId;
 }
コード例 #2
0
 // Create a default Game Entity model
 public GameEntityModel(
     State state,
     string characterName,
     string animationName,
     string viewModelName,
     PhysicWorldModel worldModel,
     Model inputModel,
     FixedVector3 position,
     FixedVector3 stepTolerance,
     string controllerFactoryId,
     string viewFactoryId,
     int updatingOrder
     ) : base(controllerFactoryId, viewFactoryId, updatingOrder)
 {
     physicsModelId = state.AddModel(new PhysicPointModel(this.Index, position, stepTolerance));
     worldModel.pointModels.Add(physicsModelId);
     animationModelId = state.AddModel(new AnimationModel(this.Index, characterName, animationName, viewModelName));
     if (inputModel != null)
     {
         inputModelId = state.AddModel(inputModel);
     }
     else
     {
         inputModelId = new ModelReference(ModelReference.InvalidModelIndex);
     }
     anchoredEntities = new List <ModelReference>();
     ownedEntities    = new List <ModelReference>();
     customVariables  = new Dictionary <string, int>();
     mIsFacingRight   = true;           // default face objects to the right
 }
コード例 #3
0
 public GameEntityModel(
     State state,
     PhysicWorldModel worldModel,
     PhysicPointModel physicsModel,
     AnimationModel animationModel,
     Model inputModel,
     string controllerFactoryId,
     string viewFactoryId,
     int updatingOrder
     ) : base(controllerFactoryId, viewFactoryId, updatingOrder)
 {
     animationModel.ownerId = this.Index;
     physicsModel.ownerId   = this.Index;
     physicsModelId         = state.AddModel(physicsModel);
     worldModel.pointModels.Add(physicsModelId);
     animationModelId = state.AddModel(animationModel);
     if (inputModel != null)
     {
         inputModelId = state.AddModel(inputModel);
     }
     else
     {
         inputModelId = new ModelReference(ModelReference.InvalidModelIndex);
     }
     anchoredEntities = new List <ModelReference>();
     ownedEntities    = new List <ModelReference>();
     customVariables  = new Dictionary <string, int>();
     mIsFacingRight   = true;
 }
コード例 #4
0
 // Constructor
 public PhysicPointModel(ModelReference ownerId)
     : this(ownerId,
            DefaultVCFactoryIds.PhysicPointControllerFactoryId,
            DefaultVCFactoryIds.PhysicPointViewFactoryId,
            DefaultUpdateOrder.PhysicsUpdateOrder
            )
 {
 }
コード例 #5
0
        public HitInformation HitCollisionCheck(
            FixedVector3 offset, bool facingRight,
            FrameData other, FixedVector3 otherOffset, bool otherFacingRight,
            List <AnimationHittenEntities> hittenEntities,
            ModelReference targetEntityId
            )
        {
            if (hits.Count == 0 || other.collisions.Count == 0)
            {
                return(null);
            }
            if (hits.Count == 1 &&
                hittenEntities != null &&
                hittenEntities.Count > hits[0].hitData.hitboxID &&
                hittenEntities[hits[0].hitData.hitboxID].entities.Find(x => x == targetEntityId) != null
                )
            {
                // already hit this entity
                return(null);
            }

            Box offsettedBox      = OffsettedBox(hitBoundingBox, offset, facingRight);
            Box otherOffsettedBox = OffsettedBox(other.collisionBoundingBox, otherOffset, otherFacingRight);

            if (offsettedBox.Intersects(otherOffsettedBox))
            {
                if (hits.Count == 1 && other.collisions.Count == 1)
                {
                    return(new HitInformation(hits[0].hitData, offsettedBox, other.collisions[0].collisionId, otherOffsettedBox));
                }
                foreach (HitBox hitBox in hits)
                {
                    // Check if this hit already hit this entity
                    if (hittenEntities != null &&
                        hittenEntities.Count > hitBox.hitData.hitboxID &&
                        hittenEntities[hitBox.hitData.hitboxID].entities.Find(x => x == targetEntityId) != null
                        )
                    {
                        // already hit this entity
                        continue;
                    }

                    // Check collisions against each collision box of the entity
                    offsettedBox = OffsettedBox(hitBox.box, offset, facingRight);
                    foreach (CollisionBox collisionBox in other.collisions)
                    {
                        otherOffsettedBox = OffsettedBox(collisionBox.box, otherOffset, otherFacingRight);
                        if (offsettedBox.Intersects(otherOffsettedBox))
                        {
                            return(new HitInformation(hitBox.hitData, offsettedBox, collisionBox.collisionId, otherOffsettedBox));
                        }
                    }
                }
            }
            return(null);
        }
コード例 #6
0
 // Constructor
 public PhysicPointModel(ModelReference ownerId, FixedVector3 position, FixedVector3 stepTolerance)
     : this(ownerId,
            position,
            stepTolerance,
            DefaultVCFactoryIds.PhysicPointControllerFactoryId,
            DefaultVCFactoryIds.PhysicPointViewFactoryId,
            DefaultUpdateOrder.PhysicsUpdateOrder
            )
 {
 }
コード例 #7
0
 // Constructor
 public PhysicPointModel(ModelReference ownerId,
                         string controllerFactoryId,
                         string viewFactoryId,
                         int updatingOrder
                         ) : base(controllerFactoryId, viewFactoryId, updatingOrder)
 {
     this.ownerId      = ownerId;
     velocityAffectors = new Dictionary <string, FixedVector3>();
     isActive          = true;
 }
コード例 #8
0
 // Constructor
 public AnimationModel(ModelReference ownerId,
                       string characterName,
                       string animationName,
                       string viewModelName
                       ) : this(ownerId,
                                characterName,
                                animationName,
                                viewModelName,
                                DefaultVCFactoryIds.AnimationControllerFactoryId,
                                DefaultVCFactoryIds.AnimationViewFactoryId,
                                DefaultUpdateOrder.AnimationsUpdateOrder
                                )
 {
 }
コード例 #9
0
 // Constructor
 public PhysicPointModel(ModelReference ownerId,
                         FixedVector3 position,
                         FixedVector3 stepTolerance,
                         string controllerFactoryId,
                         string viewFactoryId,
                         int updatingOrder
                         ) : base(controllerFactoryId, viewFactoryId, updatingOrder)
 {
     this.ownerId       = ownerId;
     velocityAffectors  = new Dictionary <string, FixedVector3>();
     this.position      = this.lastPosition = position;
     this.stepTolerance = stepTolerance;
     isActive           = true;
 }
コード例 #10
0
        // Find out which team an entity pertains to
        public static int GetEntityTeam(ModelReference entityReference)
        {
            WorldModel        world      = StateManager.state.MainModel as WorldModel;
            TeamsManagerModel teamsModel = StateManager.state.GetModel(world.teamsModelId) as TeamsManagerModel;

            for (int i = 0; i < teamsModel.teams.Length; ++i)
            {
                TeamData teamData = teamsModel.teams[i];
                if (teamData.entities.Contains(entityReference))
                {
                    return(i);
                }
            }
            return(-1);
        }
コード例 #11
0
 // Constructor
 public AnimationModel(ModelReference ownerId,
                       string characterName,
                       string animationName,
                       string viewModelName,
                       string controllerFactoryId,
                       string viewFactoryId,
                       int updatingOrder
                       ) : base(controllerFactoryId, viewFactoryId, updatingOrder)
 {
     this.characterName = characterName;
     this.animationName = animationName;
     this.viewModelName = viewModelName;
     this.currentFrame  = 0;
     this.ownerId       = ownerId;
 }
コード例 #12
0
        // Check collision against other entity
        public bool CollisionCollisionCheck(GameEntityModel model, GameEntityModel otherModel)
        {
            AnimationModel      animModel      = GetAnimationModel(model);
            AnimationModel      otherAnimModel = GetAnimationModel(otherModel);
            AnimationController animController = animModel.Controller() as AnimationController;
            FixedVector3        position       = GetRealPosition(model);
            FixedVector3        otherPosition  = GetRealPosition(otherModel);

            if (animController.CollisionCollisionCheck(animModel, position, model.IsFacingRight(), otherAnimModel, otherPosition, otherModel.IsFacingRight()))
            {
                // Both entities get knowing they hit each other
                GameEntityController otherController = otherModel.Controller() as GameEntityController;
                otherController.lastCollisionEntityId = model.Index;
                lastCollisionEntityId = otherModel.Index;
//				Debug.Log("Collision detected");
                return(true);
            }
            return(false);
        }
コード例 #13
0
        // Find any entity interacting with the one from the required team, except if it matches the given exception reference
        public static GameEntityModel GetInteractionEntityWithEntityFromTeam(int teamId, int playerNumber, ModelReference exception)
        {
            GameEntityModel originalEntity = GetEntityFromTeam(teamId, playerNumber);

            if (originalEntity == null)
            {
                return(null);
            }
            return(GetInteractionEntity(originalEntity, exception));
        }
コード例 #14
0
ファイル: Model.cs プロジェクト: gsaurus/back_to_the_streets
 // Default constructor
 public Model()
 {
     Index = new ModelReference();
 }
コード例 #15
0
 // Create a copy adding the entity information (used for hitter and hitten entity)
 public HitInformation HitWithEntity(ModelReference entityId)
 {
     return(new HitInformation(this, entityId));
 }
コード例 #16
0
 // Clear temporary information
 // Called from teams manager before any hit/collision checks
 public void ClearHitsInformation()
 {
     lastHits.Clear();
     lastHurts.Clear();
     lastCollisionEntityId = new ModelReference(ModelReference.InvalidModelIndex);
 }
コード例 #17
0
        // Find any entity interacting with the one from the required team, except if it matches the given exception reference
        public static GameEntityModel GetInteractionEntity(GameEntityModel originalEntity, ModelReference exception)
        {
            if (originalEntity == null)
            {
                return(null);
            }
            ModelReference interactionReference = new ModelReference();

            foreach (ModelReference entityRef in originalEntity.anchoredEntities)
            {
                if (entityRef != exception)
                {
                    interactionReference = entityRef;
                    break;
                }
            }

            if (originalEntity.parentEntity != null && interactionReference == ModelReference.InvalidModelIndex && originalEntity.parentEntity != exception)
            {
                interactionReference = originalEntity.parentEntity;
            }
            if (interactionReference == ModelReference.InvalidModelIndex)
            {
                // Need to check with controller to see last hitter / hitten entities
                GameEntityController controller = originalEntity.Controller() as GameEntityController;
                foreach (HitInformation hitInfo in controller.lastHurts)
                {
                    if (hitInfo.entityId != exception)
                    {
                        interactionReference = hitInfo.entityId;
                        break;
                    }
                }
                if (interactionReference == ModelReference.InvalidModelIndex)
                {
                    foreach (HitInformation hitInfo in controller.lastHits)
                    {
                        if (hitInfo.entityId != exception)
                        {
                            interactionReference = hitInfo.entityId;
                            break;
                        }
                    }
                }
            }

            if (interactionReference != ModelReference.InvalidModelIndex)
            {
                return(StateManager.state.GetModel(interactionReference) as GameEntityModel);
            }

            // No direct interaction, check from owned entities
            GameEntityModel interactionEntity;
            GameEntityModel ownedEntity;

            foreach (ModelReference entityRef in originalEntity.ownedEntities)
            {
                ownedEntity       = StateManager.state.GetModel(entityRef) as GameEntityModel;
                interactionEntity = GetInteractionEntity(ownedEntity, exception);
                if (interactionEntity != null)
                {
                    return(interactionEntity);
                }
            }

            // No interactions found
            return(null);
        }