Beispiel #1
0
 public override void Init(Rectangle gameBounds)
 {
     base.Init(gameBounds);
     gameManager = GameManager.Instance;
     position.X = new Random(DateTime.Now.Millisecond).Next(gameBounds.Width - 128) + gameBounds.X + 64;
     position.Y = -coconutSize.Height;
     Collider = new Collider(position, coconutSize, false);
 }
Beispiel #2
0
 public virtual bool CollidesWith(Collider collider)
 {
     if (collider is MultiCollider && collisionBounds.Intersects(collider.CollisionBounds))
     {
         foreach (Collider col in ((MultiCollider)collider).Colliders)
         {
             if (collisionBounds.Intersects(col.CollisionBounds))
                 return true;
         }
         return false;
     }
     return collisionBounds.Intersects(collider.CollisionBounds);
 }
Beispiel #3
0
 public virtual bool IsInside(Collider collider)
 {
     return collider.CollisionBounds.Contains(collisionBounds);
 }
Beispiel #4
0
 private Vector2 CalculateCurrentColPos(Collider col)
 {
     if (direction == Direction.Left)
     {
         return new Vector2(base.CollisionBounds.X + (col.InitBounds.X * currentScale), base.CollisionBounds.Y + (col.InitBounds.Y * currentScale));
     }
     else if(direction == Direction.Right)
     {
         return new Vector2((base.CollisionBounds.X + base.CollisionBounds.Width) - (col.InitBounds.X * currentScale + col.CollisionBounds.Width), base.CollisionBounds.Y + (col.InitBounds.Y * currentScale));
     }
     return new Vector2();
 }
Beispiel #5
0
 public override bool IsInside(Collider collider)
 {
     if (base.IsInside(collider))
     {
         return true;
     }
     foreach (Collider col in Colliders)
     {
         if (col.Contains(collider)) return true;
     }
     return false;
 }
Beispiel #6
0
 public override bool CollidesWith(Collider collider)
 {
     if (!base.CollidesWith(collider))
     {
         return false;
     }
     foreach (Collider col in Colliders)
     {
         if (col.CollidesWith(collider)) return true;
     }
     return false;
 }
Beispiel #7
0
 /// <summary>
 /// Add an new collider to the multi collider important the new collider has to be placed relativ to 0,0 the multi collider will do the positionning
 /// himself
 /// </summary>
 /// <param name="col">Collider to add</param>
 public void AddCollider(Collider col)
 {
     col.MoveToPoint(CalculateCurrentColPos(col));
     Colliders.Add(col);
 }
Beispiel #8
0
 internal void HandleInput(TouchCollection touchCollection)
 {
     bool touchReleased = false;
     foreach (TouchLocation touch in touchCollection)
     {
         if (touch.State == TouchLocationState.Released)
         {
             touchReleased = true;
         }
     }
     if (touchReleased && playerState == PlayerState.Climbing)
     {
         playerState = PlayerState.Jumping;
         collider = jumpCollider;
         collider.MoveToPoint(position);
         if(CurrentAnimation != jumpAnimation)
             CurrentAnimation = jumpAnimation;
         headingDirection = (Direction)((int)headingDirection * -1);
         FitAnimationDirection();
     }
 }
Beispiel #9
0
        public override void Update(GameTime gameTime)
        {
            if (playerState != PlayerState.Dying && playerState != PlayerState.Dead)
            {
                playerScore += 1;
                if (isImmortal)
                {
                    immortalTime += gameTime.ElapsedGameTime.Milliseconds;
                    if (immortalTime > 2000)
                        isImmortal = false;
                }
            }
            if (playerState == PlayerState.Jumping)
            {
                position.X += (int)headingDirection * (10 + GameManager.Instance.GameSpeed);
                position.Y = position.X > gameYCenter ? position.Y + (1 * ((position.X - gameYCenter) / monkeyJumpGravity) * (int)headingDirection) : position.Y - (1 * ((gameYCenter - position.X) / monkeyJumpGravity) * (int)headingDirection);
                collider.MoveToPoint(position);

                if (position.X < gameBounds.X || position.X > gameBounds.Right)
                {
                    position.X = position.X < gameBounds.X ? gameBounds.X : gameBounds.Right;
                    position.Y = monkeyYLevel;
                    collider = climbCollider;
                    collider.MoveToPoint(position);
                    playerState = PlayerState.Climbing;
                    CurrentAnimation = climbAnimation;
                }
            }
            else if (playerState == PlayerState.Dying)
            {
                position.Y += gameTime.ElapsedGameTime.Milliseconds / 10 * GameManager.Instance.GameSpeed * 2f;
                collider.MoveToPoint(position);
                CurrentAnimation.Rotation += 0.9f;

                if (position.Y > gameBounds.Bottom)
                {
                    playerState = PlayerState.Dead;
                }
            }

            base.Update(gameTime);
        }