123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- /*
- let mapState = {
- create: function(){},
- update: function(){},
- ---------------------------- end of phaser functions
- func_loadGame: function(){},
- }
- */
- let mapState = {
- create: function() {
- if(levelType=="C"){
- this.gameStateString = "game"+levelShape+"Two";
- this.endStateString = "end"+levelShape+"Two";
- this.menuStateString = "menu"+levelShape+"Two";
- }else{
- this.gameStateString = "game"+levelShape+"One";
- this.endStateString = "end"+levelShape+"One";
- this.menuStateString = "menu"+levelShape+"One";
- }
-
- // Background
- game.add.image(0, 40, 'bgmap');
-
- // Navigation buttons
- buttonSettings["func_addButtons"](true,false,
- true,true,false,
- false,false,
- this.menuStateString,false);
-
- // Styles for labels
- const stylePlace = { font: '26px Arial', fill: '#ffffff', align: 'center'};
- const styleMenu = { font: '30px Arial', fill: '#000000', align: 'center'};
-
- // Progress bar
- let percentText = passedLevels*25;
- let percentBlocks = passedLevels;
- for(let p=0;p<percentBlocks;p++){
- let block = game.add.image(660+p*37.5, 10, 'block');
- block.scale.setTo(2.6, 1);
- }
- game.add.text(820, 10, percentText+'%', styleMenu);
- game.add.text(650, 10, lang.difficulty + ' ' + levelDifficulty, styleMenu).anchor.setTo(1,0);
- game.add.image(660, 10, 'pgbar');
-
- //Road
- this.points = {
- 'x': [ 90, 204, 318, 432, 546, 660 ],
- 'y': [ 486, 422, 358, 294, 230, 166 ]
- };
-
- if(this.gameStateString=="gameSquareOne"){
- //Garage
- let garage = game.add.image(this.points.x[0], this.points.y[0], 'garage');
- garage.scale.setTo(0.4);
- garage.anchor.setTo(0.5, 1);
- //Farm
- let farm = game.add.image(this.points.x[5], this.points.y[5], 'farm');
- farm.scale.setTo(0.6);
- farm.anchor.setTo(0.1, 0.7);
- }else{
- //House
- let house = game.add.image(this.points.x[0], this.points.y[0], 'house');
- house.scale.setTo(0.7);
- house.anchor.setTo(0.7, 0.8);
- //School
- let school = game.add.image(this.points.x[5], this.points.y[5], 'school');
- school.scale.setTo(0.35);
- school.anchor.setTo(0.2, 0.7);
- }
- //Trees and Rocks
-
- const rocks = {
- 'x': [156, 275, 276, 441, 452, 590, 712],
- 'y': [309, 543, 259, 156, 419, 136, 316]
- }
- const r_types = [1, 1, 2, 1, 2, 2, 2];
-
- for(let i=0; i<r_types.length; i++){
- if(r_types[i]==1){
- let sprite = game.add.image(rocks.x[i], rocks.y[i], 'rock');
- sprite.scale.setTo(0.32);
- sprite.anchor.setTo(0.5, 0.95);
- }else if(r_types[i]==2){
- let sprite = game.add.image(rocks.x[i], rocks.y[i], 'birch');
- sprite.scale.setTo(0.4);
- sprite.anchor.setTo(0.5, 0.95);
- }
- }
- const trees = {
- 'x': [105, 214, 354, 364, 570, 600, 740, 779],
- 'y': [341, 219, 180, 520, 550, 392, 488, 286]
- }
- const t_types = [2, 4, 3, 4, 1, 2, 4, 4];
-
- for(let i=0; i<t_types.length; i++){
- let sprite = game.add.image(trees.x[i], trees.y[i], 'tree'+t_types[i]);
- sprite.scale.setTo(0.6);
- sprite.anchor.setTo(0.5, 0.95);
- }
-
- // places
- for (let p = 1; p < this.points.x.length -1; p++){
- let place;
- if(p<levelPosition){
- place = game.add.image(this.points.x[p], this.points.y[p], 'place_b');
- }else if (levelMove && p==levelPosition){
- place = game.add.image(this.points.x[p], this.points.y[p], 'place_b');
- }else{
- place = game.add.image(this.points.x[p], this.points.y[p], 'place_a');
- }
- place.anchor.setTo(0.5, 0.5);
- place.scale.setTo(0.3);
- let sign = game.add.image(this.points.x[p]-20, this.points.y[p]-60, 'sign');
- sign.anchor.setTo(0.5, 1);
- sign.scale.setTo(0.4);
- if(p>0 && p<this.points.x.length-1){
- let text = game.add.text(this.points.x[p]-23, this.points.y[p]-84, p, stylePlace);
- text.anchor.setTo(0.35, 0.5);
- }
- }
- if(this.gameStateString=="gameSquareOne"){
- this.character = game.add.sprite(this.points.x[levelPosition], this.points.y[levelPosition], 'tractor');
- let walk = this.character.animations.add('walk',[0,1,2,3,4]);
- this.character.animations.play('walk', 5, true);
- this.character.angle -= 25;
- }else{
- this.character = game.add.sprite(this.points.x[levelPosition], this.points.y[levelPosition], 'kid_run');
- this.character.animations.add('run');
- this.character.animations.play('run', 6, true);
- }
- this.character.anchor.setTo(0.5, 1);
- this.character.scale.setTo(0.5);
- game.physics.arcade.enable(this.character);
- // Delay to next level
- this.count = 0;
- this.wait = 60;
-
- },
- update: function() {
-
- // Wait 2 seconds before moving or staring a game
- this.count ++;
- if(this.count<=this.wait) return;
-
- // If movement is stopped or position is 6 (final), load game
- if(this.gameStateString=="gameSquareOne"){
- if(levelPosition==8){
- levelMove = false;
- }
- }else if(this.gameStateString=="gameCircleOne"){
- if(levelPosition==6){
- levelMove = false;
- }
- }else if(this.gameStateString=="gameSquareTwo"){
- if(levelPosition==5){
- levelMove = false;
- }
- }
- if(!levelMove){
- this.func_loadGame();
- }
-
- // If momevent is enabled, move to next point from actual
- if(levelMove){
- game.physics.arcade.moveToXY(
- this.character,
- this.points.x[levelPosition+1],
- this.points.y[levelPosition+1],
- 100
- );
-
- // I kid/tractor reached the end, stop movement
- if(Math.ceil(this.character.x)==this.points.x[levelPosition+1] || Math.ceil(this.character.y)==this.points.y[levelPosition+1]){
- levelMove=false;
- levelPosition += 1; //Update position
- }
- }
- },
-
- //MapLoading function
- func_loadGame: function(){
-
- if(audioStatus){
- beepSound.play();
- }
- if(levelPosition<5){
- game.state.start(this.gameStateString);
- }else{
- game.state.start(this.endStateString);
- }
- }
-
- };
|