Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Multiple loop and begin functions.

Author
Message
Daqs
9
Years of Service
User Offline
Joined: 23rd May 2015
Location:
Posted: 23rd May 2015 12:07
I'm making a simple game on template_mac using Tier 2 C++. I came across template.cpp and template.h which have begin, loop and end functions.

I'm trying to have multiple scenes (game states) in my game such as main menu, levels, etc. for which I need to have separate begin, loop functions for each game state.

Can someone tell me how to do it? do I need to derive the template.cpp class to have access to these functions in a separate class? Thanks.
Daqs
9
Years of Service
User Offline
Joined: 23rd May 2015
Location:
Posted: 23rd May 2015 12:37
so basically, I'm simply asking if there's a way to have multiple begin, loop functions for independent scripts? If not, how do you guys handle different scenes/game states?
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 23rd May 2015 22:12
I don't use Tier 2, but the principle is the same.


You should try to create one main game loop. Within this, you can handle all of your levels with the same game logic.

Your scripts/logic should be rationalised so it can be handled in the same way for every level.

For example, take MuckyPaws' Manic Miner project. He has 40 levels, but one game loop. In a very simple format he:

Loads level from a text file. Each character in the file defines a space, solid block, eroding block, conveyor belt, key etc. He has a routine to read any file and create the level.

From this point, everything works the same. If you press a key, Miner Willy walks. Every time he reaches a new block, the logic examines the block and makes the same decision for any level, for that block type. The decision might be walk (solid block), start eroding block, continue eroding block, fall, collect key, exit level.

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
IronManhood
9
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 23rd May 2015 23:32
For menus, you could use a switch statement.



or you could use a if elseif.

Daqs
9
Years of Service
User Offline
Joined: 23rd May 2015
Location:
Posted: 24th May 2015 01:31
Thanks guys!
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 24th May 2015 03:21 Edited at: 25th May 2015 08:39
What you should do is define an interface and have your scenes implement it.

E.g


And then you can implement different scenes and just simply call something like this:


You should be abstracting most of your operations away. Arguably I wouldn't even have the if condition in app::Loop() but it's just an example.

Login to post a reply

Server time is: 2024-11-25 21:46:05
Your offset time is: 2024-11-25 21:46:05