I believe in creating reusable short
well documented code. If my class is over 200 lines of code, I
usually consider breaking it up into smaller segments so that I can have
an easier time when bug testing.
To this end the first step is
usually planning. When you begin you should consider what the object you're
making will have to do and what kind of functionality it will have.
For a character it will have:
1)To take input from the user.
2) be able to move
3) to detect collisions
4)to have gravity.
5) have a health system
6)to be able to attack
4)to have gravity.
5) have a health system
6)to be able to attack
7) a random generator (this is for
when attacking, if we want to give a chance for higher damage etc.)
8) power up
9)be able to animate
9)be able to animate
We will design these systems to
communicate between each other when necessary and also to be interchangeable;
that way when we are creating new objects, such as an enemy object further down
the line. We will be able to attach these same classes and just modify some of
the variables so that we are not starting from the beginning.
After we have listed what we want
the character to do we have to detail out each function we have listed and
create what is called "pseudo code". Pseudo code is a term used by
programmers to mean a class or function written out in English that plans the
logic behind the programming before actually beginning to type out any lines of
code.
We'll begin with the Input class.
When
the game updates
if input
is either up arrow or w key
move
the character forward.
if
input is either down arrow or s key
move
the character backward.
if
input is either a key or left arrow
turn
the character to the left.
if
input is either right key or d key
turn
the character to the right.
if
input is space bar
make
the character jump
if
input is right click
make
the character attack the current target.
If you look at the above bit of
"pseudo code" it doesn't looks so scary does it? That is because it
really is not. Coding is simply breaking harder tasks into smaller ones and
then figuring out how to make the game work exactly the way that you want.
Now that we've figured out what
exactly what we want to say we have to go line by line and decide how to turn
this pseudo code into actual code. That will be begun in the next tutorial. See you then.


