123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- const navigation = {
- list: [],
- prevState: undefined,
- audioIcon: undefined,
- showAnswerIcon: undefined,
- labelLeft: undefined,
- labelRight: undefined,
- add: {
- left: (icons, prevState) => {
- navigation.prevState = prevState;
- const iconSize = 75;
- let x = 10;
- navigation.labelLeft = game.add.text(x, 110, '', textStyles.p_);
- navigation.labelLeft.align = 'left';
- icons.forEach((icon) => {
- if (icon === 'back') {
- if (!prevState) {
- console.error(
- "Game error: You tried to add a 'back' icon without the 'state' parameter."
- );
- return;
- } else {
- navigation.prevState = prevState;
- }
- }
- if (icon === 'show_answer' && !self.utils.showAnswer) {
- console.error(
- "Game error: You tried to add a 'show_answer' icon without a 'showAnswer()' function o the game state."
- );
- return;
- }
- const asset = game.add.image(x, 10, icon, 1.5);
- navigation.showAnswerIcon = asset;
- navigation.list.push(asset);
- x += iconSize;
- });
- },
- right: (icons) => {
- const iconSize = 75;
- let x = context.canvas.width - iconSize - 10;
- navigation.labelRight = game.add.text(x + 60, 110, '', textStyles.p_);
- navigation.labelRight.align = 'right';
- icons.forEach((icon) => {
- let asset;
- if (icon === 'audio') {
- asset = game.add.sprite(x, 10, icon, 1, 1.5);
- asset.curFrame = audioStatus ? 0 : 1;
- navigation.audioIcon = asset;
- }
- if (icon === 'lang') asset = game.add.image(x, 10, 'lang', 1.5);
- navigation.list.push(asset);
- x -= iconSize;
- });
- },
- },
- changeState: (state) => {
- if (audioStatus) game.audio.popSound.play();
- game.event.clear(self);
- game.state.start(state);
- },
- disableIcon: (icon) => {
- icon.alpha = 0;
- icon.isDisabled = true;
- },
- onInputDown: (x, y) => {
- navigation.list.forEach((icon) => {
- if (game.math.isOverIcon(x, y, icon) && !icon.isDisabled) {
- const iconName = icon.name;
- switch (iconName) {
- case 'menu':
- navigation.changeState('menu');
- break;
- case 'lang':
- navigation.changeState('lang');
- break;
- case 'back':
- const state = navigation.prevState;
- navigation.changeState(state);
- break;
- case 'show_answer':
- if (navigation.showAnswerIcon.alpha === 1) {
- if (audioStatus) game.audio.popSound.play();
- self.utils.showAnswer();
- navigation.disableIcon(navigation.showAnswerIcon);
- }
- break;
- case 'audio':
- if (audioStatus) {
- audioStatus = false;
- navigation.audioIcon.curFrame = 1;
- } else {
- audioStatus = true;
- navigation.audioIcon.curFrame = 0;
- game.audio.popSound.play();
- }
- game.render.all();
- break;
- default:
- console.error('Game error: error in navigation icon');
- }
- }
- });
- },
- onInputOver: (x, y) => {
- let isOverIcon = false;
- navigation.list.forEach((icon) => {
- if (game.math.isOverIcon(x, y, icon) && !icon.isDisabled) {
- isOverIcon = true;
- const iconName = icon.name;
- switch (iconName) {
- case 'menu':
- navigation.labelLeft.name = game.lang.nav_menu;
- break;
- case 'lang':
- navigation.labelRight.name = game.lang.nav_lang;
- break;
- case 'back':
- navigation.labelLeft.name = game.lang.nav_back;
- break;
- case 'show_answer':
- navigation.labelLeft.name = game.lang.nav_help;
- break;
- case 'audio':
- navigation.labelRight.name = game.lang.audio;
- break;
- }
- }
- });
- if (!isOverIcon) {
- if (navigation.labelLeft) navigation.labelLeft.name = '';
- if (navigation.labelRight) navigation.labelRight.name = '';
- } else {
- document.body.style.cursor = 'pointer';
- }
- },
- };
- const sendToDatabase = function (extraData) {
-
- if (moodle) {
- if (self.result) moodleVar.hits[curMapPosition - 1]++;
- else moodleVar.errors[curMapPosition - 1]++;
- moodleVar.time[curMapPosition - 1] += game.timer.elapsed;
- const url = iLMparameters.iLM_PARAM_ServerToGetAnswerURL;
- const grade = '' + getEvaluation();
- const report = getAnswer();
- const data =
- 'return_get_answer=1' +
- '&iLM_PARAM_ActivityEvaluation=' +
- encodeURIComponent(grade) +
- '&iLM_PARAM_ArchiveContent=' +
- encodeURIComponent(report);
- const init = {
- method: 'POST',
- body: data,
- headers: {
- 'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
- },
- };
- fetch(url, init)
- .then((response) => {
- if (response.ok) {
- if (isDebugMode) console.log('Processing...');
- } else {
- console.error('Game error: Network response was not ok.');
- }
- })
- .catch((error) => {
- console.error(
- 'Game error: problem with fetch operation - ' + error.message + '.'
- );
- });
- } else {
-
-
-
- const data =
- 'line_ip=143.107.45.11' +
- '&line_name=' +
- playerName +
- '&line_lang=' +
- langString +
- extraData;
- const url = 'php/save.php';
- const init = {
- method: 'POST',
- body: data,
- headers: { 'Content-type': 'application/x-www-form-urlencoded' },
- };
- fetch(url, init)
- .then((response) => {
- if (response.ok) {
- if (isDebugMode) console.log('Processing...');
- response.text().then((text) => {
- if (isDebugMode) {
- console.log(text);
- }
- });
- } else {
- console.error('Game error: Network response was not ok.');
- }
- })
- .catch((error) => {
- console.error(
- 'Game error: problem with fetch operation - ' + error.message + '.'
- );
- });
- }
- };
- const renderBackground = (type) => {
- if (type === 'plain') {
-
- game.add.geom.rect(
- 0,
- 0,
- context.canvas.width,
- context.canvas.height,
- colors.blueBg
- );
- return;
- }
- if (type === 'scale') {
-
- game.add.image(0, 0, 'bg_snow', 1.8);
- const floor = {
- width: 128,
- last: context.canvas.width / 128,
- tiles: [3, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 4],
- };
- for (let i = 0; i < floor.tiles.length; i++) {
- game.add
- .sprite(i * floor.width, context.canvas.height, 'floor_snow', 0, 2)
- .anchor(0, 1);
- game.add
- .sprite(
- i * floor.width,
- context.canvas.height - 65,
- 'floor_snow',
- floor.tiles[i],
- 2
- )
- .anchor(0, 1);
- }
- game.add
- .image(-2, context.canvas.height - 410, 'wood_shelf', 2)
- .anchor(0, 1);
- game.add
- .image(-2, context.canvas.height - 650, 'wood_shelf', 2)
- .anchor(0, 1);
- game.add
- .sprite(4 * floor.width, context.canvas.height - 65, 'floor_snow', 7, 2)
- .anchor(0, 1);
- game.add
- .sprite(8 * floor.width, context.canvas.height - 65, 'floor_snow', 8, 2)
- .anchor(0, 1);
- game.add
- .sprite(13 * floor.width, context.canvas.height - 65, 'floor_snow', 7, 2)
- .anchor(0, 1);
- return;
- }
-
- game.add.image(0, 0, 'bg_default', 2.2);
-
- game.add.image(300, context.canvas.height / 2 - 50, 'cloud', 1.5);
- game.add.image(700, context.canvas.height / 2 + 50 - 50, 'cloud', 1.5);
- game.add.image(1280, context.canvas.height / 2 - 50 - 50, 'cloud', 1.5);
-
- const floorSize = 150;
- if (type === 'farmRoad') {
- game.add.image(0, context.canvas.height - floorSize, 'floor_grass', 1.5);
- for (let i = 1; i < context.canvas.width / floorSize - 1; i++) {
- game.add.image(
- i * floorSize,
- context.canvas.height - floorSize,
- 'floor_road'
- );
- }
- game.add.image(
- context.canvas.width - floorSize,
- context.canvas.height - floorSize,
- 'floor_grass',
- 1.5
- );
- return;
- }
- for (let i = 0; i < context.canvas.width / floorSize; i++) {
- game.add.image(
- i * floorSize,
- context.canvas.height - floorSize,
- 'floor_grass',
- 1.5
- );
- }
- if (type === 'end') {
- game.add.geom.rect(
- 0,
- context.canvas.height - floorSize * 2 + 15,
- 150 * (context.canvas.width / floorSize),
- 150,
- '#48d813'
- );
- return;
- }
- };
- const getFrameInfo = function () {
- let x0 = (y0 = 300);
-
- let width = context.canvas.width - 2 * x0;
- let height = context.canvas.height - 2 * y0;
- let rect = function () {
- game.add.geom.rect(x0, y0, width, height, 'transparent', 1, colors.red, 2);
- };
- let point = function (offsetW, offsetH) {
- for (let i = 0, y1 = y; i < 4; i++) {
- x1 = x0;
- for (let j = 0; j < 7; j++) {
- let sqr = game.add.geom.rect(x1, y1, 20, 20, colors.red);
- sqr.anchor(0.5, 0.5);
- x1 += offsetW;
- }
- y1 += offsetH;
- }
- };
- return { x: x0, y: y0, width, height, rect, point };
- };
- const moveList = function (list, x, y) {
- list.forEach((item) => {
- item.x += x;
- item.y += y;
- });
- };
|