Minigame Monday: Snaker
Snaker:
With the minigames I've made so far for MM, I've used Python and pygame as an easy way to quickly write simple games, something the language is great for. However, one downside to writing games in Python is that they can't be played in browser. I took a look into ways around this problem, and the main issue is that normal pygame operation would involve blocking browser updates, thus making it impossible to embed. While there may be ways to get around this using slightly different libraries, it would require a lot of refactoring code to fit. So instead of trying to use a language not designed for web apps, why not just switch to one that is? I decided to make a game in JavaScript using Phaser. ...tiny problem, I hadn't used Phaser before, and slightly bigger problem, I also hadn't used JavaScript, so making something at all playable using a language and framework I was completely blind to in a single day might be a bit of an ask. But I wasn't going to let that stop me.
Snaker gameplay |
- The concept:
Obviously I didn't want anything too complex when using a completely new language, so I decided to make a variation of the classic game of snake. Rather than the snake growing when eating the dot however, I imagined the dot as a ball, and you would have to hit it into a target on the border around the game (Like Snooker, so Snaker, get it?). If you hit the target, you would grow, but if you missed and hit the wall you would lose. To get the ball into the right place, you would have to hit the ball into yourself, allowing you to reposition it.
- The challenge:
Pretty simple answer here, setting up and using a framework and language I hadn't before. To actually run JavaScript locally I found I needed to run a local web server, but I quickly managed to get this and phaser installed and running. It was here that I encountered my biggest problem (no, still not that I'd not used JavaScript before), that there wasn't a clear method for me to debug issues with the game. JavaScript is an interpreted language, not a compiled language, so no nice compiler warnings saying "Hey, you forgot a close bracket". Instead, I was simply getting a black screen. Likewise, no handy breakpoints allowing me to pause and step through behaviour; when I got a problem, it was just me and my code. I believe Phaser does contain debugging tools based around displaying information on the screen, but I didn't have time to look into them fully. For future JavaScript apps, I plan to look into this, and also ways I can make my development enviroment smarter for more feedback.
The next issue was my unfamilarity with Phaser. Phaser seems to contain its own physics and movement system, which is great, but not really what I wanted for Snaker. I decided to adopt a method of clearing the screen and adding new objects to it every update cycle, which while it worked, was probably not the ideal way of doing things. I also quickly noticed that the game became laggy, so I made sure to store a reference to each object I was adding so they could be safely removed on the next tick, fixing this issue. Before creating further games with Phaser, I want to look at more examples so I understand the more normal way of using objects.
JavaScript, as I've been hinting at, wasn't actually too difficult to use. The language is very similar to C++ in form and syntax, and where the language does differ it was very easy to google and find out exactly how. I did find not having such a good error and warning system on the IDE made it a little harder, as it meant errors crept through to the debug stage whereas with say Phython I would have spotted them sooner. But with the language itself I had no issues, my most time-consuming bug actually coming from missing a "break" statement in a switch case, which is the exact same syntax as C++. Whoops.
- The result:
Not as polished as I'd like it to be |
Comments
Post a Comment