-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
224 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = []; | ||
}; |
Oops, something went wrong.