Stop your game when your object is stuck by the Physics Engine in Corona SDK

In this small post I will share some code which might be useful when your developing a game which uses the physics engine like in my personal RollyBear Project.

The problem I have been trying to solve was to prompt the game-over screen when the physics engine positions RollyBear (or the object) in a state that the object is not affected anymore by the physics. For the player this means that (s)he is stuck and need to re-start the level. I think from a design point of view it would be nicer when the game can control for this situation and prompt the game-over screen (or try again screen).

I achieved this by checking for the .isAwake state provided by the Corona SDK. When “true” this means the object is still affected by the physics engine, when false the object is not affected anymore by the physics engine.


So create a function which checks every 3 seconds if the object.isAwake == false.
When the object is not anymore “awake” then we stop the timer, pause the physics engine and show a try-again overlay. Of course, it’s up to you to decide what needs to happen when your object is not affected anymore by the physics engine. I used 3 seconds as interval, in case the object starts to move again for whatever reason.

function evaluateAwake() 
    if (rollybear.isAwake == false) then
       storyboard.showOverlay( "gameoveroverlay" ,{effect = "fade"  ,  params ={curLevel = currentLevel}, isModal = true} )

objectAwake = timer.performWithDelay(3000, evaluateAwake, 0) -- check if rollybear is moving every 3 second

As you can see it is very simple, but effective.

Corona SDK: Create the Game Splash Screen

In this post I show you how you can add a splash screen to your Corona SDK project. A splash screen is a screen which is displayed when the user starts the game, often you mention or display your brand or the name of your development studio. As I’m creating a game during my travels in Asia I decided to make a splash screen which displays my website logo of Code and Travel.

Continue reading

Building Level 6-8 of RollyBear World

In the last post I provided the explanation of Level 1 -5 of Rolly Bear World, in this consecutive post I will do the same for Level 6 -8. I will only explain the key changes to the code. In case you missed some of the core functionalities build in Rolly Bear World, make sure you visit this page with all available tutorials.

Level 6
Level six is not much different from level 3 with the exception that this time the spring is fixed in the gameplay and not an available platform for the user to change. Just look at the code of level 6 and you will see we use the exact same concepts for creating the animated spring object only now as a fixed object.

Continue reading

Building Level 1-5 of RollyBear World

Before we start building level 1 to 5 I would like thank you for all the comments and emails I got with travel wishes or questions about Lua development. Unfortunately I have not been able to blog a lot in the last two months as the Internet in Laos and Philippines was just not great (softly speaking). Anyway I did had time to make some progress on Rolly Bear World. I’m currently in Manila on route to Hong Kong, so probably my connectivity will improve over the next days. I complete already 9 levels of my Rolly Bear World Project. This post will discuss the first 5 of them.
Continue reading

Corona SDK: Make code reusable

This is a short update on our Rolly Bear World project. I’m starting to create all the different levels for Rolly Bear World, and realized that some of the code will be reused across all levels. To avoid bugs in future changes I decided to make some of the code and functions available on a global level so that all separate level files can reuse these functions. I created a separate lua file called platformListeners.lua, which contain the listener functions for the platforms in the game. These are:

- movePlatform (the function to drag the platform around the screen)
- rotatePlatform (the function to rotate the platform on the screen).

In each level file we need to require this newly created .lua file, so that each individual lua level file can actually access these functions.

So make sure, in case you’re making this change as well to include in the level01.lua, level02.lua files:

local platformlisteners = require ("platformListeners")

The code listed below has been removed from level01.lua and added to the new .lua file called platformListeners.lua, I also made some additional changes which I explain below.

Continue reading

Corona SDK: cancel timers with multiple instances of an object

In the last couple of days I have been stuck on killing the timer function within Corona SDK properly. I have searched on the web many solutions but somehow they did not work for me. I solved the issue, and I thought given the many entries already on the web I thought it would be useful to share my solution.

Continue reading

Corona SDK: Adding Music and SoundEffects to Rolly Bear

In this post and tutorial we will add audio to the Rolly Bear World Project. Personally, I think this changes a lot of how the game feels. So i’m glad I reached this point.

In this post we will add
- Sound effects
- Background Music
- Via Pause Menu the user can change the settings for both

Continue reading

Corona SDK: Go to next level when level is finished.

In this tutorial I added a few new lines of code to my Rolly Bear World project. The events which needed happen when a user completes a level is still missing at this point. When Rolly Bear gets successfully launched and bounced to the treasure chest, the chest should open and a trophy should be rewarded to the user. Next, an overlay should be displayed to navigate the user either back to the level selection screen or to the next level of the game.

See screenshots:

Continue reading

Corona SDK: Restart, Pause and select Level Menu

Some of the progress I made in the last days is the creation of an overlay menu which is triggered by the storyboard.overlay function of Corona SDK. When the user clicks on the pause button an overlay appears with 3 options: Pause the game, go to the level selection screen, and reload the level. In this post we will create this kind of overlay. See the video below for the implementation in my Rolly Bear World Project.

Continue reading

Re-scale Corona SDK display Objects based on Location

It has been a while since my last post. In this post we use Corona SDK to rescale display objects based on the location on the screen. Depending on the level in the Rolly Bear game a user has more or less platforms available to use. In case of many platforms we don’t want to much cluther on the screen, so we want them to be smaller when the user doesn’t need them. We can achieve this by adding a runtime listener to the platforms to check for its location. Accordingly we can re-scale the platforms.

See the small video how it works:

Continue reading