claw-machine-js
Version:
A physics based claw-machine simulation
70 lines (69 loc) • 3.55 kB
TypeScript
import { IClaw } from '../interfaces/Claw.ts';
import { IBall } from '../interfaces/Ball.ts';
import { ICollisionPoints } from '../interfaces/ICollisionPoints.ts';
import { IInitialBall } from '../interfaces/InitialBall.ts';
/**
* calculates the collision points for the claw and the divider line
*
* @param claw the current claw
* @param clawSize the size of the claw
* @param clawWidth the width of the claw
* @param width the width of the canvas
* @param height the height of the canvas
* @param dividerLineWidth the space width on the right side of the canvas
* @param dividerLineThickness the thickness of the divider line itself
* @param dividerLineHeight the height of the divider line
*/
export declare const getCollisionPoints: (claw: IClaw, clawSize: number, clawWidth: number, width: number, height: number, dividerLineWidth: number, dividerLineThickness: number, dividerLineHeight: number) => ICollisionPoints;
/**
* iterates through all balls and calculates the new positions after the collision with other balls
*
* @param balls the list of all balls in the machine
* @param gravity the current gravity effecting all balls
* @param width the width of the claw machine
* @param height the height of the claw machine
* @param friction the friction if the ball hits another ball
* @param groundFriction friction if a ball hits the ground
* @param handleClawTouchedBall function that if called, if a ball touches the inner claw
* @param claw the current claw
* @param collisionPoints object that contains all points of the canvas edges, the claw and the divider line to calculate the collisions
*/
export declare const calculateNewBallPositionsAfterCollision: (balls: IBall[], gravity: number, width: number, height: number, friction: number, groundFriction: number, handleClawTouchedBall: () => void, claw: IClaw, collisionPoints: ICollisionPoints) => IBall[];
/**
* checks if there are balls inside the claw if the claw reaches the upper height of the canvas
*
* @param balls all balls in the machine
* @param dividerLineHeight the height of the divider line
*/
export declare const checkIfOneOrMoreBallsAreAllGrabbed: (balls: IBall[], dividerLineHeight: number) => boolean;
/**
* calculates the new claw y position to reach the targetY position
*
* @param claw the current claw
* @param clawStartPositionY the idle height of the claw
*/
export declare const calculateNewClawYPosition: (claw: IClaw, clawStartPositionY: number) => void;
/**
* calculates the new claw x position to reach the targetX position
*
* @param claw the current claw
* @param width the with of the claw machine
*/
export declare const calculateNewClawXPosition: (claw: IClaw, width: number) => void;
/**
* calculates the new claw angle to reach the target Angle
*
* @param claw the current claw
*/
export declare const calculateNewClawAnglePosition: (claw: IClaw) => void;
/**
* creates the initial Balls array for array and skips balls that have already been dropped
*
* @param balls list of all balls inside the machine
* @param alreadyDroppedBalls list of already dropped balls
* @param width with of the claw machine
* @param height height of the claw machine
* @param ballRadius standard Radius for the balls (used if no individual ball radius provided)
* @param dividerLineWidth width of the drop zone on the right side
*/
export declare const createInitialBalls: (balls: IInitialBall[], alreadyDroppedBalls: IBall[], width: number, height: number, ballRadius: number, dividerLineWidth: number) => IBall[];