cleaning[2]...
This commit is contained in:
parent
2dfe434cf4
commit
027476826f
@ -1,15 +1,17 @@
|
||||
{
|
||||
"gameName": "quizEngine",
|
||||
"gameVersion": [0, 0, 1],
|
||||
"gameName": "Game Name",
|
||||
"gameVersion": [1, 0, 0],
|
||||
"debug": true,
|
||||
"lang": "en-us",
|
||||
"loader": {"w": 200, "h": 20},
|
||||
|
||||
"colors": {
|
||||
"back": "#2f3542",
|
||||
"strokeSize": 1.5,
|
||||
"buttonFill": "#a4b0be",
|
||||
"buttonStroke": "#191C23",
|
||||
"buttonFont": "#000000",
|
||||
|
||||
"answer": {
|
||||
"stroke": "#191C23",
|
||||
"wrong": "#ff6b81",
|
||||
@ -17,5 +19,6 @@
|
||||
"notPassed": "#a4b0be"
|
||||
}
|
||||
},
|
||||
|
||||
"music": "music.mp3"
|
||||
}
|
||||
|
16
js/engine.js
16
js/engine.js
@ -1,5 +1,21 @@
|
||||
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() функция
|
||||
|
68
js/index.js
68
js/index.js
@ -19,25 +19,12 @@ let cW = null; // canvas with
|
||||
let cH = null; // canvas height
|
||||
let game = {}; // main game variable
|
||||
let images = {};
|
||||
let buttons = {};
|
||||
let buttonsUi = {};
|
||||
let music = {};
|
||||
|
||||
// Engine init ------------------------------------------
|
||||
// ------------------------------------------------------
|
||||
window.onload = function() {
|
||||
// set html page language
|
||||
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;
|
||||
Engine.Init(game);
|
||||
|
||||
// init canvas id and sizes
|
||||
canvas = document.getElementById('game');
|
||||
@ -48,7 +35,6 @@ window.onload = function() {
|
||||
console.log(`Canvas size ${cW} x ${cH}`);
|
||||
game.orientation = Engine.setOrientation(canvas);
|
||||
|
||||
|
||||
// loading Logo image
|
||||
let imageLogo = new Image();
|
||||
imageLogo.src = "assets/logo.png";
|
||||
@ -89,59 +75,14 @@ window.onload = function() {
|
||||
canvas.addEventListener('mousemove', e => {
|
||||
let mousePos = Buttons.getMousePos(canvas, e);
|
||||
|
||||
for (const [key, value] of Object.entries(buttonsUi)) {
|
||||
if (Buttons.isInside(mousePos, value)) {
|
||||
console.log("hover", key)
|
||||
}
|
||||
}
|
||||
// NOTE: put your code here
|
||||
}, false);
|
||||
|
||||
// click by buttons
|
||||
canvas.addEventListener('click', e => {
|
||||
let mousePos = Buttons.getMousePos(canvas, e);
|
||||
|
||||
if (game.loadedState) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
// NOTE: put your code here
|
||||
}, false);
|
||||
|
||||
window.requestAnimationFrame(gameLoop);
|
||||
@ -165,6 +106,7 @@ function update() {
|
||||
game.appearanceAplha -= 0.01;
|
||||
}
|
||||
|
||||
// game loading -------------------------------------
|
||||
if (!game.loadedState) {
|
||||
if (game.loader.pointer < config.loader.w - 50 && game.loader.direction)
|
||||
game.loader.pointer += 1;
|
||||
@ -175,8 +117,6 @@ function update() {
|
||||
|
||||
game.loader.pointer -= 1;
|
||||
}
|
||||
|
||||
console.log(game.loader.pointer);
|
||||
}
|
||||
|
||||
// game ---------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user