First Game

Starting a new game and adding objects. If you are new to C++ reading a tutorial on the C++ preprossesor would be helpfull.

Starting A Game

Copy the CPlusPlusTranslator files in to the folder where you are making the game. Create a file "main.cpp". It will serve as the main game file. This file should contain the following code.

#include "main.h"



startGame()

endGame

Starting with the first line "#include "main.h"". The "#include" is a preprocessor directive that inserts one file into another. "startGame()" this is a CPlusPlusTransaltor two part function that opens and prepares a game including setting up a window. The "endGame" function finishes the game setup, runs the game and finally closes the game

Create a file "main.h", the file will link "main.cpp" to all of the other required files. It should contain.

#ifndef INC_CPLUSPLUSTRANSLATOR_H

	#include "include\CPlusPlusTranslator.h"

#endif

"ifndef INC_CPLUSPLUSTRANSLTOR_H" this is a preprocessor directive that checks if the CPlusPlusTranslator has already been included.

Now that you have a game working it is time to add objects.

Adding Objects

Create a new file "objects.h", and place the following code inside.

newObject(player);



startNewObject(player)

	startObjectvar

		objectvar playerSpeed;

	endObjectvar



	createEvent

	stepEvent

	drawEvent

endNewObject

"newObject(player)" this tells the library to create a new object. Then the functions "startNewObject(player)" and "endNewObject" enclose the definition of the new object. "startObjectvar" and "endObjectvar" enclose the object variables. "objectvar" this actually declares the variable. The next three functions determine what events will be used.

Now create a file to contain player called "player.cpp", and put this code inside.

#include "objcects.h"



usingObject(player);



startCreateEvent(player)

endEvent 



startStepEvent(player)

endEvent 



startDrawEvent(player)

endEvent	

"usingObject(player);" this tells the library what objects will be programmed in this file. Then the next three groups two functions enclose the contents of their respective events.

before you can use the object player you must do two things. First, the "main.h" must be linked to "object.h". place the following code in "main.h" to link them.

#include "objcects.h"

Second, the game must be instructed to create an instance of object player. Place the following code in "main.cpp" in between "gameStart()" and "gameEnd".

instance_create(0,0,player);

The object player is now setup and you can start adding functions to the events.

in the draw event, in between "startDrawEvent(player)" and "endEvent", place the following code.

draw_set_color(c_red);

draw_rectangle(x-8,y-8,x+8,y+8,0);

Now in the create event place.

playerSpeed=3;

The last thing will be to add this code in the step event.

if (keyboard_check(vk_left))

{

	x -= playerSpeed;

}



if (keyboard_check(vk_right))

{

	x += playerSpeed;

}



if (keyboard_check(vk_up))

{

	y -= playerSpeed;

}



if (keyboard_check(vk_down))

{

	y += playerSpeed;

}

You have successfully made your first game in CPlusPlusTranslator.