-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.js
48 lines (43 loc) · 1.76 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const configForm = document.getElementById('configForm');
var fireButtonInput;
const gameDiv = document.getElementById("gameDiv");
var timeLimit;
var fireButton;
// start a new game when user clicks Start Game button
configForm.addEventListener("submit", function(event) {
event.preventDefault();
fireButtonInput = document.getElementById("fireButtonInput");
timeLimit = document.getElementById("timeLimit");
fireButton = fireButtonInput.value;
gameTimeLimit = timeLimit.value * 60 * 1000; // Minutes to miliseconds
if (player !== undefined) {// If player was assigned the game started before and should restart
//restartGame();
ctx.clearRect(0, 0, canvas.width, canvas.height);
enemies.length = 0; // Remove all enemies
lastEnemyBulletFired = undefined;
speedIncreases = BASE_SPEED_INCREASES;
timerForSpeedIncreases = 0;
enemySpeed = enemyBaseSpeed;
enemyBulletSpeed = [enemyBulletBaseSpeed[0],enemyBulletBaseSpeed[1]];
playerScore = 0;
$('#ScoreText').text(playerScore);
setupGame();
setTimeout(() => {newGame();}, 1000);
}
else { // Game never started before so do first time setup.
setupGame();
setTimeout(() => {newGame();}, 1000);
}
giveFocusToDiv(gameDiv);
// newGame();
});
function restartSettings(){
var fireButtonLabel = document.getElementById('fireButtonInput');
var timeLimitLabel = document.getElementById('timeLimit');
var playerLabel = document.getElementById('selectText');
var playerLabel_level = document.getElementById('selectText_level');
fireButtonLabel.value = "s";
timeLimitLabel.value = "5";
playerLabel.innerText = "Select Your Player";
playerLabel_level.innerText = "Game Level";
}