Skip to content

Commit 62d150f

Browse files
committed
Score display and other minor updates
1 parent e6218d6 commit 62d150f

File tree

3 files changed

+42
-14
lines changed

3 files changed

+42
-14
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Q*bert port in Javascript and HTML canvas
2-
Adaptation of the famous Q*bert arcade game in Javascript, using HTML canvas. This project is still under development, enemies need to be implemented.
2+
Adaptation of the famous Q*bert arcade game in Javascript, using HTML canvas.
3+
You can play a live version at https://alainsmet.com/qbert/qbert.html
34

4-
Check a live version at https://alainsmet.com/qbert/qbert.html
5+
This project is currently under development, the main items that need to be implemented are :
6+
* Collisions with enemies
7+
* Tune the characters generator for each level / round
8+
* Freeze the enemies when Q*bert jumps on a green ball
9+
* Logic behind Sam and Slick when they jump on a cube
510

611
![Game screenshot](screenshot.png)

qbert.html

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,11 @@
13211321
computeQbertStartPosition(currentPlayer);
13221322
allowMovement = true;
13231323
flyingDiskSequence = false;
1324-
generateCharacters = true;
1324+
if (generateCharacters == false) {
1325+
generateCharacters = true;
1326+
characterDropTimer = characterDropTime;
1327+
}
1328+
13251329
}
13261330
}
13271331
}
@@ -2042,7 +2046,7 @@
20422046
case 'wrongway':
20432047
newCharacter.targetRow = 1;
20442048
newCharacter.targetCube = 1;
2045-
newCharacter.gravityFactor = 0.1;
2049+
newCharacter.gravityFactor = 0.8;
20462050
newCharacter.angle = -120;
20472051
newCharacter.vx = 0;
20482052
newCharacter.vy = 0;
@@ -2057,7 +2061,7 @@
20572061
case 'ugg':
20582062
newCharacter.targetRow = 1;
20592063
newCharacter.targetCube = 1;
2060-
newCharacter.gravityFactor = 1;
2064+
newCharacter.gravityFactor = 0.8;
20612065
newCharacter.angle = -240;
20622066
newCharacter.vx = 0;
20632067
newCharacter.vy = 0;
@@ -3340,24 +3344,43 @@
33403344
}
33413345

33423346
function drawScore() {
3343-
ctx.font = fontsList.bold;
3347+
drawScorePlayer(0, (currentPlayer == 0) ? true : false);
3348+
if (nbPlayer == 2) {
3349+
drawScorePlayer(1, (currentPlayer == 1) ? true : false);
3350+
}
3351+
}
3352+
3353+
function drawScorePlayer(player, isActive) {
33443354

3345-
let stringToWrite = playerString + ' ' + (currentPlayer + 1);
3355+
ctx.font = fontsList.bold;
3356+
ctx.fillStyle = fontsColors.purple;
3357+
3358+
let stringToWrite = playerString + ' ' + (player + 1);
33463359
let stringPosX = screenPaddingX;
3347-
if (currentPlayer === 1) {
3360+
if (player == 1) {
33483361
stringPosX = canvas.width - screenPaddingX - ctx.measureText(stringToWrite).width;
33493362
}
3350-
let gradientPlayerString = ctx.createLinearGradient(stringPosX, screenPaddingY, stringPosX, 25);
3351-
for (let i = 0; i < gradientStopPlayerString.length;i++) {
3352-
gradientPlayerString.addColorStop(gradientStopPlayerString[i].stop, gradientStopPlayerString[i].color);
3363+
3364+
if (isActive == true) {
3365+
let fillRectMargin = 3;
3366+
ctx.fillStyle = fontsColors.red;
3367+
ctx.fillRect(stringPosX + ctx.measureText(stringToWrite).width - ctx.measureText(player).width - fillRectMargin, screenPaddingY - fontHeightSpacing + fontDefaultSize / 4, ctx.measureText(player).width + 2 * fillRectMargin, fontHeightSpacing);
3368+
stringToWrite = playerString + ' ';
3369+
ctx.fillStyle = topColorList[targetTopColorIndex()];
3370+
ctx.fillText(player + 1, stringPosX + ctx.measureText(stringToWrite).width, screenPaddingY);
3371+
let gradientPlayerString = ctx.createLinearGradient(stringPosX, screenPaddingY, stringPosX, fontDefaultSize);
3372+
for (let i = 0; i < gradientStopPlayerString.length;i++) {
3373+
gradientPlayerString.addColorStop(gradientStopPlayerString[i].stop, gradientStopPlayerString[i].color);
3374+
}
3375+
ctx.fillStyle = gradientPlayerString;
3376+
33533377
}
3354-
ctx.fillStyle = gradientPlayerString;
33553378
ctx.fillText(stringToWrite, stringPosX, screenPaddingY);
33563379
ctx.font = fontsList.standard;
33573380
ctx.fillStyle = fontsColors.orange;
3358-
stringToWrite = scorePlayer[currentPlayer];
3381+
stringToWrite = scorePlayer[player];
33593382
stringPosX = screenPaddingX;
3360-
if (currentPlayer === 1) {
3383+
if (player == 1) {
33613384
stringPosX = canvas.width - screenPaddingX - ctx.measureText(stringToWrite).width;
33623385
}
33633386
ctx.fillText(stringToWrite, stringPosX, screenPaddingY + fontHeightSpacing);

screenshot.png

743 KB
Loading

0 commit comments

Comments
 (0)