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.

rollybearstuck

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
       timer.cancel(objectAwake) 
       physics.pause()
       storyboard.showOverlay( "gameoveroverlay" ,{effect = "fade"  ,  params ={curLevel = currentLevel}, isModal = true} )
       rollybear:pause()
    end   
end 

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 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: 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

Corona SDK: Display Object Rotation

We already have the platforms in Rolly Bear World and we can move them around. In this post we extend our code base so that the user can rotate them. In case you missed the post about making display objects in Corona SDK drag and moveable on the screen, click here.

Watch the movie of the implementation.

Continue reading

Going Object-Oriented with Corona SDK and Rolly Bear World

I have been working on Rolly Bear World now for almost two months and some of my lua files are getting very crowded with code blocks and repetition of similar code patterns. In this post, we will not add any additional functionality to Rolly Bear World; but we will be restructuring some of the code and creating some Object-Oriented patterns.

Start with creating a new lua file in your project and call it fixedScene.lua. In this lua file we will add all the static scene objects of the levels: the invisible walls, the 2 bushes, the background bush, the floor, the two wooden signs, the chest, and the rock. In fixedScene.lua create a function called createStaticBackgroundElements and copy/ paste all the static elements in this function. Next create a global group variable called: myStaticgroup = display.newGroup. We need to insert each background element in this group. So we can handle the removal of these objects between scenes later via our Storyboard implementation.

Continue reading

Corona SDK – Drag and Move Display Objects

In the last post we created the display objects (platforms) for Rolly Bear World using a for-loop. In the final game the user should be able to drag or move these platforms to a strategic position to get Rolly Bear to the treasure chest. In the code below we create this functionality for the user to drag the platforms around the screen.

Continue reading