Skip to content

Commit

Permalink
Use named modules
Browse files Browse the repository at this point in the history
  • Loading branch information
quantuminformation committed Jul 10, 2016
1 parent 3bc6b43 commit 9fc96b4
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 27 deletions.
2 changes: 1 addition & 1 deletion lib/Common.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Stuff that's shared among a lot of things in this game
*/
export default {
export const common = {
defaultY: 1,// presently all the objects are on the same horizontal plane

MEDIUM_UNIT_SIZE: 1,
Expand Down
8 changes: 4 additions & 4 deletions lib/Ground.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Common from "./Common";
import {common} from "./Common";
/**
*
* The ground (actually a grid in space) that the game sits upon
Expand All @@ -12,11 +12,11 @@ export default class Ground {
constructor(scene) {

//Creation of a plane with a texture
this.mesh = BABYLON.Mesh.CreatePlane("ground", Common.MEDIUM_SIZE_MAP, scene);
this.mesh = BABYLON.Mesh.CreatePlane("ground", common.MEDIUM_SIZE_MAP, scene);
var matGround = new BABYLON.StandardMaterial("matGround", scene);
matGround.diffuseTexture = new BABYLON.Texture("lib/assets/img/background.png", scene);
matGround.diffuseTexture.uScale = Common.MEDIUM_SIZE_MAP_SUBDIVISIONS;
matGround.diffuseTexture.vScale = Common.MEDIUM_SIZE_MAP_SUBDIVISIONS;
matGround.diffuseTexture.uScale = common.MEDIUM_SIZE_MAP_SUBDIVISIONS;
matGround.diffuseTexture.vScale = common.MEDIUM_SIZE_MAP_SUBDIVISIONS;
matGround.specularColor = new BABYLON.Color3(0, 0, 0);
this.mesh.material = matGround;
this.mesh.rotation.x = Math.PI / 2;
Expand Down
2 changes: 1 addition & 1 deletion lib/WebAudio.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Common from "./Common";
import {common} from "./Common";
/**
*
* Game sounds
Expand Down
2 changes: 1 addition & 1 deletion lib/ai/AttackStrategy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Common from "./Common";
import {common} from "../Common";
/**
*
* AttackStrategy
Expand Down
18 changes: 11 additions & 7 deletions lib/game.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Core from "./gameUnits/Core";
import Formations from "./utils/Formations.ts";
import Common from "./Common";
import {common} from "./Common";
import {IGameUnit} from "./gameUnits/IGameUnit";
import Ground from "./Ground";
import Lobby from "./hud/Lobby";
Expand Down Expand Up @@ -164,11 +164,15 @@ class Game {
var unit = selectedUnits[i];

//pythagoras
var distance = Math.sqrt(Math.pow(pickResult.x - unit.mesh.position.x, 2) + Math.pow(pickResult.z - unit.mesh.position.z, 2));
var framesNeeded = Math.round((distance / Common.MEDIUM_SPEED) * Common.ANIMATIONS_FPS);
var distance = Math.sqrt(Math.pow(pickResult.x - unit.mesh.position.x, 2)
+ Math.pow(pickResult.z - unit.mesh.position.z, 2));
var framesNeeded = Math.round((distance / common.MEDIUM_SPEED) * common.ANIMATIONS_FPS);
console.log('dist: ' + distance + ' frames' + framesNeeded);

var animationBezierTorus = new BABYLON.Animation("animationCore", "position", Common.ANIMATIONS_FPS, BABYLON.Animation.ANIMATIONTYPE_VECTOR3, BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
var animationBezierTorus = new BABYLON.Animation("animationCore", "position",
common.ANIMATIONS_FPS,
BABYLON.Animation.ANIMATIONTYPE_VECTOR3,
BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
var keysBezierTorus = [];
keysBezierTorus.push({frame: 0, value: unit.mesh.position});

Expand All @@ -192,18 +196,18 @@ class Game {
var cores = [];
for (var i = 0; i < this.startingNumberOfCores; i++) {
var core = new Core(this._scene, true);
core.mesh.position.y = Common.defaultY;
core.mesh.position.y = common.defaultY;
cores.push(core)
}
return cores;
}

setUpDummyEnemys() {
var core = new Core(this._scene, false);
core.mesh.position = new Vector3(10, Common.defaultY, 10);
core.mesh.position = new Vector3(10, common.defaultY, 10);
this.enemyUnits.push(core);
var core2 = new Core(this._scene, false);
core2.mesh.position = new Vector3(11, Common.defaultY, 11);
core2.mesh.position = new Vector3(11, common.defaultY, 11);
this.enemyUnits.push(core2);
}

Expand Down
6 changes: 4 additions & 2 deletions lib/gameUnits/CenterOfMassMarker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import UnitCommand from '../utils/UnitCommand';
import Common from "../Common";
import {common} from "../Common";
import {IGameUnit} from "../gameUnits/IGameUnit";
import ActionEvent = BABYLON.ActionEvent;
import Laser from "../weapons/Laser";
Expand All @@ -26,7 +26,9 @@ export default class CenterOfMassMarker {
*/
constructor(scene, isOwn) {

this.mesh = BABYLON.Mesh.CreateBox("sphere1", {width: Common.MEDIUM_UNIT_SIZE,height: Common.MEDIUM_UNIT_SIZE}, scene);
this.mesh = BABYLON.Mesh.CreateBox("sphere1", {
width: common.MEDIUM_UNIT_SIZE,height: common.MEDIUM_UNIT_SIZE
}, scene);
this.isOwn = isOwn;

var material = new BABYLON.StandardMaterial("green", scene);
Expand Down
6 changes: 3 additions & 3 deletions lib/gameUnits/Core.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import UnitCommand from '../utils/UnitCommand';
import Common from "../Common";
import {common} from "../Common";
import {IGameUnit} from "../gameUnits/IGameUnit";
import ActionEvent = BABYLON.ActionEvent;
import Laser from "../weapons/Laser";
Expand All @@ -20,7 +20,7 @@ export default class Core implements IGameUnit {
modifiers:Array<any>;
hitPoints:number = 10;
click:(e:MouseEvent)=>void;
baseSpeed:number = Common.MEDIUM_SPEED;
baseSpeed:number = common.MEDIUM_SPEED;
weapon:Laser = new Laser();
mass:number = 1;

Expand All @@ -40,7 +40,7 @@ export default class Core implements IGameUnit {
*/
constructor(scene, isOwn, isSelected = false) {

this.mesh = BABYLON.Mesh.CreateSphere("sphere1", 8, Common.MEDIUM_UNIT_SIZE, scene);
this.mesh = BABYLON.Mesh.CreateSphere("sphere1", 8, common.MEDIUM_UNIT_SIZE, scene);
// this.mesh.parentClass = this;
this.isSelected;//selected units receive commands
this.modifiers = [];//powerups,shields etc
Expand Down
6 changes: 3 additions & 3 deletions lib/hud/GameOverlay.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {IGameUnit} from "../gameUnits/IGameUnit";
import Common from "../Common";
import {common} from "../Common";
import Config from "../Config";
import BoundingInfo = BABYLON.BoundingInfo;
import FreeCamera = BABYLON.FreeCamera;
Expand Down Expand Up @@ -35,7 +35,7 @@ export default class GameOverlay {

createEvents() {
this._onPointerDown = (evt:PointerEvent) => {
if (evt.button != Common.MOUSE.LEFT) {
if (evt.button != common.MOUSE.LEFT) {
return;
}
console.log("pointer down")
Expand Down Expand Up @@ -68,7 +68,7 @@ export default class GameOverlay {
}

this._onPointerUp = (evt:PointerEvent) => {
if (evt.button != Common.MOUSE.LEFT) {
if (evt.button != common.MOUSE.LEFT) {
return;
}
console.log("pointer up")
Expand Down
7 changes: 4 additions & 3 deletions lib/utils/Formations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Common from "../Common"
import {common} from "../Common"
import {IGameUnit} from "../gameUnits/IGameUnit";
import Vector3 = BABYLON.Vector3;

Expand Down Expand Up @@ -26,7 +26,8 @@ export default class Formations {
for (var i = 0; i < amount; i++) {
var angleDeg = i * (360 / amount);
var angleRad = (angleDeg / 360) * 2 * Math.PI;
var customVector = new BABYLON.Vector3(-Math.cos(angleRad) * spacing, Common.defaultY * spacing, -Math.sin(angleRad) * spacing);
var customVector = new BABYLON.Vector3(-Math.cos(angleRad) * spacing,
common.defaultY * spacing, -Math.sin(angleRad) * spacing);
arr.push(center.add(customVector));
}

Expand All @@ -48,7 +49,7 @@ export default class Formations {
totalZ += unit.mesh.position.z * unit.mass
})

return new Vector3 (totalX / totalMass,Common.defaultY, totalZ / totalMass);
return new Vector3 (totalX / totalMass,common.defaultY, totalZ / totalMass);
}
static Distance2D(from:Vector3,to:Vector3) {
return Math.sqrt(Math.pow(from.x - to.x, 2) + Math.pow(from.z -to .z, 2));
Expand Down
4 changes: 2 additions & 2 deletions lib/weapons/Laser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {IGameUnit} from "../gameUnits/IGameUnit";
import WeaponModifier from "../modifiers/WeaponModifier";
import StandardMaterial = BABYLON.StandardMaterial;
import Formations from "../utils/Formations";
import Common from "../Common";
import {common} from "../Common";
import {IWeapon} from "./IWeapon";

/**
Expand Down Expand Up @@ -62,7 +62,7 @@ export default class Laser implements IWeapon {
material.emissiveColor = BABYLON.Color3.Green();
mesh.material = material;

var animationFadeOut = new BABYLON.Animation("animationCore", "position", Common.ANIMATIONS_FPS, BABYLON.Animation.ANIMATIONTYPE_VECTOR3, BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
var animationFadeOut = new BABYLON.Animation("animationCore", "position", common.ANIMATIONS_FPS, BABYLON.Animation.ANIMATIONTYPE_VECTOR3, BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
/* var keys = [];
keys.push({frame: 0, value: 1});
Expand Down

0 comments on commit 9fc96b4

Please sign in to comment.