<commit_before>'use strict';

!function(){
	
	var fps     = 60;
	var step    = 1/fps;
	var meter   = 24; // number of pixels per meter
	var gravity = 9.8 * meter;// acceleration due to gravity, m/s
	var jumpImpulse  = gravity/2 * fps;
	var flapImpulse  = gravity/3 * fps;
	var glideImpulse = gravity/3 * fps;
	var walkImpulse  = gravity/4 * fps;
	var walkmaxdx    = gravity;
	var maxdx   = gravity * 5;
	var maxdy   = gravity * 10;


	var ENTER    = 13;
	var ESC      = 27;
	var SPACE    = 32;
	var LEFT     = 37;
	var UP       = 38;
	var RIGHT    = 39;
	var DOWN     = 40;
	var KEY_A    = 65;
	var KEY_D    = 68;
	var KEY_G    = 71;
	var KEY_P    = 80;
	var KEY_S    = 83;
	var KEY_W    = 87;
	var COMMA    = 188;
	var PERIOD   = 190;

	var yellowBird = {
		sy: [ 1, 1, 1, 1, 0,  0,  0],
		sx: [ 1,23,46,70,90,113,140],
		sw: [19,19,19,19,19, 19, 19],
		sh: [19,19,19,19,19, 19, 19] // or 13 for flying frames
	};
	var blueBird = {
		sy: [28,28,28,28,27, 28, 28],
		sx: [ 1,23,46,70,90,113,140],
		sw: [19,19,19,19,19, 19, 19],
		sh: [19,19,19,19,19, 19, 19]
	};
	var greenBird = {
		sy: [50,50,50,49,48, 50, 50],
		sx: [ 0,23,46,69,90,113,140],
		sw: [19,19,19,19,19, 19, 19],
		sh: [19,19,19,19,19, 19, 19]
	};
	var burst = {
		sy: [ 90, 90],
		sx: [111,129],
		sw: [ 11, 11],
		sh: [ 11, 11]
	}
	var creatures = [yellowBird, blueBird, greenBird];


	var link     = document.getElementById('resume-content');
	var arena    = document.getElementById('arena');
	var arenaSky = document.querySelector('#arena .sky');
	var arenaGround  = document.querySelector('#arena .ground');
	var spritesheet  = new Image();
	var monsterCount = 1;
	var drops    = document.createElement('div'); // Chunks of resume to insert when the player does good things
	var canvas   = document.getElementById('canvas');
	var ctx      = canvas.getContext('2d');
	var width    = canvas.width  = window.innerWidth;
	var height   = canvas.height = window.innerHeight;
	var skyHeight= arena.scrollHeight;
	var landWidth= arena.clientWidth;
	var player   = {};
	var monsters = [];
	var pause    = false;
	var godMode  = false;

	var score    = 0;
	var topScore = 0;


	var dt = 0;
	var now = window.performance.now();
	var last = now;

	waitForContent()
	.then(loadContent)
	.then(initGame)
	.then(frame);

	//-------------------------------------------------------------------------
	// UTILITIES
	//-------------------------------------------------------------------------

	function clamp(val, min, max) {
		return Math.max(min, Math.min(max, val));
	}

	function wrap(val, min, max) {
		return val < min ? max : (val > max ? min: val);
	}

	function overlap(entity1, entity2) {
		var r = (entity2.w + entity1.w) / 2 // Minimum distance between centers for a collision to occur
		var cv = {x: entity2.x - entity1.x, y: entity2.y - entity1.y}; // Collision vector
		cv.d = Math.sqrt(cv.x * cv.x + cv.y * cv.y); // distance
		var s = cv.d - r; // separation distance

		if (s > 0) return null; // No collision

		// normalize our collision vector to get the collision normal vector
		var collNrml = { // Collision Normal Vector
			x: cv.x / cv.d,
			y: cv.y / cv.d
		};
		var relVel = { // Relative Velocity Vector
			x: entity2.dx - entity1.dx, 
			y: entity2.dy - entity1.dy
		};
		var velRelNrml = { // Velocity Relative to Normal Vector
			x: relVel.x * collNrml.x,
			y: relVel.y * collNrml.y
		}
		velRelNrml.d = Math.sqrt(velRelNrml.x * velRelNrml.x + velRelNrml.y * velRelNrml.y);
		
		var impulse = -0.75 * // coefficient of restitude == 0.5, all entities have mass == 1, -(1+0.5)/2 == 0.75
						(relVel.x * collNrml.x + relVel.y * collNrml.y) /
						(collNrml.x * collNrml.x + collNrml.y * collNrml.y);
		var collImp = { // Collision Impulse Vector
			x: collNrml.x * impulse,
			y: collNrml.y * impulse
		};
		return collImp;
	}


	// t: current time
	// b: start value
	// c: change in value
	// d: duraiton
	Math.linearTween = function (t, b, c, d) {
		return c*t/d + b;
	};
	Math.easeInQuadTween = function (t, b, c, d) {
		t /= d;
		return c*t*t + b;
	};
	Math.easeOutQuadTween = function (t, b, c, d) {
		t /= d;
		return -c*t*(t-2) + b;
	};
	Math.easeInOutQuadTween = function (t, b, c, d) {
		t /= d/2;
		if (t < 1) return c/2*t*t + b;
		--t;
		return -c/2 * (t*(t-2) - 1) + b;
	};

	//-------------------------------------------------------------------------
	// SETUP
	//-------------------------------------------------------------------------

	function waitForContent(){
		// Wait for content to be retreived by the browser
		return new Promise(function (resolve, reject){
			spritesheet.src = 'spritesheet.png'; // Should wait for this too... TODO
			if (link.import) {
				// content already loaded
				setTimeout(resolve,0);
			} else {
				// not loaded yet, listen for load event
				link.onload = resolve;
				link.addEventListener('load', resolve);
			}	
		});
	}

	function loadContent(){
		// We pull out all of the tags (ignoring raw text nodes) from the resume
		// and stick those into our drops. The drops then are placed into the
		// arena at a time as needed

		var resume = link.import.querySelector('body');
		
		while (resume.firstChild){
			var node = resume.removeChild(resume.firstChild);
			if (node.nodeType == Node.ELEMENT_NODE)
				drops.appendChild(node);
		}

		if (drops.firstChild) {
			arenaSky.appendChild(drops.firstChild);
		}
	}

	function initGame(){
		initPlayer();
		initRandomMonster();
		// initDebugMonster(100);
		// initDebugMonster(200);
		// initDebugMonster(400);
		// initDebugMonster(800);
		// initDebugMonster(1000);
		// initDebugMonster();
		document.addEventListener('keydown',   function(event) { return handleInput(event, event.keyCode, true)}, false);
		document.addEventListener('keyup',     function(event) { return handleInput(event, event.keyCode,false)}, false);
		document.addEventListener('touchstart',function(event) { return handleInput(event, UP,  true)}, false);
		document.addEventListener('touchend',  function(event) { return handleInput(event, UP, false)}, false);
		document.addEventListener('wheel',     function(event) {
			pause = true;
			arena.classList.add('mouse-scrolling');<commit_msg>switch to oldschook xhr to support safari. stupid safari. and ff. stupid ff.<commit_after>'use strict';

!function(){
	
	var fps     = 60;
	var step    = 1/fps;
	var meter   = 24; // number of pixels per meter
	var gravity = 9.8 * meter;// acceleration due to gravity, m/s
	var jumpImpulse  = gravity/2 * fps;
	var flapImpulse  = gravity/3 * fps;
	var glideImpulse = gravity/3 * fps;
	var walkImpulse  = gravity/4 * fps;
	var walkmaxdx    = gravity;
	var maxdx   = gravity * 5;
	var maxdy   = gravity * 10;


	var ENTER    = 13;
	var ESC      = 27;
	var SPACE    = 32;
	var LEFT     = 37;
	var UP       = 38;
	var RIGHT    = 39;
	var DOWN     = 40;
	var KEY_A    = 65;
	var KEY_D    = 68;
	var KEY_G    = 71;
	var KEY_P    = 80;
	var KEY_S    = 83;
	var KEY_W    = 87;
	var COMMA    = 188;
	var PERIOD   = 190;

	var yellowBird = {
		sy: [ 1, 1, 1, 1, 0,  0,  0],
		sx: [ 1,23,46,70,90,113,140],
		sw: [19,19,19,19,19, 19, 19],
		sh: [19,19,19,19,19, 19, 19] // or 13 for flying frames
	};
	var blueBird = {
		sy: [28,28,28,28,27, 28, 28],
		sx: [ 1,23,46,70,90,113,140],
		sw: [19,19,19,19,19, 19, 19],
		sh: [19,19,19,19,19, 19, 19]
	};
	var greenBird = {
		sy: [50,50,50,49,48, 50, 50],
		sx: [ 0,23,46,69,90,113,140],
		sw: [19,19,19,19,19, 19, 19],
		sh: [19,19,19,19,19, 19, 19]
	};
	var burst = {
		sy: [ 90, 90],
		sx: [111,129],
		sw: [ 11, 11],
		sh: [ 11, 11]
	}
	var creatures = [yellowBird, blueBird, greenBird];


	var link     = document.getElementById('resume-content');
	var arena    = document.getElementById('arena');
	var arenaSky = document.querySelector('#arena .sky');
	var arenaGround  = document.querySelector('#arena .ground');
	var spritesheet  = new Image();
	var monsterCount = 1;
	var drops    = document.createElement('div'); // Chunks of resume to insert when the player does good things
	var canvas   = document.getElementById('canvas');
	var ctx      = canvas.getContext('2d');
	var width    = canvas.width  = window.innerWidth;
	var height   = canvas.height = window.innerHeight;
	var skyHeight= arena.scrollHeight;
	var landWidth= arena.clientWidth;
	var player   = {};
	var monsters = [];
	var pause    = false;
	var godMode  = false;

	var score    = 0;
	var topScore = 0;


	var dt = 0;
	var now = window.performance.now();
	var last = now;

	waitForContent()
	.then(loadContent)
	.then(initGame)
	.then(frame);

	//-------------------------------------------------------------------------
	// UTILITIES
	//-------------------------------------------------------------------------

	function clamp(val, min, max) {
		return Math.max(min, Math.min(max, val));
	}

	function wrap(val, min, max) {
		return val < min ? max : (val > max ? min: val);
	}

	function overlap(entity1, entity2) {
		var r = (entity2.w + entity1.w) / 2 // Minimum distance between centers for a collision to occur
		var cv = {x: entity2.x - entity1.x, y: entity2.y - entity1.y}; // Collision vector
		cv.d = Math.sqrt(cv.x * cv.x + cv.y * cv.y); // distance
		var s = cv.d - r; // separation distance

		if (s > 0) return null; // No collision

		// normalize our collision vector to get the collision normal vector
		var collNrml = { // Collision Normal Vector
			x: cv.x / cv.d,
			y: cv.y / cv.d
		};
		var relVel = { // Relative Velocity Vector
			x: entity2.dx - entity1.dx, 
			y: entity2.dy - entity1.dy
		};
		var velRelNrml = { // Velocity Relative to Normal Vector
			x: relVel.x * collNrml.x,
			y: relVel.y * collNrml.y
		}
		velRelNrml.d = Math.sqrt(velRelNrml.x * velRelNrml.x + velRelNrml.y * velRelNrml.y);
		
		var impulse = -0.75 * // coefficient of restitude == 0.5, all entities have mass == 1, -(1+0.5)/2 == 0.75
						(relVel.x * collNrml.x + relVel.y * collNrml.y) /
						(collNrml.x * collNrml.x + collNrml.y * collNrml.y);
		var collImp = { // Collision Impulse Vector
			x: collNrml.x * impulse,
			y: collNrml.y * impulse
		};
		return collImp;
	}


	// t: current time
	// b: start value
	// c: change in value
	// d: duraiton
	Math.linearTween = function (t, b, c, d) {
		return c*t/d + b;
	};
	Math.easeInQuadTween = function (t, b, c, d) {
		t /= d;
		return c*t*t + b;
	};
	Math.easeOutQuadTween = function (t, b, c, d) {
		t /= d;
		return -c*t*(t-2) + b;
	};
	Math.easeInOutQuadTween = function (t, b, c, d) {
		t /= d/2;
		if (t < 1) return c/2*t*t + b;
		--t;
		return -c/2 * (t*(t-2) - 1) + b;
	};

	//-------------------------------------------------------------------------
	// SETUP
	//-------------------------------------------------------------------------

	function waitForContent(){
		// Wait for content to be retreived by the browser
		return new Promise(function (resolve, reject){
			spritesheet.src = 'spritesheet.png'; // Should wait for this too... TODO
			var req = new XMLHttpRequest();
			req.addEventListener('load', resolve);
			req.open('GET', '/resume.html');
			req.send();
		});
	}

	function loadContent(xhr){
		// We pull out all of the tags (ignoring raw text nodes) from the resume
		// and stick those into our drops. The drops then are placed into the
		// arena at a time as needed
debugger;
		var resume = document.createElement('div');
		resume.innerHTML = xhr.currentTarget.response;
		
		while (resume.firstChild){
			var node = resume.removeChild(resume.firstChild);
			if (node.nodeType == Node.ELEMENT_NODE)
				drops.appendChild(node);
		}

		if (drops.firstChild) {
			arenaSky.appendChild(drops.firstChild);
		}
	}

	function initGame(){
		initPlayer();
		initRandomMonster();
		// initDebugMonster(100);
		// initDebugMonster(200);
		// initDebugMonster(400);
		// initDebugMonster(800);
		// initDebugMonster(1000);
		// initDebugMonster();
		document.addEventListener('keydown',   function(event) { return handleInput(event, event.keyCode, true)}, false);
		document.addEventListener('keyup',     function(event) { return handleInput(event, event.keyCode,false)}, false);
		document.addEventListener('touchstart',function(event) { return handleInput(event, UP,  true)}, false);
		document.addEventListener('touchend',  function(event) { return handleInput(event, UP, false)}, false);
		document.addEventListener('wheel',     function(event) {
			pause = true;
			arena.classList.add('mouse-scrolling');
{'fraction_non_alphanumeric': 0.19297677805647706, 'fraction_numerical': 0.046201148960271866, 'mean_word_length': 2.461215345841501, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3466737', 'n_tokens_mistral': 5177, 'n_tokens_neox': 4454, 'n_words': 1217}