Skip to content

Instantly share code, notes, and snippets.

@robsbots
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robsbots/9586107 to your computer and use it in GitHub Desktop.
Save robsbots/9586107 to your computer and use it in GitHub Desktop.
/* This starts a "multi line comment
This ends a multi line comment */
/* Anything within a comment is ignored so you can put what ever you like in a comment.
This can go on for line after line.
The last line should finish with */
/* This can be very handy when writing software.
If you write a new piece of code, you can put comments around the old piece and test out a new part
*/
// If you just want one line for a comment use the double slash.
// Curly braces are used to make blocks of code such as this :
if(mBallX<=0) { // The bracket here starts a block of code
mBallSpeedX=-mBallSpeedX;
mBallSpeedy=-mBallSpeedX;
} // This bracket finishes a block of code
// If mBallX if smaller than or equal to 0, then the code within the block is processed
// If not then that whole block of code is skipped over
// A block can be one line of code or more
if(mBallX<0) { // New block
if(mBallY<0) { // Another new block
mBallSpeedX=-mBallSpeedX;
mBallSpeedy=-mBallSpeedX;
} // End of second block
} // End of first block
/* The first block of code is only run if mBallX is smaller than 0.
if it is, the first block is run. In this block we check if mBallY is maller than 0. If it is then the second block is run.
If the first check was false. mBallX was bigger than 0, then the first block is skipped altogether and the second check
is never actually done. */
/* You can have blocks within blocks, but every opening curly bracket has to have a closing curly bracket to go with it.
If is sometimes useful to comment the start of each new block as I have done above (You might want more useful comments though), then comment the corresponding closing closing bracket so we know which bracket goes with which opening bracket.
*/
// To create a new variable you must start out by difining it.
private float mBallX = 0;
// "private" means the variable is only available to the small part of the code it is defined in.
// There are better ways to explain that and hopefully someone will improve on this :)
// You also need a type. "float" in this case, this is a variable that can contain a number with decimal places, such as 3.2
// An "integer" would be a number with no decimal places. A whole number such as 3 or 4.
// We can also initialise the variable. We give it its starting value. In this case 0
// The value the variable contains can be changed as the program runs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment