Esempio n. 1
0
        // Filter hit by hitter entity location
        private static GameEntityModel getHitEntityIfConformingOrientationOptions(HitInformation hit, OrientationOptions orientationOptions, GameEntityModel model)
        {
            GameEntityModel hitterModel = StateManager.state.GetModel(hit.entityId) as GameEntityModel;

            if (orientationOptions == OrientationOptions.any)
            {
                return(hitterModel);
            }

            PhysicPointModel modelPoint  = GameEntityController.GetPointModel(model);
            PhysicPointModel hitterPoint = GameEntityController.GetPointModel(hitterModel);
            bool             isFrontal;

            if (model.IsFacingRight())
            {
                isFrontal = hitterPoint.position.X >= modelPoint.position.X;
            }
            else
            {
                isFrontal = hitterPoint.position.X <= modelPoint.position.X;
            }
            if (isFrontal == (orientationOptions == OrientationOptions.fromFront))
            {
                return(hitterModel);
            }
            return(null);
        }
Esempio n. 2
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;
 }
Esempio n. 3
0
 // Filter hit by hit IDs list
 private static bool isHitConformingHitId(HitInformation hit, AnyOrAllOptions hitIdsOptions, int[] hitIds)
 {
     if (hitIdsOptions == AnyOrAllOptions.anyOf)
     {
         return(hitIds != null && hitIds.Contains(hit.hitData.hitboxID));
     }
     else
     {
         return(hitIds == null || !hitIds.Contains(hit.hitData.hitboxID));
     }
 }
Esempio n. 4
0
 // Filter hit by collision IDs list
 private static bool isHitConformingCollisionId(HitInformation hit, AnyOrAllOptions collisionIdsOptions, int[] collisionIds)
 {
     if (collisionIdsOptions == AnyOrAllOptions.anyOf)
     {
         return(collisionIds != null && collisionIds.Contains(hit.collisionId));
     }
     else
     {
         return(collisionIds == null || !collisionIds.Contains(hit.collisionId));
     }
 }
Esempio n. 5
0
 // Filter hit by types list
 private static bool isHitConformingType(HitInformation hit, AnyOrAllOptions typesOptions, int[] types)
 {
     if (typesOptions == AnyOrAllOptions.anyOf)
     {
         return(types != null && types.Contains((int)hit.hitData.type));
     }
     else
     {
         return(types == null || !types.Contains((int)hit.hitData.type));
     }
 }
        // Face to same direction as hitter is facing
        public static void FaceToHitterDirection(GameEntityModel model, bool oppositeFacing)
        {
            GameEntityController controller = model.Controller() as GameEntityController;
            PhysicPointModel     pointModel = GameEntityController.GetPointModel(model);

            if (pointModel != null && controller.lastHurts.Count > 0)
            {
                HitInformation  info   = controller.lastHurts[0];
                GameEntityModel hitter = StateManager.state.GetModel(info.entityId) as GameEntityModel;
                model.mIsFacingRight = hitter.IsFacingRight();
                if (oppositeFacing)
                {
                    model.mIsFacingRight = !model.IsFacingRight();
                }
            }
        }
        // Check Hit against other entity
        public void HitCollisionCheck(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);
            HitInformation      hitInformation = animController.HitCollisionCheck(
                animModel, position, model.IsFacingRight(),
                otherAnimModel, otherPosition, otherModel.IsFacingRight()
                );

            if (hitInformation != null)
            {
                // Both entities get knowing one hit the other
                GameEntityController otherController = otherModel.Controller() as GameEntityController;
                otherController.lastHurts.Add(hitInformation.HitWithEntity(model.Index));
                lastHits.Add(hitInformation.HitWithEntity(otherModel.Index));
                // Debug.Log(model.Index + " hit " + otherModel.Index);
            }
        }
Esempio n. 8
0
        // Hit check against other controller & model
        // Params: animation models of both entities, offsets and orientation of both entities
        public HitInformation HitCollisionCheck(
            AnimationModel model, FixedVector3 offset, bool facingRight,
            AnimationModel otherModel, FixedVector3 otherOffset, bool otherFacingRight
            )
        {
            AnimationController otherController = otherModel.Controller() as AnimationController;
            FrameData           data            = framesData[model.currentFrame % framesData.Length];
            FrameData           otherData       = otherController.framesData[otherModel.currentFrame % otherController.framesData.Length];

            if (data == null || otherData == null)
            {
                return(null);
            }
            HitInformation hitInformation = data.HitCollisionCheck(offset, facingRight, otherData, otherOffset, otherFacingRight, model.hittenEntitiesByHitId, otherModel.ownerId);

            if (hitInformation != null)
            {
                // store hitten so that it doesn't get hit again by this hit
                EnsureHittenData(model, hitInformation.hitData.hitboxID);
                model.hittenEntitiesByHitId[hitInformation.hitData.hitboxID].entities.Add(otherModel.ownerId);
            }
            return(hitInformation);
        }