void AutoControl() { isSquishing = true; if (squishCooldown > 0) { squishCooldown--; } if (squishCooldown <= 0) //cooldown just ran out { isMoving = true; isSquishing = false; squishCooldown = maxSquishCooldown; Entity nearestGoal = GetNearestGoal(); if (nearestGoal == null) { return; } //calculate angle aimAngle = GameMath.GetAngleBetweenPoints(x, y, nearestGoal.x, nearestGoal.y); AddForce(jumpForce, aimAngle); } }
void UserControl() { if (isSelected && !isInGroup) { isSquishing = true; if (squishCooldown > 0) { squishCooldown--; } //calculate aim angle float angleToMouse = GameMath.GetAngleBetweenPoints(x * Renderer.cam.scale, y * Renderer.cam.scale, InputManager.mouseX, InputManager.mouseY); aimAngle = angleToMouse + (float)Math.PI; //calculate mouse pull pullDistance = GameMath.GetDistanceBetweenPoints((x + 4) * Renderer.cam.scale, (y + 4) * Renderer.cam.scale, InputManager.mouseX, InputManager.mouseY); pullPercentage = (float)(pullDistance / maxPullDistance); if (pullPercentage > 1) { pullPercentage = 1; } if (pullPercentage < 0.3f) { pullPercentage = 0.5f; } //calculate target positioning float targetDist = maxJumpDistance * pullPercentage; currentJumpForce = jumpForce * pullPercentage; } else { if (wasSelected == isSelected) //only reset if the mouse wasn't JUST released { isSquishing = false; squishCooldown = maxSquishCooldown; } } //jump is ready! (mouse has been released, no longer squishing if (isSquishing && wasSelected && !isSelected) { isSquishing = false; squishCooldown = maxSquishCooldown; //Jump(aimAngle); AddForce(currentJumpForce, aimAngle); //Game.debugOutput = currentJumpForce.ToString(); currentJumpForce = jumpForce; //reset jump force //Jump(CalculateJumpAngle()); } }
public void Bounce(Entity col) { float movementAngle = GameMath.GetAngleBetweenPoints(x, y, v.vX, v.vY); if (Math.Abs((x + 4) - (col.x + (col.width / 2))) >= Math.Abs((y + 4) - (col.y + (col.height / 2)))) { //predominantly horizontal v.vX = -v.vX; } else { //predominantly vertical v.vY = -v.vY; } }
public float GetAngleOfAcceleration() { return(GameMath.GetAngleBetweenPoints(x, y, x + a.aX, y + a.aY)); }
public float GetAngleOfMotion() { return(GameMath.GetAngleBetweenPoints(x, y, x + v.vX, y + v.vY)); }
public override void Update() { if (GetStrengthOfMotion() == 0) { isMoving = false; } else { isMoving = true; } if (isMoving) { movingTime++; } if (movingTime > maxMovingTime) { v = new Velocity(0, 0); movingTime = 0; } //execute jump if (!isMoving) { isSquishing = true; if (squishCooldown > 0) { squishCooldown--; } if (squishCooldown <= 0) //if cooldown just ran out { isMoving = true; isSquishing = false; squishCooldown = maxSquishCooldown; Entity nearestGoal = GetNearestGoal(); if (nearestGoal == null) { return; } //calculate aim angle aimAngle = GameMath.GetAngleBetweenPoints(x, y, nearestGoal.x, nearestGoal.y); //move towards target AddForce(jumpForce, aimAngle); } } //handle tounge if (!tounge.isOut) { //update position tounge.x = x; tounge.y = y; //search for something to grab foreach (Entity e in EntityManager.GetEntities()) { if (e.GetType() == typeof(Pickup) && GameMath.GetDistanceBetweenPoints(x, y, e.x, e.y) < toungeRange) { Pickup p = (Pickup)e; tounge.SetTarget(new Vector2(p.x, p.y), p); tounge.isOut = true; } } } //update tounge if out if (tounge.isOut) { tounge.Update(); } UpdateSprite(); base.Update(); }