Main Concept and User Interaction:
Super Mario has been the greatest game I’ve ever played, and I have so many good memories associated with it. I used to play it with my whole family after my dad came back from work. Since I was a child, I didn’t know how tired he was after finishing his job, but I kept begging him to play with me. Even though he was apparently exhausted, he always said yes to me, and I was absolutely happy and excited every night. Super Mario is thus a fundamental part of my childhood. For this midterm project, I wanted to bring back that childhood memory by making a simple version of Super Mario Bros 2, a Wii game I used to play with my family.
Most Uncertain Part of My Midterm Project:
The most uncertain part of my midterm project is how to actually make Super Mario run and jump using the sprite concepts that we learned in class. Since I had no experience making animations where a character responds to key presses, I started the project by completing this feature. I first went to a website called “The Spriters Resource” to get sprite images of Super Mario and then imported them into my project. But since the sprite images had a green background, I had to remove it using another website “Remove Background” and make the background transparent so that Mario matched the canvas background.
Code Snippet:
As you can see, this is the code I wrote to animate Mario running and jumping. I used the same logic that we discussed in class. If a user presses the right arrow, Mario runs to the right. If a user presses the up arrow, Mario jumps vertically. I used modulo to make sure the running animation loops back to the first frame and doesn’t go over the limit.
let isRunning = false; let isJumping = !onGround; //Make mario run towards right if (keyIsDown(RIGHT_ARROW)) { x += speed; isRight = true; isRunning = true; } //Make mario run towards left if (keyIsDown(LEFT_ARROW)) { x -= speed; isRight = false; isRunning = true; } //make mario always stay inside the canvas x = constrain(x, 0, width); //animation for running if (isRunning && onGround) { //every 6 frame, move to the next sprite if (frameCount % 6 === 0) { index = (index + 1) % sprites[1].length; //use modulo to loop through the same animation } drawMario(sprites[1][index]); //draw running Mario } //Animation for jumping else if (isJumping) { drawMario(sprites[3][0]); //sprite for jumping } //sprite for idle else { drawMario(sprites[0][0]); }
Sketch:
Reflections and Future Improvements:
It was relatively easier than I expected to implement the animation of Mario running and jumping because I only had to apply the concepts we learned in class, such as using nested arrays to store each sprite image and if-else statements to trigger certain actions when a certain key is pressed. However, I still need to fix one critical issue, which is when Mario runs too fast, the background image glitches. I am still not sure how to solve this issue, so I would like to ask my professor during the next class. To make it more like Super Mario Bros 2, I need to add some obstacles such as blocks, pitfalls, Koopa Paratroopas, Bullet Bills, and Goombas. I would also like to add a score tracking system where the longer you play, the higher your score gets. This is to make the game more interesting and fun.