<commit_before>// ---
// Copyright (c) 2010 <NAME>, http://www.kesiev.com/
// ---

/**
 * Gamecycle contains your basic game loop: intro, menus, 
 * crossfading between stages/lifes, gameover and ending. 
 */
var gamecycle={

	/**
	 * Gamecycle constructor - initializes a new game object
	 * 
	 * @param	id		unique id of object
	 * @param	group		name of group to store the object in
	 */
	createMaingame:function(id,group) {
	return gbox.addObject({
		id:id,
		group:group,
		counter:0,
		difficulty:0,
		
		// state transition
		state:100,  
		isready:false, 
		
		hud:{},
		
		/**
		 * This method is called whenever you load a new map. It's meant to be
		 * overridden when you create your game.
		 */
		changeLevel:function() { },
		
		/**
		 * This method is called every time a player is "reborn". This method is 
		 * meant to be overridden since you have to do garbage collection. 
		 */
		newLife:function() { },
		
		// level intro animation
		gameIntroAnimation:function(reset) {
			if (reset) {
				toys.resetToy(this,"default-blinker");
			} else {
				gbox.blitFade(gbox.getBufferContext(),{alpha:1});
				return toys.text.blink(this,"default-blinker",gbox.getBufferContext(),{font:"small",text:"LETS BEGIN!",valign:gbox.ALIGN_MIDDLE,halign:gbox.ALIGN_CENTER,dx:0,dy:0,dw:gbox.getScreenW(),dh:gbox.getScreenH(),blinkspeed:5,times:6});
			}
		 },
		 
		levelIntroAnimation:function(reset) {
			if (reset) {
				toys.resetToy(this,"default-blinker");
			} else {
				gbox.blitFade(gbox.getBufferContext(),{alpha:1});
				return toys.text.blink(this,"default-blinker",gbox.getBufferContext(),{font:"small",text:"GET READY!",valign:gbox.ALIGN_MIDDLE,halign:gbox.ALIGN_CENTER,dx:0,dy:0,dw:gbox.getScreenW(),dh:gbox.getScreenH(),blinkspeed:5,times:6});
			}
		 },
	  
		 // Life intro animation
		 newlifeIntroAnimation:function(reset) {
			 if (reset) {
				toys.resetToy(this,"default-blinker");
			} else {
				gbox.blitFade(gbox.getBufferContext(),{alpha:1});
				return toys.text.fixed(this,"default-blinker",gbox.getBufferContext(),{font:"small",text:"GET READY!",valign:gbox.ALIGN_MIDDLE,halign:gbox.ALIGN_CENTER,dx:0,dy:0,dw:gbox.getScreenW(),dh:gbox.getScreenH(),time:30});
			}
		},
		
		// gameover animation
		gameoverIntroAnimation:function(reset) {
			 if (reset) {
				toys.resetToy(this,"default-blinker");
			} else {
				gbox.blitFade(gbox.getBufferContext(),{alpha:1});
				return toys.text.fixed(this,"default-blinker",gbox.getBufferContext(),{font:"small",text:"GAME OVER",valign:gbox.ALIGN_MIDDLE,halign:gbox.ALIGN_CENTER,dx:0,dy:0,dw:gbox.getScreenW(),dh:gbox.getScreenH(),time:50});
			}
		},
		
		// game title animation
		gameTitleIntroAnimation:function(reset) {
			if (!reset) {
				gbox.blitFade(gbox.getBufferContext(),{alpha:1});
				gbox.blitText(gbox.getBufferContext(),{font:"small",text:"GAME TITLE",valign:gbox.ALIGN_MIDDLE,halign:gbox.ALIGN_CENTER,dx:0,dy:0,dw:gbox.getScreenW(),dh:gbox.getScreenH()-100});
			}
		},
		
		// End level animation
		endlevelIntroAnimation:function(reset) {
			 if (reset) {
				 toys.resetToy(this,"default-blinker");
			} else {
				return toys.text.blink(this,"default-blinker",gbox.getBufferContext(),{font:"small",text:"WELL DONE!",valign:gbox.ALIGN_MIDDLE,halign:gbox.ALIGN_CENTER,dx:0,dy:0,dw:gbox.getScreenW(),dh:gbox.getScreenH(),blinkspeed:5,times:10});
			}
		},
		
		// Game ending
		gameEndingIntroAnimation:function(reset) {
			if (reset) {
				toys.resetToy(this,"default-blinker");
			} else {
				gbox.blitFade(gbox.getBufferContext(),{alpha:1});
				return toys.text.blink(this,"default-blinker",gbox.getBufferContext(),{font:"small",text:"CONGRATULATIONS!",valign:gbox.ALIGN_MIDDLE,halign:gbox.ALIGN_CENTER,dx:0,dy:0,dw:gbox.getScreenW(),dh:gbox.getScreenH(),blinkspeed:5,times:10});
			}		  	
		},
		
		// PRESS START
		pressStartIntroAnimation:function(reset) {
			if (reset) {
				toys.resetToy(this,"default-blinker");
			} else {
				toys.text.blink(this,"default-blinker",gbox.getBufferContext(),{font:"small",text:"PRESS A TO START",valign:gbox.ALIGN_MIDDLE,halign:gbox.ALIGN_CENTER,dx:0,dy:Math.floor(gbox.getScreenH()/3),dw:gbox.getScreenW(),dh:Math.floor(gbox.getScreenH()/3)*2,blinkspeed:10});
				return gbox.keyIsHit("a");
			}
		},
		
		/**
		 * This method is called when the player dies.
		 */
		gameIsOver:function() { return true; },
		
		/** 
		 * Actions done during the game (i.e. stage is clear or other ending conditions)
		 */
		gameEvents:function() {
		
		},
		
		gameMenu:function(reset) {
			if (reset) {
				toys.resetToy(this,"difficulty");
			} else {
				gbox.blitFade(gbox.getBufferContext(),{alpha:0.5});
				if (toys.ui.menu(this,"difficulty",{font:"small",keys:{up:"up",down:"down",ok:"a",cancel:"b"},selector:">",items:["EASY","NORMAL","HARD"],x:10,y:10})) {
					if (toys.getToyValue(this,"difficulty","ok") == -1) return -1;
					else {
						this.difficulty=toys.getToyValue(this,"difficulty","selected");
						return true;
					}
				}
				return false;
			}
		},
	  
		// CHECK
		
		gameIsHold:function() { // Use this clause to check collision and kill player: if true the level is changing
			return (this.state==400)||(this.state==401);
		},
		
		isCompleted:function() {
			return (this.state==800);
		},
		
		// GAME CYCLE
		
		getNextLevel:function() {
			return this._nextlevel;
		},
		
		gotoLevel:function(level) {
			this._nextlevel=level;
			this.setState(400);
		},
		
		playerDied:function(data) {
			this._loselife=data;
			this.setState(500);
		},
		
		gameIsCompleted:function() {
			this.setState(800);
		},
		
		// PRIVATES
		
		setState:function(st) {
			this.state=st;
			this.isready=false;
		},
		
		_resetGroups:function() {
			var g=gbox.getGroups();
			for (var i=0;i<g.length;i++)
				if (g[i]!=this.group) gbox.clearGroup(g[i]);
			gbox.soloGroup(this.group);
		},

		stateIsReady:function() { this.isready=true; },
		blit:function() {
			var ok=false;
			switch (this.state) {
				case 100:
				case 101:
				case 102: { // Press Start / Menu
					if (!this.isready&&(this.state==100)) {
						this._resetGroups();
						this.gameTitleIntroAnimation(true);
					}
					this.gameTitleIntroAnimation(false);
					switch (this.state) {
						case 100: { // Press to start
							if (!this.isready) {
								this.pressStartIntroAnimation(true);
								this.stateIsReady();<commit_msg>remove weird variable... that didnt do anything!<commit_after>// ---
// Copyright (c) 2010 <NAME>, http://www.kesiev.com/
// ---

/**
 * Gamecycle contains your basic game loop: intro, menus, 
 * crossfading between stages/lifes, gameover and ending. 
 */
var gamecycle={

	/**
	 * Gamecycle constructor - initializes a new game object
	 * 
	 * @param	id		unique id of object
	 * @param	group		name of group to store the object in
	 */
	createMaingame:function(id,group) {
	return gbox.addObject({
		id:id,
		group:group,
		counter:0,
		difficulty:0,
		
		// state transition
		state:100,  
		isready:false, 
		
		hud:{},
		
		/**
		 * This method is called whenever you load a new map. It's meant to be
		 * overridden when you create your game.
		 */
		changeLevel:function() { },
		
		/**
		 * This method is called every time a player is "reborn". This method is 
		 * meant to be overridden since you have to do garbage collection. 
		 */
		newLife:function() { },
		
		// level intro animation
		gameIntroAnimation:function(reset) {
			if (reset) {
				toys.resetToy(this,"default-blinker");
			} else {
				gbox.blitFade(gbox.getBufferContext(),{alpha:1});
				return toys.text.blink(this,"default-blinker",gbox.getBufferContext(),{font:"small",text:"LETS BEGIN!",valign:gbox.ALIGN_MIDDLE,halign:gbox.ALIGN_CENTER,dx:0,dy:0,dw:gbox.getScreenW(),dh:gbox.getScreenH(),blinkspeed:5,times:6});
			}
		 },
		 
		levelIntroAnimation:function(reset) {
			if (reset) {
				toys.resetToy(this,"default-blinker");
			} else {
				gbox.blitFade(gbox.getBufferContext(),{alpha:1});
				return toys.text.blink(this,"default-blinker",gbox.getBufferContext(),{font:"small",text:"GET READY!",valign:gbox.ALIGN_MIDDLE,halign:gbox.ALIGN_CENTER,dx:0,dy:0,dw:gbox.getScreenW(),dh:gbox.getScreenH(),blinkspeed:5,times:6});
			}
		 },
	  
		 // Life intro animation
		 newlifeIntroAnimation:function(reset) {
			 if (reset) {
				toys.resetToy(this,"default-blinker");
			} else {
				gbox.blitFade(gbox.getBufferContext(),{alpha:1});
				return toys.text.fixed(this,"default-blinker",gbox.getBufferContext(),{font:"small",text:"GET READY!",valign:gbox.ALIGN_MIDDLE,halign:gbox.ALIGN_CENTER,dx:0,dy:0,dw:gbox.getScreenW(),dh:gbox.getScreenH(),time:30});
			}
		},
		
		// gameover animation
		gameoverIntroAnimation:function(reset) {
			 if (reset) {
				toys.resetToy(this,"default-blinker");
			} else {
				gbox.blitFade(gbox.getBufferContext(),{alpha:1});
				return toys.text.fixed(this,"default-blinker",gbox.getBufferContext(),{font:"small",text:"GAME OVER",valign:gbox.ALIGN_MIDDLE,halign:gbox.ALIGN_CENTER,dx:0,dy:0,dw:gbox.getScreenW(),dh:gbox.getScreenH(),time:50});
			}
		},
		
		// game title animation
		gameTitleIntroAnimation:function(reset) {
			if (!reset) {
				gbox.blitFade(gbox.getBufferContext(),{alpha:1});
				gbox.blitText(gbox.getBufferContext(),{font:"small",text:"GAME TITLE",valign:gbox.ALIGN_MIDDLE,halign:gbox.ALIGN_CENTER,dx:0,dy:0,dw:gbox.getScreenW(),dh:gbox.getScreenH()-100});
			}
		},
		
		// End level animation
		endlevelIntroAnimation:function(reset) {
			 if (reset) {
				 toys.resetToy(this,"default-blinker");
			} else {
				return toys.text.blink(this,"default-blinker",gbox.getBufferContext(),{font:"small",text:"WELL DONE!",valign:gbox.ALIGN_MIDDLE,halign:gbox.ALIGN_CENTER,dx:0,dy:0,dw:gbox.getScreenW(),dh:gbox.getScreenH(),blinkspeed:5,times:10});
			}
		},
		
		// Game ending
		gameEndingIntroAnimation:function(reset) {
			if (reset) {
				toys.resetToy(this,"default-blinker");
			} else {
				gbox.blitFade(gbox.getBufferContext(),{alpha:1});
				return toys.text.blink(this,"default-blinker",gbox.getBufferContext(),{font:"small",text:"CONGRATULATIONS!",valign:gbox.ALIGN_MIDDLE,halign:gbox.ALIGN_CENTER,dx:0,dy:0,dw:gbox.getScreenW(),dh:gbox.getScreenH(),blinkspeed:5,times:10});
			}		  	
		},
		
		// PRESS START
		pressStartIntroAnimation:function(reset) {
			if (reset) {
				toys.resetToy(this,"default-blinker");
			} else {
				toys.text.blink(this,"default-blinker",gbox.getBufferContext(),{font:"small",text:"PRESS A TO START",valign:gbox.ALIGN_MIDDLE,halign:gbox.ALIGN_CENTER,dx:0,dy:Math.floor(gbox.getScreenH()/3),dw:gbox.getScreenW(),dh:Math.floor(gbox.getScreenH()/3)*2,blinkspeed:10});
				return gbox.keyIsHit("a");
			}
		},
		
		/**
		 * This method is called when the player dies.
		 */
		gameIsOver:function() { return true; },
		
		/** 
		 * Actions done during the game (i.e. stage is clear or other ending conditions)
		 */
		gameEvents:function() {
		
		},
		
		gameMenu:function(reset) {
			if (reset) {
				toys.resetToy(this,"difficulty");
			} else {
				gbox.blitFade(gbox.getBufferContext(),{alpha:0.5});
				if (toys.ui.menu(this,"difficulty",{font:"small",keys:{up:"up",down:"down",ok:"a",cancel:"b"},selector:">",items:["EASY","NORMAL","HARD"],x:10,y:10})) {
					if (toys.getToyValue(this,"difficulty","ok") == -1) return -1;
					else {
						this.difficulty=toys.getToyValue(this,"difficulty","selected");
						return true;
					}
				}
				return false;
			}
		},
	  
		// CHECK
		
		gameIsHold:function() { // Use this clause to check collision and kill player: if true the level is changing
			return (this.state==400)||(this.state==401);
		},
		
		isCompleted:function() {
			return (this.state==800);
		},
		
		// GAME CYCLE
		
		getNextLevel:function() {
			return this._nextlevel;
		},
		
		gotoLevel:function(level) {
			this._nextlevel=level;
			this.setState(400);
		},
		
		playerDied:function(data) {
			this._loselife=data;
			this.setState(500);
		},
		
		gameIsCompleted:function() {
			this.setState(800);
		},
		
		// private methods
		
		setState:function(st) {
			this.state=st;
			this.isready=false;
		},
		
		_resetGroups:function() {
			var g=gbox.getGroups();
			for (var i=0;i<g.length;i++)
				if (g[i]!=this.group) gbox.clearGroup(g[i]);
			gbox.soloGroup(this.group);
		},

		stateIsReady:function() { this.isready=true; },
		blit:function() {
			switch (this.state) {
				case 100:
				case 101:
				case 102: { // Press Start / Menu
					if (!this.isready&&(this.state==100)) {
						this._resetGroups();
						this.gameTitleIntroAnimation(true);
					}
					this.gameTitleIntroAnimation(false);
					switch (this.state) {
						case 100: { // Press to start
							if (!this.isready) {
								this.pressStartIntroAnimation(true);
								this.stateIsReady();
{'fraction_non_alphanumeric': 0.17042685323480858, 'fraction_numerical': 0.01477871236538008, 'mean_word_length': 3.9929356357927785, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4474147', 'n_tokens_mistral': 5601, 'n_tokens_neox': 4652, 'n_words': 634}