iPad only, gamedev – week #6 – A little interaction

Implementing our first interactions will be easy!

Two or three weeks ago I changed from the iPad Air to the iPad Pro 12.9" with the Smart Keyboard. Yep, it is really better than my previous setup and I’m really enjoying it! I had also to change the code editor, Koder app was crashing too much and messing up my work. So I finally bought Coda app which is really as good as it seems! Don’t regret on spending such money because, after all, these are my work tools and this has to be seen as an investment (the truth that hurts in the pockets hahaha).

Let’s code a little more on our Play.js file creating the content of our createScenario function:

Yes, I’ll keep making you write all the code!

There is nothing special here, just the creation of the left and right barriers, the ground and platforms randomly positioned on the screen with random sizes. We can test our code now and see that each time the game loads, there will be new platforms. The randomness helps us to create a more diverse world in the game with a new challenge every time for the player. This method is faster than to design a bunch of levels but we need to be very careful to not create a level which is impossible to finish, like a platform that is impossible to reach.

Speaking of the player, lets finally create it on the createPlayer function:

What, just that to create the player? Yep! If you test the game right now you will see the player running off the screen… To let our player interact with the scenario and respond to our controls we must add a little more code for collision detection between the player and the other elements in the scene. Lets write some lines in our update function:

As you can see, Phaser has handy functions to handle collisions. We must verify when occurs a collision between the player and every other element. When a collision is detected, the function collideBarrier will be called and will receive the player and the object colliding with it as params. We must create this function to test our game now, writing it right after the function that will create enemies:

The logic is that, when colliding on the sides of the barriers, the player will run to the other side of the screen and, every time it just touches the ground, the number of jumps that it can do will be restored (I’m thinking to let the player do two jumps, one in the ground and other in mid air).

Testing the game now must give us the player running side to side of the screen. Time to do the jumps, right? Yes! In the next week we will handle the jumps when the user touches the screen and create the enemies to compete with.

I hope you’re enjoying the series! Feel free to drop a comment if you want! See you!

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.