Coding For Dummies - WAS: Coding Competition...I Like It


The university I attended started with started the Computer Games Technology Course using Game Maker http://www.yoyogames.com/gamemaker/studio/free I don't even recognise the pictures of it, as it appears to have changed a whole lot since I used it. But you really could create simple games without really writing code. Then as you started to get the hang of it, you can start adding little bits of code here and there. Seemed like quite a nice starting point to me. It used to either come with, or have downloadable, sample projects for basic games (pong, maybe breakout, etc.) so might be worth checking out.
 
In terms of simple to program/read languages, with the right API C++ can be pretty decent I believe, for instance:
 


// Couple of sprites, one for a good guy, one for a bad guy
SpriteHandle goodGuyRunning;
SpriteHandle badGuyRunning;

// Loads sprites from XML (which defines animation speed, texture, etc.)
Api.Graphics.GetSpriteHandle( "character/goodguy/running.xml", goodGuyRunning );
Api.Graphics.GetSpriteHandle( "character/badguy/running.xml", badGuyRunning);

// Set positions.
goodGuyRunning.SetPosition( 100, 20 );
badGuyRunning.SetPosition( 200, 20 );

// Enable.
goodGuyRunning.Enable( );
badGuyRunning.Enable( );
 
Hopefully it is quite readable, and it shows how to get two characters running on the spot at two different positions on the screen (100,20 for one and 200,20 for the other). Then you can add a little more:
 


// Position of character
Vector2 position( 100, 20 );

// Called each frame.
void Update( )
{
// Get Joystick X axis (-1 for left, 0 for center, 1 for right)
float xAxis = Api.IO.GetJoystickAxis( Joystick::Axis0 );

// Move the characters position according to the joystick axis.
position.x += xAxis;

// Update good guys position.
goodGuyRunning.SetPosition( position );
}
 
So each frame it just moves the character position based on the joystick X axis being pushed left/right. Of course this may not be acceptable, as the character will only move a maximum of 1 pixel per frame, so we could introduce a little more:


// Position of character
Vector2 position( 100, 20 );

// Speed of character, amount of pixels to move per second (maximum)
float speed = 40.0f;

// Called each frame.
void Update( )
{
// Get Joystick X axis (-1 for left, 0 for center, 1 for right)
float xAxis = Api.IO.GetJoystickAxis( Joystick::Axis0 );

// Movement amount, up to -40 (when joystick fully left) to +40 (when joystick fully right)
float movement = xAxis * speed;

// Move the characters position according to the movement delta we just calculated.
position.x += movement;

// Update good guys position.
goodGuyRunning.SetPosition( position );
}
And from there you may want to add a little more, like for dealing with collision:
 


// Just create a good guy sprite SpriteHandle goodGuyRunning;
// And a physics body for him. DynamicPhysicsBody goodGuyPhysics;
void Initialise( )
{
// Loads from XML (which defines animation speed, texture, etc.)
Api.Graphics.GetSpriteHandle( "character/goodguy/running.xml", goodGuyRunning );

// Rather than setting the characters position directly, lets create some physics and
// attach (parent) the sprite to the physics.
// 1. Add some shapes to our physics body (one body can have multiple shapes, for example a head, torso, legs)
goodGuyPhysics.AddShapesFromSprite( goodGuyRunning );

// 2. Now we have a physics body with a shape that is the same size as our sprite, we can attach our sprite to
// to the physicsbody.
goodGuyRunning.SetParent( goodGuyPhysics);
 
// 3. Set initial position of physics body.
goodGuyPhysics.SetPosition( 100, 20 );
}

void Update( )
{
// Character will automatically fall under gravity and collide when it hits surfaces. If we want to move him around
// we will want to apply impulses of movement to him. Bear with me...
float xAxis = Api.IO.GetJoystickAxis( Joystick::Axis0 );

// Create an impulse, nothing in the Y axis, and some scaled force in the X axis...
Vector2 impulse( xAxis * speed, 0.0f );

// Apply the impulse to the character
goodGuyPhysics.ApplyImpulse( impulse );
}


I could go on, but, well, I don't know, maybe I have seen C/C++ code for too long, but to me the above isn't that hard to read, even to someone who doesn't know code. Although not identical, the above isn't far off from the API I use myself.
 
Last edited by a moderator:
What?  No recommendations for Pascal?  :D
I thought about, but wasn't sure, how good fpc works for the pandora. But yes, for the protocol: Pascal is in may opinion the best language to learn developing. ;)
 
Again, I'll have to disagree that C is a beginner's language - I'm extremely proficient in Object-Pascal (FPC/Delphi) and several flavours of assembler. And I cannot code in C whatsoever, it's impenetrable to me. I just cannot get my head around it at all - it's all gibberish and makes no sense whatsoever.

And don't get me started on Makefiles - what the hell are they even for?

Etc, etc.

D.
 
Again, I'll have to disagree that C is a beginner's language - I'm extremely proficient in Object-Pascal (FPC/Delphi) and several flavours of assembler. And I cannot code in C whatsoever, it's impenetrable to me. I just cannot get my head around it at all - it's all gibberish and makes no sense whatsoever.


And don't get me started on Makefiles - what the hell are they even for?


Etc, etc.


D.
Took me a while to understand C; I found BASIC and Assembler easy to pick up. I still hate the amount of braces required, and semicolon line enders. I'm not sure though, I would probably not suggest it as a first language, but I probably wouldn't dissuade anyone from it either.

As long as the fundamentals are learnt and understood (Data types, Variables, and Program Flow), any language can be "tacked on"

Totally with you on makefiles. I've never made a makefile yet. I used to have a batch script for compiling my x86 assembler projects, but I couldn't tell you wtf to put in a makefile. So I use Visual Studio and Code::Blocks and let them take care of the compiler :)
 
I guess the best language for beginners is the language they can understand and make sense of.

I had no problems with C and command line compiling, but to this day I have HUGE issues with IDEs and high level languages, I guess every person is different.
 
For years (first 25) I didn't think I could understand anything beyond Quick Basic.. I was pushed into a situation where it was imperative to learn programming. I can now say I can learn just about any language in a few days once I can figure out nuances. I suppose like anything hard, it just requires time and pressure to break into it.
 
Last edited by a moderator:
I'd love to learn something like C or Java that you could really program in...but I am afraid of it, because I'm afraid I'll do something that will like, blow up my computer or something.
  1. Its pretty difficult to mess-up your computer by accident
  2. The worst that can happen is having to restore things from your backups - you cannot damage your physical/expensive hardware by making a mistake in your program
  3. Always keep backups of everything you care about
  4. If you use example code and on-line tutorials as a starting point, you should safe from wrecking things.
 
I could go on, but, well, I don't know, maybe I have seen C/C++ code for too long, but to me the above isn't that hard to read.
I'm semi comfortable with C++, but some of that scared me. There were so many function names it may not be clear to a beginner that you defined them yourself, rather than having to memorise thousands of them. I think showing complete small programs is less scary than snippets from large programs where you're taking it on faith that the comments are telling the truth. Oh and += is not at all obvious until you learn what it does. :)


I'll put my hand in this time for Scratch. There was a nice version of Frogger done in Scratch in one issue of the Raspberry Pi magazine (MagPi) which is just the right level of complexity for a beginner to puzzle over and learn lots from.
 
Binky, I'd most likely use a dedicated SD card for testing stuff, so that nothing I care about would get screwed.

But, like I said, perhaps a course at my local community college may be the way to go.

Once I get my work caught up to where I'd have some time to dedicate to it.

I think my problem is I try to bite off more than I can chew, fail, and get discouraged.  I think a structured class in a college setting, would give you baby steps, and build on what you first learned, so that you don't get discouraged...and you always have teachers and other students to help you out that way.

The reality is, I'm gonna need a bunch of hand-holding.

and that isn't what you guys here are for...nor should you be.  But college is a good place to get some of that.
 
For years (first 25) I didn't think I could understand anything beyond Quick Basic.. I was pushed into a situation where it was imperative to learn programming. I can now say I can learn just about any language in a few days once I can figure out nuances. I suppose like anything hard, it just requires time and pressure to break into it.
that's what I mean, choose a good training method and forget the language, once you know how to program you can adapt yourself to any language quite fast... people who can't adapt don't really know how to program in my opinion, they are just assembler or pure C code spawner... most OOP and other software design can be used with any language (and yes even non OOP language... with pain...)
 
I could go on, but, well, I don't know, maybe I have seen C/C++ code for too long, but to me the above isn't that hard to read.
I'm semi comfortable with C++, but some of that scared me. There were so many function names it may not be clear to a beginner that you defined them yourself, rather than having to memorise thousands of them. I think showing complete small programs is less scary than snippets from large programs where you're taking it on faith that the comments are telling the truth. Oh and += is not at all obvious until you learn what it does. :)


I'll put my hand in this time for Scratch. There was a nice version of Frogger done in Scratch in one issue of the Raspberry Pi magazine (MagPi) which is just the right level of complexity for a beginner to puzzle over and learn lots from.
I have always used editors that provide some form of auto complete, I personally think this is great for beginners (and everyone else too). So you can just type Api. and then it auto gives you a list, for example ->Graphics ->Physics ->Audio ->IO, from there you can decide what you want to do, if it is play a music track then it feels obvious to me that you'd go for Api.Audio. which again provides a list ->GetMusicHandle ->GetSfxHandle, so in this case we want to play a music track so we'd go for Api.Audio.GetMusicHandle it tells you it is a function and as soon as you hit open parenthesis i.e. Api.Audio.GetMusicHandle( it brings up details about the parameters, e.g. [param1 std::string] filename to .ogg file you wish to load [param2 MusicHandle] handle to load track into. At which point it has held you hand to typing:


MusicHandle handle;
Api.Audio.GetMusicHandle( "level0bgm.ogg", handle );

And then the auto complete kicks in again, you type handle. (with a dot after) and it brings up a list of methods e.g. ->Play ->Pause ->Stop ->SetVolume ->SetShouldLoop, so if we want to play the track it will automate:


handle.Play( );

As I say, I have used C/C++ for long enough that it is hard to appreciate a new users perspective very well, but I am trying to recall how I went about getting into programming, and I certainly found the break through for me was when I started using a nice API. When I first started out with Windows programming it was one big mess of confusion! I haven't actually seen/tried Scratch, so have no idea how well it stacks up against C++ for a beginner.
 
I'd say, Steven, that what you're saying is indeed correct, but it is far, far above the level of complete beginner :) That is my experience too, after I'm reasonably proficient in the general idea of programming and what I can expect from my language, and so on. On the beginner level, though, one needs to come to grips whit stuff like "This thing is a variable. It can be assigned a value. That there is a while loop. It repeats the stuff contained in the brackets after it" and so on. Mixing an IDE and an API into this will only increase the confusion.
 
I'd say, Steven, that what you're saying is indeed correct, but it is far, far above the level of complete beginner :) That is my experience too, after I'm reasonably proficient in the general idea of programming and what I can expect from my language, and so on. On the beginner level, though, one needs to come to grips whit stuff like "This thing is a variable. It can be assigned a value. That there is a while loop. It repeats the stuff contained in the brackets after it" and so on. Mixing an IDE and an API into this will only increase the confusion.
You are right. I forget that everyone doesn't understand while/for loops/variables, doh! I guess come back in 10 years when everyone who has gone through school will probably have been taught the basics! :)
 
Indeed, I can clearly remember the day when I learnt the code:


10 LET x=x+1
Which little snippet was a revelation for me - you could increment a variable and write it back into itself! From that point onwards I was able to write simple games with characters which had coordinates, instead of simple "guess the number" type text-orientated stuff. That was the turning point for me - I'd not even seen a FOR..NEXT loop at that point.

It is things like this that make C completely useless for an absolute beginner to learn with. You need to start with a much, much simpler language.

D.
 
10 LET x=x+1
Its also important to remember that in programming, variables can be given helpful names:

e.g. 


sheep = sheep+1
if (sheep==10){
print("There are ten sheep")
}
Some of my first programs used nothing but single-letter variables - agurgh!
 
10 LET x=x+1
 
 Its also important to remember that in programming, variables can be given helpful names:

e.g. 

sheep = sheep+1
if (sheep==10){
print("There are ten sheep")
}Some of my first programs used nothing but single-letter variables - agurgh!
Yes, but if those were used on one of the old 8bit BASICs, then there were very good reasons for using single letters - firstly that some BASICs only allowed one letter, secondly that longer names took up more bytes in memory (yes, we really were that tight for RAM back then) and thirdly each time a variable is accessed in an interpreted BASIC it has to be looked up[1], and string-compares are far faster on one-byte strings than they are on longer strings!
Edit: "x" is a helpful name! What else would you use as a horizontal coordinate variable? :)

Ahh, the good old days.

D.

[1] PandaBAS is an interpreter, but doesn't do variable lookups so you can use any length variable name you like with no speed penalty.
 
Last edited by a moderator:
Back
Top