Skip to content

Commit

Permalink
Issue #98 Resolved merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
hal255 committed Dec 1, 2018
2 parents 816a867 + 64ac8df commit 2e1283a
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 130 deletions.
10 changes: 6 additions & 4 deletions client/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ const config = {
}
},
neutralMap:{
velocity: 120,
mapsCount: 2,
//velocity: 120,
//mapsCount: 2,
xRegion: 0.5,
zOrder: -1,
imgKey: "neutralMap",
imgSrc: "assets/img/floorBgAsset.png"
},
Expand Down Expand Up @@ -150,7 +152,7 @@ config.default.settings = {
tileHeight: 58,
tileWidth: 74,
wrapOffset: -1,
mapVelocity: 25,
mapVelocity: 10,
maxMapVelocity: 150,
difficultyInterval: 10000, //10 seconds
difficulty: "easy"
Expand All @@ -169,7 +171,7 @@ config.default.player = {
src: "../spriteLocation.png"
};

config.default.fog = {
config.default.darkness = {
key: "fog",
src: "assets/img/fogLayer.png"
}
Expand Down
56 changes: 29 additions & 27 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,35 @@

<html>

<head>

<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="author" content="@ean_dream" />
<meta name="description" content="An HTML5 Game Built with Phaser" />

<script type="text/javascript" src="lib/phaser.min.js"></script>
<script type="text/javascript" src="config/config.js"></script>
<script type="text/javascript" src="js/init.js"></script>
<script type="text/javascript" src="js/boot.js"></script>
<script type="text/javascript" src="js/load.js"></script>
<script type="text/javascript" src="js/menu.js"></script>
<script type="text/javascript" src="js/colorUtilities.js"></script>
<script type="text/javascript" src="js/gameLoopTools/neutralMap.js"></script>
<script type="text/javascript" src="js/gameLoopTools/playerUtilities.js"></script>
<script type="text/javascript" src="js/gameLoopTools/blockUtilities.js"></script>
<script type="text/javascript" src="js/gameLoopTools/fogUtilities.js"></script>
<script type="text/javascript" src="js/gameLoop.js"></script>
<script type="text/javascript" src="js/gameOverState.js"></script>
<script type="text/javascript" src="js/stateManager.js"></script>

<link rel="stylesheet" href="css/style.css">

<title>Path Light</title>

</head>
<head>

<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="author" content="@ean_dream" />
<meta name="description" content="An HTML5 Game Built with Phaser" />

<script type="text/javascript" src="lib/phaser.min.js"></script>
<script type="text/javascript" src="config/config.js"></script>
<script type="text/javascript" src="js/transformUtilities.js"></script>
<script type="text/javascript" src="js/init.js"></script>
<script type="text/javascript" src="js/boot.js"></script>
<script type="text/javascript" src="js/load.js"></script>
<script type="text/javascript" src="js/menu.js"></script>
<script type="text/javascript" src="js/gameLoopTools/colorUtilities.js"></script>
<script type="text/javascript" src="js/gameLoopTools/mapController.js"></script>
<script type="text/javascript" src="js/gameLoopTools/neutralMap.js"></script>
<script type="text/javascript" src="js/gameLoopTools/playerUtilities.js"></script>
<script type="text/javascript" src="js/gameLoopTools/blockUtilities.js"></script>
<script type="text/javascript" src="js/gameLoopTools/darknessUtilities.js"></script>
<script type="text/javascript" src="js/gameLoop.js"></script>
<script type="text/javascript" src="js/gameOverState.js"></script>
<script type="text/javascript" src="js/stateManager.js"></script>

<link rel="stylesheet" href="css/style.css">

<title>Path Light</title>

</head>

<body>

Expand Down
24 changes: 14 additions & 10 deletions client/js/gameLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

let gameLoop = {};
gameLoop = {
// phaser default methods (subStates) -------------------------

init: (data) => {
data = typeof data === "undefined" ? {} : data;
gameLoop.player = data.player || config.default.player;
Expand All @@ -19,8 +21,10 @@ gameLoop = {
else {
gameLoop.debugMode = false;
}

mapController.init();
neutralMap.init();
},
// phaser default methods (subStates) -------------------------

create: () => {
game.physics.startSystem(Phaser.Physics.ARCADE);
Expand All @@ -34,7 +38,7 @@ gameLoop = {
];
gameLoop.player.sprite = game.add.sprite(...playerStartData);
playerUtilities.create(gameLoop.player);
fogUtilities.create(gameLoop.player);
darknessUtilities.create(gameLoop.player);
// clicking the mouse during this state will change the control type to mouse
game.input.onDown.add(() => { gameLoop.player.controlType = config.default.controls.mouse; });

Expand All @@ -50,11 +54,11 @@ gameLoop = {
gameLoop.debug.controls = game.input.keyboard;
};

gameLoop.difficultyIncrease = gameLoop.manageDifficulty();
//gameLoop.difficultyIncrease = gameLoop.manageDifficulty(); // idk what this does lol
},

update: () => {
neutralMap.updateMap(); // update neutral map states[]
mapController.update();
playerUtilities.update(gameLoop.player);

//gameLoop.score.amount += gameLoop.score.bonus1;
Expand All @@ -63,12 +67,12 @@ gameLoop = {
gameLoop.score.interface.setText(gameLoop.score.text + gameLoop.score.amount);

if(gameLoop.debugMode){
let upScrollCheat = gameLoop.debug.controls.isDown(Phaser.KeyCode.OPEN_BRACKET);
let downScrollCheat = gameLoop.debug.controls.isDown(Phaser.KeyCode.CLOSED_BRACKET);
//let upScrollCheat = gameLoop.debug.controls.isDown(Phaser.KeyCode.OPEN_BRACKET);
//let downScrollCheat = gameLoop.debug.controls.isDown(Phaser.KeyCode.CLOSED_BRACKET);
let gameOverCheat = gameLoop.debug.controls.isDown(Phaser.KeyCode.SPACEBAR);

upScrollCheat ? neutralMap.setMapSpeed(-gameLoop.difficulty) : -1;
downScrollCheat ? neutralMap.setMapSpeed(gameLoop.difficulty) : -1;
//upScrollCheat ? neutralMap.setMapSpeed(-gameLoop.difficulty) : -1;
//downScrollCheat ? neutralMap.setMapSpeed(gameLoop.difficulty) : -1;
gameOverCheat ? game.state.start("end") : -1;
}

Expand All @@ -84,8 +88,8 @@ gameLoop = {
return;
};

gameLoop.velocity *= data.velocityIncrease;
neutralMap.setMapSpeed(gameLoop.velocity);
//gameLoop.velocity *= data.velocityIncrease;
//neutralMap.setMapSpeed(gameLoop.velocity);
//blockUtilities.setVelocity(gameLoop.velocity);

};
Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions client/js/gameLoopTools/darknessUtilities.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const darknessUtilities = {};
darknessUtilities.create = (player) => {
let darknessSprite = game.make.sprite(0, 0, config.default.darkness.key);
let darknessCenter = [0.5, 0.5];
darknessSprite.anchor.setTo(...darknessCenter);
player.sprite.addChild(darknessSprite);
};
7 changes: 0 additions & 7 deletions client/js/gameLoopTools/fogUtilities.js

This file was deleted.

91 changes: 91 additions & 0 deletions client/js/gameLoopTools/mapController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// This implementation of the map controller takes the same data as every other phaser state, which is the config variable.
// This avoids having to pass all the data needed for the mapController in explicitly, as all the data the controller needs is in the config.

const mapController = {};
// mapController properties - this is my C# influence ^_^ (Eric)
mapController.bottom;
mapController.top;
mapController.speed;
mapController.mapObjects; // Anything in here will move down with the map
// Anything in mapObjects must have a .height, .anchor, and .y component so that their positions can be defined and manipulated.
// Anything in mapObjects must also not use its .fullyOnMap property
// Optionally, anything in mapObjects can have these callbacks: .onFullyOnMap, .onFullyLeftMap

mapController.init = (data) => {
data = typeof data === "undefined" ? {} : data;
// external data
mapController.settings = data.settings || config.default.settings;
mapController.bottom = data.height || config.init.screenHeight;

// assign to internal member data
mapController.top = 0;
mapController.speed = mapController.settings.mapVelocity;
mapController.mapObjects = [];
};

/*
* Adds an object to the map to start traveling downwards.
*/
mapController.addToMap = (object) => {
if (object.height == null || object.anchor == null || object.y == null) {
console.log("Cannot add %s to the map because it doesn't contain .height, .anchor, or a .y property!", object);
return null;
}

let objectTop = transformUtilities.getTopPosition(object.y, object.height, object.anchor.y);
if (mapController.top <= objectTop)
object.fullyOnMap = true;
else
object.fullyOnMap = false;
mapController.mapObjects.push(object);
return object;
};

/*
* Adds an object specifically to the top of the map, right above where it will become visible.
*/
mapController.addToTopOfMap = (object) => {
let addedObj = mapController.addToMap(object); // This lets one function perform the null check without overriding the passed in object
if (addedObj == null)
return;
object = addedObj;
object.y = mapController.top - object.height * (1 - object.anchor.y); // anchor.y = 0 means anchor is at top of object
object.fullyOnMap = false;
};

mapController.update = () => {
for (i = mapController.mapObjects.length - 1; i >= 0; i--) { // Backwards iteration since items could be removed from the array
let object = mapController.mapObjects[i];

if (object.y == null) { // This is in case the mapController is not destroyed upon game state change
mapController.mapObjects.splice(i, 1);
continue;
}

object.y += mapController.speed;

let objectTop = transformUtilities.getTopPosition(object.y, object.height, object.anchor.y);

if (object.fullyOnMap === false) {
if (mapController.top <= objectTop) {
if (typeof (object.onFullyOnMap) === "function") {
object.onFullyOnMap(transformUtilities.getTopPosition(object.y, object.height, object.anchor.y));
}
object.fullyOnMap = true;
}
}

if (mapController.bottom <= objectTop) {
if (typeof (object.onFullyLeftMap) === "function")
object.onFullyLeftMap();
//if (typeof (object.destroy) === "function") // this should be used if there's some custom destruction method attached to .onFullyLeftMap
// object.destroy();
object.destroy();
mapController.mapObjects.splice(i, 1);
}
}
};

mapController.destroy = () => {
mapController.mapObjects = [];
};
Loading

0 comments on commit 2e1283a

Please sign in to comment.