<commit_before>/**
 * Main game javascript
 * Requires:
 * - all game related models and views
 * Contains:
 * - Mainloop
 */
define(['backbone','kinetic','howler','jquery','gamemodel','gameview','linemodel', 'obstaclemodel'], function (Backbone, Kinetic, Howler, JQuery,GameModel, GameView,LineModel, ObstacleModel) {


	var keyStates = [];
	function onKeyDown(evt){
		keyStates[evt.keyCode] = true;
	}

	function onKeyUp(evt){
		keyStates[evt.keyCode] = false;
	}
	/*function onMouseMove(evt){
	  }*/


	window.addEventListener('keydown', onKeyDown, true);
	window.addEventListener('keyup', onKeyUp, true);

	//window.addEventListener('mousemove', onMouseMove, false);
	var test = function() {
		var FPS = 1000/30;
		console.log('Game started');
		var game_doc = Backbone.Collection.extend({ model: GameModel });
		var game_model = new GameModel;
		var game_view = new GameView({ el: '#container', model: game_model });

		console.log('Render');
		game_view.render(function() {

			//var sound = new Howl({
			//  urls: ['web/sounds/Electro_House_Loop.ogg'],
			//  loop: true,
			//  volume: 0.5,
			//  }).play();

			var play_sound = true;
			var x = 0;
			var leftover = 0;
			var selectPoint = 199;
			var moving = false;
			var movingtoline = 0;
			var playerspeedx = 0;
			var playerspeedy = 0;
			var movespeedx = 0;
			var movespeedy = 0;
			var health = 0;
			var numObstacles = 4;
			var obstacle = [];
			var curObstacleLine = [];
			var collisionTimer = 90;
			var collisionState = false;
			var targetx = 0;
			var targety = 0;
			var bgMusicState = false;
			var bgMusic = null;


			var lives = 1;
			var bgScale = 1;
			var endGameState = false;

			// State machine variables
			var startGameState = 0;
			var gameOverState = 1;
			var inGameState = 2;
			var goinState = 3;
			var changeLevelState = 4; 
			var state = startGameState;

			game_view.layer.on('mousemove', function() {
				console.log('move');
			});
			var gameLayerLoop = new Kinetic.Animation(function(frame) {
				// How many logic updates needs to be done to keep up 
				// with the target FPS?
				//
				// Current implementation problem: samples 
				// frame-by-frame which is not good (a bit jerky)
				// A more sophisticated version required with 
				// fps "planning" for number of updates

				var numUpdates = Math.floor((frame.timeDiff + leftover) / FPS);
				for(var i = 0; i < numUpdates; i++) {

					if(state === startGameState) {
						// initialize
						health = 0.5;
						state = inGameState;
					} else if(state === goinState) {
					
					} else if(state === inGameState) {
					
					// Update health
					game_model.myHBFill.width(health*144);
					
					x = x + 1;
					if(x % 10 == 0)	 {
						bgScale+=0.01;
						game_model.sprites[9].setScaleX(bgScale);
						game_model.sprites[9].setScaleY(bgScale);
						game_model.sprites[9].setY(game_model.sprites[9].getY()-1*bgScale);
						game_model.sprites[9].setX(game_model.width/2-75*bgScale);
						game_view.bglayer.draw();
					}

					hzPoints = [];
					for(var j = 0; j < game_model.myLineModel.length; j++) {
						if( j === game_model.currentLine) {
							game_model.myLine[j].stroke('red');
						} else {
							game_model.myLine[j].stroke('white');
						
						}
						game_model.myLineModel[j].addPoint(j*5-7.5,Math.sin(x*(Math.PI/180))+2.5);
						//console.log(game_model.myLineModel[j].getPoints());

						game_model.myLine[j].attrs.points = game_model.myLineModel[j].getPoints();

						game_model.myLineModel[j].movePoints();
						curPoint = game_model.myLineModel[j].getPoint(selectPoint);
						if(curPoint !== null) {
							hzPoints.push(curPoint[0]);
							hzPoints.push(curPoint[1]);
						}<commit_msg>Added health(mood) regenerating based on time and alternating waves.<commit_after>/**
 * Main game javascript
 * Requires:
 * - all game related models and views
 * Contains:
 * - Mainloop
 */
define(['backbone','kinetic','howler','jquery','gamemodel','gameview','linemodel', 'obstaclemodel'], function (Backbone, Kinetic, Howler, JQuery,GameModel, GameView,LineModel, ObstacleModel) {


	var keyStates = [];
	function onKeyDown(evt){
		keyStates[evt.keyCode] = true;
	}

	function onKeyUp(evt){
		keyStates[evt.keyCode] = false;
	}
	/*function onMouseMove(evt){
	  }*/


	window.addEventListener('keydown', onKeyDown, true);
	window.addEventListener('keyup', onKeyUp, true);

	//window.addEventListener('mousemove', onMouseMove, false);
	var test = function() {
		var FPS = 1000/30;
		console.log('Game started');
		var game_doc = Backbone.Collection.extend({ model: GameModel });
		var game_model = new GameModel;
		var game_view = new GameView({ el: '#container', model: game_model });

		console.log('Render');
		game_view.render(function() {

			//var sound = new Howl({
			//  urls: ['web/sounds/Electro_House_Loop.ogg'],
			//  loop: true,
			//  volume: 0.5,
			//  }).play();

			var play_sound = true;
			var x = 0;
			var leftover = 0;
			var selectPoint = 199;
			var moving = false;
			var movingtoline = 0;
			var playerspeedx = 0;
			var playerspeedy = 0;
			var movespeedx = 0;
			var movespeedy = 0;
			var health = 0;
			var numObstacles = 4;
			var obstacle = [];
			var curObstacleLine = [];
			var collisionTimer = 90;
			var collisionState = false;
			var targetx = 0;
			var targety = 0;
			var bgMusicState = false;
			var bgMusic = null;


			var lives = 1;
			var bgScale = 1;
			var endGameState = false;

			// State machine variables
			var startGameState = 0;
			var gameOverState = 1;
			var inGameState = 2;
			var goinState = 3;
			var changeLevelState = 4; 
			var state = startGameState;
			var healthUpTimer = 150;

			game_view.layer.on('mousemove', function() {
				console.log('move');
			});
			var gameLayerLoop = new Kinetic.Animation(function(frame) {
				// How many logic updates needs to be done to keep up 
				// with the target FPS?
				//
				// Current implementation problem: samples 
				// frame-by-frame which is not good (a bit jerky)
				// A more sophisticated version required with 
				// fps "planning" for number of updates

				var numUpdates = Math.floor((frame.timeDiff + leftover) / FPS);
				for(var i = 0; i < numUpdates; i++) {

					if(state === startGameState) {
						// initialize
						health = 0.5;
						state = inGameState;
					} else if(state === goinState) {
					
					} else if(state === inGameState) {
					
					healthUpTimer -= 1;
					
					if(healthUpTimer <= 0) {
						health += 0.02;
						if(health > 1) {
							health = 1;
						}
						healthUpTimer = 150;
					}
					
					// Update health
					game_model.myHBFill.width(health*144);
					
					x = x + 1;
					if(x % 10 == 0)	 {
						bgScale+=0.01;
						game_model.sprites[9].setScaleX(bgScale);
						game_model.sprites[9].setScaleY(bgScale);
						game_model.sprites[9].setY(game_model.sprites[9].getY()-1*bgScale);
						game_model.sprites[9].setX(game_model.width/2-75*bgScale);
						game_view.bglayer.draw();
					}

					hzPoints = [];
					for(var j = 0; j < game_model.myLineModel.length; j++) {
						if( j === game_model.currentLine) {
							game_model.myLine[j].stroke('red');
						} else {
							game_model.myLine[j].stroke('white');
						
						}
						game_model.myLineModel[j].addPoint(j*5-7.5,Math.sin((x+j*80)*(Math.PI/180))+2.5);
						//console.log(game_model.myLineModel[j].getPoints());

						game_model.myLine[j].attrs.points = game_model.myLineModel[j].getPoints();

						game_model.myLineModel[j].movePoints();
						curPoint = game_model.myLineModel[j].getPoint(selectPoint);
						if(curPoint !== null) {
							hzPoints.push(curPoint[0]);
							hzPoints.push(curPoint[1]);
						}
{'fraction_non_alphanumeric': 0.14390084801043704, 'fraction_numerical': 0.018656229615133725, 'mean_word_length': 2.881518987341772, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2036497', 'n_tokens_mistral': 3398, 'n_tokens_neox': 2613, 'n_words': 579}