Free source: Scratch me
If you want to download the code for this game scroll to the bottom of the article. If you want to test the game click here.
Do you know the lottery ticket which you have to scratch to find three the same items to win? I kinda made a game on this idea.
This game took me more time than I expected to make. Do you want to guess what was the hardest part? Images. Initially I was thinking to make 5 categories with 30 images. I wanted to include luxury cars and hot girls, but ended up with only 3x10 and no cars, no girls...
There is not much code in a game and an expert could write it in an hour or two, but I kept running into problems so it took me more than a few days. To gather images it took me even more time... I did not want to add random images, I wanted them to be beautiful, I had chosen not a standard size, so there was a need to resize all images, I also did not want to waste my bandwidth, so I had to optimize the images... So much annoying work...
BTW all images are from https://pixabay.com/
Okay, lets dive into code.
This game is different because I first time tried to make preloader. I read about states in Emanuele Feronato article and applied everything I learned in it. To say the truth, I ran into some problems with functions, for some reasons I could not build them in the state like in the example. It just did not work for me, so I wrote them outside the state.
Now lets talk about interesting part: how to create rounded rectangles with Phase:
Second line: we fill rectangle with random color.
First line: we prepare "canvas" for our rectangle.
Third line: we draw rectangle. 0, 0 means that we draw it at the top left corner of the "canvas", as we draw rounded squares width and height is the same. The last value is roundness.
I store all rounded rectangles in array that it could be easy to access as there are a lot of them (start with 2, but end with more than 2000).
We also want to allow people to destroy rectangles on mouse move, so we add one action:
It is strange, but when I tried to use destroy function I kept getting error messages in the console. When I changed it to kill error messages disappeared.
The rest part of code is really easy and self explanatory.
You can download game code here.
At this point the game is kind of boring. What you can do? Make a test. Lets say: guess a city, guess an event, guess a famous person. Less you need to scratch to make a correct guess, more points you make. What do you think about this idea?
If you make something interesting with this code, don't forget to inform email@example.com