Skip to content

Commit

Permalink
Updated highscores sent data to version 0.0.2.
Browse files Browse the repository at this point in the history
game.data.options moved to game.options.
.
  • Loading branch information
FranciscoKnebel committed Feb 19, 2018
1 parent 19ca5fd commit 0f54214
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 29 deletions.
2 changes: 1 addition & 1 deletion docs/js/app.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spaceinvader",
"version": "0.1.5",
"version": "0.1.6",
"main": "main.js",
"scripts": {
"build": "grunt dist && npm run build-linux && npm run build-win32 && npm run build-darwin",
Expand Down
16 changes: 8 additions & 8 deletions js/entities/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,25 @@ game.Player = me.Sprite.extend({
const currentVolume = me.audio.getVolume();

if (currentVolume <= 1.0) {
me.audio.setVolume(currentVolume + game.data.options.sound.changeRatio.keys);
me.audio.setVolume(currentVolume + game.options.sound.changeRatio.keys);
}
}

if (me.input.isKeyPressed('volume-mute')) {
if (game.data.options.muted === true) {
if (game.options.muted === true) {
me.audio.unmuteAll();
} else {
me.audio.muteAll();
}

game.data.options.muted = !game.data.options.muted;
game.options.muted = !game.options.muted;
}

if (me.input.isKeyPressed('volume-minus')) {
const currentVolume = me.audio.getVolume();

if (currentVolume >= game.data.options.sound.changeRatio.keys) {
me.audio.setVolume(currentVolume - game.data.options.sound.changeRatio.keys);
if (currentVolume >= game.options.sound.changeRatio.keys) {
me.audio.setVolume(currentVolume - game.options.sound.changeRatio.keys);
}
}

Expand All @@ -79,10 +79,10 @@ game.Player = me.Sprite.extend({

if (event.deltaY < 0) {
if (currentVolume <= 1.0) {
me.audio.setVolume(currentVolume + game.data.options.sound.changeRatio.wheel);
me.audio.setVolume(currentVolume + game.options.sound.changeRatio.wheel);
}
} else if (currentVolume >= game.data.options.sound.changeRatio.wheel) {
me.audio.setVolume(currentVolume - game.data.options.sound.changeRatio.wheel);
} else if (currentVolume >= game.options.sound.changeRatio.wheel) {
me.audio.setVolume(currentVolume - game.options.sound.changeRatio.wheel);
}

me.input.registerPointerEvent('wheel', me.game.viewport, (event2) => {
Expand Down
7 changes: 6 additions & 1 deletion js/entities/ui/startButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

game.menuButton1 = game.menuButton.extend({
onClick() {
me.state.change(me.state.PLAY, game.data.level);
game.data.startPlayTime = new Date();

game.data.level = 0;
game.data.score = 0;

me.state.change(me.state.PLAY, game.data.level, true);
}
});

Expand Down
4 changes: 2 additions & 2 deletions js/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ const game = {
onload() {
let options;
if (me.device.isMobile) {
options = game.data.options.mobile;
options = game.options.mobile;
} else {
options = game.data.options.default;
options = game.options.default;
}

if (!me.video.init(options.resolution.height, options.resolution.height, options.rendering)) {
Expand Down
6 changes: 3 additions & 3 deletions js/game_options.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
game.data.options = {
game.options = {
sound: {
muted: false,
changeRatio: {
Expand Down Expand Up @@ -36,8 +36,8 @@ game.data.options = {
};

game.constants = {
highscoresURI: 'https://spaceinvader-highscores.herokuapp.com',
// highscoresURI: 'localhost:3000',
// highscoresURI: 'https://spaceinvader-highscores.herokuapp.com',
highscoresURI: 'localhost:3000',
version: '<<si_release_version>>',
version_date: '<<si_current_date>>'
};
4 changes: 2 additions & 2 deletions js/highscores.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
game.socket = io(game.constants.highscoresURI);

game.socket.submitNewScore = (points, name) => {
game.socket.emit('new score', points, name, game.constants.version);
game.socket.submitNewScore = (points, level, name) => {
game.socket.emit('new score', points, level, name, me.device.isMobile, game.constants.version);
};

game.socket.on('score saved', () => {
Expand Down
5 changes: 4 additions & 1 deletion js/screens/help.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
game.HelpScreen = me.ScreenObject.extend({
onResetEvent(fromStartMenu) {
me.audio.pauseTrack();
me.audio.play('hit');

me.game.world.addChild(new me.ColorLayer('background', '#000000'), 0);

me.game.world.addChild(
Expand Down Expand Up @@ -58,7 +61,7 @@ game.HelpScreen = me.ScreenObject.extend({
if (fromStartMenu) {
me.state.change(me.state.MENU);
} else {
me.state.change(me.state.PLAY, game.data.level);
me.state.change(me.state.PLAY, game.data.level, false);
}
}
});
Expand Down
6 changes: 3 additions & 3 deletions js/screens/lost.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ game.LostScreen = me.ScreenObject.extend({

// Time buffer for the user to not spam through the screen.
const timeCountdown = new Date();
let timeLeft = game.data.options.constants.bufferTimeLimitMS;
let timeLeft = game.options.constants.bufferTimeLimitMS;

me.game.world.addChild(
new (me.Renderable.extend({
Expand Down Expand Up @@ -61,7 +61,7 @@ game.LostScreen = me.ScreenObject.extend({

if (timeLeft > 0) {
// There is still time left on the buffer, so recalculate
timeLeft = game.data.options.constants.bufferTimeLimitMS - (new Date() - timeCountdown);
timeLeft = game.options.constants.bufferTimeLimitMS - (new Date() - timeCountdown);
}

if (timeLeft > 0) {
Expand All @@ -86,7 +86,7 @@ game.LostScreen = me.ScreenObject.extend({
500, 'text', 10,
(name) => {
if (name.length > 0) {
game.socket.submitNewScore(game.data.score, name);
game.socket.submitNewScore(game.data.score, game.data.level + 1, name);
}
}
), 3);
Expand Down
9 changes: 7 additions & 2 deletions js/screens/play.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
game.PlayScreen = me.ScreenObject.extend({
onResetEvent(level) {
me.audio.playTrack('tronicles');
onResetEvent(level, fromStartMenu) {
if (fromStartMenu) {
me.audio.playTrack('tronicles');
} else {
me.audio.resumeTrack();
}

let background = '#000';

if (game.colors.backgrounds.level.length > level) {
Expand Down
6 changes: 5 additions & 1 deletion js/screens/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ game.StartMenuScreen = me.ScreenObject.extend({
switch (menuChoice.current) {
case 1:
game.data.startPlayTime = new Date();
me.state.change(me.state.PLAY, game.data.level);

game.data.level = 0;
game.data.score = 0;

me.state.change(me.state.PLAY, game.data.level, true);
break;
case 2:
me.state.change(me.state.HELP, true);
Expand Down
6 changes: 3 additions & 3 deletions js/screens/won.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ game.WonScreen = me.ScreenObject.extend({

// Time buffer for the user to not spam through the screen.
const timeCountdown = new Date();
let timeLeft = game.data.options.constants.bufferTimeLimitMS;
let timeLeft = game.options.constants.bufferTimeLimitMS;

me.game.world.addChild(
new (me.Renderable.extend({
Expand Down Expand Up @@ -61,7 +61,7 @@ game.WonScreen = me.ScreenObject.extend({

if (timeLeft > 0) {
// There is still time left on the buffer, so recalculate
timeLeft = game.data.options.constants.bufferTimeLimitMS - (new Date() - timeCountdown);
timeLeft = game.options.constants.bufferTimeLimitMS - (new Date() - timeCountdown);
}

if (timeLeft > 0) {
Expand Down Expand Up @@ -90,7 +90,7 @@ game.WonScreen = me.ScreenObject.extend({

if (action === 'continue' && bufferTimeLimitIsDone) {
game.data.level += 1;
me.state.change(me.state.PLAY, game.data.level);
me.state.change(me.state.PLAY, game.data.level, false);
}
});
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spaceinvader",
"version": "0.1.5",
"version": "0.1.6",
"main": "main.js",
"scripts": {
"build": "grunt dist && npm run build-linux && npm run build-win32 && npm run build-darwin",
Expand Down

0 comments on commit 0f54214

Please sign in to comment.