(cheat sheet)
Task for today
Create a simple movement script for 2D platformer
- More left, right, and jump
James’ Script
- Define Class Variables
private float moveSpeed;
- Start method used to define values of those variables we defined before.
moveSpeed = 2.0f;
TOO Lost and Confused!!
Did my own research to help me understand how to solve the task.
STRUCTURE OF A PROGRAM
Statement – Write sentences to convey to the compiler to tell them to do a task
; terminates a C++ statement
3 TYPES OF STATEMENTS
1
2
3
|
int x;
x = 5;
std::cout << x;
|
DECLARATION STATEMENTS
int x;
- This is a declaration statement – Telling the compiler x is a variable
- Variable is the name for the memory place its held.
- Variables must be declared before use – Meaning the compiler needs to know the pace to get the info from.
ASSIGNMENT STATEMENTS
x = 5;
- Computer knows that x = 5
OUTPUT STATEMENT
std::cout << x;
- Prints x onto the screen.
EXPRESSIONS
x = 2+3;
- x can be equal to an equation, though the answer to the equation will e assigned to x.
- So x = 2+3 , 2+ 3 = 5 and so x= 5 and this will be stored.
- Type of assigned statement
- Can include ‘values (such as 2), variables (such as x), operators (such as +) and functions (which return an output value based on some input value)’
FUNCTIONS
- Group of statements
- Must contain main – refers to special function
- Statements done in order – first first, second line second etc.
LIBRARIES AND C++ LIBRARIES
- Library = collection of precompiled code – Function
- Extend what the program can do.
- C++ Standard Library – Provides additional functionality
iostream is most common library – Allows you to write to the screen and get input
PREPROCESSOR DIRECTIVE
- Special type of statement
- Refers to line 1 of this code
- Tells compiler to add contents of iosteam header to program
SECOND LINE
int main ()
{
}
- Declare main function
std::cout <<“Hello world!”;
- First statement – output statement
return 0;
-
RETURN STATEMENT – “
When an executable program finishes running, the main() function sends a value back to the operating system that indicates whether it was run successfully or not.
This particular return statement returns the value of 0 to the operating system, which means “everything went okay!”. Non-zero numbers are typically used to indicate that something went wrong, and the program had to abort. We will discuss return statements in more detail when we discuss functions”