Browse Source

Final commit!

master
Jeasonfire 4 years ago
parent
commit
f17d656f20
9 changed files with 80 additions and 12 deletions
  1. 22
    6
      js/gameState.js
  2. 13
    0
      js/gui.js
  3. 3
    0
      js/preloadingState.js
  4. BIN
      res/img/infobutton.png
  5. BIN
      res/img/infoscreen.png
  6. BIN
      res/img/restart.png
  7. 21
    6
      src/gameState.ts
  8. 18
    0
      src/gui.ts
  9. 3
    0
      src/preloadingState.ts

+ 22
- 6
js/gameState.js View File

@@ -14,6 +14,7 @@ var GameState = (function () {
this.averageHunger = 0;
this.houseBuildingCooldown = 0.1;
this.lastHouseBuilt = 0;
this.changingVolume = false;
}
GameState.prototype.create = function () {
gui.close();
@@ -133,25 +134,40 @@ var GameState = (function () {
}
};
GameState.prototype.updateSound = function (vol) {
var _this = this;
if (this.averageHunger < Person.MILDLY_HUNGRY) {
if (this.happyMusic.volume == 0) {
this.game.add.tween(this.happyMusic).to({ volume: vol }, 500, Phaser.Easing.Default, true);
if (this.happyMusic.volume == 0 && !this.changingVolume) {
this.changingVolume = true;
this.game.add.tween(this.happyMusic).to({ volume: vol }, 500, Phaser.Easing.Default, true).onComplete.add(function () { _this.changingVolume = false; }, this);
this.game.add.tween(this.worryMusic).to({ volume: 0 }, 500, Phaser.Easing.Default, true);
this.game.add.tween(this.dangerMusic).to({ volume: 0 }, 500, Phaser.Easing.Default, true);
}
}
else if (this.averageHunger < Person.VERY_HUNGRY) {
if (this.worryMusic.volume == 0) {
if (this.worryMusic.volume == 0 && !this.changingVolume) {
this.changingVolume = true;
this.game.add.tween(this.happyMusic).to({ volume: 0 }, 500, Phaser.Easing.Default, true);
this.game.add.tween(this.worryMusic).to({ volume: vol }, 500, Phaser.Easing.Default, true);
this.game.add.tween(this.worryMusic).to({ volume: vol }, 500, Phaser.Easing.Default, true).onComplete.add(function () { _this.changingVolume = false; }, this);
this.game.add.tween(this.dangerMusic).to({ volume: 0 }, 500, Phaser.Easing.Default, true);
}
}
else {
if (this.dangerMusic.volume == 0) {
if (this.dangerMusic.volume == 0 && !this.changingVolume) {
this.changingVolume = true;
this.game.add.tween(this.happyMusic).to({ volume: 0 }, 500, Phaser.Easing.Default, true);
this.game.add.tween(this.worryMusic).to({ volume: 0 }, 500, Phaser.Easing.Default, true);
this.game.add.tween(this.dangerMusic).to({ volume: vol }, 500, Phaser.Easing.Default, true);
this.game.add.tween(this.dangerMusic).to({ volume: vol }, 500, Phaser.Easing.Default, true).onComplete.add(function () { _this.changingVolume = false; }, this);
}
}
if (!this.changingVolume) {
if (this.happyMusic.volume != 0) {
this.happyMusic.volume = vol;
}
if (this.worryMusic.volume != 0) {
this.worryMusic.volume = vol;
}
if (this.dangerMusic.volume != 0) {
this.dangerMusic.volume = vol;
}
}
};

+ 13
- 0
js/gui.js View File

@@ -18,6 +18,10 @@ var GameGUI = (function () {
this.averageHungerFull = this.game.make.sprite(475, 528, "hungerFull");
this.averageHungerFull.smoothed = false;
this.averageHungerFull.scale.setTo(8, 8);
this.infoScreen = this.game.make.sprite(0, 0, "infoscreen");
var infoButton = this.game.make.button(625, 551, "infobutton", this.toggleInfoScreen, this);
this.toggleInfoScreen();
var restartButton = this.game.make.button(680, 550, "restart", this.restart, this);
foregroundGroup.add(this.buttonAutoFarm);
foregroundGroup.add(this.workingPeople);
foregroundGroup.add(this.amountOfHouses);
@@ -25,6 +29,9 @@ var GameGUI = (function () {
foregroundGroup.add(avgText);
foregroundGroup.add(this.averageHungerEmpty);
foregroundGroup.add(this.averageHungerFull);
foregroundGroup.add(this.infoScreen);
foregroundGroup.add(infoButton);
foregroundGroup.add(restartButton);
}
GameGUI.prototype.update = function (peopleAmt, freePeopleAmt, housesAmt, toolType, averageHunger) {
var time = this.game.time.totalElapsedSeconds();
@@ -63,5 +70,11 @@ var GameGUI = (function () {
this.buttonAutoFarm.setFrames(5, 4, 6, 7);
}
};
GameGUI.prototype.toggleInfoScreen = function () {
this.infoScreen.visible = !this.infoScreen.visible;
};
GameGUI.prototype.restart = function () {
this.game.state.restart();
};
return GameGUI;
})();

+ 3
- 0
js/preloadingState.js View File

@@ -16,6 +16,9 @@ var PreloadingState = (function () {
this.game.load.image("playButton", "./res/img/playButton.png");
this.game.load.image("playButtonUnderline", "./res/img/playButtonUnderline.png");
this.game.load.image("mainMenuBackground", "./res/img/mainMenuBackground.png");
this.game.load.image("restart", "./res/img/restart.png");
this.game.load.image("infoscreen", "./res/img/infoscreen.png");
this.game.load.image("infobutton", "./res/img/infobutton.png");
this.game.load.spritesheet("house", "./res/img/house.png", 32, 32);
this.game.load.spritesheet("farm", "./res/img/farm.png", 32, 32);
this.game.load.spritesheet("person", "./res/img/person.png", 12, 12);

BIN
res/img/infobutton.png View File


BIN
res/img/infoscreen.png View File


BIN
res/img/restart.png View File


+ 21
- 6
src/gameState.ts View File

@@ -40,6 +40,7 @@ class GameState {

private houseBuildingCooldown: number = 0.1;
private lastHouseBuilt: number = 0;
private changingVolume: boolean = false;

public create(): void {
gui.close();
@@ -178,22 +179,36 @@ class GameState {

private updateSound(vol: number): void {
if (this.averageHunger < Person.MILDLY_HUNGRY) {
if (this.happyMusic.volume == 0) {
this.game.add.tween(this.happyMusic).to({volume: vol}, 500, Phaser.Easing.Default, true);
if (this.happyMusic.volume == 0 && !this.changingVolume) {
this.changingVolume = true;
this.game.add.tween(this.happyMusic).to({volume: vol}, 500, Phaser.Easing.Default, true).onComplete.add(() => {this.changingVolume = false;}, this);
this.game.add.tween(this.worryMusic).to({volume: 0}, 500, Phaser.Easing.Default, true);
this.game.add.tween(this.dangerMusic).to({volume: 0}, 500, Phaser.Easing.Default, true);
}
} else if (this.averageHunger < Person.VERY_HUNGRY) {
if (this.worryMusic.volume == 0) {
if (this.worryMusic.volume == 0 && !this.changingVolume) {
this.changingVolume = true;
this.game.add.tween(this.happyMusic).to({volume: 0}, 500, Phaser.Easing.Default, true);
this.game.add.tween(this.worryMusic).to({volume: vol}, 500, Phaser.Easing.Default, true);
this.game.add.tween(this.worryMusic).to({volume: vol}, 500, Phaser.Easing.Default, true).onComplete.add(() => {this.changingVolume = false;}, this);
this.game.add.tween(this.dangerMusic).to({volume: 0}, 500, Phaser.Easing.Default, true);
}
} else {
if (this.dangerMusic.volume == 0) {
if (this.dangerMusic.volume == 0 && !this.changingVolume) {
this.changingVolume = true;
this.game.add.tween(this.happyMusic).to({volume: 0}, 500, Phaser.Easing.Default, true);
this.game.add.tween(this.worryMusic).to({volume: 0}, 500, Phaser.Easing.Default, true);
this.game.add.tween(this.dangerMusic).to({volume: vol}, 500, Phaser.Easing.Default, true);
this.game.add.tween(this.dangerMusic).to({volume: vol}, 500, Phaser.Easing.Default, true).onComplete.add(() => {this.changingVolume = false;}, this);
}
}
if (!this.changingVolume) {
if (this.happyMusic.volume != 0) {
this.happyMusic.volume = vol;
}
if (this.worryMusic.volume != 0) {
this.worryMusic.volume = vol;
}
if (this.dangerMusic.volume != 0) {
this.dangerMusic.volume = vol;
}
}
}

+ 18
- 0
src/gui.ts View File

@@ -8,6 +8,7 @@ class GameGUI {
private currentTool: Phaser.Text;
private averageHungerFull: Phaser.Sprite;
private averageHungerEmpty: Phaser.Sprite;
private infoScreen: Phaser.Sprite;

private autoFarmRefresh: boolean;

@@ -33,6 +34,12 @@ class GameGUI {
this.averageHungerFull.smoothed = false;
this.averageHungerFull.scale.setTo(8, 8);

this.infoScreen = this.game.make.sprite(0, 0, "infoscreen");
var infoButton = this.game.make.button(625, 551, "infobutton", this.toggleInfoScreen, this);
this.toggleInfoScreen();

var restartButton = this.game.make.button(680, 550, "restart", this.restart, this);

foregroundGroup.add(this.buttonAutoFarm);
foregroundGroup.add(this.workingPeople);
foregroundGroup.add(this.amountOfHouses);
@@ -40,6 +47,9 @@ class GameGUI {
foregroundGroup.add(avgText);
foregroundGroup.add(this.averageHungerEmpty);
foregroundGroup.add(this.averageHungerFull);
foregroundGroup.add(this.infoScreen);
foregroundGroup.add(infoButton);
foregroundGroup.add(restartButton);
}

public update(peopleAmt: number, freePeopleAmt: number, housesAmt: number, toolType: TileType, averageHunger: number): void {
@@ -82,4 +92,12 @@ class GameGUI {
this.buttonAutoFarm.setFrames(5, 4, 6, 7);
}
}

private toggleInfoScreen(): void {
this.infoScreen.visible = !this.infoScreen.visible;
}

private restart(): void {
this.game.state.restart();
}
}

+ 3
- 0
src/preloadingState.ts View File

@@ -20,6 +20,9 @@ class PreloadingState {
this.game.load.image("playButton", "./res/img/playButton.png");
this.game.load.image("playButtonUnderline", "./res/img/playButtonUnderline.png");
this.game.load.image("mainMenuBackground", "./res/img/mainMenuBackground.png");
this.game.load.image("restart", "./res/img/restart.png");
this.game.load.image("infoscreen", "./res/img/infoscreen.png");
this.game.load.image("infobutton", "./res/img/infobutton.png");

// Spritesheets
this.game.load.spritesheet("house", "./res/img/house.png", 32, 32);

Loading…
Cancel
Save