示例#1
0
 public void MoveTo(float posX, float posY, int duration)
 {
     moveDistance     = MathFunctions.getDistanceTo(this.position, new Vector2(posX, posY));
     moveAcceleration = 0;
     moveSpeed        = (float)(moveDistance / duration);
     moveDuration     = duration;
     moveAngle        = MathFunctions.getAngleTo(this.position, new Vector2(posX, posY));
     movePosition     = new Vector2(posX, posY);
 }
示例#2
0
 public void CheckCollision()
 {
     for (int i = currentScene.playerBulletList.Count() - 1; i >= 0; i--)
     {
         if (MathFunctions.getDistanceTo(this.position, currentScene.playerBulletList[i].getPosition()) <= bulletHitBox)
         {
             currentScene.playerBulletList[i].setAlive(false);
             health--;
         }
     }
 }
示例#3
0
        /*protected override void CheckCollision(Vector2 playerPosition)
         * {
         *  Vector2 origo = position + new Vector2((float)Math.Cos(angle) * (length / 2), (float)Math.Sin(angle) * (width / 2));
         *  test = Vector2.Zero;
         *  if (MathFunctions.getDistanceTo(origo, playerPosition) <= (length/2))
         *  {
         *      float checkAngle;
         *      Vector2 checkHit;
         *      checkAngle = MathFunctions.getAngleTo(Vector2.Zero, velocity) + MathFunctions.getAngleTo(origo, playerPosition);
         *      checkHit = new Vector2((float)Math.Cos(MathHelper.ToRadians(checkAngle))*(length*0.45f),(float)Math.Sin(MathHelper.ToRadians(checkAngle))*(width*0.45f));
         *      test = origo + checkHit;
         *      //if (checkHit.Length() <= MathFunctions.getDistanceTo(origo, playerPosition))
         *      if (checkHit.Length() >= MathFunctions.getDistanceTo(origo, playerPosition))
         *      {
         *          //setAlive(false);
         *      }
         *  }
         * }
         * ^*/
        protected override void CheckCollision(PlayerCharacter player)
        {
            origo      = position + new Vector2((float)Math.Cos(angle) * (length / 2), (float)Math.Sin(angle) * (length / 2));
            checkAngle = MathHelper.ToRadians(MathFunctions.getAngleTo(origo, player.getPosition()) - MathHelper.ToDegrees(angle));
            float distance = ((width / 2) * (length / 2)) / (float)Math.Sqrt((Math.Pow((length / 2) * Math.Sin(checkAngle), 2)) + (Math.Pow((width / 2) * Math.Cos(checkAngle), 2)));

            test = origo + new Vector2((float)Math.Cos(checkAngle - angle) * distance, (float)Math.Sin(checkAngle - angle) * distance);
            if (MathFunctions.getDistanceTo(origo, player.getPosition()) <= distance && player.getAlive() == true)
            {
                setAlive(false);
                player.takeHit();
            }
        }
示例#4
0
        public void MoveTo2(float posX, float posY, float acceleration)
        {
            moveDuration = 0;
            moveSpeed    = 0;
            float tempDistance = 0;

            moveDistance     = MathFunctions.getDistanceTo(this.position, new Vector2(posX, posY));
            moveAcceleration = acceleration;
            while (tempDistance < moveDistance)
            {
                moveSpeed    += acceleration;
                tempDistance += moveSpeed;
                moveDuration += 1;
            }
            tempDistance -= moveDistance;
            moveAngle     = MathFunctions.getAngleTo(this.position, new Vector2(posX, posY));
            position     -= new Vector2((float)Math.Cos(MathHelper.ToRadians(moveAngle)) * tempDistance, (float)Math.Sin(MathHelper.ToRadians(moveAngle)) * tempDistance);
            movePosition  = new Vector2(posX, posY);
        }