Legend of the Moon Stones - creating a Javascript videogame

Legend of the Moon Stones - creating a Javascript videogame

By Quaro | the dev diary | 25 Aug 2020


Every summer I try to use my spare time for a new project. This year I decided to create a (very!) simple videogame to improve my javascript skills and put in some nice pixel art.

6d1c5dcb283bf2c01918f776640861c715f29d58c1a348ea84b6afca6127aa88.jpeg

The concept

I wanted to keep it simple, and since most of the games are nowadays created for mobile phones, I wanted the most basic inputs: two big buttons at the bottom of the screen so that it's easily playable on a smartphone. I decided for a main character at the center of the screen, with enemies approaching from both sides and the 2 buttons for left and right attack. That's all.

The world 

Since I wanted a simple and fast game, I went for the most classical setting: the fantasy knight against a monster invasion. Thinking about the title, I decided for "Legend of the Moon Stones", so I incorporated the concept of collecting different stones for some power-ups and nice effects. 

Then I opened Gimp and started putting some pixels together to create the main character.

c29bb6d51cb234148517ed6cb383052d87ad50fa55f5567ea266a9dde3143313.gif

(click on the image for animation)

For the background, I used some different layers to add some depth, and created a daytime, mountain background for my hero's adventure.

0534a311b6801d2b20417f4f970e9ed3b017ddeb4e7c179f4db18a2d2b75c689.png

Next, I created the art for the first enemy, a slow, weak zombie warrior for the first level of the game.

129a764ad363629096bd9ee285cffcf0911b95cac083ee2d1cf486af1bd034ed.gif

(click on the image for animation)

Start screen

With some art in place, I created a new web project, put together a Javascript canvas and some CSS for a main screen with height and width suitable for all the desktop and mobile phones (I used 144x256, automatically zoomed to fit the screen height).

I used the setInterval() Javascript function to show animations on the screen: this function simply draws everything, then sleeps for a specified amount of milliseconds, giving my game an (almost) fixed framerate. For my test, I used a 20ms sleep, so that the screen is refreshed 50 times in a second (50fps). This framerate isn't exact of course, because you should add the compute time for every frame an addition to the sleep time, but for modern devices (and with simple graphics like mine) this time is negligible.

I used the different layers of the background to create a nice transition. For the main title, I downloaded a free comics font from dafont.com and traced it using Gimp.

4d9e8c32d18be682729118dee17cffbdee405889f4f7b1b03db14c3deb4f5e77.gif

(click on the image for animation)

First level

In order to win a level, you simply have to kill a certain number of enemies: I set it to 50 for the first one, and the only type of enemy will be the weak zombies, since it's a sort of tutorial to teach how to play. The enemies spawning rate is increased after you kill some of them.

02ec2ef02fbaf66dd274b44d45af83ed158f4641d0a516841281474f34a74408.gif

(click on the image for animation)

The starting blocks are all in place, now it's just a matter of adding stuff to keep it interesting and fun to code (and hopefully to play!)

What's next 

There's still a lot to code obviously: first, I need to manage to stones spawning and collection, player's life, level progression, different kind of enemies. Then sound fx and music, a simple story progression, maybe with some different "worlds" to play in, etc.

More posts to come while  I progress further with the development. Thanks for reading!

 

 


Quaro
Quaro

web / gis developer and freelance illustrator


the dev diary
the dev diary

Discussion, challenges and solutions for web developers

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.