Skip to content

Commit e6218d6

Browse files
committed
Updated instructions scene
1 parent 86b2304 commit e6218d6

File tree

1 file changed

+79
-86
lines changed

1 file changed

+79
-86
lines changed

qbert.html

Lines changed: 79 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -526,10 +526,15 @@
526526
let blinkingTime = 1;
527527
let blinkingTimer = blinkingTime;
528528
let blinkingOnState = true;
529+
530+
// Instructions scene variables
529531

532+
let startInstructionQbertJumpTime = 2;
530533
let instructionsTime = 3;
531534
let instructionsTimer = instructionsTime;
532535
let instructionsShow = [];
536+
let currentInstruction = -1;
537+
let showNextInstruction = false;
533538
let instructionsEnd = false;
534539
let instructionsAnimationInit = false;
535540
let instructionsBallHit = false;
@@ -1017,22 +1022,38 @@
10171022
qbertTitlePosY = canvas.height - screenPaddingY - 150;
10181023
break;
10191024
case 'instructions':
1025+
showNextInstruction = false;
10201026
instructionsEnd = false;
10211027
instructionsAnimationInit = false;
10221028
instructionsBallHit = false;
10231029
allowMovement = false;
10241030
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+
10251049
let newRedBall = new Character('redball');
10261050
newRedBall.show = false;
10271051
newRedBall.x = 200;
10281052
newRedBall.y = 100;
10291053
newRedBall.width = 50;
10301054
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];
10361057
initInstructionsShow();
10371058
break;
10381059
case 'demo':
@@ -1106,21 +1127,55 @@
11061127
}
11071128

11081129
function updateInstructionsScene(secondsPassed) {
1130+
instructionsTimer -= secondsPassed;
11091131
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;
11141164
instructionsBallHit = true;
1165+
qbertTitle.knelt = true;
11151166
playSound('hit');
11161167
}
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;
11191170
instructionsBallHit = false;
11201171
showSwear = true;
1172+
qbertTitle.knelt = false;
11211173
playSound('swear');
11221174
}
1123-
updateObjects(secondsPassed);
1175+
if (instructionsAnimationInit == true && instructionsTimer <= 0) {
1176+
sceneController('demo');
1177+
}
1178+
updateObjects(secondsPassed, true);
11241179
}
11251180

11261181
function updateDemoScene(secondsPassed) {
@@ -1428,50 +1483,6 @@
14281483
}
14291484
}
14301485

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-
14751486
function moveGreenBall(direction) {
14761487
switch (direction) {
14771488
case 'right':
@@ -1688,12 +1699,12 @@
16881699
character.targetX = character.x + 2 * cos30;
16891700
character.targetY = canvas.height + character.height;
16901701
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);
16931704
}
16941705
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);
16971708
}
16981709
character.showOnTop = true;
16991710
}
@@ -1738,19 +1749,18 @@
17381749
character.targetY = canvas.height + character.height;
17391750
character.showOnTop = true;
17401751
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);
17431754
}
17441755
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);
17471758
}
17481759
}
17491760
computeCharacterSpeeds(character, 25);
17501761
break;
17511762
}
17521763

1753-
//console.log(direction, character.currentRow, character.currentCube);
17541764
}
17551765

17561766
function removeCurrentDisk() {
@@ -2032,7 +2042,7 @@
20322042
case 'wrongway':
20332043
newCharacter.targetRow = 1;
20342044
newCharacter.targetCube = 1;
2035-
newCharacter.gravityFactor = 1;
2045+
newCharacter.gravityFactor = 0.1;
20362046
newCharacter.angle = -120;
20372047
newCharacter.vx = 0;
20382048
newCharacter.vy = 0;
@@ -2049,8 +2059,6 @@
20492059
newCharacter.targetCube = 1;
20502060
newCharacter.gravityFactor = 1;
20512061
newCharacter.angle = -240;
2052-
newCharacter.x = canvas.width - screenPaddingX;
2053-
newCharacter.y = pyramidPosY + 500;
20542062
newCharacter.vx = 0;
20552063
newCharacter.vy = 0;
20562064
newCharacter.setTarget = 'xy';
@@ -2174,12 +2182,12 @@
21742182
}
21752183
}
21762184

2177-
function updateObjects(secondsPassed) {
2185+
function updateObjects(secondsPassed, forceKneltState = false) {
21782186
for (let i = 0; i < objectsList.length; i++) {
21792187
let object = objectsList[i];
21802188
if (object.show == true) {
21812189
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; }
21832191
if (object.moving == false) {
21842192
if (object.playLandingSound == true && isOutOfBounds(object) == false) {
21852193
playSound(object.landingSound);
@@ -2274,19 +2282,6 @@
22742282
object.x = targetX;
22752283
object.vx = 0;
22762284
}
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-
// }
22902285
if (object.vy > 0 && (object.y - targetY) > 0 && targetYHitDown == true) {
22912286
object.y = targetY;
22922287
object.vy = 0;
@@ -2311,7 +2306,6 @@
23112306
object.y += gravityY * secondsPassed ** 2 / 2 + object.vy * secondsPassed;
23122307
object.vx += gravityX * secondsPassed;
23132308
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));
23152309
}
23162310
return false;
23172311
}
@@ -2745,10 +2739,9 @@
27452739
drawPushStart();
27462740
drawQbertLogo(screenPaddingX, screenPaddingY, 250, 80);
27472741
drawInstructions();
2748-
drawQbert('faceright', qbertSize, qbertTitlePosX, qbertTitlePosY, instructionsBallHit);
27492742
drawObjects();
27502743
if (showSwear == true) {
2751-
drawSwear(qbertTitlePosX - 30, qbertTitlePosY - 75, 150, 75);
2744+
drawSwear(objectsList[0].x - 30, objectsList[0].y - 75, 150, 75);
27522745
}
27532746
}
27542747

0 commit comments

Comments
 (0)