Skip to content

Commit

Permalink
Issue #98 Implemented particles, but need to emit from staff and not …
Browse files Browse the repository at this point in the history
…from face
  • Loading branch information
hal255 committed Dec 1, 2018
1 parent 8a4a575 commit 7ebd91e
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 6 deletions.
Binary file added client/assets/img/bubble.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
12 changes: 10 additions & 2 deletions client/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,16 @@ config.default.player = {
};

config.default.darkness = {
key: "fog",
src: "assets/img/fogLayer.png"
key: "darkness",
src: "assets/img/darknessLayer.png"
}

config.default.particles = {
key: "particles",
src: "assets/img/bubble.png",
emitter: {},
offsetX: 0,
offsetY: 0
}

config.default.blocks = {
Expand Down
1 change: 1 addition & 0 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<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/gameLoopTools/particlesUtilities.js"></script>
<script type="text/javascript" src="js/gameLoopTools/scoreUtilities.js"></script>
<script type="text/javascript" src="js/gameLoop.js"></script>
<script type="text/javascript" src="js/gameOverState.js"></script>
Expand Down
11 changes: 7 additions & 4 deletions client/js/gameLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ gameLoop = {

init: (data) => {
data = typeof data === "undefined" ? {} : data;
gameLoop.player = data.player || config.default.player;
gameLoop.score = data.score || config.default.score;
gameLoop.width = data.width || config.init.screenWidth;
gameLoop.height = data.height || config.init.screenHeight;
gameLoop.player = data.player || config.default.player;
gameLoop.score = data.score || config.default.score;
gameLoop.particles = data.particles || config.default.particles;
gameLoop.width = data.width || config.init.screenWidth;
gameLoop.height = data.height || config.init.screenHeight;
gameLoop.xStartRegion = data.xStartRegion || config.gameLoop.xStartRegion;
gameLoop.yStartRegion = data.yStartRegion || config.gameLoop.yStartRegion;
gameLoop.difficulty = data.difficulty || config.default.settings.difficulty;
Expand Down Expand Up @@ -39,6 +40,7 @@ gameLoop = {
gameLoop.player.sprite = game.add.sprite(...playerStartData);
playerUtilities.create(gameLoop.player);
darknessUtilities.create(gameLoop.player);
particlesUtilities.create(gameLoop.particles, 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 @@ -55,6 +57,7 @@ gameLoop = {
update: () => {
mapController.update();
playerUtilities.update(gameLoop.player);
particlesUtilities.update(gameLoop.particles, gameLoop.player);

// update score
scoreUtilities.setText(gameLoop.score, gameLoop.score.amount + gameLoop.score.bonus);
Expand Down
34 changes: 34 additions & 0 deletions client/js/gameLoopTools/particlesUtilities.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const particlesUtilities = {};
particlesUtilities.create = (particles, player) => {
let emitterX = player.sprite.x + config.default.particles.offsetX;
let emitterY = player.sprite.y + config.default.particles.offsetY;
particles.emitter = game.add.emitter(emitterX, emitterY, 200);

particles.emitter.makeParticles(config.default.particles.key);

particles.emitter.setRotation(0, 100);
particles.emitter.setAlpha(1, 1);
particles.emitter.setScale(0.3, 0, 0.3, 0, 3000);
particles.emitter.gravity = 200;

// false means don't explode all the sprites at once, but instead release at a rate of one particle per 100ms
// The 5000 value is the lifespan of each particle before it's killed
particles.emitter.start(false, 1000, 100);
};

particlesUtilities.update = (particles, player) => {
var px = player.sprite.body.velocity.x;
var py = player.sprite.body.velocity.y;

px *= -1;
py *= -1;

particles.emitter.minParticleSpeed.set(px, py);
particles.emitter.maxParticleSpeed.set(px, py);

particles.emitter.emitX = player.sprite.x + config.default.particles.offsetX;
particles.emitter.emitY = player.sprite.y + config.default.particles.offsetY;

// emitter.forEachExists(game.world.wrap, game.world);
game.world.wrap(player.sprite, 64);
};
1 change: 1 addition & 0 deletions client/js/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ loadState = {
game.load.image(config.default.blocks.quarter.key, config.default.blocks.quarter.src);
game.load.image(config.default.neutralMap.key, config.default.neutralMap.src);
game.load.image(config.default.darkness.key, config.default.darkness.src);
game.load.image(config.default.particles.key, config.default.particles.src);

// Game over loads
game.load.image(config.gameOverState.restartButton.key, config.gameOverState.restartButton.src);
Expand Down

0 comments on commit 7ebd91e

Please sign in to comment.