cleaning[2]...
This commit is contained in:
parent
2dfe434cf4
commit
027476826f
@ -1,15 +1,17 @@
|
|||||||
{
|
{
|
||||||
"gameName": "quizEngine",
|
"gameName": "Game Name",
|
||||||
"gameVersion": [0, 0, 1],
|
"gameVersion": [1, 0, 0],
|
||||||
"debug": true,
|
"debug": true,
|
||||||
"lang": "en-us",
|
"lang": "en-us",
|
||||||
"loader": {"w": 200, "h": 20},
|
"loader": {"w": 200, "h": 20},
|
||||||
|
|
||||||
"colors": {
|
"colors": {
|
||||||
"back": "#2f3542",
|
"back": "#2f3542",
|
||||||
"strokeSize": 1.5,
|
"strokeSize": 1.5,
|
||||||
"buttonFill": "#a4b0be",
|
"buttonFill": "#a4b0be",
|
||||||
"buttonStroke": "#191C23",
|
"buttonStroke": "#191C23",
|
||||||
"buttonFont": "#000000",
|
"buttonFont": "#000000",
|
||||||
|
|
||||||
"answer": {
|
"answer": {
|
||||||
"stroke": "#191C23",
|
"stroke": "#191C23",
|
||||||
"wrong": "#ff6b81",
|
"wrong": "#ff6b81",
|
||||||
@ -17,5 +19,6 @@
|
|||||||
"notPassed": "#a4b0be"
|
"notPassed": "#a4b0be"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"music": "music.mp3"
|
"music": "music.mp3"
|
||||||
}
|
}
|
||||||
|
16
js/engine.js
16
js/engine.js
@ -1,5 +1,21 @@
|
|||||||
import config from './config.json';
|
import config from './config.json';
|
||||||
|
|
||||||
|
export function Init(gameObject) {
|
||||||
|
gameObject.orientation = null;
|
||||||
|
gameObject.appearanceAplha = 0;
|
||||||
|
gameObject.loadedState = false;
|
||||||
|
gameObject.finish = false;
|
||||||
|
gameObject.currentQuest = 0;
|
||||||
|
gameObject.loader = null;
|
||||||
|
|
||||||
|
// set html page language
|
||||||
|
document.documentElement.lang = config.lang;
|
||||||
|
// TODO: set html title
|
||||||
|
|
||||||
|
// set html body background-color
|
||||||
|
document.body.style.background = config.colors.back;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Функция, которая загружает изображения в документ
|
* Функция, которая загружает изображения в документ
|
||||||
* и по завершению выполнятся callback() функция
|
* и по завершению выполнятся callback() функция
|
||||||
|
68
js/index.js
68
js/index.js
@ -19,25 +19,12 @@ let cW = null; // canvas with
|
|||||||
let cH = null; // canvas height
|
let cH = null; // canvas height
|
||||||
let game = {}; // main game variable
|
let game = {}; // main game variable
|
||||||
let images = {};
|
let images = {};
|
||||||
let buttons = {};
|
|
||||||
let buttonsUi = {};
|
|
||||||
let music = {};
|
let music = {};
|
||||||
|
|
||||||
// Engine init ------------------------------------------
|
// Engine init ------------------------------------------
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
// set html page language
|
Engine.Init(game);
|
||||||
document.documentElement.lang = config.lang;
|
|
||||||
|
|
||||||
// set html body background-color
|
|
||||||
document.body.style.background = config.colors.back;
|
|
||||||
|
|
||||||
game.orientation = null;
|
|
||||||
game.appearanceAplha = 0;
|
|
||||||
game.loadedState = false;
|
|
||||||
game.finish = false;
|
|
||||||
game.currentQuest = 0;
|
|
||||||
game.loader = null;
|
|
||||||
|
|
||||||
// init canvas id and sizes
|
// init canvas id and sizes
|
||||||
canvas = document.getElementById('game');
|
canvas = document.getElementById('game');
|
||||||
@ -48,7 +35,6 @@ window.onload = function() {
|
|||||||
console.log(`Canvas size ${cW} x ${cH}`);
|
console.log(`Canvas size ${cW} x ${cH}`);
|
||||||
game.orientation = Engine.setOrientation(canvas);
|
game.orientation = Engine.setOrientation(canvas);
|
||||||
|
|
||||||
|
|
||||||
// loading Logo image
|
// loading Logo image
|
||||||
let imageLogo = new Image();
|
let imageLogo = new Image();
|
||||||
imageLogo.src = "assets/logo.png";
|
imageLogo.src = "assets/logo.png";
|
||||||
@ -89,59 +75,14 @@ window.onload = function() {
|
|||||||
canvas.addEventListener('mousemove', e => {
|
canvas.addEventListener('mousemove', e => {
|
||||||
let mousePos = Buttons.getMousePos(canvas, e);
|
let mousePos = Buttons.getMousePos(canvas, e);
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(buttonsUi)) {
|
// NOTE: put your code here
|
||||||
if (Buttons.isInside(mousePos, value)) {
|
|
||||||
console.log("hover", key)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
// click by buttons
|
// click by buttons
|
||||||
canvas.addEventListener('click', e => {
|
canvas.addEventListener('click', e => {
|
||||||
let mousePos = Buttons.getMousePos(canvas, e);
|
let mousePos = Buttons.getMousePos(canvas, e);
|
||||||
|
|
||||||
if (game.loadedState) {
|
// NOTE: put your code here
|
||||||
for (const [key, value] of Object.entries(buttonsUi)) {
|
|
||||||
if (Buttons.isInside(mousePos, value)) {
|
|
||||||
// Music button
|
|
||||||
if (key == "uiMusic") {
|
|
||||||
music.music.suspend();
|
|
||||||
|
|
||||||
if (music.music.state == "suspended") {
|
|
||||||
music.music.resume();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Info button
|
|
||||||
if (key == "uiInfo") {
|
|
||||||
game.showInfo = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(buttons)) {
|
|
||||||
if (!game.finish && key != undefined) {
|
|
||||||
if (Buttons.isInside(mousePos, value)) {
|
|
||||||
Game.checkAnswer(gameData.questions[game.currentQuest], value.data);
|
|
||||||
|
|
||||||
if (game.currentQuest < gameData.questions.length - 1) {
|
|
||||||
game.currentQuest += 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
game.finish = true;
|
|
||||||
game.showAlpha = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (game.finish && buttons.btnRestart != undefined) {
|
|
||||||
if (Buttons.isInside(mousePos, buttons.btnRestart)) {
|
|
||||||
Game.restartGame(game, gameData.questions);
|
|
||||||
delete buttons.btnRestart;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
window.requestAnimationFrame(gameLoop);
|
window.requestAnimationFrame(gameLoop);
|
||||||
@ -165,6 +106,7 @@ function update() {
|
|||||||
game.appearanceAplha -= 0.01;
|
game.appearanceAplha -= 0.01;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// game loading -------------------------------------
|
||||||
if (!game.loadedState) {
|
if (!game.loadedState) {
|
||||||
if (game.loader.pointer < config.loader.w - 50 && game.loader.direction)
|
if (game.loader.pointer < config.loader.w - 50 && game.loader.direction)
|
||||||
game.loader.pointer += 1;
|
game.loader.pointer += 1;
|
||||||
@ -175,8 +117,6 @@ function update() {
|
|||||||
|
|
||||||
game.loader.pointer -= 1;
|
game.loader.pointer -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(game.loader.pointer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// game ---------------------------------------------
|
// game ---------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user