Example #1
0
 public OPancarte(Vector2 location)
     : base("opancarte", location)
 {
     hitbox = new Hitbox(BaseSrcRect);
     _text = "";
     LayerDepth = 75;
 }
Example #2
0
    private static bool CollidesWithHitbox(Hitbox hitbox1, GameObject gameObject1, Hitbox hitbox2, GameObject gameObject2)
    {
        if (hitbox2.Type != HitboxType.Hittable)
            return false;

        if (hitbox1.Shape == HitboxShape.Rectangle && hitbox2.Shape == HitboxShape.Rectangle)
        {
            Rect rect1 = new Rect(gameObject1.transform.position.x + hitbox1.Boundaries.x,
                                  gameObject1.transform.position.y + hitbox1.Boundaries.y,
                                  hitbox1.Boundaries.width, hitbox1.Boundaries.height);

            Rect rect2 = new Rect(gameObject2.transform.position.x + hitbox2.Boundaries.x,
                                  gameObject2.transform.position.y + hitbox2.Boundaries.y,
                                  hitbox2.Boundaries.width, hitbox2.Boundaries.height);

            return RectangleCollision(rect1, rect2);
        }
        else
            return false;

        //else if (hitbox1.Shape == HitboxShape.Circle && hitbox2.Shape == HitboxShape.Circle)
        //{
        //    return CircleCollision(hitbox1, hitbox2);
        //}
        //else
        //{
        //    if (hitbox1.Shape == HitboxShape.Rectangle)
        //        return MixCollision(hitbox1, hitbox2);
        //    else
        //        return MixCollision(hitbox2, hitbox1);
        //}
    }
Example #3
0
 public OShip(Vector2 location)
     : base("ship", location)
 {
     hitbox = new Hitbox(BaseSrcRect);
     LayerDepth = 50;
     _question = 0;
 }
Example #4
0
 public Entity(Vector2 position)
 {
     active = true;
     this.position = position;
     hitbox = new Hitbox(new Vector2(0, 0), 0, 0);
     hitbox.Update(this);
 }
Example #5
0
 public OBox(Vector2 location)
     : base("box", location)
 {
     hitbox = new Hitbox(new Rectangle(10, 35, 40, 30));
     Activated = false;
     LayerDepth = 130;
 }
Example #6
0
 public Entity(Vector2 position, Hitbox hitbox)
 {
     active = true;
     this.position = position;
     this.hitbox = hitbox;
     hitbox.Update(this);
 }
Example #7
0
    public void DrawGizmo(Hitbox hitbox, Transform transform)
    {
        Vector3 hitboxPos = new Vector3(hitbox.Position.x * transform.localScale.x,
                                                    hitbox.Position.y * transform.localScale.y,
                                                    0f);

        Gizmos.DrawSphere(hitboxPos + transform.position, hitbox.Boundaries.width);
    }
        public PhysicsComponent(int width, int height, PhysicsType type)
        {
            gravityScale = 1.0;
            velocity = Vector2.Zero;
            hitBox = new Hitbox(width, height);
            this.type = type;

            //PhysicsSystem.Instance.addComponent(this);
        }
        // Aligns the given point with the given hitbox and returns it.
        public static Vector2 alignPoint(Vector2 point, Hitbox entity)
        {
            // newPoint = (cos*(X-U) + sin*(Y-V), -sin*(X-U) + cos*(Y-V))
            Vector2 newPoint = new Vector2(point.x - entity.hitbox.x, point.y - entity.hitbox.y);
            float x = (entity.cos*newPoint.x) + (entity.sin*newPoint.y);
            float y = -(entity.sin*newPoint.x) + (entity.cos*newPoint.y);
            newPoint.x = x; newPoint.y = y;

            return newPoint;
        }
Example #10
0
    private Hitbox DrawMove(Hitbox currentHitbox, TargetComponents targetComponents)
    {
        Vector3 handlePosition = currentHitbox.GetHandlePosition();
        Vector3 moveHandlePos = Handles.FreeMoveHandle(handlePosition + targetComponents.GameObject.transform.position, Quaternion.identity, 0.05f, Vector3.one, Handles.RectangleCap);
        moveHandlePos -= targetComponents.GameObject.transform.position;

        currentHitbox.Boundaries = new Rect(moveHandlePos.x, moveHandlePos.y,
                                                currentHitbox.Boundaries.width,
                                                currentHitbox.Boundaries.height);

        return currentHitbox;
    }
Example #11
0
    public void DrawGizmo(Hitbox hitbox, Transform transform)
    {
        Vector3 hitboxPos = new Vector3((hitbox.Boundaries.x + hitbox.Boundaries.width / 2) * transform.localScale.x,
                                                        (hitbox.Boundaries.y + hitbox.Boundaries.height / 2) * transform.localScale.y,
                                                        0f);
        Vector3 hitboxSize = new Vector3(hitbox.Boundaries.width, hitbox.Boundaries.height, 0.1f);

        Debug.Log(hitboxPos);
        Debug.Log(hitboxSize);
        Debug.Log("---");

        Gizmos.DrawCube(hitboxPos + transform.position, hitboxSize);
    }
Example #12
0
    public Hitbox DrawSceneHandle(Hitbox hitbox, TargetComponents targetComponents)
    {
        if (Tools.current == Tool.Move)
        {
            return DrawMove(hitbox, targetComponents);
        }
        else if (Tools.current == Tool.Scale)
        {
            return DrawScale(hitbox, targetComponents);
        }

        return hitbox;
    }
Example #13
0
 public override void OnPlayerCollide(Room room, int x, int y, Player player)
 {
     const float offset = 0.25f;
     const float size = Tile.tileSize * (1 - 2 * offset);
     Hitbox lavaBox = new Hitbox(Tile.tileSize * new Vector2(x + offset, y + offset), size, size);
     Hitbox playerBox = player.hitbox;
     if (playerBox.topRight.X >= lavaBox.bottomLeft.X && playerBox.topLeft.X <= lavaBox.bottomRight.X
         && playerBox.bottomLeft.Y >= lavaBox.topLeft.Y && playerBox.topLeft.Y <= lavaBox.bottomLeft.Y)
     {
         player.invincible = 0;
         player.TakeDamage(10);
     }
 }
Example #14
0
        public OPlatform(Vector2 location, Rectangle size)
            : base("oplatform", location)
        {
            dRect.Width = size.Width;
            dRect.Height = size.Height;

            hitbox = new Hitbox(size);
            Floor = new Floor(Rectangle.Empty)
            {
                IsMoving = true,
                IsPassable = true
            };
        }
Example #15
0
    public static bool CollidesWithlist(Hitbox hitbox, GameObject gameObject1, Hitbox[] hitboxes, GameObject gameObject2)
    {
        bool collisionHappened = false;

        for (int i = 0; i < hitboxes.Length; i++)
        {
            collisionHappened = CollidesWithHitbox(hitbox, gameObject1, hitboxes[i], gameObject2);

            if (collisionHappened)
                return true;
        }

        return collisionHappened;
    }
Example #16
0
    public Hitbox CreateHitbox(HitboxInfo hbi)
    {
        if (ListHitboxes.Instance == null)
        {
            Debug.LogWarning("LIstHitboxes not found. Please add a Gameobject with the ListHItboxes prefab");
            return(null);
        }
        var go = GameObject.Instantiate(ListHitboxes.Instance.Hitbox, transform.position, Quaternion.identity);

        hbi.hitCallback.Add(RegisterHit);
        Hitbox newBox = go.GetComponent <Hitbox>();

        newBox.InitFromHitboxInfo(hbi, gameObject, GetComponent <FactionHolder>());
        return(newBox);
    }
Example #17
0
    public void CreateHitbox(Creature owner, float radius, int damage, Vector3 velocity, float duration, string nameOfHitbox = null)
    {
        GameObject _obj    = Instantiate(HitboxPrefab, owner.transform.position + (owner.transform.forward * 0.5f), Quaternion.identity) as GameObject;
        Hitbox     _hitbox = _obj.GetComponent <Hitbox>();

        _hitbox.Owner    = owner;
        _hitbox.Radius   = radius;
        _hitbox.Damage   = damage;
        _hitbox.Duration = duration;
        _hitbox.name     = nameOfHitbox ?? "Hitbox (" + owner.name + ")";

        _hitbox.SetVelocity(velocity);

        StartCoroutine(_hitbox.Begin());
    }
    /// <summary>
    ///
    /// </summary>
    /// <param name="hitbox1"></param>
    /// <param name="hitbox2"></param>
    private void OnHitboxStayHitboxEvent(Hitbox hitbox1, Hitbox hitbox2)
    {
        print(hitbox1.name + "  " + hitbox2.name + " stayed!");
        InteractionHandler hitHandler1 = hitbox1.InteractionHandler;
        InteractionHandler hitHandler2 = hitbox2.InteractionHandler;

        if (hitHandler1)
        {
            hitHandler1.OnClash(hitbox2);
        }
        if (hitHandler2)
        {
            hitHandler2.OnClash(hitbox1);
        }
    }
Example #19
0
    //[Header("Boomerang")]
    //public bool hasBeenThrown = false;//collision
    //public bool doCollision = false;//collision
    //public bool boomerangFlag = false;//ai on
    //public float boomerangTime = 20;//time spent turning back to the player
    //public float orient = 0; //direction boomerang turns  in the boomerang state
    //public float turnAmount = 0; //how much boomerang has turned, used to end the state
    //public float direction; //
    //public int state;
    //public Vector3 velocity;
    //public Vector3 friction = new Vector3(0.95f, 0.99f, 0.95f);
    private void Awake()
    {
        kzSprite     = GetComponent <SpriteRenderer>();
        kzRB         = GetComponent <Rigidbody2D>();
        kzColl       = GetComponent <Collider2D>();
        thrower      = GameEngine.gameEngine.mainCharacter;
        hitbox       = GetComponent <Hitbox>();
        audioManager = AudioManager.instance;
        if (audioManager == null)
        {
            Debug.LogError("No Audio Manager in Scene");
        }

        kState = ThrowingState.Recalling;
    }
Example #20
0
 public PlayerToken(int id, string texture, Vector2 position, Vector2 scale, int depth, BoardSpace space) : base(position)
 {
     this.id        = id;
     color          = colors[texture];
     Collider       = new Hitbox(20, 20, -5, -5);
     AnimationSpeed = 12f;
     Depth          = depth;
     this.scale     = scale;
     Name           = GetFullPath(texture);
     textures       = GFX.Gui.GetAtlasSubtextures(Name);
     AddTag(TagsExt.SubHUD);
     AddTag(Tags.PauseUpdate);
     AddTag(Tags.FrozenUpdate);
     currentSpace = space;
 }
Example #21
0
        public override void Update(GameTime GameTime)
        {
            ButtonHitbox = HitboxUpdater.UpdateHitbox(GamePosition, 32, 32, this.InCameraWorld);

            IsClicked = ClickSystem.IsClickedOn(ButtonHitbox, this.InCameraWorld);

            if (IsClicked)
            {
                Graphic.GraphicColor = new Color(Color.OrangeRed, 255);
            }
            else
            {
                Graphic.GraphicColor = new Color(Color.White, 255);
            }
        }
Example #22
0
        public override void endProjectile(Enemy e)
        {
            speed = 0;

            if (e != null)
            {
                drawingEnd = true;

                hitbox = new Hitbox(endTexture.getTexture().Width, endTexture.getTexture().Height);

                texture = endTexture;
                position = e.getFeet();
                e.stun(500);
            }
        }
Example #23
0
    public override void _Ready()
    {
        Joint = GetNode <Spatial>("EverythingJoint");
        Mesh  = Joint.GetNode <MeshInstance>("Mesh");
        Head  = Joint.GetNode <Hitbox>("HeadHitbox");
        Feet  = Joint.GetNode <Hitbox>("FeetHitbox");

        CamJoint = GetNode <Spatial>("CamJoint");
        Cam      = CamJoint.GetNode <Camera>("Cam");
        Holder   = Cam.GetNode <WeaponHolder>("WeaponHolder");

        Cam.Current = false;

        base._Ready();
    }
Example #24
0
        public LaserEmitter(EntityData data, Vector2 offset) : base(data.Position + offset)
        {
            Add((Component)(startupSprite = new Sprite(GFX.Game, "objects/pandorasBox/laser/emitter/start")));
            startupSprite.AddLoop("start", "", 0.1f);
            startupSprite.JustifyOrigin(0.5f, 1f);
            startupSprite.Play("start");
            startupSprite.OnLastFrame = onLastFrame;
            startupSprite.Stop();

            Add((Component)(idleSprite = new Sprite(GFX.Game, "objects/pandorasBox/laser/emitter/idle")));
            idleSprite.AddLoop("idle", "", 0.125f);
            idleSprite.JustifyOrigin(0.5f, 1f);
            idleSprite.Play("idle");
            idleSprite.Visible = false;

            flag         = data.Attr("flag", "");
            direction    = data.Attr("direction", "");
            beamDuration = data.Int("beamDuration", -1);
            inverted     = Boolean.Parse(data.Attr("inverted", "false"));
            id           = data.ID;
            color        = ColorHelper.GetColor(data.Attr("color", "White"));

            inStartupAnimation = false;

            Collider = new Hitbox(16f, 32f, -8f, -32f);

            Depth = 50;

            Add((Component)(bloom = new BloomPoint(new Vector2(0, -24), 0.3f, 4f)));
            Add((Component)(light = new VertexLight(new Vector2(0, -24), Color.White, 1f, 48, 64)));

            Add(new StaticMover
            {
                SolidChecker    = new Func <Solid, bool>(IsRiding),
                JumpThruChecker = new Func <JumpThru, bool>(IsRiding),
                OnMove          = delegate(Vector2 v)
                {
                    if (laserbeam != null)
                    {
                        laserbeam.Position += v;
                    }
                },
                OnDestroy = delegate()
                {
                    RemoveSelf();
                }
            });
        }
Example #25
0
    // Update is called once per frame
    void Update()
    {
        Vector3 mousePosition = GetWorldPositionOnPlane(Input.mousePosition, 0);

        curCooldown = Mathf.Max(0f, curCooldown - Time.deltaTime);

        if (Input.GetButton("Fire1"))
        {
            if (curCooldown <= 0f)
            {
                curCooldown = cooldownTime;

                Vector2 targetRotation = mousePosition - transform.position;

                GameObject obj = ObjectPoolA.Instance.Instantiate(
                    bulletTag,
                    source.transform.position,
                    Quaternion.Euler(0f, 0f, Mathf.Rad2Deg * Mathf.Atan2(targetRotation.y, targetRotation.x))
                    );

                Hitbox box = obj.GetComponentInChildren <Hitbox>();
                if (stat != null)
                {
                    box?.setDamage(stat.getDamage());
                }

                SpriteRenderer renderer = obj.GetComponent <SpriteRenderer>();
                if (renderer != null)
                {
                    renderer.flipY = targetRotation.x < 0;
                }

                if (flairTag.Length > 0)
                {
                    GameObject flair = ObjectPoolA.Instance.Instantiate(
                        flairTag,
                        source.transform.position,
                        Quaternion.Euler(0f, 0f, Mathf.Rad2Deg * Mathf.Atan2(targetRotation.y, targetRotation.x))
                        );
                    flair.transform.parent = source.transform;
                }

                ScreenShakeController.instance.StartShake(.1f, .05f);

                anim?.SetState(GunStates.Shoot);
            }
        }
    }
Example #26
0
    public HitResult TakeHit(Hitbox hb)
    {
        ExecuteEvents.Execute <ICustomMessageTarget> (gameObject, null, (x, y) => x.OnHit(hb, hb.Creator));
        HitboxDoT hd = hb as HitboxDoT;

        if (hd != null)
        {
            TakeDoT(hd);
            return(HitResult.NONE);
        }
        if (GetComponent <AIFighter>())
        {
            GetComponent <AIFighter> ().OnHit(hb);
        }
        Resistence r = GetAverageResistences(hb.Element);
        float      d;

        d = hb.Damage - (hb.Damage * (r.Percentage / 100f));
        d = DamageObj(d);

        ApplyHitToPhysicsSS(hb);
        float s = hb.Stun - (hb.Stun * Mathf.Min(1f, (r.StunResist / 100f)));

        if (hb.Stun > 0f && m_fighter)
        {
            if (s <= 0f)
            {
                return(HitResult.BLOCKED);
            }
            m_fighter.RegisterStun(s, true, hb);
        }
        if (Health <= 0f)
        {
            Killer = hb.Creator;
        }
        if (d == 0f)
        {
            return(HitResult.NONE);
        }
        else if (d < 0f)
        {
            return(HitResult.HIT);
        }
        else
        {
            return(HitResult.HEAL);
        }
    }
        public TriggerSpikesOriginal(Vector2 position, int size, Directions direction, string overrideType)
            : base(position)
        {
            this.size         = size;
            this.direction    = direction;
            this.overrideType = overrideType;

            switch (direction)
            {
            case Directions.Up:
                outwards = new Vector2(0f, -1f);
                Collider = new Hitbox(size, 3f, 0f, -3f);
                Add(new SafeGroundBlocker());
                Add(new LedgeBlocker(UpSafeBlockCheck));
                break;

            case Directions.Down:
                outwards = new Vector2(0f, 1f);
                Collider = new Hitbox(size, 3f, 0f, 0f);
                break;

            case Directions.Left:
                outwards = new Vector2(-1f, 0f);
                Collider = new Hitbox(3f, size, -3f, 0f);

                Add(new SafeGroundBlocker());
                Add(new LedgeBlocker(SideSafeBlockCheck));
                break;

            case Directions.Right:
                outwards = new Vector2(1f, 0f);
                Collider = new Hitbox(3f, size, 0f, 0f);

                Add(new SafeGroundBlocker());
                Add(new LedgeBlocker(SideSafeBlockCheck));
                break;
            }

            Add(pc = new PlayerCollider(OnCollide));

            Add(new StaticMover {
                OnShake         = OnShake,
                SolidChecker    = IsRiding,
                JumpThruChecker = IsRiding
            });

            Depth = Depths.Dust;
        }
Example #28
0
        /// <summary>
        /// Create the hitbox group of the given index.
        /// </summary>
        /// <param name="index">The index of the hitbox group.</param>
        public void CreateHitboxGroup(int index)
        {
            // Group was already created.
            if (hitboxGroups.ContainsKey(index))
            {
                return;
            }

            // Variables.
            BoxGroup      currentGroup    = combatManager.CurrentAttack.attackDefinition.boxGroups[index];
            List <Hitbox> groupHitboxList = new List <Hitbox>(currentGroup.boxes.Count);

            // Keep track of what the hitbox ID has hit.
            if (!hurtablesHit.ContainsKey(currentGroup.ID))
            {
                hurtablesHit.Add(currentGroup.ID, new List <IHurtable>());
                hurtablesHit[currentGroup.ID].Add(combatManager);
            }

            // Loop through all the hitboxes in the group.
            for (int i = 0; i < currentGroup.boxes.Count; i++)
            {
                // Instantiate the hitbox with the correct position and rotation.
                BoxDefinition hitboxDefinition = currentGroup.boxes[i];
                Vector3       pos = controller.GetVisualBasedDirection(Vector3.forward) * hitboxDefinition.offset.z
                                    + controller.GetVisualBasedDirection(Vector3.right) * hitboxDefinition.offset.x
                                    + controller.GetVisualBasedDirection(Vector3.up) * hitboxDefinition.offset.y;

                Hitbox hitbox = InstantiateHitbox(controller.transform.position + pos,
                                                  Quaternion.Euler(controller.transform.eulerAngles + hitboxDefinition.rotation));

                // Attach the hitbox if neccessary.
                if (currentGroup.attachToEntity)
                {
                    hitbox.transform.SetParent(controller.transform, true);
                }

                hitbox.Initialize(controller.gameObject, controller.visual.transform, currentGroup.boxes[i].shape,
                                  currentGroup.hitboxHitInfo, hurtablesHit[currentGroup.ID]);
                int cID        = currentGroup.ID;
                int groupIndex = index;
                hitbox.OnHurt += (hurtable, hitInfo) => { OnHitboxHurt(hurtable, hitInfo, cID, groupIndex); };
                hitbox.Activate();
                groupHitboxList.Add(hitbox);
            }
            // Add the hitbox group to our list.
            hitboxGroups.Add(index, groupHitboxList);
        }
        protected override void Update()
        {
            base.Update();

            foreach (Drawable draw in TouhouSharpPlayfield.GameField.Current)
            {
                if (draw is DrawableBullet drawableProjectile && drawableProjectile.Hitbox != null)
                {
                    if (Hitbox.HitDetect(Hitbox, drawableProjectile.Hitbox))
                    {
                        Hurt(drawableProjectile.Projectile.Damage);
                        drawableProjectile.Expire();
                    }
                }
            }
        }
Example #30
0
        public void FindCollisionActorsFast(ActorBase self, Hitbox hitbox, Func <ActorBase, bool> callback)
        {
            AABB aabb = hitbox.ToAABB();

            collisions.Query((actor) => {
                if (self == actor || (actor.CollisionFlags & CollisionFlags.CollideWithOtherActors) == 0)
                {
                    return(true);
                }
                if (actor.Hitbox.Intersects(ref hitbox))
                {
                    return(callback(actor));
                }
                return(true);
            }, ref aabb);
        }
Example #31
0
    /// <summary>
    /// <inheritdoc />
    /// </summary>
    /// <returns></returns>
    public override int GetDamage(Hitbox target)
    {
        //Deal damage from enemy to player
        if (target is PlayerHitbox)
        {
            if (OverridePlayerDamage != -1)
            {
                return(Commons.EnemyProgression.GetScaledDamage(OverridePlayerDamage));
            }

            return(Commons.EnemyProgression.GetScaledDamage(Damage));
        }

        //Deal damage from player to enemy
        return(Commons.PlayerProgression.GetScaledDamage(Damage));
    }
Example #32
0
 // Use this for initialization
 void Start()
 {
     if (playerBehaviour == null)
     {
         playerBehaviour = GetComponent <PlayerBehaviour>();
     }
     if (playerAnimator == null)
     {
         playerAnimator = transform.GetChild(0).GetComponent <Animator>();
     }
     if (playerHitbox == null)
     {
         playerHitbox = GetComponent <Hitbox>();
     }
     lastCurrentLife = playerHitbox.getCurrentLife();
 }
Example #33
0
    public override void ChildHitboxEnterEvent(Collider2D collision, Hitbox hitbox)
    {
        base.ChildHitboxEnterEvent(collision, hitbox);

        if (collision.CompareTag("Enemy"))
        {
            PlatformerCreature platformerCreature = collision.GetComponent <PlatformerCreature>();
            if (platformerCreature != null)
            {
                if (platformerCreature.OnHitboxEvent(hitbox))
                {
                    //StartCoroutine(HitStop());
                }
            }
        }
    }
Example #34
0
        private Entity Magician()
        {
            var weakness = new EffectWeakness();

            weakness.AddOrUpdateWeaknesses(AttackEffect.Tearing, 0.1f);
            weakness.AddOrUpdateWeaknesses(AttackEffect.Piercing, 0.1f);
            var hitbox = new Hitbox(15, weakness);
            var sm     = (EntityStateMachine)Binder.Inject(new HealingStateMachine());

            return(new Magician(hitbox, sm)
            {
                Name = "Magician",
                Weapon = new MagicWand(),
                MovementType = MovementType.Walk
            });
        }
Example #35
0
        private Entity Healer()
        {
            var weakness = new EffectWeakness();

            weakness.AddOrUpdateWeaknesses(AttackEffect.Tearing, 0.3f);
            weakness.AddOrUpdateWeaknesses(AttackEffect.Piercing, 0.3f);
            var hitbox = new Hitbox(15, weakness);
            var sm     = (EntityStateMachine)Binder.Inject(new HealingStateMachine());

            return(new Healer(hitbox, sm)
            {
                Name = "Healer",
                MovementType = MovementType.Walk,
                Healing = 5
            });
        }
Example #36
0
        private Entity Knight(Weapon weapon, MovementType movement)
        {
            var weakness = new EffectWeakness();

            weakness.AddOrUpdateWeaknesses(AttackEffect.Tearing, 0.15f);
            weakness.AddOrUpdateWeaknesses(AttackEffect.Shock, 0.1f);
            var hitbox = new Hitbox(15, weakness);
            var sm     = (EntityStateMachine)Binder.Inject(new DefaultStateMachine());

            return(new Knight(hitbox, sm)
            {
                Name = $"Knight-{weapon.ToString().Split('.').Last()}-{movement}",
                Weapon = weapon,
                MovementType = movement
            });
        }
Example #37
0
    public virtual void Start()
    {
        // set spawn position to the position they were placed in at runtime
        spawnPosition = transform.position;

        targetPosition = spawnPosition;

        // Link the controller to this pawn
        controller = GetComponent <Controller>();

        // set senses to the gameObject
        sight      = GetComponent <LineOfSight>();
        hearing    = GetComponent <Hearing>();
        noiseMaker = GetComponent <NoiseMaker>();
        hitbox     = GetComponent <Hitbox>();
    }
Example #38
0
 // Use this for initialization
 void Start()
 {
     if (enemyBrain == null)
     {
         enemyBrain = GetComponent <IABrain>();
     }
     if (enemyAnimator == null)
     {
         enemyAnimator = transform.GetChild(0).GetComponent <Animator>();
     }
     if (enemyHitbox == null)
     {
         enemyHitbox = GetComponent <Hitbox>();
     }
     lastCurrentLife = enemyHitbox.getCurrentLife();
 }
Example #39
0
        public Asteroid(Vector2 location, Vector2 speed, Vector2 scale, bool collidable)
            : base("asteroid", location, new Rectangle(Application.Random.GetRandomInt(0, 2) * 64, 0, 64, 64), speed, scale)
        {
            mass = Application.Random.GetRandomFloat(5f, 50f); //scale and weight could be linked,

            if (collidable)
            {
                int w = DstRect.Width;
                int h = DstRect.Height;
                hitbox = new Hitbox(new Rectangle(-w / 4, -h / 4, DstRect.Width - 2 * w / 4, DstRect.Height - 2 * h / 4));
            }

            FloorCollisionDetected = floorCollisionHandler;

            SetSpriteOriginToMiddle();
        }
Example #40
0
        public List <Collectible> GetPlayerCollectibleCollisions(Vector2 playerPosition)
        {
            List <Collectible> collectibleCollisions = new List <Collectible>();

            Hitbox playerHitbox = GetPlayerHitbox(playerPosition);

            foreach (Tuple <Collectible, Hitbox> collectibleWithHitbox in collectiblesWithHitboxes)
            {
                if (playerHitbox.CollidesWith(collectibleWithHitbox.Item2))
                {
                    collectibleCollisions.Add(collectibleWithHitbox.Item1);
                }
            }

            return(collectibleCollisions);
        }
Example #41
0
    public int addHitbox(float xPos, float yPos, float width, float height, int damage, float xKnock, float yKnock, float hitstun, float blockstun, eAttackType type)
    {
        for (int z = 0; z < 5; z++)
        {
            if (m_hitboxes[z] == null)
            {
                m_hitboxes[z] = new Hitbox(xPos, yPos, width, height, damage, xKnock, yKnock, hitstun, blockstun, type);

                Debug.Log("Hitbox " + z + " created");

                return(z);
            }
        }

        return(-1);
    }
Example #42
0
    public void Damage(Hitbox zHitboxSource)
    {
        Locomotor.Stop();

        Attributes.Life -= zHitboxSource.Damage;

        if (Attributes.Life < 1)
        {
            Attributes.Life = 0;
            Die();
        }
        else
        {
            Graphics.Animate(Graphics.Animations.DAMAGED);
        }
    }
Example #43
0
    /// <summary>
    /// This method checks to see if we are overlapping a hitbox and if that overlap is valid. If we return
    /// true then it is defined as a valid hitbox interaction
    /// </summary>
    /// <param name="OtherHitbox"></param>
    /// <returns></returns>
    public bool IsOverlappingHitboxAndValid(Hitbox OtherHitbox)
    {
        //We return false if the hitbox we are checking against comes from the same actor
        if (this.AssociatedHitboxInteractionComponent == OtherHitbox.AssociatedHitboxInteractionComponent)
        {
            return(false);
        }

        //If the hitboxes are the same type we also do not register it as a valid overlap
        if (this.AssignedHitboxType == OtherHitbox.AssignedHitboxType)
        {
            return(false);
        }

        return(this.AssociatedBounds.IsOverlappingBounds(OtherHitbox.AssociatedBounds));
    }
Example #44
0
        public Vector2 ImpulseApplication(Hitbox a, Hitbox b)
        {
            Vector2 minim  = satTest.mtvRet();
            Vector2 minim2 = satTest.mtvRet();

            //Vector2 cNormal = a.Centre - b.Centre; //might work

            //Vector2 cNormal = a.Centre - b.Centre;
            Vector2 combVel   = a.Velocity - b.Velocity;
            Vector2 cNormal   = Vector2.Normalize(combVel);
            float   cVelocity = Vector2.Dot(a.Velocity - b.Velocity, cNormal);

            cNormal *= cVelocity;

            return(cNormal);
        }
Example #45
0
 // Update is called once per frame
 void Update()
 {
     timer -= Time.deltaTime;
     if (timer <= 0)
     {
         Vector3    explosionSpawnPoint = new Vector3(transform.position.x, transform.position.y, -2.0f);
         GameObject explosion           = Instantiate(explosionPrefab, explosionSpawnPoint, transform.rotation) as GameObject;
         // TODO: Add custom grenade explosion animation instead of scaling the small one
         explosion.transform.localScale = explosion.transform.localScale * 3.0f;
         Hitbox hitbox = explosion.GetComponent <Hitbox>();
         hitbox.damage    = damage;
         hitbox.knockback = 2000;
         hitbox.SetSize(2, 2);
         Destroy(gameObject);
     }
 }
Example #46
0
 public override void OnHitConfirm(GameObject other, Hitbox hb, HitResult hr)
 {
     if (!hitFirst)
     {
         if (mAbility != null)
         {
             mAbility.SetTarget(other);
             mAbility.UseAbility();
         }
         else
         {
             Debug.Log("Ability not assigned to " + GetType());
         }
         hitFirst = true;
     }
 }
        private static void DrawAssistedHitbox(On.Monocle.Hitbox.orig_Render orig, Hitbox self, Camera camera, Player player,
                                               Vector2 hitboxPosition)
        {
            Collider origCollider = player.Collider;
            Collider hurtbox      = (Collider)PlayerHurtbox.GetValue(player);
            Vector2  origPosition = player.Position;

            player.Position = hitboxPosition;

            orig(self, camera, HitboxColor);
            player.Collider = hurtbox;
            Draw.HollowRect(hurtbox, HurtboxColor);
            player.Collider = origCollider;

            player.Position = origPosition;
        }
Example #48
0
 public Enemy_Mummy(float x, float y) : base(x, y)
 {
     Layer          = -500;
     this.MaxHP     = scene.stage.MaxHP;
     this.CurrentHP = this.MaxHP;
     SetHitbox(35, 46, ColliderTags.EnemyUnit);
     Hitbox.SetPosition(9, 17);
     spritemap.Add(Animation.Shoot, scene.GetAnimationString(0, 21), 3).NoRepeat();
     spritemap.Add(Animation.Death, scene.GetAnimationString(22, 67), 3).NoRepeat();
     spritemap.Add(Animation.Run, scene.GetAnimationString(68, 85), 3);
     spritemap.Play(Animation.Run);
     AddGraphic(spritemap);
     scene.Add(this);
     scene.enemyList.Add(this);
     runtime = (int)spritemap.Anim(Animation.Run).TotalDuration *scene.random.Next(3, 12);
 }
Example #49
0
        public byte GetCollisionMaskWith(Hitbox other)
        {
            byte mask = 0;

            /* Check bottom collision */
            if (top < other.bottom && bottom > other.bottom)
            {
                mask++;
            }

            mask <<= 1;

            /* Check right collision */
            if (left < other.right && right > other.right)
            {
                mask++;
            }

            mask <<= 1;

            /* Check top collision */
            if (top < other.top && bottom > other.top)
            {
                mask++;
            }

            mask <<= 1;

            /* Check left collision */
            if (left < other.left && right > other.left)
            {
                mask++;
            }

            mask <<= 1;

            return mask;
        }
Example #50
0
    private Hitbox DrawScale(Hitbox currentHitbox, TargetComponents targetComponents)
    {
        Vector3 ScaleHandleXPos;
        Vector3 ScaleHandleYPos;

        ScaleHandleXPos = Handles.FreeMoveHandle(currentHitbox.GetHandleXScale() + targetComponents.GameObject.transform.position,
                                                 Quaternion.identity,
                                                 0.05f,
                                                 Vector3.one,
                                                 Handles.DotCap);
        ScaleHandleXPos -= targetComponents.GameObject.transform.position;

        ScaleHandleYPos = Handles.FreeMoveHandle(currentHitbox.GetHandleYScale() + targetComponents.GameObject.transform.position,
                                                 Quaternion.identity,
                                                 0.05f,
                                                 Vector3.one,
                                                 Handles.DotCap);
        ScaleHandleYPos -= targetComponents.GameObject.transform.position;

        currentHitbox.Boundaries = new Rect(currentHitbox.Boundaries.x, currentHitbox.Boundaries.y,
                                      ScaleHandleXPos.x - currentHitbox.Boundaries.x,
                                      ScaleHandleYPos.y - currentHitbox.Boundaries.y);
        return currentHitbox;
    }
        // Checks whether the given rectangle intersects with the given circle.
        public static bool collisionCheckRectAndCircle(Hitbox a, Hitbox b)
        {
            float maxRadSum = a.halfSize.x + a.halfSize.y + Mathf.Max(b.halfSize.x, b.halfSize.y);
            if((Mathf.Abs(a.hitbox.x - b.hitbox.x) > maxRadSum) || (Mathf.Abs(a.hitbox.y - b.hitbox.y) > maxRadSum)){
                return false;
            }

            Vector2 alignedCenter = alignPoint(new Vector2(b.hitbox.x, b.hitbox.y), a);
            alignedCenter.x = Mathf.Abs(alignedCenter.x);
            alignedCenter.y = Mathf.Abs(alignedCenter.y);

            if(alignedCenter.x <= a.halfSize.x){
                if(alignedCenter.y <= a.halfSize.y){
                    return true;
                }
                return (alignedCenter.y < (a.halfSize.y + b.halfSize.y));
            }
            if(alignedCenter.y <= a.halfSize.y){
                return (alignedCenter.x < (a.halfSize.x + b.halfSize.x));
            }
            float distanceX, distanceY;
            distanceX = alignedCenter.x - a.halfSize.x;
            distanceY = alignedCenter.y - a.halfSize.y;
            return ((distanceX*distanceX) + (distanceY*distanceY)) < (b.halfSize.x*b.halfSize.y);
        }
Example #52
0
 public void setOnFrameRangeHitbox(int startFrame, int endFrame, Hitbox hitbox)
 {
     if (startFrame < 1 || startFrame > framemax || endFrame < 1 || endFrame > framemax)
         throw new ArgumentOutOfRangeException("frame", "Frames need to be between 1 and framemax");
     if (endFrame < startFrame)
         throw new ArgumentOutOfRangeException("frame", "End frame cannot be less than start frame");
     for (int i = startFrame; i <= endFrame; i++)
     {
         if (hitbox == null)
             onFrameHitboxes[i - 1] = new Hitbox(0, 0);
         else
             onFrameHitboxes[i - 1] = hitbox;
     }
 }
Example #53
0
        /// <summary>
        /// New sprite
        /// </summary>
        /// <param name="assetName">TODO</param>
        /// <param name="location">Screen location</param>
        /// <param name="spriteRect">Spritesheet source rectangle</param>
        /// <param name="speed">Moving speed</param>
        /// <param name="scale">Scale</param>
        public Entity(String assetName, Vector2 location, Rectangle spriteRect, Vector2 scale)
        {
            this.assetName = assetName;

            this.location = location;
            this.sRect = spriteRect;
            this.scale = scale;

            this.ComputeDstRect();

            //Default
            this.spriteOrigin = Vector2.Zero;
            this.flip = SpriteEffects.None;
            this.animation = null; //No animation

            this.IsRemovable = true;
            this.Size = new Vector2(spriteRect.Width, spriteRect.Height);

            this.hitbox = null;
            this.awarenessbox = null;

            this.Color = Color.White;

            IsAlive = true;

            Floor = null;
            LayerDepth = 100;
        }
 // Main control method for collisions between hitboxs, this identifies which specific collision detection method
 //      should be used and applies it, returning the result.
 public static bool collisionCheck(Hitbox a, Hitbox b)
 {
     switch(a.shape){
             case Shape.Circle:
         switch(b.shape){
                 case Shape.Circle:
             // Circle - Circle collision.
             return collisionCheckCircles(a, b);
                 case Shape.Rectangle:
             // Circle - Rectangle collision.
             return collisionCheckRectAndCircle(b, a);
                 default: break;
         }
         break;
             case Shape.Rectangle:
         switch(b.shape){
                 case Shape.Circle:
             // Rectangle - Circle collision.
             return collisionCheckRectAndCircle(a, b);
                 case Shape.Rectangle:
             // Rectangle - Rectangle collision.
             return collisionCheckRects(a, b);
                 default: break;
         }
         break;
             default: break;
     }
     return (a.hitbox.x == b.hitbox.x) && (a.hitbox.y == b.hitbox.y);
 }
 // Internal method for checking rectangle to rectangle collisions.
 private static bool collisionCheckRectsDirected(Hitbox a, Hitbox b)
 {
     Vector2 center = new Vector2(b.hitbox.x, b.hitbox.y);
     b.rotate(-2*b.angle);
     Vector2 rotated_b1 = alignPoint(new Vector2(b.hitbox.x + b.halfSize.x, b.hitbox.y + b.halfSize.y), b);
     Vector2 rotated_b2 = alignPoint(new Vector2(b.hitbox.x - b.halfSize.x, b.hitbox.y + b.halfSize.y), b);
     b.rotate(-2*b.angle);
     Vector2 rotated_b3 = center - rotated_b1;
     rotated_b1 += center;
     Vector2 rotated_b4 = center - rotated_b2;
     rotated_b2 += center;
     return pointInRect(a, rotated_b1) || pointInRect(a, rotated_b2) || pointInRect(a, rotated_b3) ||
             pointInRect(a, rotated_b4);
 }
 // Checks whether the given point is inside the given rectangle.
 public static bool pointInRect(Hitbox a, Vector2 b)
 {
     Vector2 alignedPoint = alignPoint(b, a);
     return (alignedPoint.x <= a.halfSize.x) && (alignedPoint.y <= a.halfSize.y) &&
             (-alignedPoint.x <= a.halfSize.x) && (-alignedPoint.y <= a.halfSize.y);
 }
 // Checks whether the given rectangles intersect. Will not detect cases where none of either rectangle's
 //      corners are touching or inside the other rectangle.
 public static bool collisionCheckRects(Hitbox a, Hitbox b)
 {
     float maxRadSum = a.halfSize.x + a.halfSize.y + b.halfSize.x + b.halfSize.y;
     if((Mathf.Abs(a.hitbox.x - b.hitbox.x) > maxRadSum) || (Mathf.Abs(a.hitbox.y - b.hitbox.y) > maxRadSum)){
         return false;
     }
     return collisionCheckRectsDirected(a, b) || collisionCheckRectsDirected(b, a);
 }
Example #58
0
 public void setOnFrameHitbox(int frame, Hitbox hitbox)
 {
     if (frame < 1 || frame > framemax)
         throw new ArgumentOutOfRangeException("frame", "Frame needs to be between 1 and framemax");
     if (hitbox == null)
         onFrameHitboxes[frame - 1] = new Hitbox(0, 0);
     else
         onFrameHitboxes[frame - 1] = hitbox;
 }
        // Checks whether the given circles intersect.
        public static bool collisionCheckCircles(Hitbox a, Hitbox b)
        {
            float sumRadius, xDiff, yDiff;

            sumRadius = a.halfSize.x + b.halfSize.x;
            xDiff = a.hitbox.x - b.hitbox.x;
            yDiff = a.hitbox.y - b.hitbox.y;

            return ((xDiff*xDiff) + (yDiff*yDiff) <= (sumRadius*sumRadius));
        }
        // Checks whether the given circle intersects with the given line segment.
        public static bool collisionCheckCircleAndLine(Hitbox circle, Vector2 a, Vector2 b)
        {
            Vector2 segment = b - a,
                    relCircle = new Vector2(circle.hitbox.x - a.x, circle.hitbox.y - a.y),
                    closest;

            float segmentLength = segment.magnitude;
            segment.Normalize();
            float relCircleProj = Vector2.Dot(relCircle, segment);

            if(relCircleProj < 0){ closest = a; }
            else if(relCircleProj > segmentLength){ closest = b; }
            else{ closest = relCircleProj*segment; }

            Vector2 distToCircle = new Vector2(circle.hitbox.x - closest.x, circle.hitbox.y - closest.y);
            if(distToCircle.sqrMagnitude < circle.hitbox.width*circle.hitbox.height){
                return true;
            }
            return false;
        }