Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu.js jsdocs #104

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions client/js/gameLoopTools/playerUtilities.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
const playerUtilities = {};

/**
* Creates player avatar
* @param {Object} player - classless object
* @return {Object} - returns object with character classes
*/
playerUtilities.create = (player) => {
game.physics.enable(player.sprite, Phaser.Physics.ARCADE);
player.sprite.body.collideWorldBounds = true;
const spriteCenter = [0.5, 0.5];
player.sprite.anchor.setTo(...spriteCenter);
};

/**
*
* @param {Object} player
*/
playerUtilities.update = (player) => {
playerUtilities.move(player, player.controlType);
};

/**
* Determines the device the user is on and moves character accordingly
* @param {Object} player - object representing the character
* @param {Number} type - defines whether play is using a keyboard, mouse or phone
* @returns {Number} - the type of device the user is playing on
*/
playerUtilities.move = (player, type) => {
let mouseType = type === 0;
let keyboardType = type === 1;
Expand All @@ -23,6 +39,12 @@ playerUtilities.move = (player, type) => {

return type;
};

/**
* Moves the player in the direction of keyboard press.
* @param {Object} player - The player object.
* @param {Number} playerSpeed - The current speed of the player.
*/
playerUtilities.mouseMovement = (player, playerSpeed) => {
let movementVector = {
x: game.input.x - player.x,
Expand Down
17 changes: 15 additions & 2 deletions client/js/menu.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
// initialize menuState 1st so it functions as a namespace
/**
* Initializes the menuState 1st; declaring all the variables for width, height, etc.. so menuState will functions as a namespace.
* @function init
* @param {Object} data An object declaring the width, height, background, title, startButton, and startButtonDots
* @return {Object}
*/
let menuState = {};
menuState = {
init: (data) => {
Expand All @@ -11,7 +16,15 @@ menuState = {
menuState.startButton = data.menuState.startButton || config.menuState.startButton;
menuState.startButtonDots = data.menuState.startButtonDots || config.menuState.startButtonDots;
},

/** $pure
* Makes sure the background image fills the game display no matter the size of the background.
* @function getScaleValueToEnvelopeRect
* @param {Object} childWidth Background width
* @param {Object} childHeight Background height
* @param {Object} parentWidth The game display's width
* @param {Object} parentHeight The game display's height
* @return {Number}
*/
getScaleValueToEnvelopeRect: (childWidth, childHeight, parentWidth, parentHeight) => {
let xScale = parentWidth / childWidth;
let yScale = parentHeight / childHeight;
Expand Down