|
526 | 526 | let blinkingTime = 1;
|
527 | 527 | let blinkingTimer = blinkingTime;
|
528 | 528 | let blinkingOnState = true;
|
| 529 | + |
| 530 | + // Instructions scene variables |
529 | 531 |
|
| 532 | + let startInstructionQbertJumpTime = 2; |
530 | 533 | let instructionsTime = 3;
|
531 | 534 | let instructionsTimer = instructionsTime;
|
532 | 535 | let instructionsShow = [];
|
| 536 | + let currentInstruction = -1; |
| 537 | + let showNextInstruction = false; |
533 | 538 | let instructionsEnd = false;
|
534 | 539 | let instructionsAnimationInit = false;
|
535 | 540 | let instructionsBallHit = false;
|
|
1017 | 1022 | qbertTitlePosY = canvas.height - screenPaddingY - 150;
|
1018 | 1023 | break;
|
1019 | 1024 | case 'instructions':
|
| 1025 | + showNextInstruction = false; |
1020 | 1026 | instructionsEnd = false;
|
1021 | 1027 | instructionsAnimationInit = false;
|
1022 | 1028 | instructionsBallHit = false;
|
1023 | 1029 | allowMovement = false;
|
1024 | 1030 | showSwear = false;
|
| 1031 | + currentInstruction = -1; |
| 1032 | + |
| 1033 | + let newQbert = new Character('qbert'); |
| 1034 | + newQbert.width = qbertSize; |
| 1035 | + newQbert.height = qbertSize; |
| 1036 | + newQbert.gravityFactor = 0.8; |
| 1037 | + newQbert.x = screenPaddingX; |
| 1038 | + newQbert.y = screenPaddingY + 100; |
| 1039 | + newQbert.targetX = newQbert.x; |
| 1040 | + newQbert.targetY = newQbert.y; |
| 1041 | + newQbert.setTarget = 'xy'; |
| 1042 | + newQbert.pauseTimer = startInstructionQbertJumpTime; |
| 1043 | + newQbert.landingSound = 'jump'; |
| 1044 | + newQbert.playLandingSound = false; |
| 1045 | + |
| 1046 | + instructionsPosX = newQbert.x + qbertSize + 80; |
| 1047 | + instructionsPosY = newQbert.y + qbertSize + 60; |
| 1048 | + |
1025 | 1049 | let newRedBall = new Character('redball');
|
1026 | 1050 | newRedBall.show = false;
|
1027 | 1051 | newRedBall.x = 200;
|
1028 | 1052 | newRedBall.y = 100;
|
1029 | 1053 | newRedBall.width = 50;
|
1030 | 1054 | newRedBall.height = 50;
|
1031 |
| - objectsList = [newRedBall]; |
1032 |
| - qbertTitlePosX = screenPaddingX; |
1033 |
| - qbertTitlePosY = screenPaddingY + 100; |
1034 |
| - instructionsPosX = qbertTitlePosX + qbertSize + 80; |
1035 |
| - instructionsPosY = qbertTitlePosY + qbertSize + 60; |
| 1055 | + |
| 1056 | + objectsList = [newQbert, newRedBall]; |
1036 | 1057 | initInstructionsShow();
|
1037 | 1058 | break;
|
1038 | 1059 | case 'demo':
|
|
1106 | 1127 | }
|
1107 | 1128 |
|
1108 | 1129 | function updateInstructionsScene(secondsPassed) {
|
| 1130 | + instructionsTimer -= secondsPassed; |
1109 | 1131 | blinkingPushStart(secondsPassed);
|
1110 |
| - showInstructions(secondsPassed); |
1111 |
| - if (objectsList[0].y >= (qbertTitlePosY - 50) && objectsList[0].show == true && instructionsBallHit == false) { |
1112 |
| - objectsList[0].vx = 200; |
1113 |
| - objectsList[0].vy = -500; |
| 1132 | + |
| 1133 | + let qbertTitle = objectsList[0]; |
| 1134 | + let redBall = objectsList[1]; |
| 1135 | + |
| 1136 | + if (qbertTitle.moving == false && showNextInstruction == true) { |
| 1137 | + if (currentInstruction >= 0) { |
| 1138 | + instructionsShow[currentInstruction] = true; |
| 1139 | + } |
| 1140 | + showNextInstruction = false; |
| 1141 | + } |
| 1142 | + |
| 1143 | + if (qbertTitle.moving == false && qbertTitle.pauseTimer <= 0 && currentInstruction < instructionsShow.length) { |
| 1144 | + if (currentInstruction < instructionsShow.length - 1) { |
| 1145 | + qbertTitle.playLandingSound = true; |
| 1146 | + qbertTitle.setTarget = 'xy'; |
| 1147 | + qbertTitle.targetX = qbertTitle.x + qbertInstructionsOffsetX; |
| 1148 | + qbertTitle.targetY = qbertTitle.y + (instructionsLines[currentInstruction + 1].length + 1) * fontHeightSpacing; |
| 1149 | + qbertTitle.pauseTimer = instructionsTime; |
| 1150 | + computeCharacterSpeeds(qbertTitle, 25); |
| 1151 | + showNextInstruction = true; |
| 1152 | + } |
| 1153 | + currentInstruction += 1; |
| 1154 | + } else if (qbertTitle.moving == false && qbertTitle.pauseTimer <= 0 && currentInstruction >= instructionsShow.length && instructionsAnimationInit == false) { |
| 1155 | + redBall.show = true; |
| 1156 | + redBall.x = qbertTitle.x; |
| 1157 | + instructionsAnimationInit = true; |
| 1158 | + instructionsTimer = instructionsTime; |
| 1159 | + } |
| 1160 | + |
| 1161 | + if (redBall.show == true && redBall.y >= (qbertTitle.y - 50) && instructionsBallHit == false) { |
| 1162 | + redBall.vx = 200; |
| 1163 | + redBall.vy = -500; |
1114 | 1164 | instructionsBallHit = true;
|
| 1165 | + qbertTitle.knelt = true; |
1115 | 1166 | playSound('hit');
|
1116 | 1167 | }
|
1117 |
| - if (objectsList[0].y >= canvas.height && objectsList[0].show == true && instructionsBallHit == true) { |
1118 |
| - objectsList[0].show = false; |
| 1168 | + if (redBall.show == true && redBall.y >= canvas.height && instructionsBallHit == true) { |
| 1169 | + redBall.show = false; |
1119 | 1170 | instructionsBallHit = false;
|
1120 | 1171 | showSwear = true;
|
| 1172 | + qbertTitle.knelt = false; |
1121 | 1173 | playSound('swear');
|
1122 | 1174 | }
|
1123 |
| - updateObjects(secondsPassed); |
| 1175 | + if (instructionsAnimationInit == true && instructionsTimer <= 0) { |
| 1176 | + sceneController('demo'); |
| 1177 | + } |
| 1178 | + updateObjects(secondsPassed, true); |
1124 | 1179 | }
|
1125 | 1180 |
|
1126 | 1181 | function updateDemoScene(secondsPassed) {
|
|
1428 | 1483 | }
|
1429 | 1484 | }
|
1430 | 1485 |
|
1431 |
| - function instructionsShowStepper() { |
1432 |
| - if (instructionsEnd == true) { |
1433 |
| - return; |
1434 |
| - } |
1435 |
| - for (let i = 0; i < instructionsShow.length; i++) { |
1436 |
| - if (instructionsShow[i] == false) { |
1437 |
| - instructionsShow[i] = true; |
1438 |
| - return; |
1439 |
| - } |
1440 |
| - } |
1441 |
| - instructionsEnd = true; |
1442 |
| - } |
1443 |
| - |
1444 |
| - function showInstructions(secondPassed) { |
1445 |
| - instructionsTimer -= secondPassed; |
1446 |
| - if (instructionsTimer <= 0) { |
1447 |
| - instructionsShowStepper(); |
1448 |
| - if (instructionsEnd == false) { |
1449 |
| - let currentInstructionIndex = 0; |
1450 |
| - for (let i = 0; i < instructionsShow.length; i++) { |
1451 |
| - if (instructionsShow[i] == true) { |
1452 |
| - currentInstructionIndex = i; |
1453 |
| - } |
1454 |
| - } |
1455 |
| - if (currentInstructionIndex >= 0) { |
1456 |
| - qbertTitlePosX += qbertInstructionsOffsetX; |
1457 |
| - qbertTitlePosY += (instructionsLines[currentInstructionIndex].length + 1) * fontHeightSpacing; |
1458 |
| - playSound('jump'); |
1459 |
| - } |
1460 |
| - } else { |
1461 |
| - if (instructionsAnimationInit == false) { |
1462 |
| - for (let i = 0; i < objectsList.length; i++) { |
1463 |
| - objectsList[i].show = true; |
1464 |
| - objectsList[i].x = qbertTitlePosX; |
1465 |
| - } |
1466 |
| - instructionsAnimationInit = true; |
1467 |
| - } else { |
1468 |
| - sceneController('demo'); |
1469 |
| - } |
1470 |
| - } |
1471 |
| - instructionsTimer = instructionsTime; |
1472 |
| - } |
1473 |
| - } |
1474 |
| - |
1475 | 1486 | function moveGreenBall(direction) {
|
1476 | 1487 | switch (direction) {
|
1477 | 1488 | case 'right':
|
|
1688 | 1699 | character.targetX = character.x + 2 * cos30;
|
1689 | 1700 | character.targetY = canvas.height + character.height;
|
1690 | 1701 | if (character.type == 'wrongway') {
|
1691 |
| - character.targetX = canvas.width + character.width; |
1692 |
| - character.targetY = character.y - sin30 - cubeHeight; |
| 1702 | + character.targetX = character.x + canvas.width * Math.cos(30 * Math.PI / 180); |
| 1703 | + character.targetY = character.y - sin30 - cubeHeight - canvas.width * Math.sin(30 * Math.PI / 180); |
1693 | 1704 | }
|
1694 | 1705 | if (character.type == 'ugg') {
|
1695 |
| - character.targetX = - character.width; |
1696 |
| - character.targetY = character.y; |
| 1706 | + character.targetX = character.x - canvas.width * Math.cos(30 * Math.PI / 180); |
| 1707 | + character.targetY = character.y + sin30 + cubeHeight - canvas.width * Math.sin(30 * Math.PI / 180); |
1697 | 1708 | }
|
1698 | 1709 | character.showOnTop = true;
|
1699 | 1710 | }
|
|
1738 | 1749 | character.targetY = canvas.height + character.height;
|
1739 | 1750 | character.showOnTop = true;
|
1740 | 1751 | if (character.type == 'wrongway') {
|
1741 |
| - character.targetX = canvas.width + character.width; |
1742 |
| - character.targetY = character.y; |
| 1752 | + character.targetX = character.x + canvas.width * Math.cos(30 * Math.PI / 180); |
| 1753 | + character.targetY = character.y + sin30 + cubeHeight - canvas.width * Math.sin(30 * Math.PI / 180); |
1743 | 1754 | }
|
1744 | 1755 | if (character.type == 'ugg') {
|
1745 |
| - character.targetX = - character.width; |
1746 |
| - character.targetY = character.y - sin30 - cubeHeight; |
| 1756 | + character.targetX = character.x - canvas.width * Math.cos(30 * Math.PI / 180); |
| 1757 | + character.targetY = character.y - sin30 - cubeHeight - canvas.width * Math.sin(30 * Math.PI / 180); |
1747 | 1758 | }
|
1748 | 1759 | }
|
1749 | 1760 | computeCharacterSpeeds(character, 25);
|
1750 | 1761 | break;
|
1751 | 1762 | }
|
1752 | 1763 |
|
1753 |
| - //console.log(direction, character.currentRow, character.currentCube); |
1754 | 1764 | }
|
1755 | 1765 |
|
1756 | 1766 | function removeCurrentDisk() {
|
|
2032 | 2042 | case 'wrongway':
|
2033 | 2043 | newCharacter.targetRow = 1;
|
2034 | 2044 | newCharacter.targetCube = 1;
|
2035 |
| - newCharacter.gravityFactor = 1; |
| 2045 | + newCharacter.gravityFactor = 0.1; |
2036 | 2046 | newCharacter.angle = -120;
|
2037 | 2047 | newCharacter.vx = 0;
|
2038 | 2048 | newCharacter.vy = 0;
|
|
2049 | 2059 | newCharacter.targetCube = 1;
|
2050 | 2060 | newCharacter.gravityFactor = 1;
|
2051 | 2061 | newCharacter.angle = -240;
|
2052 |
| - newCharacter.x = canvas.width - screenPaddingX; |
2053 |
| - newCharacter.y = pyramidPosY + 500; |
2054 | 2062 | newCharacter.vx = 0;
|
2055 | 2063 | newCharacter.vy = 0;
|
2056 | 2064 | newCharacter.setTarget = 'xy';
|
|
2174 | 2182 | }
|
2175 | 2183 | }
|
2176 | 2184 |
|
2177 |
| - function updateObjects(secondsPassed) { |
| 2185 | + function updateObjects(secondsPassed, forceKneltState = false) { |
2178 | 2186 | for (let i = 0; i < objectsList.length; i++) {
|
2179 | 2187 | let object = objectsList[i];
|
2180 | 2188 | if (object.show == true) {
|
2181 | 2189 | object.moving = !computeObjectPosition(object, secondsPassed, object.height, object.setTarget, object.targetX, object.targetY, object.targetYHitDown);
|
2182 |
| - object.knelt = !object.moving; |
| 2190 | + if (forceKneltState == false) { object.knelt = !object.moving; } |
2183 | 2191 | if (object.moving == false) {
|
2184 | 2192 | if (object.playLandingSound == true && isOutOfBounds(object) == false) {
|
2185 | 2193 | playSound(object.landingSound);
|
|
2274 | 2282 | object.x = targetX;
|
2275 | 2283 | object.vx = 0;
|
2276 | 2284 | }
|
2277 |
| - // if (object.vx > 0 && (object.x - targetX) > 0) { |
2278 |
| - // object.x = targetX; |
2279 |
| - // object.vx = 0; |
2280 |
| - // if (object.type == 'wrongway') { |
2281 |
| - // console.log('hit1'); |
2282 |
| - // } |
2283 |
| - // } else if (object.vx < 0 && (object.x - targetX) < 0) { |
2284 |
| - // object.x = targetX; |
2285 |
| - // object.vx = 0; |
2286 |
| - // if (object.type == 'wrongway') { |
2287 |
| - // console.log('hit2'); |
2288 |
| - // } |
2289 |
| - // } |
2290 | 2285 | if (object.vy > 0 && (object.y - targetY) > 0 && targetYHitDown == true) {
|
2291 | 2286 | object.y = targetY;
|
2292 | 2287 | object.vy = 0;
|
|
2311 | 2306 | object.y += gravityY * secondsPassed ** 2 / 2 + object.vy * secondsPassed;
|
2312 | 2307 | object.vx += gravityX * secondsPassed;
|
2313 | 2308 | object.vy += gravityY * secondsPassed;
|
2314 |
| - //console.log(object.type, 'vx :', object.vx.toFixed(1), gravityX.toFixed(1), 'vy :', object.vy.toFixed(1), gravityY.toFixed(1)); |
2315 | 2309 | }
|
2316 | 2310 | return false;
|
2317 | 2311 | }
|
|
2745 | 2739 | drawPushStart();
|
2746 | 2740 | drawQbertLogo(screenPaddingX, screenPaddingY, 250, 80);
|
2747 | 2741 | drawInstructions();
|
2748 |
| - drawQbert('faceright', qbertSize, qbertTitlePosX, qbertTitlePosY, instructionsBallHit); |
2749 | 2742 | drawObjects();
|
2750 | 2743 | if (showSwear == true) {
|
2751 |
| - drawSwear(qbertTitlePosX - 30, qbertTitlePosY - 75, 150, 75); |
| 2744 | + drawSwear(objectsList[0].x - 30, objectsList[0].y - 75, 150, 75); |
2752 | 2745 | }
|
2753 | 2746 | }
|
2754 | 2747 |
|
|
0 commit comments