How do you code?

Blitz3D Forums/Blitz3D Beginners Area/How do you code?

Hello, all. (Hope you all had a nice Xmas)

Ok I'm new to BBPlus as alot of you might know from all the topics I've created. :P, But now I'm kinda getting fed up. I start coding my game come to a problem find out the solution is a new function I could use. Then end up having to recode half the game to use this new function. And its been repeating itself lately. So I would like to know how everyone codes there games. What functions they also include and the structure of the game. Thank you all this will be a mager step in the right direction for moi. :D

Well it's a pain but you have to walk before you run- what you experienced will happen but that's part of the learning process and I don't think anyone will be able to give you a magical 'secret recipe'. My best advice to you is to look around for demos that do something cool you want to do in your game then learn from them- it really is the easiest way to pick stuff up in my opinion.

Oh yeah, keep it modular is a good tip.

Did Kurt really say that? I used to use that catchphrase- got it from the film Highlander.

Merry Xmas

Cheers RAM,

But I was thinking on more the lines of the code layout. Like:

Load Window
Load Variables
Load Graphics
Load Objects/Values

Main Loop

Select Case()
Case 1: Developer's Logo

Case 2: Splash Screen

Case 3: Game Running

Do Math
Draw Graphics
Keyboard Input

Case 4: Game Over

End Select

End Loop

But how would you do it?

PS: It was written on Kurt Cobains suicide note.

Well that looks ok but what do you mean by main loop? If your game is running, there is no need to be running that 'select' each time - keep the game loop as an enclosed function that only exits at 'game over'. I've never actually managed to finish a project (one day) so I've never done the whole menu system thing!

RE Kurt- interesting- didn't know that.

The way i usually do it, is to not have big blocks of code in the main loop. Use functions for each block of code. You've got the idea in having a select statement to run different main functions, depending on the mode of the game.

The main loop i use everytime without fail is as follows.

Graphics 800,600
SetBuffer BackBuffer()

<set up types if any>

<set up main global variable>

<do any preprocessing>

; ----- MAIN LOOP -----
While Not KeyHit(1)
  Cls


  update_controls()
  update_player()
  update_backround_tasks()
  draw_everything
  Flip
Wend
End
; ----- END OF MAIN LOOP -----

Function update_controls()
...
...
..
..
End Function



This way, all your actual code is in functions, and can be tested away from the rest of the main program. I usually however put the controls in the main loop, dunno why really :) Functions SHOULDN'T really depend on each other too.

Includes for:
Types, Globals, Arrays, Functions

this way if anything goes wrong I know exactly where to look, this also makes updating stuff much easier and more readable :). Saying that Hunted is over 30 includes now this includes the sswift shadow system and Surreal's BlitzPlay Pro v2.0 :)

I code modular.
I split up certain parts of the game into either includes or functions. You see if the game works to a certain stage i can go on and go back later to optimize or anything. learning a language isn't always the easiest thing todo. What i usualy do is if i want todo 1 thing i search the entire command refrence to see how i could possibly do it. If that doesnt help i usualy search for sample code, else i ask for help.

Could I do it this way?:

Load Window
Load Variables
Load Graphics

Function_Collision_Detection_Ball()
<Code here>
End Function

Function_Collision_Detection_Pad()
<Code here>
End Function

Function_Collision_Detection_Box()
<Code here>
End Function

Main Loop

Select Case()
Case 1: Developer's Logo
Case 2: Splash Screen
Case 3: Game Running

Call Function_Collision_Detection_Ball()
Call Function_Collision_Detection_Pad()
Call Function_Collision_Detection_Box()

Draw Graphics
Keyboard Input

Case 4: Game Over

End Select

End Loop

And is there a standard way of laying out structure for a 2D video game, or is it differant with every programmer? Like a personal thing. Rather than being told.

As i say, i do mines the same way most of the time :) And that looks pretty good (your code layout). ALWAYS indent things too. make reading code sooooooooo much easier :) See the thread in the general discussion on this:

http://www.blitzbasic.com/Community/posts.php?topic=28642

Good tips in there :)

I did indent that, but for so reason the forum unindented it.

Ye\ah, the froum does that some things. soo rry for that bad garmmer i tjust back from the pub :) seems like your donig not bad tho :)

As a general forum tip, use the "code" and "/code" tags when you want to write a code example, and use spaces when you want to show an indent. (4 or 5 spaces to one indent seems to be an average value - I personally use 5 spaces for every indent. Seems to work well enough.)

Coding in general is very different and individual from person to person. before trying to make your own first game, my recommendation is to make small demo's to get-to-grips with the language, syntax, advantages and pitfalls. after a while when you feel confident, try to put the pieces together, and slowly but surely, a game will evolve

also do little things and test them instead of doing large lumps of code ie a few 100 lines( until you get good at coding) without testing them.