Skip to content

Commit

Permalink
Add a method
Browse files Browse the repository at this point in the history
  • Loading branch information
kjirou committed Jan 10, 2017
1 parent 8f13639 commit e1e0395
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -46,6 +46,7 @@
"sanitize.css": "4.1.0",
"string": "3.3.3",
"uuid": "3.0.1",
"victor": "1.1.0",
"vinyl-source-stream": "1.1.0",
"watchify": "3.7.0"
},
Expand Down
3 changes: 3 additions & 0 deletions src/state-models/complex-apis.js
Expand Up @@ -215,6 +215,9 @@ const computeTick = ({ allies, enemies, bullets, gameStatus }) => {
}

// TODO: 弾を発射する
// - 発射点・着弾点の算出
// - 行動から bullet state の生成
// - 対象が範囲のときに unit の位置から着弾するマス目を逆算して算出
// TODO: 対象が範囲の場合は範囲を持たす。

// Comsume AP
Expand Down
12 changes: 12 additions & 0 deletions src/state-models/location.js
Expand Up @@ -9,6 +9,8 @@
/** @module */
const angles = require('angles');

const { STYLES } = require('../immutable/constants');


const createNewLocationState = (y, x) => {
return { y, x };
Expand All @@ -24,6 +26,7 @@ const areSameLocations = (...locations) => {
};

/**
* Add any locations as vectors
* @param {...State~Location} locations
* @return {State~Location}
*/
Expand All @@ -37,6 +40,14 @@ const addLocations = (...locations) => {
return createNewLocationState(y, x);
};

/**
* @param {...State~Location} squareLocation
* @return {State~Location}
*/
const calculateCenterOfSquare = (squareLocation) => {
return addLocations(squareLocation, createNewLocationState(STYLES.SQUARE_HEIGHT / 2, STYLES.SQUARE_WIDTH / 2));
};

/**
* @param {State~Location} a
* @param {State~Location} b
Expand Down Expand Up @@ -99,6 +110,7 @@ const performPseudoVectorAddition = (initial, terminal, scalar) => {
module.exports = {
addLocations,
areSameLocations,
calculateCenterOfSquare,
createNewLocationState,
measureAngleWithTopAsZero,
measureDistance,
Expand Down
7 changes: 7 additions & 0 deletions test/state-models/location.js
Expand Up @@ -3,6 +3,7 @@ const assert = require('power-assert');
const {
addLocations,
areSameLocations,
calculateCenterOfSquare,
createNewLocationState,
measureAngleWithTopAsZero,
measureDistance,
Expand All @@ -22,6 +23,12 @@ describe('state-models/location', () => {
});
});

describe('calculateCenterOfSquare', () => {
it('can execute correctly', () => {
assert.deepStrictEqual(calculateCenterOfSquare(_loc(0, 48)), _loc(24, 72));
});
});

describe('areSameLocations', () => {
it('can execute correctly', () => {
assert.strictEqual(areSameLocations(_loc(0, 0), _loc(0, 0)), true);
Expand Down

0 comments on commit e1e0395

Please sign in to comment.