top of page

Week 3: Make a game!

Wh..what? A game? A couple of weeks into learning?



Challenge accepted!


You have until Wednesday 28th October to upload your game as briefed in the session on Friday 23rd (Individual task, Single control)

Oh so there are tons of step by step tutorials of hyper-casual games for people from an art background, should be easy!

Or.. is it?

Planning stage

As a coding pleb like me, I started dreaming way too high for a start. I actually dared to think that I can do agar.io style shooter without a step by step tutorial and barely any knowledge of coding?

We in Lithuania like to say "Not all that glitters is gold.” meaning: Not everything actually is as it looks. And my game was an actual definition of this phrase.


After a few hours of head-scratching and browsing through tutorials, I came back on the ground and had a couple of new ideas: creating some sort of obstacle or falling game.


Good, so now all I have to do is make my artistic side shine and hide the fact that the code is as simple as it can be!

Right, so all I need to do is do research on the style, rethink those aesthetics, dream of several sprites with nice animations, have a difficult time picking the perfect one, sketch them, trace them, color them, think of a background, color palette... LEARN TO CODE.

In 4 days...

Something is not right.


At least I figured quite early that the code is what takes most of the time and got rid of the idea to make nice aesthetics.


So if I can't use the power of art to seduce players or make outstanding mechanics... I can make them laugh! And what usually makes people laugh?


MEMEz (In Adam's voice).


So in a day, I was finally able to pitch a full game idea to myself:

A hyper-casual box stacker, where memes from different periods are falling on your screen, and it is your objective to stack them on top of each other while guessing the peak year or month for each one of them.

Game concept and description:

"Tired of scrolling through endless posts on Reddit? Sweat no more, because all the memes are now falling for you on their own! All the memes are hand-picked and fermented by the dearest meme lords of the Reddit community, so make sure to stack them all. Are you a part of the community too, and can guess the peak date for each of these memes?


Due to this being the first game, I struggled more than I thought I will and after drowning in endless errors, I couldn't fix them all in time. Stacking is unavailable as new randomized objects won't spawn."









And so it begins...


I picked the first meme template that I could think of to speed up the process and background based on the meme land of the internet: Reddit.


One of the first steps after implementing the asset and the background was to give each object that is interactive a tag:

- Box - the main asset, which requires physics(Rigidbody 2D) for a sense of weight and gravity.

- Platform - base ground with a Box Collider 2D component, which prevents the box from falling outside of the main camera.

- Game over - an object, just below the platform, which is triggered (If the box falls over the platform), restarts the game (Box Collider 2D).

-Box Spawner - the name speaks for itself.


I assigned the Background, Game over, and a Box Spawner as children of the Main Camera, as I imagined them all move up with the camera after 3 boxes are stacked (SPOILER alert: it didn't work). Moved my box into the Prefabs folder to have it linked with all settings and components and just like that, I was ready for the scariest bosses of them all: THE SCRIPT.



The neverending coding phase


I started by opening up BoxScript and BoxSpawner classes. To avoid as many mistakes as possible (note, as many as POSSIBLE), I proceeded to thinking ahead and noting down that I will need both: a function for the action of spawning and cloning different prefabs. This is where I discovered the Instantiate function. Instantiate function is commonly used in the context of cloning a prefab, and my preconfigured object(Randomized boxes) will need to spawn over and over again as soon as the fallen one hits the platform.


After adding

 Vector3 temp = transform.position; 
 temp.z = 0f; //preventing the box from spawning in the negative z axis

I was now able to see the box reacting to the assigned gravity from the initial position of x=0, Y=3.4 that I set up manually within the Unity interface.


After I was able to spawn the box on the platform in the game mode, my next step was to stop falling as soon as it spawned and making it move from left to right. To execute this plan, I came back to the BoxScript class and included:

private float min_X = -2.2f, max_X = 2.2f;

Followed by other variables like

private bool canMove;
private float move_Speed  =  2f;
private RigidBody 2D myBody;
private bool gameOver;
private bool ignoreCollision;
private bool ignoreTrigger;

Meaning that the box is about to be able to move from left to right, hitting the borders of the game, with the speed of 2.


After setting all the variables I was now able to assign the component to the main BoxScipt and make the actual movement reactive and smooth.





Preview:


Woo, input time!


All of the work regarding the action of the input was happening in the GameplayController class.

I started off by introducing a singleton pattern in my code. This was to make all the content in the GameplayController to be used globally while being written only once. However, the input is also supposed to be detected within the GameplayController when calling the DropBox() function in the BoxScript. So the journey here is only getting more and more interesting.

Great! So now all I have left is assigning DropBox() to the BoxScript and setting it to false so it stops the canMove() function on the landing and...


WUOLAH! Oh....

Alright... but they do move and react to the input though, so how about I just carry on with the code for a bit...




However one thing is for certain now, it is crucial to call the currentBox as a public variable not only in the controller but also being called in the BoxScrypt as:


GameplayController.instance.currentBox = this;

Game over it is then... (ironically enough, that didn't work either)

From this point on, I have two spawned boxes and only one of them who lands after the click. G-great. But what about ending the game if it falls out of the platform?

This is when I introduced

void Landed() {}

And called out the GameplayController instance to proceed on coding the camera controller and BoxSpawner:

And speaking of SpawnNewBox, I proceeded to code it in more detail by invoking the instance in GameplayController and BoxSpawner classes.








Looks clean, now just to close my eyes and compile in 3... 2... 1...


TADA!


...



Now from this point, I wish I could tell you the exact steps I did to make it come back to the point of at least one box on the screen. Even if I could not get another box spawning after the first one lands on the platform, I do remember a long day of a lot of research and playing around with the code. The chaos disappeared when I was playing around with float numbers and I happened to change the one in the BoxSpawner from 1 to 0. It was a long road to a quick fix but the long road to fix the spawning mechanic did not come to an end. With help from my fellow peers on discord, I came across

Debug.Log("NewBox")

To try and make that second box spawn, even if it's the same one, I looked through missing brackets spaces, potentially badly assigned integers and typos. Nothing seemed to make my game listen to me.


EXPECTATIONS VS REALITY



FINAL THOUGHTS

After digesting all of my processes after I posted a failed game to itch.io I concluded and wrote down a couple of possible mistakes:

  1. My main issue was with spawning and cloning a prefab. And for that responsible is the instantiate function. I could’ve made a mistake when calling it out in different classes.

  2. Method Invoke(“Text”); is also responsible for the spawning, and the simple mistake that I could’ve made here was writing the method in the capital letter when Visual studio was suggesting to write all in lowercase (invoke(“NewBox”, 2f);)

Like many game developers, I started this project ambitious and with a lot of plans. And like a lot of developers, I got hit with reality. The order of the code might not always make sense in the code mentioned in the blog. I had to reverse engineer it while writing the dev log about it, as it's been published a week before I sat down to write about it. As this was my first game in C# made in such a short time, I did not care for anything else while making it, especially having to write a blog on the side, even if that would've helped with the accuracy of it. I stumbled upon a lot more mistakes than mentioned above, and it definitely had more steps. I planned to include a randomizer that would pick random boxes from a certain asset folder and a working camera that would slide up after a player has stacked three boxes.


I searched far for the code and wide for the solutions to the errors, but even if I ended up with an unfinished stack of memes, I left with a lot of lessons for future projects.



Lesson of the day: Don't be a clown game dev, get those rose tinted glasses off and don't expect to build an advanced playable game with no experience.

Comments


bottom of page