Skip to content

Commit

Permalink
Added comments and fixed open/close button
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashley Pridgeon authored and Ashley Pridgeon committed Aug 23, 2020
1 parent 82f4fb0 commit 7ad8ad1
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 55 deletions.
Binary file modified lib/.DS_Store
Binary file not shown.
116 changes: 61 additions & 55 deletions lib/scenes/MainGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export default class MainGame extends Phaser.Scene{
this.load.image('button', './assets/buttons/ATPButton.png');
this.load.image('button_2', './assets/buttons/waterButton.png');
this.load.image('button_3', './assets/buttons/stomButton.png');


};


Expand All @@ -55,20 +57,20 @@ export default class MainGame extends Phaser.Scene{
this.background = new GameScreen({scene: this}); //Most of the resource text is kept in the GameScreen class
this.cameras.main.setBackgroundColor('#b9ff8d');

this.epidermisSprite = this.add.sprite(315, 85, 'epidermisSprite').setScale(5).setOrigin(0,0);
this.stomata1 = null;
this.StomataGroup = this.add.group();
this.epidermisSprite = this.add.sprite(315, 85, 'epidermisSprite').setScale(5).setOrigin(0,0); //The plant epidermis
this.stomata1 = null; //The initial stomata
this.StomataGroup = this.add.group(); //A group to add all stomata

this.plant = this.add.sprite(825, 495, 'plantStart').setScale(5).setOrigin(0,0);
this.plant2 = this.add.sprite(865, 515, 'plant').setScale(5).setOrigin(0,0).setVisible(false);
this.plant = this.add.sprite(825, 495, 'plantStart').setScale(5).setOrigin(0,0); //The growing potted plant in the corner

this.meristemoid1 = this.add.sprite(550, 205, 'meristemoid1').setInteractive()
this.meristemoid1 = this.add.sprite(550, 205, 'meristemoid1').setInteractive() //The initial meristemoid cell
.setScale(5)
.setOrigin(0,0);



//Animations for the growing plant
//Animations for the growing potted plant

this.anims.create({
key: 'plantStart',
frames: this.anims.generateFrameNumbers('plantStart', {start: 1, end: 10}),
Expand Down Expand Up @@ -109,7 +111,7 @@ export default class MainGame extends Phaser.Scene{
text2: '25 CO2',
helptext: 'Use CO2 to buy ATP. ATP can then be used to upgrade your plant'});

this.buyATP.button.on('pointerdown', function (event) { //if you click on it this makes it go red and adds 10 to the score
this.buyATP.button.on('pointerdown', function (event) { //Upon clicking the button ATP increases and CO2 decreases
if (gameData.CO2Levels >= 25){
gameData.ATPLevels += gameData.ATPGain;
gameData.CO2Levels -= 25;
Expand All @@ -129,11 +131,11 @@ export default class MainGame extends Phaser.Scene{
helptext: 'Increase the amount of ATP you get per CO2',
cost: 10 });

this.upgradeATP.button.on('pointerdown', function (event) { //if you click on it this makes it go red and adds 10 to the score
this.upgradeATP.button.on('pointerdown', function (event) { //Upon clicking this button the amount of ATP generated per button 1 is increased
if (gameData.ATPLevels >= this.upgradeATP.cost){
gameData.ATPGain *= 2;
gameData.ATPLevels -= this.upgradeATP.cost;
this.upgradeATP.cost *= 1.5;
this.upgradeATP.cost *= 1.5; //Also the cost of this button is increased by x 1.5
this.upgradeATP.text2Button.setText(this.upgradeATP.cost.toFixed(2) + ' ATP');
this.buyATP.text1Button.setText('Buy ' + gameData.ATPGain);
if (gameData.WaterLoss == 0){
Expand Down Expand Up @@ -163,11 +165,11 @@ export default class MainGame extends Phaser.Scene{

this.chloroplastSprite = null;

this.buyPhotosynthesis.button.on('pointerdown', function (event) { //if you click on it this makes it go red and adds 10 to the score
this.buyPhotosynthesis.button.on('pointerdown', function (event) { //Upon clicking this button photosynthesis is activated
if (gameData.ATPLevels >= this.buyPhotosynthesis.cost){
gameData.PhotosynthesisLevels += 1;
gameData.PhotosynthesisLevels += 1; //The update function add animation to the chloroplastSprite once photosynthesis levels > 0
gameData.ATPLevels -= this.buyPhotosynthesis.cost;
this.buyPhotosynthesis.cost *= 1.5;
this.buyPhotosynthesis.cost *= 1.5; //Increases the cost of this button by 1.5
this.buyPhotosynthesis.text2Button.setText(this.buyPhotosynthesis.cost.toFixed(2) + ' ATP');
this.background.ATPGainRateText.setVisible(true);
};
Expand All @@ -184,11 +186,11 @@ export default class MainGame extends Phaser.Scene{
text2: '100 ATP',
helptext: 'Use ATP to increase the water levels of your plant'});

this.waterPlants.button.on('pointerdown', function (event) { //if you click on it this makes it go red and adds 10 to the score
this.waterPlants.button.on('pointerdown', function (event) { //Upon clicking this button water levels are increased
if (gameData.ATPLevels >= 100){
gameData.WaterLevels += 1000;
gameData.ATPLevels -= 100;
this.rain = this.physics.add.group({
this.rain = this.physics.add.group({ //The update function eventually destroys rain particles
key: 'rain',
repeat: 7,
setXY: { x: 20, y: 0, stepX: 170}
Expand All @@ -209,7 +211,7 @@ export default class MainGame extends Phaser.Scene{
helptext: 'Buy this to automatically water your plant'})
.setDepth(1);

this.autoWatering.button.on('pointerdown', function (event) { //if you click on it this makes it go red and adds 10 to the score
this.autoWatering.button.on('pointerdown', function (event) { //Upon clicking this button automatic increases in watering are activated
if (gameData.ATPLevels >= 1000){
gameData.autoWater += 1
gameData.ATPLevels -= 1000
Expand All @@ -227,7 +229,7 @@ export default class MainGame extends Phaser.Scene{
text2: '1000 ATP',
helptext: 'Fuel stomatal closure by using up ATP'});

this.closeStomata.button.on('pointerdown', function (event) {
this.closeStomata.button.on('pointerdown', function (event) { //Upon clicking this button stomatal closing or opening animations are triggered
if (gameData.ATPLevels >= 1000){
if(this.stomata1.stomata.StomataState == 'open'){
if(this.stomata1.stomata.ABASignalling == true){
Expand Down Expand Up @@ -261,16 +263,18 @@ export default class MainGame extends Phaser.Scene{

},this);

this.closeStomata.button.on('pointerup', function (event) { //once you click off it goes back to normal
this.closeStomata.button.on('pointerup', function (event) { //Once you have clicked on this button the stomatal state is changed from open to closed or vice versa
if (gameData.ATPLevels >= 1000){
gameData.ATPLevels -= 1000;
if(this.stomata1.stomata.StomataState == 'open'){
this.stomata1.stomata.StomataState = 'closed';
this.closeStomata.text1Button.setText('Open Stomata');
return;
};
if(this.stomata1.stomata.StomataState == 'closed'){
this.stomata1.stomata.StomataState = 'open';
this.closeStomata.text1Button.setText('Close Stomata');
return;
};
};
},this);
Expand All @@ -287,20 +291,20 @@ export default class MainGame extends Phaser.Scene{
text2: '1000 ATP',
helptext: 'Decrease the water loss rate of your plant by upgrading the waxy cuticle'});

this.upgradeWaxyCuticle.button.on('pointerdown', function (event) { //if you click on it this makes it go red and adds 10 to the score
this.upgradeWaxyCuticle.button.on('pointerdown', function (event) { //Upon clicking this button epidermis is upgraded
if(gameData.ATPLevels >= 1000){
this.upgradeWaxyCuticle.button.destroy();
this.upgradeWaxyCuticle.text1Button.destroy();
this.upgradeWaxyCuticle.text2Button.destroy();
this.upgradeWaxyCuticle.helpText.destroy();
gameData.WaterLoss *= 0.5;
gameData.waxyCuticle = true;
gameData.waxyCuticle = true;
gameData.ATPLevels -= 1000;
if(gameData.drought == true){
this.epidermisSprite.setFrame(2);
this.epidermisSprite.setFrame(2);
};
if(gameData.drought == false){
this.epidermisSprite.setFrame(1);
this.epidermisSprite.setFrame(1); //Changes to waxy cuticle sprite if not in drought mode otherwise update function will eventually change it after drought
};
};
},this);
Expand All @@ -319,7 +323,7 @@ export default class MainGame extends Phaser.Scene{
this.upgradeABASignalling.button.setVisible(false);
this.upgradeABASignalling.text1Button.setVisible(false);

this.upgradeABASignalling.button.on('pointerdown', function(event){
this.upgradeABASignalling.button.on('pointerdown', function(event){ //Upon clicking this button stomata will change sprite to the ABA sprite (blue ring)
if(gameData.ATPLevels >= 1000){
this.upgradeABASignalling.button.destroy();
this.upgradeABASignalling.text1Button.destroy();
Expand Down Expand Up @@ -356,30 +360,32 @@ export default class MainGame extends Phaser.Scene{
this.setTint(0xff0000);
});

this.meristemoidMotherCell.on('pointerup', function (event) { //once you click off it goes back to normal
this.meristemoidMotherCell.on('pointerup', function (event) { //Upon clicking this cell aonther stomata is generated
this.meristemoidMotherCell.clearTint();
this.meristemoidMotherCell.destroy();
this.meristemoid2Text.destroy();
this.stomata2 = new Stomata({scene: this, x: 335, y: 145, key1: 'stomata'}).setOrigin(0,0);
this.StomataGroup.add(this.stomata2);
gameData.StomataNumber += 1;
if(this.stomata1.stomata.StomataState == 'open'){
if(this.stomata1.stomata.ABASignalling == true){
this.stomata2.stomata.anims.play('stomABA');
};
if(this.stomata1.stomata.ABASignalling == false){
this.stomata2.stomata.anims.play('stom');
};
};
if(this.stomata1.stomata.StomataState == 'closed'){
if(this.stomata1.stomata.ABASignalling == true){
this.stomata2.stomata.anims.play('stomABAClosed');
if(gameData.ATPLevels > 1000)
{
this.meristemoidMotherCell.destroy();
this.meristemoid2Text.destroy();
this.stomata2 = new Stomata({scene: this, x: 335, y: 145, key1: 'stomata'}).setOrigin(0,0);
this.StomataGroup.add(this.stomata2);
gameData.StomataNumber += 1;
if(this.stomata1.stomata.StomataState == 'open'){ //Sets up the correct sprite to show for the second stomata
if(this.stomata1.stomata.ABASignalling == true){
this.stomata2.stomata.anims.play('stomABA');
};
if(this.stomata1.stomata.ABASignalling == false){
this.stomata2.stomata.anims.play('stom');
};
};
if(this.stomata1.stomata.ABASignalling == false){
this.stomata2.stomata.anims.play('stomClosed');
if(this.stomata1.stomata.StomataState == 'closed'){
if(this.stomata1.stomata.ABASignalling == true){
this.stomata2.stomata.anims.play('stomABAClosed');
};
if(this.stomata1.stomata.ABASignalling == false){
this.stomata2.stomata.anims.play('stomClosed');
};
};
};

},this);


Expand All @@ -391,7 +397,7 @@ export default class MainGame extends Phaser.Scene{
this.setTint(0xff0000);
});

this.meristemoid1.on('pointerup', function (event) { //once you click off it goes back to normal
this.meristemoid1.on('pointerup', function (event) { //Upon clicking the initial meristemoid a new stomata is formed and new buttons are shown
gameData.CO2Gain += 1;
this.background.START_Clickthiscell.destroy();
this.background.CO2LevelsText.setVisible(true);
Expand All @@ -409,7 +415,7 @@ export default class MainGame extends Phaser.Scene{

//BUY ATP - unlock upgrade ATP buying + photosynthesis

this.buyATP.button.on('pointerdown', function (event) { //if you click on it this makes it go red and adds 10 to the score
this.buyATP.button.on('pointerdown', function (event) { //Upon clicking buy ATP for the first time new buttons are shown
if (gameData.CO2Levels >= 25){
this.background.ATPLevelsText.setVisible(true);
this.upgradeATP.button.setVisible(true);
Expand All @@ -423,7 +429,7 @@ export default class MainGame extends Phaser.Scene{

//UPGRADE ATP - add phostosynthesis and water options

this.upgradeATP.button.on('pointerdown', function (event) { //if you click on it this makes it go red and adds 10 to the score
this.upgradeATP.button.on('pointerdown', function (event) { //Upon clicking upgrade ATP for the first time even more new buttons are shown
if (this.upgradeATP.cost > 10){
this.buyPhotosynthesis.button.setVisible(true);
this.buyPhotosynthesis.text1Button.setVisible(true);
Expand All @@ -444,7 +450,7 @@ export default class MainGame extends Phaser.Scene{

//WATERING - unlock automatic watering

this.waterPlants.button.on('pointerdown', function (event) { //if you click on it this makes it go red and adds 10 to the score
this.waterPlants.button.on('pointerdown', function (event) { //Upon clicking water plants for the first time the automatic watering button is shown
if (gameData.ATPLevels >= 100){
this.autoWatering.button.setVisible(true);
this.autoWatering.text1Button.setVisible(true);
Expand Down Expand Up @@ -474,8 +480,8 @@ export default class MainGame extends Phaser.Scene{

gameData.timer += 1;

if( gameData.timer > 10 && this.stomata1 != null){

if( gameData.timer > 10 && this.stomata1 != null){ //alters resource flux depending on open or closed state of stomata
if(this.stomata1.stomata.StomataState == 'closed' && this.stomata1.stomata.prevStomataState == 'open'){
gameData.WaterLoss *= 0.1;
gameData.CO2Gain *= 0.1;
Expand Down Expand Up @@ -508,7 +514,7 @@ export default class MainGame extends Phaser.Scene{
};


//DROUGHT SCENARIO LOOP
//DROUGHT SCENARIO LOOP - changes scenario 10% chance of drought and automatically moves stomata if ABA signalling is upgraded

gameData.timer2 += 1;

Expand Down Expand Up @@ -555,7 +561,7 @@ export default class MainGame extends Phaser.Scene{
gameData.timer2 = 0;
};

//WATER LEVELS LOW
//WATER LEVELS LOW - if water levels are low a red tint is shown. Then is water completely runs out games cuts to intro scene

if(gameData.WaterLevels < 100){
this.epidermisSprite.setTint(0xff0000);
Expand All @@ -571,7 +577,7 @@ export default class MainGame extends Phaser.Scene{
this.scene.start('IntroScene');
};

//DESTROY RAIN
//DESTROY RAIN - destroys rain droplets once they fall from screen

if(this.rain != null){
if(this.rain.children.entries[1].y > 1000){
Expand All @@ -580,7 +586,7 @@ export default class MainGame extends Phaser.Scene{
};
};

//PHOTOSYNTHESIS SPEED
//PHOTOSYNTHESIS SPEED - increases the speed of chloroplasts upon increase in photosynthesis levels

if(gameData.PhotosynthesisLevels == 1 && gameData.prevPhotosynthesisLevels == 0){
this.chloroplastSprite = this.add.sprite(315,85, 'epidermisChloroplasts').setScale(5).setOrigin(0,0);
Expand All @@ -593,10 +599,10 @@ export default class MainGame extends Phaser.Scene{
gameData.prevPhotosynthesisLevels = gameData.PhotosynthesisLevels;
};

//PLANT GROWTH
//PLANT GROWTH - upon increases in biomass the potted plant will grow an extra layer of leaves

if(gameData.BioMass > gameData.BioMassUpgrade ){
this.add.sprite(gameData.Plantx, gameData.Planty, 'plant2').setScale(5).setOrigin(0,0).play('plantLeaves');
this.add.sprite(gameData.Plantx, gameData.Planty, 'plant').setScale(5).setOrigin(0,0).play('plantLeaves');
gameData.BioMassUpgrade *= 2;
gameData.Planty -= 25;
};
Expand Down
1 change: 1 addition & 0 deletions src/stomata.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default class Stomata extends Phaser.GameObjects.Sprite {
this.stomata.anims.play('stom');
});


this.scene.add.existing(this);
};
};

0 comments on commit 7ad8ad1

Please sign in to comment.