Exemplo n.º 1
0
 public void update()
 {
     if (_leftStick.value.Length() > 0.1)
     {
         Angle = (float)Math.Atan2(_leftStick.value.Y, _leftStick.value.X);
         entity.transform.rotation = Angle;
         //_body.addImpulse(new Vector2(_leftStick.value.X * 5, _leftStick.value.Y * 5));
         _body.setVelocity(_leftStick.value * 300);
     }
 }
Exemplo n.º 2
0
 public void Reset(bool fromPlayer1 = true)
 {
     transform.position = new Vector2(Screen.width / 2 + 75 * (fromPlayer1 ? -1 : 1), Screen.height / 2);
     _rigidBody.setVelocity(_moveSpeed * (fromPlayer1 ? 1 : -1));
 }
Exemplo n.º 3
0
        //wow refactor me pls
        private void CheckGrounded()
        {
            if (!_shouldUpdate)
            {
                return;
            }
            _isUpdating = true;
            var phys              = Physics.getAllColliders();
            var colliders         = phys.AsEnumerable();
            var rect              = new RectangleF(playerEntity.entity.transform.position.X + 10, playerEntity.entity.transform.position.Y - 20, 20, 4);
            var neighborColliders = Physics.boxcastBroadphaseExcludingSelf(playerEntity.entity.colliders[0]);


            if (_player.activeState == Player.State.Climb)
            {
                playerEntity.shouldUseGravity = false;
            }
            else
            {
                playerEntity.shouldUseGravity = true;
            }

            if (_player.IgnoreGravity)
            {
                //playerEntity.shouldUseGravity = false;
                playerEntity.setVelocity(new Vector2(playerEntity.velocity.X, playerEntity.velocity.Y * 0.75f));
            }
            else
            {
                playerEntity.shouldUseGravity = true;
            }


            // loop through and check each Collider for an overlap
            foreach (var collider in neighborColliders)
            {
                if (collider.entity.tag == 30)
                {
                    if (collider.overlaps(_player.entity.colliders[0]))
                    {
                        if (!_player.ShouldBounce)
                        {
                            Console.WriteLine("SHOULD BOUNCE HERE");
                            _player.ShouldBounce = true;
                        }
                    }
                }

                //climbables
                if (collider.overlaps(playerEntity.entity.colliders[2]))
                {
                    if (collider.physicsLayer == 500 && _player.YAxisInput != 0)
                    {
                        _player.activeState = Player.State.Climb;
                        _player.LadderInUse = collider;
                    }
                }
                if (collider.overlaps(playerEntity.entity.colliders[0]))
                {
                    //enemies
                    if (collider.entity.tag == 5)
                    {
                    }
                    //drops
                    if (collider.entity.tag == 4)
                    {
                    }

                    //instadeath like spikes ;-;
                    if (collider.physicsLayer == 501)
                    {
                        if (collider.overlaps(playerEntity.entity.colliders[0]))
                        {
                            _player.Health = 0;
                        }
                    }
                }
            }

            //not on ladder, stop climbing
            if (_player.LadderInUse != null && !_player.LadderInUse.overlaps(playerEntity.entity.colliders[0]) && _player.activeState != Player.State.Float)
            {
                _player.activeState = Player.State.Normal;
                _player.LadderInUse = null;
            }


            foreach (var collider in colliders)
            {
                if (collider.physicsLayer == 100)
                {
                    //drops
                    if (collider.entity.tag == 4)
                    {
                        var drop = collider.entity.getComponent <Drop>();
                        if (drop.Collected)
                        {
                            drop.entity.destroy();
                            continue;
                        }
                        drop.SetMoveDirection(drop.transform.position, _player.transform.position);
                        drop.ActiveState = Drop.State.Follow;
                        if (collider.entity.colliders[0].overlaps(playerEntity.entity.colliders[0]))
                        {
                            drop.Collected = true;
                            _player.UpdateDropCount(drop.Value);
                            drop.entity.detachFromScene();
                        }
                    }
                }

                if (collider.physicsLayer == 1)
                {
                    //enemies
                    if (collider.entity.tag == 5)
                    {
                        var enemy = collider.entity.getComponent <Enemy>();
                        if (enemy.ActiveState == Enemy.State.Attack)
                        {
                            if (enemy._attackCount > 0 && collider.entity.colliders[1].overlaps(playerEntity.entity.colliders[0]) && _player.activeState != Player.State.Roll && enemy.AttackCanDamage)
                            {
                                _player.activeState = Player.State.Knockback;

                                if (!_player.IsInvuln)
                                {
                                    _shaking = true;
                                    _player.DoHurt(1);
                                }
                            }
                        }
                        if (enemy.Dead)
                        {
                            var pos = enemy.transform.position;
                            for (var i = 0; i < 5; i++)
                            {
                                var mult = -1;
                                if (i % 2 == 0)
                                {
                                    mult = 1;
                                }

                                var posX       = pos.X + 5 * i * mult;
                                var posY       = pos.Y - 5 * i * mult - 5;
                                var dropEntity = CreateDrop(new Vector2(posX, posY));
                            }
                            collider.entity.detachFromScene();
                            return;
                        }
                        if (collider.entity.getComponent <Enemy>().ActiveState != Enemy.State.Stun)
                        {
                            collider.entity.getComponent <Enemy>().CheckInRange(collider.entity.transform.position, playerEntity.transform.position);
                        }
                        if (Vector2.Distance(collider.entity.transform.position, _player.transform.position) < 100)
                        {
                            collider.entity.getComponent <Enemy>().SetMoveDirection(collider.entity.transform.position, playerEntity.transform.position);
                        }
                        else
                        {
                            collider.entity.getComponent <Enemy>().ActiveState = Enemy.State.Stun;
                        }
                    }
                    if (_player.activeState == Player.State.Attack)
                    {
                        if (collider.overlaps(playerEntity.entity.colliders[1]) && collider.entity.getComponent <Enemy>().ActiveState != Enemy.State.Stun)
                        {
                            collider.entity.getComponent <Enemy>().ActiveState = Enemy.State.Stun;
                            if (_player.ThirdAttack == true)
                            {
                                collider.entity.getComponent <Enemy>().DoHurt(2);
                                _shaking = true;
                            }
                            else
                            {
                                collider.entity.getComponent <Enemy>().DoHurt(1);
                                _shaking = true;
                            }
                        }
                    }
                    if (collider.overlaps(playerEntity.entity.colliders[0]) && playerEntity.entity.colliders[0] != collider && playerEntity.entity.colliders[1] != collider && _player.activeState != Player.State.Roll && _player.activeState != Player.State.Knockback)
                    {
                        _player.activeState = Player.State.Knockback;

                        if (!_player.IsInvuln)
                        {
                            _player.DoHurt(1);
                            _shaking = true;
                        }
                        //DisplayHealthBar();
                    }
                }
                if (collider.physicsLayer == 10)
                {
                    if (playerEntity.velocity.Y == 0)
                    {
                        _player.Grounded = true;
                    }
                }
                _isUpdating = false;
            }
        }