<commit_before>/*
	main singleton object to hold and control game data
	will need properties to hold

*/
"use strict";

var app = app || {};

// works as an object property to maintain game data
app.game = {
	WIDTH: 700,
	HEIGHT: 800,

//  Closure Variables
	canvas: undefined,
	ctx: undefined,
	lastTime: 0, // calculating Delta Time
	animationID: 0,
	paused: false,
	debugging: false,
	score: 0,
	roundCount: 0,

//  Module loading
	entity: undefined,
	enemyCharacter: undefined,
	playerCharacter: undefined,
	sound: undefined,
	input: undefined,
	blaster: undefined,
	bullet: undefined,

//	Game data variables
	player: undefined,
	bullets: [],
	enemyNumber: 0,
	enemies: [],
	gameState: undefined,
	GAME_STATE: Object.freeze({
		MENU: 0,
		PLAYING: 1,
		GAME_END: 2,
	}),

	/*	Initializes the game variables
		  and launches the update loop */
	init: function(){
		window.addEventListener("keyup",this.checkDebug);
		this.canvas = document.querySelector('canvas');
		this.canvas.width = this.WIDTH;
		this.canvas.height = this.HEIGHT;
		this.ctx = this.canvas.getContext('2d');

		this.player = new this.playerCharacter(this.WIDTH/2, this.HEIGHT-40, 90);

		this.enemies.push(new this.enemyCharacter(this.WIDTH/2,15, 10));

		this.gameState = 0; // Controls which state the program starts in

		console.log("game's init successfully called.");
		this.update();
	},

	// The game's loop, updates all objects and draws them to the screen
	update: function(){
		this.animationID = requestAnimationFrame(this.update.bind(this));
		// setting dt
		var dt = this.calculateDeltaTime();

		// Menu State Logic
		if(this.gameState === this.GAME_STATE.MENU){
			this.drawHUD(this.ctx);
		} else
		// Game Loop Logic
		if(this.gameState === this.GAME_STATE.PLAYING){
			if(this.paused){
				this.drawPauseScreen(this.ctx);
				return;
			}


			// Updates

				// moves and checks for collisions
			this.moveBullets(dt);
			this.moveEntities(dt);

			// Draw Calls

				// background
			this.ctx.fillStyle = "black";
			this.ctx.fillRect(0,0,this.WIDTH,this.HEIGHT);

				// Entities
			this.drawEntities(this.ctx);
			this.drawBullets(this.ctx);

				// HUD
			this.drawHUD(this.ctx, dt);
		} else
		// End Screen Logic
		if(this.gameState === this.GAME_STATE.GAME_END){
			this.drawHUD(this.ctx,dt);
		}

	},

	drawEntities: function(ctx){
		this.player.draw(ctx);

		for(var e=0; e<this.enemies.length; e++){
			this.enemies[e].draw(ctx);
		}

	},

	drawBullets: function(ctx){
		for(var b=0; b< this.bullets.length; b++){
			var bull = this.bullets[b];
			bull.draw(ctx);
		}
	},

	drawHUD: function(ctx, dt){
		ctx.save();
		switch(this.gameState){
			case this.GAME_STATE.MENU:
			// Draw a start screen?
			ctx.save();

				//	Setting up the gradient
				var grad = ctx.createLinearGradient(0,0,0,this.HEIGHT);
				grad.addColorStop(0,"#2299DD");
				grad.addColorStop(1,"#0F24AC");
				// Background
				ctx.fillStyle = grad;
				ctx.fillRect(0,0,this.WIDTH,this.HEIGHT);
				// Text
				ctx.textAlign = "center";
				ctx.textBaseline = "middle";
				ctx.fillStyle = "#DB880C";
				ctx.font = "40pt Fascinate";
				ctx.fillText("Bullet Swell!",this.WIDTH/2,200);
				ctx.font = "25pt Fascinate";
				ctx.fillText("A basic bullet hell by: <NAME>",this.WIDTH/2,300);

				//debugger; NEED TO FIX HOW BUTTONS ARE HANDELED AND DRAWN
				document.getElementById("startButton").style.top = 350;
				document.getElementById("startButton").style.left = this.WIDTH/2;
				document.getElementById("startButton").style.display = "block";

			ctx.restore();
			break;
			case this.GAME_STATE.PLAYING:
				// Debugging
				if(this.debugging){
					ctx.strokeStyle = "white";
					ctx.font = "25pt Fascinate";
					ctx.lineWidth =2;
					ctx.strokeText("Dt: " + dt.toFixed(3), this.WIDTH - 150, this.HEIGHT - 70);
				}

				// Score
				ctx.fillStyle = "white";
				ctx.font = "30px Fascinate";
				ctx.fillText("Score: " + this.score, 30, 50);
			break;
			case this.GAME_STATE.GAME_END:
			// Draw an end game screen
			break;
		}
		ctx.restore();
	},

	pauseGame: function(){
		this.paused = true;

		cancelAnimationFrame(this.animationID);
<commit_msg>Added a basic end game screen, that needs a button.<commit_after>/*
	main singleton object to hold and control game data
	will need properties to hold

*/
"use strict";

var app = app || {};

// works as an object property to maintain game data
app.game = {
	WIDTH: 700,
	HEIGHT: 800,

//  Closure Variables
	canvas: undefined,
	ctx: undefined,
	lastTime: 0, // calculating Delta Time
	animationID: 0,
	paused: false,
	debugging: false,
	score: 0,
	roundCount: 0,

//  Module loading
	entity: undefined,
	enemyCharacter: undefined,
	playerCharacter: undefined,
	sound: undefined,
	input: undefined,
	blaster: undefined,
	bullet: undefined,

//	Game data variables
	player: undefined,
	bullets: [],
	enemyNumber: 0,
	enemies: [],
	gameState: undefined,
	GAME_STATE: Object.freeze({
		MENU: 0,
		PLAYING: 1,
		GAME_END: 2,
	}),

	/*	Initializes the game variables
		  and launches the update loop */
	init: function(){
		window.addEventListener("keyup",this.checkDebug);
		this.canvas = document.querySelector('canvas');
		this.canvas.width = this.WIDTH;
		this.canvas.height = this.HEIGHT;
		this.ctx = this.canvas.getContext('2d');

		this.player = new this.playerCharacter(this.WIDTH/2, this.HEIGHT-40, 90);

		this.enemies.push(new this.enemyCharacter(this.WIDTH/2,15, 10));

		this.gameState = 0; // Controls which state the program starts in

		console.log("game's init successfully called.");
		this.update();
	},

	// The game's loop, updates all objects and draws them to the screen
	update: function(){
		this.animationID = requestAnimationFrame(this.update.bind(this));
		// setting dt
		var dt = this.calculateDeltaTime();

		// Menu State Logic
		if(this.gameState === this.GAME_STATE.MENU){
			this.drawHUD(this.ctx);
		} else
		// Game Loop Logic
		if(this.gameState === this.GAME_STATE.PLAYING){
			if(this.paused){
				this.drawPauseScreen(this.ctx);
				return;
			}


			// Updates

				// moves and checks for collisions
			this.moveBullets(dt);
			this.moveEntities(dt);

			// Draw Calls

				// background
			this.ctx.fillStyle = "black";
			this.ctx.fillRect(0,0,this.WIDTH,this.HEIGHT);

				// Entities
			this.drawEntities(this.ctx);
			this.drawBullets(this.ctx);

				// HUD
			this.drawHUD(this.ctx, dt);
		} else
		// End Screen Logic
		if(this.gameState === this.GAME_STATE.GAME_END){
			this.drawHUD(this.ctx,dt);
		}

	},

	drawEntities: function(ctx){
		this.player.draw(ctx);

		for(var e=0; e<this.enemies.length; e++){
			this.enemies[e].draw(ctx);
		}

	},

	drawBullets: function(ctx){
		for(var b=0; b< this.bullets.length; b++){
			var bull = this.bullets[b];
			bull.draw(ctx);
		}
	},

	drawHUD: function(ctx, dt){
		ctx.save();
		switch(this.gameState){
			case this.GAME_STATE.MENU:
				// Draw a start screen?
				ctx.save();

				//	Setting up the gradient
				var grad = ctx.createLinearGradient(0,0,0,this.HEIGHT);
				grad.addColorStop(0,"#2299DD");
				grad.addColorStop(1,"#0F24AC");
				// Background
				ctx.fillStyle = grad;
				ctx.fillRect(0,0,this.WIDTH,this.HEIGHT);
				// Text
				ctx.textAlign = "center";
				ctx.textBaseline = "middle";
				ctx.fillStyle = "#DB880C";
				ctx.font = "40pt Fascinate";
				ctx.fillText("Bullet Swell!",this.WIDTH/2,200);
				ctx.font = "25pt Fascinate";
				ctx.fillText("A basic bullet hell by: Ian Hampson",this.WIDTH/2,300);

				//debugger; NEED TO FIX HOW BUTTONS ARE HANDELED AND DRAWN
				document.getElementById("startButton").style.top = 350;
				document.getElementById("startButton").style.left = this.WIDTH/2;
				document.getElementById("startButton").style.display = "block";
				ctx.restore();
			break;
			case this.GAME_STATE.PLAYING:
				// Debugging
				if(this.debugging){
					ctx.strokeStyle = "white";
					ctx.font = "25pt Fascinate";
					ctx.lineWidth =2;
					ctx.strokeText("Dt: " + dt.toFixed(3), this.WIDTH - 150, this.HEIGHT - 70);
				}

				// Score
				ctx.fillStyle = "white";
				ctx.font = "30px Fascinate";
				ctx.fillText("Score: " + this.score, 30, 50);
			break;
			case this.GAME_STATE.GAME_END:
				// Draw an end game screen
				ctx.save();
				//	Setting up the gradient
				var grad = ctx.createLinearGradient(0,0,0,this.HEIGHT);
				grad.addColorStop(0,"#2299DD");
				grad.addColorStop(1,"#0F24AC");
				// Background
				ctx.fillStyle = grad;
				ctx.fillRect(0,0,this.WIDTH,this.HEIGHT);
				// Text
				ctx.textAlign = "center";
				ctx.textBaseline = "middle";
				ctx.fillStyle = "#B90606";
				ctx.font = "40pt Fascinate";
				ctx.fillText("Game over!",this.WIDTH/2,200);
				ctx.font = "25pt Fascinate";
				ctx.fillText("Final Score: " + this.score,this.WIDTH/2,300);
				ctx.fillText("Final Round Count: " + this.roundCount,this.WIDTH/2,350);

				ctx.restore();
			break;
		}
		ctx.restore();
	},

	pauseGame: function(){
		this.paused = true;

		cancelAnimationFrame(this.animationID);

{'fraction_non_alphanumeric': 0.14891485809682806, 'fraction_numerical': 0.02125765164162493, 'mean_word_length': 3.289260143198091, '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': '5856515', 'n_tokens_mistral': 3803, 'n_tokens_neox': 3126, 'n_words': 687}