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.

Newcomers AppGameKit Corner / How do you manage your code?

Author
Message
CodeTrasher
7
Years of Service
User Offline
Joined: 18th Jul 2012
Location: Tampere, Finland
Posted: 17th Jul 2015 00:00
Hello, all!

I've owned AppGameKit for some time now. I'm not a noob when it comes to programming, but I am (still) quite a noob when we're talking about game programming and design.

I have been trying to start out with very small and basic game ideas, but I have a very bad habit to just rush into programming without a proper design or even a rough sketch of what I'm about to try to code. The outcome is, then, pretty obvious; I end up making spaghetti (or at least it seems to me) and unorganized code.

How do you guys prevent this, especially with Tier 1? For example, if you ought to code a object for a Player, its attributes and updating its logic, how do you do it? Do you create a Type and necessary methods for it and place them all in the same file or...? Do you name your methods inside included files in a way that, when calling the function outside that file, you know where that call is pointed? For example, 'Player_move()'?

I'm really sorry if my question frustrates you but I've been really struggling with myself on the matter and how should I organize the project.

Thanks in advance to anyone who is able to encourage me

Mah machine: Intel Xeon E3-1231v3 4x3.40GHz | CM Hyper 212 Evo | ASRock H97 Pro4 | 240GB SanDisk SSD | Sapphire Radeon R9 270X Dual-X 2048MB | Seagate HDD 1000GB |
8GB Crucial Ballistix Sport DDR3-1600
Maghnus
4
Years of Service
User Offline
Joined: 12th Jul 2015
Location:
Posted: 17th Jul 2015 01:15
I'm right there with you. I even made a project called "Scratchpad" so I could test bits of code without mucking up a real project.
BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 17th Jul 2015 01:16
A simple way to organise things is in a State Machine. The primary driver is not objects, but the state of things.

For example a game can have many states:

Initialise
Start
Play
End
Deinitialise

A player can have many states:

Idle
Moving
Shooting
Dead

If you write your code by state, it is easier to manage it in specific confines. For example, if the game is in ""Play" state then you know to check the player. Any other time, you can ignore him.

Writing a State Machine is usually done with SELECT / CASE statements:




I wrote a DBPro tutorial that might help you get organised, all of the principles are the same for AGK...

Part 1
Part 2 - the bit with the state machine
Part 3

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
JLMoondog
Moderator
10
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 17th Jul 2015 05:09
Mr. BatVink hit it on the nail. I've found that the best way I can stay organized and keep my code readable regardless of how many lines is to do two things.

1) Have a different file for each 'function/mechanic' of the game.
2) Everything is controlled using 'states' or 'modes'

Examples 1:



Example 2:



Best part about this system, files that handle mechanics such as, highscore, menus, functions, sound, music, particles, etc..I already have a base version of each file, fully coded made up and can drag/drop these files into a new project. This saves me days of coding and because they're universal, they work straight out of the box.

Rule of thumb, if your code looks too complicated, it probably is!

Keep it simple and you'll be a happy game developer!

CodeTrasher
7
Years of Service
User Offline
Joined: 18th Jul 2012
Location: Tampere, Finland
Posted: 17th Jul 2015 07:13
Thanks to all of you guys! You provided me with really helpful examples and patterns you are using.

I'm going to take time today to go through Batvink's tutorials on state machines, that looks very nice. I've implented a simple state machine for my games earlier, though, but never on separate game objects, and I can definitely see the benefit on it.

@JLMoondog, I got to ask you. I saw that in your example you're using #insert command instead of #include. What's the benefit from that? I know #include puts everything at the end of the main program, so does #insert take that piece of program and use it right there where you call #insert?

Thanks again for your help! I really appreciate it.

Mah machine: Intel Xeon E3-1231v3 4x3.40GHz | CM Hyper 212 Evo | ASRock H97 Pro4 | 240GB SanDisk SSD | Sapphire Radeon R9 270X Dual-X 2048MB | Seagate HDD 1000GB |
8GB Crucial Ballistix Sport DDR3-1600
JLMoondog
Moderator
10
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 17th Jul 2015 09:28
Yes, insert puts the code at the line of the command. Those extention files contain special type classifications and load saved object data for loading ingame. My functions file I put at the end of my main file.

BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 17th Jul 2015 16:54
JLMoondog hit the second nail on the head. Create all of your modules in a way that they can just be dropped into your project. I have 21 of these modules now, from animation to menu and high scores.

I have started making drop-in modules as part of my series of tutorials. They may help to get your head around how to compose them...

Parameters
Multi-language
Networking
In-game screenshots

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
CodeTrasher
7
Years of Service
User Offline
Joined: 18th Jul 2012
Location: Tampere, Finland
Posted: 17th Jul 2015 17:01
Thank you, Batwink! I think that seems to be the thing I have been lookong for! I have to take a closer look on those articles later this evening.

Mah machine: Intel Xeon E3-1231v3 4x3.40GHz | CM Hyper 212 Evo | ASRock H97 Pro4 | 240GB SanDisk SSD | Sapphire Radeon R9 270X Dual-X 2048MB | Seagate HDD 1000GB |
8GB Crucial Ballistix Sport DDR3-1600
Maghnus
4
Years of Service
User Offline
Joined: 12th Jul 2015
Location:
Posted: 17th Jul 2015 19:13
I'm also finding this very useful, and am trying to code my current app in exchangeable modules that could be used in many programs.

Login to post a reply

Server time is: 2019-07-23 23:33:10
Your offset time is: 2019-07-23 23:33:10