Skip to content

Commit c6cd15e

Browse files
authored
Update mario-game.njk
1 parent 7d83cc5 commit c6cd15e

1 file changed

Lines changed: 28 additions & 27 deletions

File tree

src/views/mario-game.njk

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8">
5-
<title>Mario Mini Game</title>
5+
<title>Mario Sprite Game</title>
66

77
<style>
88
body {
99
margin: 0;
1010
background: #5c94fc;
1111
overflow: hidden;
12-
font-family: Arial;
1312
}
1413
1514
#game {
@@ -18,31 +17,31 @@
1817
height: 100vh;
1918
}
2019
20+
/* Mario sprite */
2121
#mario {
2222
position: absolute;
23-
width: 50px;
24-
height: 50px;
25-
background: red;
23+
width: 48px;
24+
height: 48px;
2625
bottom: 50px;
2726
left: 100px;
28-
border-radius: 10px;
27+
background: url("https://i.imgur.com/Wb1qfhK.png") no-repeat center/cover;
28+
}
29+
30+
/* Goomba sprite */
31+
.goomba {
32+
position: absolute;
33+
width: 40px;
34+
height: 40px;
35+
bottom: 50px;
36+
background: url("https://i.imgur.com/6X12GQp.png") no-repeat center/cover;
2937
}
3038
3139
.ground {
3240
position: absolute;
3341
bottom: 0;
3442
width: 100%;
3543
height: 50px;
36-
background: green;
37-
}
38-
39-
.obstacle {
40-
position: absolute;
41-
width: 40px;
42-
height: 40px;
43-
background: brown;
44-
bottom: 50px;
45-
right: -40px;
44+
background: #2ecc71;
4645
}
4746
4847
#score {
@@ -51,6 +50,7 @@
5150
left: 10px;
5251
color: white;
5352
font-size: 20px;
53+
font-family: Arial;
5454
}
5555
</style>
5656
</head>
@@ -71,7 +71,7 @@
7171
let jumping = false;
7272
let score = 0;
7373
74-
// Jump function
74+
// Jump mechanic
7575
document.addEventListener("keydown", () => {
7676
if (jumping) return;
7777
@@ -97,38 +97,39 @@
9797
}, 20);
9898
});
9999
100-
// Create obstacles
101-
function createObstacle() {
102-
const obstacle = document.createElement("div");
103-
obstacle.classList.add("obstacle");
104-
game.appendChild(obstacle);
100+
// Spawn Goombas
101+
function spawnGoomba() {
102+
const goomba = document.createElement("div");
103+
goomba.classList.add("goomba");
104+
game.appendChild(goomba);
105105
106106
let position = window.innerWidth;
107107
108108
const move = setInterval(() => {
109109
if (position < -40) {
110110
clearInterval(move);
111-
obstacle.remove();
111+
goomba.remove();
112112
score++;
113113
scoreText.innerText = "Score: " + score;
114114
} else {
115-
position -= 5;
116-
obstacle.style.left = position + "px";
115+
position -= 6;
116+
goomba.style.left = position + "px";
117117
}
118118
119119
// Collision detection
120120
const marioBottom = parseInt(window.getComputedStyle(mario).bottom);
121+
121122
if (position > 80 && position < 140 && marioBottom < 90) {
122123
alert("Game Over! Score: " + score);
123124
location.reload();
124125
}
125126
126127
}, 20);
127128
128-
setTimeout(createObstacle, Math.random() * 2000 + 1000);
129+
setTimeout(spawnGoomba, Math.random() * 2000 + 1000);
129130
}
130131
131-
createObstacle();
132+
spawnGoomba();
132133
</script>
133134

134135
</body>

0 commit comments

Comments
 (0)