-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
70 lines (55 loc) · 2.09 KB
/
main.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { EvilCircle } from './EvilCircle.js';
import { MousePos } from './MousePos.js';
import { random, initializeArray, drawMap } from './util.js';
/**
* In-browser web game using the Javascript Canvas API.
*
* Player controls a ball that follows the mouse position on screen. The game is initiated
* When the mouse is clicked, the ball will start bouncing.Each square in the grid represents an uncovered
* piece which may contain: a blank space, a mine, or one of three power-ups. The game ends when all the mines
* are uncovered.
* Author: Kyle Newman Date: May 28th, 2017
*/
// global INITIALIZATIONS
(function (global) {
'use strict';
const canvas = document.querySelector('canvas');
canvas.width = global.innerWidth;
canvas.height = global.innerHeight;
const ctx = canvas.getContext('2d');
const posX = document.getElementById('x'); //use these to display the ball coordinates.
const posY = document.getElementById('y');
const score = document.getElementById('counter');
let cellSize = 0;
//GAME INITIALIZATIONS
let counter = 0; //Game Score / Mine counter
let bounced = false;
const mouse = new MousePos(canvas);
const evil = new EvilCircle(cellSize, ctx);
evil.setControls();
const cell = new Array();
const count = new Array();
const checked = new Array();
const bombs = initializeArray(cell, count, checked);
global.addEventListener('mousemove', (e) => mouse.updateMousePos(e), false);
global.addEventListener('click', (e) => mouse.setStarted(e, evil), false);
global.addEventListener('resize', function(){console.log('resized')})
// define loop that keeps drawing the scene constantly
function loop() {
cellSize = drawMap(cellSize, cell, ctx);
//drawField();
if (mouse.isStarted()) {
evil.draw();
evil.checkBounds(mouse, cellSize);
posX.textContent = "MouseX: " + evil.coordX;
posY.textContent = "MouseY: " + evil.coordY;
bounced = evil.changeHeight(null, cellSize);
if (!bounced) {
//console.log("done");
}
//evil.collisionDetect();
}
requestAnimationFrame(loop);
}
loop();
})(window);