int IndieLib() {
	//-------------------Constants------------------
	enum emode {menu, create, config};

	const char FPS =								60;

	const float dcam =								0.05f;

	const char prompt[] =							">\t";
	
	//----------------Logic variables---------------

	bool show_b_areas =								true;

	emode mode =									create;
	emode prev_mode =								create;

	float dm =										0;

	//--------------------Engine--------------------

	CIndieLib *prog = CIndieLib::Instance();
	if (!prog->Init()) return 1;
	prog->Window->SetTitle("Level Editor 1.1-alpha");
	//prog->Window->Cursor(true);

	// Render timer

	IND_Timer render_timer;
	int ticks =										0;
	int last_frame =								0;
	render_timer.Start();

	// Camera

	float cam_x =									(float) prog->Window->GetWidth() / 2;
	float cam_y =									(float) prog->Window->GetHeight() / 2;
	IND_Camera2d cam((int) cam_x, (int) cam_y);
	IND_Camera2d bcam((int) cam_x, (int) cam_y);
	
	//-------------------Resources------------------

	IND_Font t_font;
	IND_Entity2d menu_e;

	try {
		if (!prog->FontManager->Add(&t_font, "..\\res\\font_small.png", "..\\res\\font_small.xml", IND_ALPHA, IND_32))
			throw res_error();
		if (!prog->Entity2dManager->Add(4, &menu_e)) throw res_error();
	}
	catch (res_error) {
		prog->End();
		return 2;
	}

	//-----------Menu and additional info-----------

	cmd_line cmd_menu;
	
	char cmd_str[520];
	char buf[10];

	strcpy(cmd_str, prompt);

	menu_e.SetFont(&t_font);
	menu_e.SetAlign(IND_LEFT);
	menu_e.SetCharSpacing(-8);
	menu_e.SetLineSpacing(18);
	menu_e.SetText(cmd_str);
	menu_e.SetPosition(5, (float) (prog->Window->GetHeight() - 25), 0);
	menu_e.SetShow(false);

	// Information
	
	info tile_info;

	prog->Entity2dManager->Add(4, &tile_info.get_entity());
	tile_info.set_font(t_font);

	info lvl_info;
	bool update_info =								true;

	prog->Entity2dManager->Add(4, &lvl_info.get_entity());
	lvl_info.set_font(t_font);
	lvl_info.set_position(prog->Render->GetViewPortX() + 5, prog->Render->GetViewPortY() + 5, 0);
	lvl_info.add_text(unnamed_lt_file);

	//------------------Tiles manager---------------

	lt_manager ltm;
	try {
		if (!ltm.load_textures("..\\textures")) throw tm_init_fail();
	}
	catch (tm_init_fail) {
		prog->End();
		return 3;
	}

	//-------------Cofiguration manager-------------

	conf_manager conf_m;
	
	//-----------------Tile cursor------------------

	tile_cursor tcursor;

	float cur_dx = 0;
	float cur_dy = 0;

	try {
		if (!tcursor.init(*prog)) throw cursor_init_fail();
	}
	catch (cursor_init_fail) {
		prog->End();
		return 3;
	}
	tcursor.set_textures(ltm.get_textures());
	tcursor.set_tiles(ltm.get_tiles(0));

	//-----------------Config cursor----------------

	config_cursor ccursor(conf_m);

	try {
		if (!ccursor.init(*prog)) throw cursor_init_fail();
	}
	catch (cursor_init_fail) {
		prog->End();
		return 3;
	}
	ccursor.hide();

	editing_cursor *cursor;
	if (mode == create) cursor = &tcursor;

	lvl_info.add_text("\nTile set: ");
	lvl_info.add_text(tcursor.cur_tiles().get_name());
	
	//-------------------Main loop------------------

	while (!prog->Input->OnKeyPress(IND_ESCAPE) && !prog->Input->Quit()) {
		// Input update
		prog->Input->Update();

		// Count time for next rendering
		ticks = render_timer.GetTicks();
		
		// ~ button press (show command line)
		if (prog->Input->OnKeyPress(IND_BACKQUOTE) && !tcursor.active_tile()) {
			if (!menu_e.IsShow()) {
				prev_mode = mode;
				mode = menu;
			} else mode = prev_mode;

			menu_e.SetPosition((float) (cam_x - prog->Window->GetWidth() / 2 + 5),
				(float) (cam_y + prog->Window->GetHeight() / 2 - 25), 0);
			menu_e.SetShow(!menu_e.IsShow());
		}

		// Changing level info position
		lvl_info.set_position((int) cam_x - prog->Window->GetWidth() / 2 + 5,
			(int) cam_y - prog->Window->GetHeight() / 2 + 5, 0);
		
		// Changing active tile info position
		tile_info.set_position((int) cam_x + prog->Window->GetWidth() / 2 - 100,
			(int) cam_y - prog->Window->GetHeight() / 2 + 5, 0);

		//---------------Updating input due to active mode---------------
		
		switch (mode) {
		case menu: {
			// Menu input update
			char ch = '\0';

			for (char key = 97; key <= 122; key++)
				if (prog->Input->OnKeyPress(key - 97)) ch =			key;
			for (char key = 48; key <= 57; key++)
				if (prog->Input->OnKeyPress(key - 22)) ch =			key;
			if (prog->Input->OnKeyPress(IND_SPACE)) ch =			' ';
			if (prog->Input->OnKeyPress(IND_MINUS)) ch =			'-';
			//if (prog->Input->OnKeyPress(IND_AT)) ch =				':';
			//if (prog->Input->OnKeyPress(IND_CARET)) ch =			'_';
			if (prog->Input->OnKeyPress(IND_BACKSLASH)) ch =		'\\';
			if (prog->Input->OnKeyPress(IND_PERIOD)) ch =			'.';

			if (prog->Input->OnKeyPress(IND_BACKSPACE) || prog->Input->IsKeyPressed(IND_BACKSPACE, 100)) {
				cmd_menu.pop_back();
				strcpy(cmd_str, prompt);
				strcat(cmd_str, cmd_menu.get_string());
			}

			if (ch) {
				cmd_menu.push_back(ch);
				strcpy(cmd_str, prompt);
				strcat(cmd_str, cmd_menu.get_string());
			}

			// Performing command
			if (prog->Input->OnKeyPress(IND_RETURN)) {
				if (perform_command(cmd_menu.parse(), ltm, conf_m)) {
					strcpy(cmd_str, prompt);

					menu_e.SetShow(false);
					mode =											prev_mode;
					update_info =									true;

				} else {
					strcpy(cmd_str, prompt);
					strcat(cmd_str, "bad command");
				}
				cmd_menu.clear();
			}
				   } break;

		case create: {
			// Cursor update
			cursor_update(*prog, cursor, cur_dx, cur_dy);
			tcursor_update(*prog, tcursor);

			// 1 button press (set ground as current tile set)
			if (prog->Input->OnKeyPress(IND_1) && !tcursor.active_tile()) {
				tcursor.set_tiles(ltm.get_tiles(0));
				update_info =										true;
			}

			// 2 button press (set terrain as current tile set)
			if (prog->Input->OnKeyPress(IND_2) && !tcursor.active_tile()) {
				tcursor.set_tiles(ltm.get_tiles(1));
				update_info =										true;
			}

			// 3 button press (set items as current tile set)
			if (prog->Input->OnKeyPress(IND_3) && !tcursor.active_tile()) {
				tcursor.set_tiles(ltm.get_tiles(2));
				update_info =										true;
			}

					 } break;

		case config: {
			cursor_update(*prog, cursor, cur_dx, cur_dy);
					 } break;
		}

		// Non menu actions
		if (mode != menu) {
			
			// Tab button press (show/hide bounding areas OR switch working mode)
			if (prog->Input->OnKeyPress(IND_TAB))
				if (prog->Input->IsKeyPressed(IND_LCTRL)) {
					switch (mode) {
					case create:
						if (*ltm.get_lt_file() && !cursor->active_tile()) {
							mode =									config;
							cursor =								&ccursor;
							tcursor.hide();

							if (conf_m.get_doors_count())
								conf_m.update();
							else conf_m.create(ltm.get_textures(), ltm.get_tiles(1));
						}
						break;

					case config:
						mode =										create;
						cursor =									&tcursor;
						ccursor.hide();

						break;
					}
					cursor->show();
					update_info =									true;

				} else show_b_areas = !show_b_areas;

			// Camera update
			camera_update(*prog, cam, bcam, cur_dx, cur_dy, cam_x, cam_y, dm * dcam);
		}

		// Editor info
		if (update_info) {
			lvl_info.set_text("Mode: ");
			if (mode == create)
				lvl_info.add_text("create");
			else lvl_info.add_text("config");
			lvl_info.add_text("\nFile: ");
			if (*ltm.get_lt_file())
				lvl_info.add_text(ltm.get_lt_file());
			else lvl_info.add_text(unnamed_lt_file);
			lvl_info.add_text("\nTile set: ");
			lvl_info.add_text(tcursor.cur_tiles().get_name());

			update_info =											false;
		}

		// Tile info

		if (tcursor.active_tile()) {
			tile_info.set_text("Z pos: ");
			tile_info.add_text(itoa(tcursor.active_tile()->GetPosZ(), buf, 10));
			tile_info.add_text("\nZ angle: ");
			tile_info.add_text(itoa((int) tcursor.active_tile()->GetAngleZ(), buf, 10));
			tile_info.add_text("\nScale: ");
			tile_info.add_text(itoa((int) tcursor.active_tile()->GetScaleX(), buf, 10));
			tile_info.add_text(".");

			if ((int) (tcursor.active_tile()->GetScaleX() * 10) % 10 == 0)
				tile_info.add_text("0");
			if (tcursor.active_tile()->GetScaleX() * 100 < 100)
				tile_info.add_text(itoa((int) (tcursor.active_tile()->GetScaleX() * 100), buf, 10));
			else tile_info.add_text(itoa((int) (tcursor.active_tile()->GetScaleX() * 100) % 100, buf, 10));
		} else {
			tile_info.set_text("");
		}

		// Rendering

		if (ticks > last_frame + 1000/FPS) {
			
			// Viewport & camera
			prog->Render->ClearViewPort(0, 0, 0);
			prog->Render->SetViewPort2d(0, 0, prog->Window->GetWidth(), prog->Window->GetHeight());
			prog->Render->SetCamera2d(&cam);

			// Scene
			prog->Render->BeginScene();
			
			prog->Entity2dManager->RenderEntities2d(background_layer);
			prog->Entity2dManager->RenderEntities2d(objects_layer);
			prog->Entity2dManager->RenderEntities2d(items_layer);
			if (show_b_areas) {
				prog->Entity2dManager->RenderCollisionAreas(background_layer, 0, 0, 255, 255);
				prog->Entity2dManager->RenderCollisionAreas(objects_layer, 255, 0, 0, 255);
				prog->Entity2dManager->RenderCollisionAreas(items_layer, 0, 255, 0, 255);
			}
			
			prog->Render->SetCamera2d(&bcam);
			
			prog->Entity2dManager->RenderEntities2d(4);
			prog->Entity2dManager->RenderEntities2d(5);
			prog->Entity2dManager->RenderCollisionAreas(5, 255, 0, 0, 255);
			if (mode == config)
				conf_m.render_links(*prog->Render);
			
			prog->Render->EndScene();

			dm = prog->Render->GetFrameTime() / 1000.0f;
			last_frame = ticks;
		}
	}

	// Finishing

	render_timer.Stop();
	prog->End();

	return 0;
}
int IndieLib() {
#ifdef PLATFORM_WIN32
	//memory leaks for win32 creation
	FINDMEMLEAK(-1);    //When you find a mem. leak, refer to the number displayed in the console and put it here to break when it is created
#endif
	// ----- IndieLib intialization -----

	CIndieLib *mI = CIndieLib::instance();
	if (!mI->init()) return 0;
    
    //Sets the working path as the 'exe' directory. All resource paths are relative to this directory
	if (!WorkingPathSetup::setWorkingPathFromExe(NULL)) {
		std::cout<<"\nUnable to Set the working path !";
	}
	
    // ----- Fcn pointer tests initialization -----
	initTests();

	testsvectoriterator itr;
    //LOOP - Prepare Permanent tests
	for (itr = g_permanenttests.begin(); itr != g_permanenttests.end(); ++itr) {
		(*itr)->prepareTests();
	}//LOOP END

    //LOOP - Prepare Temporary tests
	for (itr = g_tests.begin(); itr != g_tests.end(); ++itr) {
		(*itr)->prepareTests();
	}//LOOP END

	// ----- Main Loop -----
	g_mainTimer.start();
	double ticks = g_mainTimer.getTicks();
	double pastticks = g_mainTimer.getTicks();
    testsvectoriterator currentTest = g_tests.begin();
    (*currentTest)->setActive(true);

	while (!mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit()) {
		// ----- Input Update ----

		mI->_input->update();

		// -------- Render -------
        mI->_render->clearViewPort(0,0,0);
		mI->_render->beginScene();
		//LOOP - Permanent Tests
		for (itr = g_permanenttests.begin(); itr != g_permanenttests.end(); ++itr) {
			(*itr)->performTests(static_cast<float>(ticks - pastticks));
		}//LOOP END

		//LOOP - Tests
		for (itr = g_tests.begin(); itr != g_tests.end(); ++itr) {
			(*itr)->performTests(static_cast<float>(ticks - pastticks));
		}//LOOP END

		mI->_entity2dManager->renderEntities2d();   //Entities rendering
		mI->_entity2dManager->renderGridAreas(g_gridcolorR,g_gridcolorG,g_gridcolorB,g_gridcolorA); //Grid areas rendering (on top of it) can be disabled per entity
		mI->_entity2dManager->renderCollisionAreas(g_collisionColorR,g_collisionColorG,g_collisionColorB,g_collisionColorA);  //Collision areas rendering (on top of it) can be disabled per entity
		mI->_render->endScene();
		//mI->_render->showFpsInWindowTitle();

		pastticks = ticks;
		ticks += g_mainTimer.getTicks();

        //Perform next test setup (if needed) Arrow keys change current temporary test using
        if (mI->_input->onKeyPress(IND_KEYRIGHT) && !mI->_input->onKeyPress(IND_KEYLEFT)){
            //Current test is not active
            (*currentTest)->setActive(false);
            currentTest++;
            
            //IF - Check limits
            if(currentTest == g_tests.end()){
                currentTest = g_tests.begin();
            }
            
            //Next test is active
            (*currentTest)->setActive(true);
        } else if (mI->_input->onKeyPress(IND_KEYLEFT) && !mI->_input->onKeyPress(IND_KEYRIGHT)){
            //Current test is not active
            (*currentTest)->setActive(false);
          
            //Decrement (taking into account limits)
            if(currentTest == g_tests.begin()){
                currentTest = g_tests.end();
            }
            currentTest--;
            
            //Next test is active
            (*currentTest)->setActive(true);
        }
            

	}

	// ----- Indielib End -----

    releaseTests();

    mI->end();
	return 0;
}
Exemple #3
0
/*
==================
Main
==================
*/
int IndieLib()			

{
    //Sets the working path as the 'exe' directory. All resource paths are relative to this directory
	if (!WorkingPathSetup::setWorkingPathFromExe(NULL)) {
		std::cout<<"\nUnable to Set the working path !";
	}
	
	// ----- IndieLib intialization -----

	CIndieLib *mI = CIndieLib::instance();
	if (!mI->init()) return 0;			

	// ----- Surface loading -----

	// Loading tile for the terrain
	IND_Surface *mSurfaceBack = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mSurfaceBack, "../../resources/twist.jpg", IND_OPAQUE, IND_32)) return 0;
	
	// Loading beetle
	IND_Surface *mSurfaceBeetle = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mSurfaceBeetle, "../../resources/beetleship.png", IND_ALPHA, IND_32)) return 0;
	
	// Loading octopus
	IND_Surface *mSurfaceOctopus = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mSurfaceOctopus, "../../resources/octopus.png", IND_ALPHA, IND_32)) return 0;

	// Loading bug
	IND_Surface *mSurfaceBug = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mSurfaceBug, "../../resources/Enemy Bug.png", IND_ALPHA, IND_32)) return 0;

	// Font
	IND_Font *mFontSmall = IND_Font::newFont();
	if (!mI->_fontManager->add(mFontSmall, "../../resources/font_small.png", "../../resources/font_small.xml", IND_ALPHA, IND_32)) return 0;

	// ----- Font creation -----

	IND_Entity2d *mTextSmallWhite = IND_Entity2d::newEntity2d();					
	mI->_entity2dManager->add(mTextSmallWhite);			// Entity adding
	mTextSmallWhite->setFont(mFontSmall);				// Set the font into the entity
	mTextSmallWhite->setLineSpacing(18);
	mTextSmallWhite->setCharSpacing(-8);
	mTextSmallWhite->setPosition(5, 5, 1);
	mTextSmallWhite->setAlign(IND_LEFT);

	// ----- Entities -----

	// Terrain
	IND_Entity2d *mTerrain = IND_Entity2d::newEntity2d();
	mI->_entity2dManager->add(mTerrain);
	mTerrain->setSurface(mSurfaceBack);

	// Beetle
	IND_Entity2d *mBeetle = IND_Entity2d::newEntity2d();
	mI->_entity2dManager->add(mBeetle);
	mBeetle->setSurface(mSurfaceBeetle);
	mBeetle->setHotSpot(0.5f, 0.5f);
	mBeetle->setPosition(150, 150, 2);

	// Octopus
	IND_Entity2d *mOctopus = IND_Entity2d::newEntity2d();
	mI->_entity2dManager->add(mOctopus);
	mOctopus->setSurface(mSurfaceOctopus);
	mOctopus->setHotSpot(0.5f, 0.5f);
	mOctopus->setPosition(450, 150, 2);

	// But
	IND_Entity2d *mBug = IND_Entity2d::newEntity2d();
	mI->_entity2dManager->add(mBug);
	mBug->setSurface(mSurfaceBug);
	mBug->setHotSpot(0.5f, 0.5f);
	mBug->setPosition(700, 150, 2);
	
	// ----- Camera ------

	// Camera for the viewport 1
	IND_Camera2d *mCamera1 = new IND_Camera2d(mI->_window->getWidth () / 2, mI->_window->getHeight() / 4);

	// Camera for the viewport 2
	IND_Camera2d *mCamera2 = new IND_Camera2d(mI->_window->getWidth () / 2, mI->_window->getHeight() / 4);

	// ----- Main Loop -----

	float mZoom = 1.0f;
	float mCameraAngle = 0;
	float mBugAngle = 0;
	char mText [2048];
	mText [0] = 0;
	float mSpeedRotation = 50;
	float mDelta;

	while (!mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit())
	{
		// ----- Input update ----

		mI->_input->update();

		// ----- Text -----

		strcpy (mText, "Use mouse wheel for zooming in/out\n");
		strcat (mText, "Use mouse buttons for rotating the camera");
		mTextSmallWhite->setText(mText);	

		// ----- Input ----

		mDelta = mI->_render->getFrameTime() / 1000.0f;

		// Camera Zoom in / out
		if (mI->_input->isMouseScroll()) {
			mZoom += mI->_input->getMouseScrollY() * K_ZOOMSPEED;
		}	

		// Camera angle
		if (mI->_input->isMouseButtonPressed(IND_MBUTTON_LEFT))			mCameraAngle += mSpeedRotation * mDelta;
		if (mI->_input->isMouseButtonPressed(IND_MBUTTON_RIGHT))		mCameraAngle -= mSpeedRotation * mDelta;

		// ----- Updating entities attributes  -----

		// Rotation of the beetle and bug
		mBugAngle += mSpeedRotation * mDelta;
		mBeetle->setAngleXYZ(0, 0, mBugAngle);
		mBeetle->setAngleXYZ(0, 0, mBugAngle);
		mBug->setAngleXYZ(0, 0, -mBugAngle);
		mBug->setAngleXYZ(0, 0, -mBugAngle);

		// Zooming and rotating the camera
		if (mZoom < 0.1f) mZoom =  0.1f;
		mCamera2->setAngle(mCameraAngle);
		mCamera2->setZoom(mZoom);

		// ----- Render  -----

		// ----- Upper viewport -----

		mI->_render->beginScene();
		mI->_render->clearViewPort(60, 60, 60);
		mI->_render->setViewPort2d(0, 0, mI->_window->getWidth(), mI->_window->getHeight() / 2);
		mI->_render->setCamera2d(mCamera1);
		mI->_entity2dManager->renderEntities2d();

		// ----- Lower viewport -----

		mI->_render->setViewPort2d(0, mI->_window->getHeight() / 2, mI->_window->getWidth(), mI->_window->getHeight() / 2);
		mI->_render->setCamera2d(mCamera2);
		mI->_entity2dManager->renderEntities2d();
		mI->_render->endScene();	
	}

	// ----- Free -----

	mI->end();

	return 0;
}
/*
==================
Main
==================
*/
int IndieLib()
{
	// ----- IndieLib intialization -----

	CIndieLib *mI = CIndieLib::Instance();
	if (!mI->Init ()) return 0;			

	// ----- Surface loading -----

	// 3d Dino loading
	IND_3dMesh mMeshDino;
	if (!mI->MeshManager->Add (&mMeshDino, "..\\resources\\trex dx\\dino videogame.x", "..\\resources\\trex dx")) return 0;

	// Font
	IND_Font mFontSmall;
	if (!mI->FontManager->Add (&mFontSmall, "..\\resources\\font_small.png", "..\\resources\\font_small.xml", IND_ALPHA, IND_32)) return 0;

	// ----- Font creation -----

	IND_Entity2d mTextSmallWhite;					
	mI->Entity2dManager->Add		(&mTextSmallWhite);			// Entity adding
	mTextSmallWhite.SetFont			(&mFontSmall);				// Set the font into the entity
	mTextSmallWhite.SetLineSpacing	(18);
	mTextSmallWhite.SetCharSpacing	(-8);
	mTextSmallWhite.SetPosition		(5, 5, 1);
	mTextSmallWhite.SetAlign		(IND_LEFT);

	// ----- Set the mesh into 3d entity -----

	// Creating 3d entity
	IND_Entity3d mDino;					
	mI->Entity3dManager->Add (&mDino);						// Entity adding
	mDino.Set3dMesh (&mMeshDino);							// Set the 3d mesh into the entity

	// ----- Cameras ------

	IND_Camera2d mCamera2d (mI->Window->GetWidth () / 2, mI->Window->GetHeight() / 2);
	IND_Camera3d mCamera3d (0.0f, 0.0f, -2.0f);
	mCamera3d.SetAspect ((float) mI->Window->GetWidth () / mI->Window->GetHeight());

	// ----- Light -----

	IND_Light mLight0;
	mI->LightManager->Add (&mLight0, IND_AMBIENT_LIGHT);
	mLight0.SetColor (1.0f, 1.0f, 1.0f, 1.0f);

	// Light 1 (Direction light)
	IND_Light mLight1;
	mI->LightManager->Add (&mLight1, IND_DIRECTIONAL_LIGHT);
	mLight1.SetColor (1.0f, 1.0f, 1.0f, 1.0f);
	mLight1.SetDirection (0.0f, -0.3f, 0.5f);
	mLight1.SetRange (1000.0f);

	// Light 2 (Point light)
	IND_Light mLight2;
	mI->LightManager->Add (&mLight2, IND_POINT_LIGHT);
	mLight2.SetPosition (3, 3, 3);
	mLight2.SetColor (0.4f, 1.0f, 0.4f, 1.0f);
	mLight2.SetRange (200);
	mLight2.SetAttenuation (0.5f);

	// Light 3 (Spot light)
	IND_Light mLight3;
	mI->LightManager->Add (&mLight3, IND_SPOT_LIGHT);
	mLight3.SetPosition (5, 5, 5);
	mLight3.SetColor (1.0f, 1.0f, 1.0f, 1.0f);
	mLight3.SetDirection (0.0f, -0.3f, 0.5f);
	mLight3.SetRange (1000);
	mLight3.SetAttenuation (0.2f);
	mLight3.SetFalloff (1.0f);
	mLight3.SetPhi (8.0f);
	mLight3.SetTheta (7);

	// ----- Main Loop -----

	mI->LightManager->Disable(&mLight2);
	mI->LightManager->Disable(&mLight3);
	float	mAngle = 0;
	char	mText [2048]; mText [0] = 0;
	int		mSpeed = 25;
	float	mDelta;

	while (!mI->Input->OnKeyPress (IND_ESCAPE) && !mI->Input->Quit())
	{
		// ----- Input update ----

		mI->Input->Update ();

		// ----- Text -----

		strcpy (mText, "Press 1, 2 or 3 in order to toggle between different lights\n");
		mTextSmallWhite.SetText	 (mText);	

		// ----- Input -----

		mDelta = mI->Render->GetFrameTime() / 1000.0f;

		// Activate only light 1
		if (mI->Input->IsKeyPressed (IND_1))
		{
			mI->LightManager->Disable(&mLight2);
			mI->LightManager->Disable(&mLight3);
			mI->LightManager->Enable(&mLight1);
		}

		// Activate only light 2
		if (mI->Input->IsKeyPressed (IND_2))
		{
			mI->LightManager->Disable(&mLight1);
			mI->LightManager->Disable(&mLight3);
			mI->LightManager->Enable(&mLight2);
		}

		// Activate only light 3
		if (mI->Input->IsKeyPressed (IND_3))
		{
			mI->LightManager->Disable(&mLight1);
			mI->LightManager->Disable(&mLight2);
			mI->LightManager->Enable(&mLight3);
		}

		// ----- Updating entities attributes  -----

		mAngle += mDelta * mSpeed;
		mDino.SetAngleXYZ (0, mAngle, 0);

		// ----- Render  -----

		mI->Render->ClearViewPort (60, 60, 60);
		mI->Render->BeginScene ();

		mI->Render->SetViewPort3d (0, 0, mI->Window->GetWidth (), mI->Window->GetHeight());
		mI->Render->SetCamera3d (&mCamera3d);
		mI->LightManager->Update ();
		mI->Entity3dManager->RenderEntities3d ();

		mI->Render->SetViewPort2d (0, 0, mI->Window->GetWidth (), mI->Window->GetHeight ());
		mI->Render->SetCamera2d (&mCamera2d);
		mI->Entity2dManager->RenderEntities2d ();

		mI->Render->EndScene ();	
	}

	// ----- Free -----

	mI->End ();

	return 0;
}
/*
==================
Main
==================
*/
int IndieLib()			
{
	// ----- IndieLib intialization -----

	CIndieLib *mI = CIndieLib::instance();
	if (!mI->init()) return 0;			

	// ----- Map loading -----
	// TODO: map loading goes here...
       
	IND_TmxMap *map = new IND_TmxMap();
	if (!mI->_tmxMapManager->add(map, "example.tmx")) return 0;

			// Get a tileset.
		//const Tmx::Tileset *tileset = map->getTmxMapHandle()->GetTileset(0);

		// Print tileset information.
		printf("Name: %s\n", map->getTmxMapHandle()->GetTileset(0)->GetName().c_str());
		printf("Margin: %d\n", map->getTmxMapHandle()->GetTileset(0)->GetMargin());
		printf("Spacing: %d\n", map->getTmxMapHandle()->GetTileset(0)->GetSpacing());
		printf("Image Width: %d\n", map->getTmxMapHandle()->GetTileset(0)->GetImage()->GetWidth());
		printf("Image Height: %d\n", map->getTmxMapHandle()->GetTileset(0)->GetImage()->GetHeight());
		printf("Image Source: %s\n", map->getTmxMapHandle()->GetTileset(0)->GetImage()->GetSource().c_str());
		printf("Transparent Color (hex): %s\n", map->getTmxMapHandle()->GetTileset(0)->GetImage()->GetTransparentColor().c_str());




	while (!mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit())
	{
		// ----- Input update ----

		mI->_input->update();

		// ----- Text -----

//		strcpy(mText, "Press space to see the grid in action. This is really cool, isn't it?");
//		mTextSmallWhite->setText(mText);

		// ----- Input ----

		// Show / Hide the grid pressing "space"
		if (mI->_input->onKeyPress(IND_SPACE))
		{
//			if (mShowGrid){

//			}else{

//			}
		}

		// ----- Updating entities attributes  -----


		// ----- Render  -----

		mI->_render->beginScene();
		mI->_render->clearViewPort(0, 0, 0);
//		mI->_entity2dManager->renderEntities2d();
//		if (mShowGrid) mI->_entity2dManager->renderGridAreas(0, 0, 0, 255);
		mI->_render->endScene();	
	}

	// ----- Free -----

	mI->end();

	return 0;
}
Exemple #6
0
int IndieLib() // main
{
	
	char TempText[30];
	
	// ----- Sound Library --------------


	// ----- new engine instance ------------
	CIndieLib *mI = CIndieLib::instance(); // engine
	if (!mI->init()) return 0;

	GameControll controller = GameControll(mI); // createing a game controller and initialize
	controller.sceneGenerator();
		

	//<------ DELTA TIME ------>
	double *delta = new double(0.1);
	double *deltaAverage = new double(0.001);
	double *mDeltaSum = new double(0.001);
	int count = 0;
	
	// time
	int gameTime = 125;

	// Create and start the timer;
	IND_Timer *mTimer = new IND_Timer();
	mTimer->start();

	bool play = false;

	float animationDelay = 30; // 30 fps animation refresh

	// ----- Main Loop -----
	while (!mI->_input->onKeyPress(IND_F12) && !mI->_input->quit() && !controller.isExitSelected())
	{
		gameTime = (int)(mTimer->getTicks() / 1000.0f); //time in seconds

		
		

		// ------ Average delta time ---------
		*delta = mI->_render->getFrameTime() / 1000.0f;
			count++;
			*mDeltaSum += *delta;

			if (count == 100){			
				count = 0;
				*deltaAverage = *mDeltaSum / 100;
				*mDeltaSum = 0;
			}

			// ----- Input Update ----
			mI->_input->update();

			// ------ Game controller update ---------------
			controller.Update(gameTime, deltaAverage);

			// ---- Update rarely -----
			// creating delay for animation
			//animationDelay -= 1000 * (*deltaAverage);
			animationDelay -= mI->_render->getFrameTime();
			if (animationDelay < 0) 
			{
				animationDelay = 30;
				controller.AnimationsUpdate();
			}
		
			

		// -------- Render -------
		mI->_render->clearViewPort(0, 0, 60);
		mI->_render->beginScene();
		mI->_entity2dManager->renderEntities2d();
		// mI->_entity2dManager->renderCollisionAreas(255, 0, 0, 255); // for tests
		mI->_render->endScene();
		mI->_render->showFpsInWindowTitle(); //FPS
		//mI->_entity2dManager->renderGridAreas(255, 255, 0, 255);
	}

	// ----- Indielib End -----
	mI->end();

	return 0;
}
int IndieLib()			

{
    //Sets the working path as the 'exe' directory. All resource paths are relative to this directory
	if (!WorkingPathSetup::setWorkingPathFromExe(NULL)) {
		std::cout<<"\nUnable to Set the working path !";
	}
	
	// ----- IndieLib intialization -----

	CIndieLib *mI = CIndieLib::instance();
	if (!mI->init()) return 0;			

	// ----- Surface loading -----

	// Font
	IND_Font *mFontBig = new IND_Font();
	if (!mI->_fontManager->add(mFontBig, "../../resources/font_big.png", "../../resources/font_big.xml", IND_ALPHA, IND_32)) return 0;

	// Loading draco
	IND_Surface *mSurfaceDraco = new IND_Surface();
	if (!mI->_surfaceManager->add(mSurfaceDraco, "../../resources/draco.png", IND_ALPHA, IND_32)) return 0;

	// ----- Entities -----

	// Title text
	IND_Entity2d *mTextTime = new IND_Entity2d();					
	mI->_entity2dManager->add(mTextTime);						// Entity adding
	mTextTime->setFont(mFontBig);							// Set the font into the entity

	// Creating 2d entity for the draco
	IND_Entity2d *mDraco = new IND_Entity2d();					
	mI->_entity2dManager->add(mDraco);						// Entity adding
	mDraco->setSurface(mSurfaceDraco);						// Set the surface into the entity
	mDraco->setHotSpot(0.5f, 0.5f);
	mDraco->setPosition(400, 330, 1);

	// ----- Changing the attributes of the 2d entities -----

	// Text showing the time
	mTextTime->setLineSpacing(18);
	mTextTime->setCharSpacing(-8);
	mTextTime->setPosition(280, 20, 1);
	mTextTime->setAlign(IND_LEFT);

	// ----- Main Loop -----

	char mTimeString[128];
	mTimeString[0] = 0;
	char mTempTime[1024];
		
	// Create and start the timer;
	IND_Timer *mTimer = new IND_Timer();
	mTimer->start();

	int mX = 0;
	int mSecond;

	while (!mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit())
	{
		// ----- Input update ----

		mI->_input->update();

		// ----- Input ----

		// Pause / Restart time when pressing space
		if (mI->_input->onKeyPress(IND_SPACE))
		{
			if (mTimer->isPaused()){
				mTimer->unpause();
			}
			else{
				mTimer->pause();
			}
		}

		// ----- Updating entities attributes  -----
 
		mSecond = (int) (mTimer->getTicks() / 1000.0f);

		// Show the time passing in seconds
		mI->_math->itoa(mSecond,mTempTime);
           						   
		strcpy (mTimeString, "Seconds: ");
		strcat (mTimeString, mTempTime);
		mTextTime->setText(mTimeString);

		// Update Draco position each second
		mDraco->setAngleXYZ(0, 0, mSecond + 10);
 
		// ----- Render  -----

		mI->_render->beginScene();
		mI->_render->clearViewPort(60, 60, 60);
		mI->_entity2dManager->renderEntities2d();
		mI->_render->endScene();	
	}

	// ----- Free -----

	mI->end();

	return 0;
}
int IndieLib()
{
    // ----- IndieLib intialization -----

    CIndieLib *mI = CIndieLib::instance();
    if (!mI->init()) return 0;

    // ----- Get Window Dimensions

    int winWidth = mI->_window->getWidth();
    int winHeight = mI->_window->getHeight();

    srand(static_cast<unsigned int>(time(0)));

    // ----- Surface loading -----

    IND_Surface *mSurfaceBack = IND_Surface::newSurface();
    if (!mI->_surfaceManager->add(mSurfaceBack, "../SpaceGame/resources/Backgrounds/18.jpg", IND_OPAQUE, IND_32)) return 0;

    /*IND_Animation* mTestA = IND_Animation::newAnimation();
    if (!mI->_animationManager->addToSurface(mTestA, "resources/animations/dust.xml", IND_ALPHA, IND_32, 255, 0, 255)) return 0;
    mTestA->getActualFramePos(0);*/

    // Loading 2D Entities

    // Background
    IND_Entity2d* mBack = IND_Entity2d::newEntity2d();
    mI->_entity2dManager->add(mBack);
    mBack->setSurface(mSurfaceBack);
    mBack->setScale((float)winWidth / mSurfaceBack->getWidth(), (float)winHeight / mSurfaceBack->getHeight());

    Controls* controls = new Controls();
    controls->loadSettings();

    ErrorHandler* error = new ErrorHandler();
    error->initialize(mI);

    Hud* mHud = new Hud();
    mHud->createHud(mI);

    Menu* mMenu = new Menu();
    mMenu->createMenu(mI);

    Save* quickSave = new Save();

    if (!SoundEngine::initialize())
    {
        error->writeError(200, 100, "Error", "SoundEngine");
    }

    vector<Planet*> mPlanets;
    Ship* mShip = NULL;

    bool loadSave = false;
    float mDelta = 0.0f;

    IND_Timer* mTimer = new IND_Timer;
    mTimer->start();

    while (!mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit() && !mMenu->isExit())
    {
        // get delta time
        mDelta = mI->_render->getFrameTime() / 1000.0f;

        if (mI->_input->isKeyPressed(controls->getMenu()))
        {
            mMenu->show();
            SoundEngine::getSoundEngine()->setAllSoundsPaused(true);
        }
        if (!mMenu->isHidden())
        {
            mMenu->updateMenu(mHud, quickSave, mPlanets, mShip);
            loadSave = mHud->getLoadingText()->isShow();
        }
        else
        {
            if (loadSave)
            {
                mDelta = 0.0;
                loadSave = false;
                SoundEngine::getSoundEngine()->setAllSoundsPaused(true);
                mHud->getLoadingText()->setShow(false);
                quickSave->loadSave(mI, mShip, mPlanets);
                mHud->showHud();
            }

            if (mShip != NULL)
            {
                if (mI->_input->onKeyPress(controls->getQuickSave()))
                {
                    quickSave->makeSave(mI, mShip, mPlanets);
                }

                mHud->updateHud(mShip);

                if (mI->_input->onKeyPress(controls->getQuickLoad()))
                {
                    deleteObjects(mHud, mShip, mPlanets);
                    loadSave = true;
                }
                if (mShip->isDestroyed())
                {
                    SoundEngine::getSoundEngine()->setAllSoundsPaused(true);
                    mHud->updateGameOverText(mShip->getScore());
                    deleteObjects(mHud, mShip, mPlanets);
                    mHud->getLoadingText()->setShow(false);
                    mHud->getGameOverText()->setShow(true);
                    mMenu->show();
                }
                if(mShip!=NULL)
                {
                    //----- Collisions -----
                    checkShipPlanetsCollisions(mI, mPlanets, mShip);
                    checkBulletsPlanetsCollisions(mI, mPlanets, mShip);
                    checkBulletsShipCollisions(mI, mPlanets, mShip);

                    //----- Movement update -----
                    mShip->updateShip(controls, mDelta);
                    if ((mTimer->getTicks() / 1000.0f) >= 3.0f)
                    {
                        mTimer->start();
                        mPlanets.at(rand() % mPlanets.size())->addSatellite();
                    }
                    for (vector<Planet*>::iterator it = mPlanets.begin(); it != mPlanets.end(); ++it)
                    {
                        (*it)->updatePlanet(mDelta, (mShip->getPosX() + 0.25f * mShip->getHeight() * cos(mShip->getAngleZRadian())), (mShip->getPosY() - 0.25f * mShip->getHeight() * sin(mShip->getAngleZRadian())));
                    }
                }
            }
        }

        //mI->_render->showFpsInWindowTitle();
        mI->_input->update();
        mI->_render->beginScene();
        mI->_entity2dManager->renderEntities2d();
        mI->_render->endScene();
    }

    // ----- Free -----
    delete controls;
    delete error;
    delete mHud;
    delete mMenu;
    delete quickSave;
    mI->_surfaceManager->remove(mSurfaceBack);
    mI->_entity2dManager->remove(mBack);
    deleteObjects(mHud, mShip, mPlanets);
    mI->end();
    return 0;
}
/*
==================
Main
==================
*/
int IndieLib()			
{
	// ----- IndieLib intialization -----

	CIndieLib *mI = CIndieLib::instance();
	if (!mI->init()) return 0;									

	// ----- Set the primitives into 2d entities -----

	// Pixel
	IND_Entity2d *mPixel = new IND_Entity2d();					
	mI->_entity2dManager->add(mPixel);			
	mPixel->setPrimitive2d(IND_PIXEL);
	mPixel->setPosition(200, 75, 0);
	mPixel->setTint(255, 255, 255);
	
	// Regular poly
	IND_Entity2d *mRegularPoly = new IND_Entity2d();					
	mI->_entity2dManager->add(mRegularPoly);			
	mRegularPoly->setPrimitive2d(IND_REGULAR_POLY);		
	mRegularPoly->setPosition(200, 75, 0);									
	mRegularPoly->setNumSides(5);
	mRegularPoly->setRadius(50);
	mRegularPoly->setTint(255, 0, 0);

	// Line
	IND_Entity2d *mLine  = new IND_Entity2d();					
	mI->_entity2dManager->add(mLine);			
	mLine->setPrimitive2d (IND_LINE);
	mLine->setLine(100, 100, 50, 50);
	mLine->setTint(0, 255, 0);

	// Rectangle
	IND_Entity2d *mRectangle = new IND_Entity2d();					
	mI->_entity2dManager->add(mRectangle);			
	mRectangle->setPrimitive2d(IND_RECTANGLE);
	mRectangle->setRectangle(350, 50, 400, 100);
	mRectangle->setTint(0, 0, 255);

	// Filled rectangle
	IND_Entity2d *mFillRectangle = new IND_Entity2d();					
	mI->_entity2dManager->add(mFillRectangle);			
	mFillRectangle->setPrimitive2d(IND_FILL_RECTANGLE);
	mFillRectangle->setRectangle(550, 40, 650, 110);
	mFillRectangle->setTint(255, 0, 0);
	mFillRectangle->setTransparency(50);

	// 2d Poly
	IND_Entity2d *mPoly2d  = new IND_Entity2d();					
	mI->_entity2dManager->add(mPoly2d);			
	mPoly2d->setPrimitive2d(IND_POLY2D);
	IND_Point mVertPoly2 [] = { {440, 200},  {480, 100},  {450, 10},  {470, 220} };		// Poly points
	mPoly2d->setPolyPoints(mVertPoly2);													
	mPoly2d->setNumLines(3);	 							// Number of edges - 1
	mPoly2d->setTint(255, 128, 255);

	// ----- Main Loop -----

	while (!mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit())
	{
		// ----- Input update -----

		mI->_input->update();

		// ----- Render -----

		mI->_render->clearViewPort (0, 0, 0);
		mI->_render->beginScene();

		// Direct bliting of primitives
		for (int i = 0; i < 400; i += 5)
		{	
			mI->_render->blitLine(70, 150, i * 2, 500, i, 255 -i, 255, 255);
			mI->_render->blitRegularPoly(600, 600, i, 70, 0, 255 - i, i, i*4, 255);
		}

		mI->_entity2dManager->renderEntities2d();
		mI->_render->endScene();	
	}

	// ----- Free -----

	mI->end();

	return 0;
}
Exemple #10
0
/*
==================
Main
==================
*/
int IndieLib()
{
    //Sets the working path as the 'exe' directory. All resource paths are relative to this directory
    if (!WorkingPathSetup::setWorkingPathFromExe(NULL)) {
        std::cout<<"\nUnable to Set the working path !";
    }

    // ----- IndieLib intialization -----

    CIndieLib *mI = CIndieLib::instance();
    if (!mI->init()) return 0;

    // ----- Animations loading -----

    // Sun animation
    IND_Animation *mAnimationSun = new IND_Animation();
    if (!mI->_animationManager->addToSurface(mAnimationSun, "../../resources/animations/sun.xml", IND_OPAQUE, IND_32)) return 0;

    // ----- Set the surface and animations into 2d entities -----

    // Sun
    IND_Entity2d *mSun = new IND_Entity2d();
    mI->_entity2dManager->add(mSun);			// Entity adding
    mSun->setAnimation(mAnimationSun);			// Set the animation into the entity

    // ----- Changing the attributes of the 2d entities -----

    mSun->toggleWrap(1);
    mSun->setRegion(0, 0, 800, 600);

    // ----- Main Loop -----

    float mDisp = 0.0f;
    float mSpeed = 0.5f;
    float mDelta;

    while (!mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit())
    {
        // ----- Input update ----

        mI->_input->update();

        // ----- Updating entities attributes  -----

        mDelta = mI->_render->getFrameTime() / 1000.0f;

        mDisp += mSpeed * mDelta;
        mSun->setWrapDisplacement(mDisp, mDisp);

        // ----- Render  -----

        mI->_render->beginScene();
        mI->_entity2dManager->renderEntities2d();
        mI->_render->endScene();
    }

    // ----- Free -----

    mI->end();

    return 0;
}
Exemple #11
0
/*
==================
Main
==================
*/
int IndieLib()		
{
    //Sets the working path as the 'exe' directory. All resource paths are relative to this directory
	if (!WorkingPathSetup::setWorkingPathFromExe(NULL)) {
		std::cout<<"\nUnable to Set the working path !";
	}
	
	// ----- IndieLib intialization -----

	CIndieLib *mI = CIndieLib::instance();
	if (!mI->init()) return 0;									

	// ----- Loading of the original image and making 4 duplicates -----

	IND_Image *mImageBugOriginal = IND_Image::newImage();
	if (!mI->_imageManager->add(mImageBugOriginal, "../../resources/Enemy Bug.png")) return 0;

	IND_Image *mImageBugGaussian = IND_Image::newImage();
	if (!mI->_imageManager->clone(mImageBugGaussian, mImageBugOriginal)) return 0;

	IND_Image *mImageBugPixelize = IND_Image::newImage();
	if (!mI->_imageManager->clone(mImageBugPixelize, mImageBugOriginal)) return 0;

	IND_Image *mImageBugContrast = IND_Image::newImage();
	if (!mI->_imageManager->clone(mImageBugContrast, mImageBugOriginal)) return 0;

	// ----- Applying filters -----

	mImageBugGaussian->gaussianBlur(5);
	mImageBugPixelize->pixelize(5);
	mImageBugContrast->contrast(60);

	// ----- Surface creation -----

	// Loading Background
	IND_Surface *mSurfaceBack = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mSurfaceBack, "../../resources/blue_background.jpg", IND_OPAQUE, IND_32)) return 0;

	// Creating the "Original Bug" surface from the IND_Image
	IND_Surface *mOriginalSurface = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mOriginalSurface, mImageBugOriginal, IND_ALPHA, IND_32)) return 0;

	// Creating the "Gaussian bug" surface from the IND_Image
	IND_Surface *mGaussianSurface = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mGaussianSurface, mImageBugGaussian, IND_ALPHA, IND_32)) return 0;
	
	// Creating the "Pixelize bug" surface from the IND_Image
	IND_Surface *mPixelizeSurface = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mPixelizeSurface, mImageBugPixelize, IND_ALPHA, IND_32)) return 0;

	// Creating the "Contrast bug" surface from the IND_Image
	IND_Surface *mContrastSurface = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mContrastSurface, mImageBugContrast, IND_ALPHA, IND_32)) return 0;

	// ----- Deleting of images -----

	mI->_imageManager->remove(mImageBugOriginal);
	mI->_imageManager->remove(mImageBugGaussian);
	mI->_imageManager->remove(mImageBugPixelize);
	mI->_imageManager->remove(mImageBugContrast);

	// ----- Set the surfaces into the 2d entities -----

	// Creating 2d entity for the background
	IND_Entity2d *mBack = IND_Entity2d::newEntity2d();				
	mI->_entity2dManager->add(mBack);					// Entity adding
	mBack->setSurface(mSurfaceBack);					    // Set the surface into the entity

	// Creating 2d entity for the "Original bug"
	IND_Entity2d *mOriginal = IND_Entity2d::newEntity2d();					
	mI->_entity2dManager->add(mOriginal);					// Entity adding
	mOriginal->setSurface(mOriginalSurface);				// Set the surface into the entity

	// Creating 2d entity for the "Gaussian bug"
	IND_Entity2d *mGaussian = IND_Entity2d::newEntity2d();					
	mI->_entity2dManager->add(mGaussian);					// Entity adding
	mGaussian->setSurface(mGaussianSurface);				// Set the surface into the entity

	// Creating 2d entity for the "pixelize bug"
	IND_Entity2d *mPixelize = IND_Entity2d::newEntity2d();					
	mI->_entity2dManager->add(mPixelize);					// Entity adding
	mPixelize->setSurface(mPixelizeSurface);				// Set the surface into the entity

	// Creating 2d entity for the "Contrast bug"
	IND_Entity2d *mContrast = IND_Entity2d::newEntity2d();					
	mI->_entity2dManager->add(mContrast);					// Entity adding
	mContrast->setSurface(mContrastSurface);				// Set the surface into the entity

	// ----- Changing the attributes of the 2d entities -----

	mOriginal->setPosition(290,  90, 0);
	mGaussian->setPosition( 50, 230, 0);
	mPixelize->setPosition(290, 230, 0);
	mContrast->setPosition(520, 230, 0);

	// ----- Main Loop -----

	while (!mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit())
	{
		mI->_input->update();
		mI->_render->beginScene();
		mI->_entity2dManager->renderEntities2d();
		mI->_render->endScene();	
	}

	// ----- Free -----

	mI->end();

	return 0;
}
Exemple #12
0
/*
==================
Main
==================
*/
int IndieLib()
{
	//Sets the working path as the 'exe' directory. All resource paths are relative to this directory

	CIndieLib *mI = CIndieLib::instance();
	if (!mI->init()) return 0;

	AnimatedGameEntity* shipExplotion = new AnimatedGameEntity(mI, Position3D(0, 0, 1), "../SpaceGame/resources/animations/Ship_Explotion.xml");
	shipExplotion->Draw();

	AnimatedGameEntity* shipRotate = new AnimatedGameEntity(mI, Position3D(0, 0, 0), "../SpaceGame/resources/animations/kali/three_oclock.xml");
	shipExplotion->Draw();




	//mDelta = mI->_render->getFrameTime() / 1000.0f;
	IND_Surface *mSurfaceBeetleship = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mSurfaceBeetleship, "../../SpaceGame/resources/beetleship.png", IND_ALPHA, IND_32)) return 0;
	//ufo->setSequence(0);
	// Font
	IND_Font *mFontSmall = IND_Font::newFont();
	if (!mI->_fontManager->add(mFontSmall, "../../SpaceGame/resources/font_small.png", "../../resources/font_small.xml", IND_ALPHA, IND_32)) return 0;

	// Creating 2d entity for the bettleship
	IND_Entity2d *mBeetleship = IND_Entity2d::newEntity2d();
	mI->_entity2dManager->add(mBeetleship);				// Entity adding
	mBeetleship->setSurface(mSurfaceBeetleship);			// Set the surface into the entity
	// ----- Font creation -----

	IND_Entity2d *mTextSmallWhite = IND_Entity2d::newEntity2d();
	mI->_entity2dManager->add(mTextSmallWhite);			// Entity adding
	mTextSmallWhite->setFont(mFontSmall);				// Set the font into the entity
	mTextSmallWhite->setLineSpacing(18);
	mTextSmallWhite->setCharSpacing(-8);
	mTextSmallWhite->setPosition(5, 5, 1);
	mTextSmallWhite->setAlign(IND_LEFT);



	mBeetleship->setHotSpot(0.5f, 0.5f);
	GameEntity* space = new Space(mI, Position3D(0, 0, 0), "../SpaceGame/resources/planetki new/space.jpg");
	space->Draw();


	//GameEntity* planet1 = new Planet(mI, Position3D(0, 0, 1), "../SpaceGame/resources/a4203_planetes_g.png");
	//planet1->DrawRegion(new Region(100, 220, 140, 150));

	//GameEntity* planet2 = new Planet(mI, Position3D(300, 0, 1), "../SpaceGame/resources/a4203_planetes_g.png");
	//planet1->setPosition(Position3D(300, 0, 1));
	//planet1->DrawRegion(new Region(100, 220, 140, 150));

	//GameEntity* ship = new Ship(mI, Position3D(300, 200, 1), "../SpaceGame/resources/rocket.png");
	//ship->Draw();



	float mAngle = 0;
	float mPos = 400;
	int mSpeed = 200;
	float mDelta;
	char mText[2048];
	mText[0] = 0;


	while (!mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit())
	{

		strcat(mText, "Use left and right arrow keys for moving the ships\n");
		strcat(mText, "Press CTRL + X or ESC key to quit");
		mTextSmallWhite->setText(mText);
		mDelta = mI->_render->getFrameTime() / 1000.0f;
		// Move entities when pressing right
		if (mI->_input->isKeyPressed(IND_KEYRIGHT)){
			mPos += mSpeed * mDelta;
		}

		// Move entities when pressing left
		if (mI->_input->isKeyPressed(IND_KEYLEFT)){
			mPos -= mSpeed * mDelta;
		}

		// If CTRL + X pressed then exit
		if (mI->_input->isKeyPressed(IND_LCTRL) && mI->_input->isKeyPressed(IND_X)){
			mI->_render->endScene();
			mI->end();
			exit(0);
		}

		mAngle += (mSpeed / 4) * mDelta;
		mBeetleship->setPosition((float)mPos, 140, 1);
		mBeetleship->setAngleXYZ(0, 0, (float)mPos);

		mI->_input->update();
		mI->_render->beginScene();
		mI->_entity2dManager->renderEntities2d();
		mI->_render->endScene();
	}

	mI->end();

	return 0;
}
int IndieLib()
{
	//Executable path

	//Sets the working path as the 'exe' directory. All resource paths are relative to this directory

	//TCHAR NPath[MAX_PATH];
	//GetCurrentDirectory(MAX_PATH, NPath);

	//std::basic_string<TCHAR> strName = NPath;
	//new std::string(strName.c_str());

	//std::string path = "D:\Vs2012 Project\C++ game development course\ShipGame\GameDevelopmentC-Cource\MyGame\SpaceGame";

	//ConfigurationReader* reader = new ConfigurationReader((path + "\GameConfiguration.ini").c_str());
	//std::string token = reader->getSetting("Token");

	//InstanceManager* iM = new InstanceManager();
	//iM->getPlayer(token, iM->getMachineName());

	CIndieLib *mI = CIndieLib::instance();
	if (!mI->init()) return 0;

	_engine = new GameEngine(mI);

	_engine->initializeFonts();
	_engine->initializeEntities();

	_firstInitializationTimer.start();

	while (!mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit())  //idle
	{
		mI->_input->update();
		_engine->processUserInput();

		if (!_firstInitializationTimer.isStarted() || _firstInitializationTimer.getTicks() > 2)
		{
			_engine->manageCollisions();
		}
		else
		{
			if (_firstInitializationTimer.isStarted())
				_firstInitializationTimer.stop();
		}

		_engine->update();

		mI->_input->update();
		mI->_render->beginScene();

		mI->_entity2dManager->renderEntities2d();
		mI->_entity2dManager->renderCollisionAreas(255, 0, 0, 255);

		mI->_render->endScene();
		
	}

	//sound->drop();
	mI->end();

	return 0;
}
Exemple #14
0
/*
==================
Main
==================
*/
int IndieLib()			
{
    //Sets the working path as the 'exe' directory. All resource paths are relative to this directory
	if (!WorkingPathSetup::setWorkingPathFromExe(NULL)) {
		std::cout<<"\nUnable to Set the working path !";
	}
	
	// ----- IndieLib intialization -----

	CIndieLib *mI = CIndieLib::instance();
	if (!mI->init()) return 0;			

	// ----- Surface loading -----

	// Loading cave
	IND_Surface *mSurfaceCave = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mSurfaceCave, "../../resources/cave.png", IND_ALPHA, IND_32)) return 0;

	// Loading cave (first plane)
	IND_Surface *mSurfaceCaveFirstPlane = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mSurfaceCaveFirstPlane, "../../resources/cave_near.png", IND_ALPHA, IND_32)) return 0;

	// Loading sky
	IND_Surface *mSurfaceSky = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mSurfaceSky, "../../resources/sky.jpg", IND_OPAQUE, IND_32)) return 0;

	// Font
	IND_Font *mFontSmall = IND_Font::newFont();
	if (!mI->_fontManager->add(mFontSmall, "../../resources/font_small.png", "../../resources/font_small.xml", IND_ALPHA, IND_32)) return 0;

	// ----- Font creation -----

	IND_Entity2d *mTextSmallWhite = IND_Entity2d::newEntity2d();					
	mI->_entity2dManager->add(3, mTextSmallWhite);				// Entity adding (Layer 3)
	mTextSmallWhite->setFont(mFontSmall);					// Set the font into the entity
	mTextSmallWhite->setLineSpacing(18);
	mTextSmallWhite->setCharSpacing	(-8);
	mTextSmallWhite->setPosition(5, 5, 1);
	mTextSmallWhite->setAlign(IND_LEFT);

	// ----- Entities -----

	// Creating 2d entity for the sky
	IND_Entity2d *mSky = IND_Entity2d::newEntity2d();					
	mI->_entity2dManager->add(0, mSky);					// Entity adding (Layer 0)
	mSky->setSurface(mSurfaceSky);
	mSky->setPosition(600, 0, 0);

	// Creating 2d entity for the cave
	IND_Entity2d *mCave = IND_Entity2d::newEntity2d();					
	mI->_entity2dManager->add(1, mCave);					// Entity adding (Layer 1)
	mCave->setSurface(mSurfaceCave);

	// Creating 2d entity for the cave (first plane)
	IND_Entity2d *mCaveFirstPlane = IND_Entity2d::newEntity2d();					
	mI->_entity2dManager->add(2, mCaveFirstPlane);				// Entity adding (Layer 2)
	mCaveFirstPlane->setSurface(mSurfaceCaveFirstPlane);

	// ----- Cameras -----

	// --- Cameras for the parallax layers --- 

	int mMiddleScreenX = mI->_window->getWidth() / 2;
	int mMiddleScreenY = mI->_window->getHeight() / 2;

	float mPosXCamera0 = (float) mMiddleScreenX;
	float mPosXCamera1 = (float) mMiddleScreenX;
	float mPosXCamera2 = (float) mMiddleScreenX;

	IND_Camera2d *mCamera0 = new IND_Camera2d((int) mPosXCamera0, mMiddleScreenY);
	IND_Camera2d *mCamera1 = new IND_Camera2d((int) mPosXCamera1, mMiddleScreenY);
	IND_Camera2d *mCamera2 = new IND_Camera2d((int) mPosXCamera2, mMiddleScreenY);

	int mSpeedLayer0 = 50;
	int mSpeedLayer1 = 162;
	int mSpeedLayer2 = 250;

	// --- Camera for showing the text that explain the input controls --- 

	IND_Camera2d *mCameraText = new IND_Camera2d((int) mI->_window->getWidth() / 2, mI->_window->getHeight() / 2);

	// --- Some variables ---

	char mText [2048];
	mText [0] = 0;
	float mDelta;

	while (!mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit())
	{
		// ----- Input update ----

		mI->_input->update();

		// ----- Text -----

		strcpy (mText, "Use right and left arrow keys for moving the camera\n");
		mTextSmallWhite->setText(mText);

		// ----- Input ----

		mDelta = mI->_render->getFrameTime() / 1000.0f;

		// Move cameras when pressing right key
		if (mI->_input->isKeyPressed(IND_KEYRIGHT))	
		{
			// Check limits
			if (mPosXCamera2 < mSurfaceCaveFirstPlane->getWidth() - mMiddleScreenX)
			{
				mPosXCamera0 += mSpeedLayer0 * mDelta;
				mPosXCamera1 += mSpeedLayer1 * mDelta;
				mPosXCamera2 += mSpeedLayer2 * mDelta;
			}
		}

		// Move cameras when pressing left key
		if (mI->_input->isKeyPressed(IND_KEYLEFT))	
		{
			// Check limits
			if (mPosXCamera2 > mMiddleScreenX)
			{
				mPosXCamera0 -= mSpeedLayer0 * mDelta;
				mPosXCamera1 -= mSpeedLayer1 * mDelta;
				mPosXCamera2 -= mSpeedLayer2 * mDelta;
			}
		}

		// ----- Updating cameras-----

		mCamera0->setPosition((int) mPosXCamera0, mMiddleScreenY);
		mCamera1->setPosition((int) mPosXCamera1, mMiddleScreenY);
		mCamera2->setPosition((int) mPosXCamera2, mMiddleScreenY);

		// ----- Render  -----

		mI->_render->clearViewPort(60, 60, 60);
		mI->_render->beginScene();

		// Render sky (Layer 0)
		mI->_render->setCamera2d(mCamera0);
		mI->_entity2dManager->renderEntities2d(0);

		// Render cave (Layer 1)
		mI->_render->setCamera2d(mCamera1);
		mI->_entity2dManager->renderEntities2d(1);

		// Render the first plane cave (Layer 2)
		mI->_render->setCamera2d(mCamera2);
		mI->_entity2dManager->renderEntities2d(2);

		// Render the text explaining the controls plane cave (Layer 3)
		mI->_render->setCamera2d(mCameraText);
		mI->_entity2dManager->renderEntities2d(3);

		mI->_render->endScene();	
	}

	// ----- Free -----

	mI->end();

	return 0;
}
/*
==================
Main
==================
*/
int IndieLib()			
{
	// ----- IndieLib intialization -----

	CIndieLib *mI = CIndieLib::instance();
	if (!mI->init()) return 0;								

	// ----- Surface loading -----

	// Loading Background
	IND_Surface *mSurfaceBack = new IND_Surface();
	if (!mI->_surfaceManager->add(mSurfaceBack, "../../resources/twist.jpg", IND_OPAQUE, IND_32)) return 0;

	// Loading Beettleship
	IND_Surface *mSurfaceBeetleship = new IND_Surface();
	if (!mI->_surfaceManager->add(mSurfaceBeetleship, "../../resources/beetleship.png", IND_ALPHA, IND_32)) return 0;

	// Loading Octopus
	IND_Surface *mSurfaceOctopus = new IND_Surface();
	if (!mI->_surfaceManager->add(mSurfaceOctopus, "../../resources/octopus.png", IND_ALPHA, IND_32)) return 0;

	// Loading Planet
	IND_Surface *mSurfacePlanet = new IND_Surface();
	if (!mI->_surfaceManager->add(mSurfacePlanet, "../../resources/planet.png", IND_ALPHA, IND_32)) return 0;

	// Font
	IND_Font *mFontSmall = new IND_Font() ;
	if (!mI->_fontManager->add(mFontSmall, "../../resources/font_small.png", "../../resources/font_small.xml", IND_ALPHA, IND_32)) return 0;

	// ----- Font creation -----

	IND_Entity2d *mTextSmallWhite = new IND_Entity2d();					
	mI->_entity2dManager->add(mTextSmallWhite);			// Entity adding
	mTextSmallWhite->setFont(mFontSmall);				// Set the font into the entity
	mTextSmallWhite->setLineSpacing(18);
	mTextSmallWhite->setCharSpacing(-8);
	mTextSmallWhite->setPosition(5, 5, 1);
	mTextSmallWhite->setAlign(IND_LEFT);

	// ----- Set the surfaces into 2d entities -----

	// Creating 2d entity for the background
	IND_Entity2d *mBack = new IND_Entity2d();					
	mI->_entity2dManager->add(mBack);				// Entity adding
	mBack->setSurface(mSurfaceBack);				// Set the surface into the entity

	// Creating 2d entity for the bettleship
	IND_Entity2d *mBeetleship = new IND_Entity2d();					
	mI->_entity2dManager->add(mBeetleship);				// Entity adding
	mBeetleship->setSurface(mSurfaceBeetleship);			// Set the surface into the entity

	// Creating 2d entity for the octopus
	IND_Entity2d *mOctopus = new IND_Entity2d();					
	mI->_entity2dManager->add(mOctopus);				// Entity adding
	mOctopus->setSurface(mSurfaceOctopus);				// Set the surface into the entity

	// Creating 2d entity for the planet
	IND_Entity2d *mPlanet = new IND_Entity2d();					
	mI->_entity2dManager->add(mPlanet);				// Entity adding
	mPlanet->setSurface(mSurfacePlanet);				// Set the surface into the entity

	// ----- Changing the attributes of the 2d entities -----

	mBack->setHotSpot(0.5f, 0.5f);
	mBack->setPosition(400, 300, 0);
	mBack->setScale(1.7f, 1.7f);

	mBeetleship->setHotSpot(0.5f, 0.5f); 

	mOctopus->setMirrorX(true);
	mOctopus->setHotSpot(0.5f, 0.5f);

	mPlanet->setHotSpot(0.5f, 0.5f);

	// ----- Main Loop -----

	float mAngle = 0;
	float mPos = 400;
	int mSpeed = 200;
	float mDelta;
	char mText [2048];
	mText [0] = 0;

	while (!mI->_input->onKeyPress (IND_ESCAPE) && !mI->_input->quit())
	{
		// ----- Input update -----

		mI->_input->update();

		// ----- Text -----

		strcpy (mText, "Use the mouse for moving the planet\n");
		strcat (mText, "Use left and right arrow keys for moving the ships\n");
		strcat (mText, "Press CTRL + X or ESC key to quit");
		mTextSmallWhite->setText(mText);	

		// ----- Input -----

		mDelta = mI->_render->getFrameTime() / 1000.0f;

		// Move entities when pressing right
		if (mI->_input->isKeyPressed(IND_KEYRIGHT)){
			mPos += mSpeed * mDelta;
		}

		// Move entities when pressing left
		if (mI->_input->isKeyPressed(IND_KEYLEFT)){
			mPos -= mSpeed * mDelta;
		}

		// If CTRL + X pressed then exit
		if (mI->_input->isKeyPressed(IND_LCTRL) && mI->_input->isKeyPressed(IND_X)){
			mI->_render->endScene();
			mI->end();
			exit(0);
		}

		mAngle += (mSpeed / 4) * mDelta;

		// ----- Updating entities attributes  -----

		// Back
		mBack->setAngleXYZ(0, 0, mAngle);		

		// Beetle
		mBeetleship->setPosition((float) mPos, 140, 1);
		mBeetleship->setAngleXYZ(0, 0, (float) mPos);

		// Planet
		mPlanet->setPosition((float) mI->_input->getMouseX(), 300, 2);
		
		// Octopus
		mOctopus->setPosition(800 - (float) mPos, 480, 3);

		// ----- Render -----

		mI->_render->beginScene();
		mI->_entity2dManager->renderEntities2d();
		mI->_render->endScene();	
	}

	// ----- Free -----

	mI->end();

	return 0;
}
/*
==================
Main
==================
*/
int IndieLib()			
{
	// ----- IndieLib intialization -----

	CIndieLib *mI = CIndieLib::instance();
	if (!mI->init()) return 0;								

	// ----- Surface loading -----

	// Loading Background
	IND_Surface *mSurfaceBack = new IND_Surface();
	if (!mI->_surfaceManager->add(mSurfaceBack, "../../resources/blue_background.jpg", IND_OPAQUE, IND_32)) return 0;

	// ----- Animations loading -----

	// Characters animations, we apply a color key of (0, 48, 152)
	IND_Animation *mAnimationCharacter1 = new IND_Animation();
	if (!mI->_animationManager->addToSurface(mAnimationCharacter1, "../../resources/animations/character1.xml", IND_ALPHA, IND_32, 0, 48, 152)) return 0;

	// Characters animations, we apply a color key of (0, 48, 152)
	IND_Animation *mAnimationCharacter2 = new IND_Animation();
	if (!mI->_animationManager->addToSurface(mAnimationCharacter2, "../../resources/animations/character2.xml", IND_ALPHA, IND_32, 0, 48, 152)) return 0;

	// Dust animation, we apply a color key of (255, 0, 255)
	IND_Animation *mAnimationDust = new IND_Animation();
	if (!mI->_animationManager->addToSurface(mAnimationDust, "../../resources/animations/dust.xml", IND_ALPHA, IND_16, 255, 0, 255)) return 0;

	// ----- Set the surface and animations into 2d entities -----

	// Creating 2d entity for the background
	IND_Entity2d *mBack = new IND_Entity2d();			
	mI->_entity2dManager->add(mBack);					// Entity adding
	mBack->setSurface(mSurfaceBack);					// Set the surface into the entity

	// Character 1
	IND_Entity2d *mPlayer1 = new IND_Entity2d();
	mI->_entity2dManager->add(mPlayer1);					// Entity adding
	mPlayer1->setAnimation(mAnimationCharacter1);				// Set the animation into the entity

	// Character 2
	IND_Entity2d *mPlayer2 = new IND_Entity2d();
	mI->_entity2dManager->add(mPlayer2);					// Entity adding
	mPlayer2->setAnimation(mAnimationCharacter2);				// Set the animation into the entity

	// Dust explosion
	IND_Entity2d *mDust = new IND_Entity2d();
	mI->_entity2dManager->add(mDust);					// Entity adding
	mDust->setAnimation(mAnimationDust);					// Set the animation into the entity

	// ----- Changing the attributes of the 2d entities -----

	// Player 1
	mPlayer1->setSequence(0);						// Choose sequence
	mPlayer1->setPosition(140, 200, 0);
	mPlayer1->setMirrorX(1);						// Horizontal mirroring
	
	// Dust explosion
	mDust->setPosition(360, 250, 0);
	
	// Player 2
	mPlayer2->setSequence(0);						// Choose sequence
	mPlayer2->setPosition(550, 200, 0);				
	mPlayer2->setNumReplays(3);						// The animation will be displayed 3 times

	// ----- Main Loop -----

	while (!mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit())
	{
		mI->_input->update();
		mI->_render->beginScene();
		mI->_entity2dManager->renderEntities2d();
		mI->_render->endScene();	
	}

	// ----- Free -----

	mI->end();

	return 0;
}
/*
==================
Main
==================
*/
int IndieLib()			
{
    //Sets the working path as the 'exe' directory. All resource paths are relative to this directory
	if (!WorkingPathSetup::setWorkingPathFromExe(NULL)) {
		std::cout<<"\nUnable to Set the working path !";
	}
	
	// ----- IndieLib intialization -----

	CIndieLib *mI = CIndieLib::instance();
	if (!mI->init()) 
		return 0;			

	// ----- Surface loading -----

	// Loading cursor
	IND_Surface *mSurfaceCursor = new IND_Surface();
	if (!mI->_surfaceManager->add(mSurfaceCursor, "../../resources/cursor.png", IND_ALPHA, IND_32))
		return 0;

	// Loading tile for the terrain
	IND_Surface *mSurfaceTerrain = new IND_Surface();
	if (!mI->_surfaceManager->add(mSurfaceTerrain, "../../resources/tiled_terrain.png", IND_OPAQUE, IND_32))
		return 0;

	// Loading alien hole 1
	IND_Surface *mSurfaceHole1 = new IND_Surface();
	if (!mI->_surfaceManager->add(mSurfaceHole1, "../../resources/hole1.png", IND_ALPHA, IND_32)) 
		return 0;
	
	// Loading alien hole 2
	IND_Surface *mSurfaceHole2 = new IND_Surface();
	if (!mI->_surfaceManager->add(mSurfaceHole2, "../../resources/hole2.png", IND_ALPHA, IND_32)) 
		return 0;

	// Font
	IND_Font *mFontSmall = new IND_Font();
	if (!mI->_fontManager->add(mFontSmall, "../../resources/font_small.png", "../../resources/font_small.xml", IND_ALPHA, IND_32)) 
		return 0;

	// ----- Animation loading -----

	IND_Animation *mAnimationUfo = new IND_Animation();
	if (!mI->_animationManager->addToSurface(mAnimationUfo, "../../resources/animations/ufo.xml", IND_ALPHA, IND_32)) 
		return 0;

	// ----- Cursor creation -----

	IND_Entity2d *mCursor = new IND_Entity2d();
	mI->_entity2dManager->add(1, mCursor);			// Entity adding in layer 1 (gui)	
	mCursor->setSurface(mSurfaceCursor);

	// ----- Terrain creation -----

	CTerrain *mTerrain = new CTerrain(X_TILES, Y_TILES, NUM_HOLES, mSurfaceTerrain, mSurfaceHole1, mSurfaceHole2);

	// ----- Font creation -----

	IND_Entity2d *mTextSmallWhite = new IND_Entity2d();					
	mI->_entity2dManager->add(1, mTextSmallWhite);		// Entity adding in layer 1 (gui)
	mTextSmallWhite->setFont(mFontSmall);			// Set the font into the entity

	mTextSmallWhite->setLineSpacing(18);
	mTextSmallWhite->setCharSpacing(-8);
	mTextSmallWhite->setPosition(15, 15, 4);
	mTextSmallWhite->setAlign(IND_LEFT);

	// ----- Ufo creation -----

	CUfo *mUfos = new CUfo[X_TILES * Y_TILES * 1024];

	int cont = 0;
	for (int i = 0; i < X_TILES * 512; i += 50) {
		for (int j = 0; j < Y_TILES * 512; j += 50, ++cont) {
			mUfos [cont].Init ((float) i, (float) j, mAnimationUfo);
		
		}
	}
		
	// ----- Camera ------

	// Camera used for moving along the terrain
	IND_Camera2d *mCameraTerrain = new IND_Camera2d(mI->_window->getWidth () / 2, mI->_window->getHeight() / 2);

	// Camera used for showing the menu options, fps, etc (this camera dosen't change)
	IND_Camera2d *mCameraGui = new IND_Camera2d(mI->_window->getWidth () / 2, mI->_window->getHeight() / 2);

	// ----- Main Loop -----

	float mZoom = 1.0f;
	float mAngle = 0;
	char mFpsString [512];
	char mFpsValueStr [15];
	char mRenderedObjectsStr [15];
	char mDiscardedObjectsStr [15];
	mFpsString [0] = 0;
	int mSpeedRotation = 50;
	float mDelta;

	while (!mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit())
	{
		// ----- Input update ----

		mI->_input->update();

		// ----- Texts -----

		strcpy (mFpsString, "Fps: ");
		mI->_render->getFpsString(mFpsValueStr);
		strcat (mFpsString, mFpsValueStr);
		strcat (mFpsString, "\n");
		strcat (mFpsString, "Rendered: ");
		mI->_render->getNumrenderedObjectsString(mRenderedObjectsStr);
		strcat (mFpsString, mRenderedObjectsStr); 
		strcat (mFpsString, "\n"); 
		strcat (mFpsString, "Discarded: ");
		mI->_render->getNumDiscardedObjectsString(mDiscardedObjectsStr);
		strcat (mFpsString, mDiscardedObjectsStr);
		mTextSmallWhite->setText(mFpsString);
		

		// ----- Input ----

		// Delta
		mDelta = mI->_render->getFrameTime() / 1000.0f;

		// Cursor position
		mCursor->setPosition((float) mI->_input->getMouseX(), (float) mI->_input->getMouseY(), 3);

		// Change resolution to 640, 480 when pressing 1
		if (mI->_input->onKeyPress(IND_1))
		{
			//if (!mI->_render->reset("Alien BenchMark", 640, 480, 32, 0, 1)) return 0; //FIXME: this is broken - figure out how to use IND_Windowproperties correctly 
			mCameraGui->setPosition(mI->_window->getWidth() / 2, mI->_window->getHeight() / 2);
			mCameraTerrain->setPosition(mI->_window->getWidth() / 2, mI->_window->getHeight() / 2);
		}

		// Change resolution to 800, 600 when pressing 2
		if (mI->_input->onKeyPress(IND_2))
		{
			//if (!mI->_render->reset("Alien BenchMark", 800, 600, 32, 0, 1)) return 0;  //FIXME: this is broken - figure out how to use IND_Windowproperties correctly 
			mCameraGui->setPosition(mI->_window->getWidth() / 2, mI->_window->getHeight() / 2);
			mCameraTerrain->setPosition(mI->_window->getWidth() / 2, mI->_window->getHeight() / 2);
		}

		// Change resolution to 1024, 768 when pressing 3
		if (mI->_input->onKeyPress(IND_3))
		{
			//if (!mI->_render->reset("Alien BenchMark", 1024, 768, 32, 0, 1)) return 0;  //FIXME: this is broken - figure out how to use IND_Windowproperties correctly 
			mCameraGui->setPosition(mI->_window->getWidth() / 2, mI->_window->getHeight() / 2);
			mCameraTerrain->setPosition(mI->_window->getWidth() / 2, mI->_window->getHeight() / 2);
		}

		// Toogle full screen when pressing "space"
		if (mI->_input->onKeyPress(IND_SPACE)) mI->_render->toggleFullScreen();

		// Camera Zoom in / out
		if (mI->_input->isMouseScroll()) {
			mZoom += mI->_input->getMouseScrollY() * K_ZOOMSPEED;
		}		

		// Camera angle
		if (mI->_input->isMouseButtonPressed(IND_MBUTTON_LEFT))	mAngle += mSpeedRotation * mDelta;
		if (mI->_input->isMouseButtonPressed(IND_MBUTTON_RIGHT)) mAngle -= mSpeedRotation * mDelta;		

		// ----- Updating entities attributes  -----

		// Zooming and rotating the camera
		if (mZoom < 0.1f) mZoom =  0.1f;
		mCameraTerrain->setAngle(mAngle);
		mCameraTerrain->setZoom(mZoom);

		// Camera translation
		if (mI->_input->getMouseX() > mI->_window->getWidth() - MOVE_TERRAIN_BY_MOUSE_AREA) mCameraTerrain->setPosition(mCameraTerrain->getPosX() + (int) CAMERA_DISPLACE, mCameraTerrain->getPosY());
		if (mI->_input->getMouseX() < MOVE_TERRAIN_BY_MOUSE_AREA) mCameraTerrain->setPosition(mCameraTerrain->getPosX() - (int) CAMERA_DISPLACE, mCameraTerrain->getPosY());
		if (mI->_input->getMouseY() > mI->_window->getHeight()- MOVE_TERRAIN_BY_MOUSE_AREA) mCameraTerrain->setPosition(mCameraTerrain->getPosX(), mCameraTerrain->getPosY() + (int) CAMERA_DISPLACE);
		if (mI->_input->getMouseY() < MOVE_TERRAIN_BY_MOUSE_AREA) mCameraTerrain->setPosition(mCameraTerrain->getPosX(), mCameraTerrain->getPosY() - (int) CAMERA_DISPLACE);

		// ----- Render  -----

		mI->_render->beginScene();
		mI->_render->clearViewPort(0, 0, 0);
		
		// --- Layer 0 (terrain) ---

		mI->_render->resetNumDiscardedObjects();
		mI->_render->resetNumrenderedObject();
		mI->_render->setViewPort2d(0, 0, mI->_window->getWidth(), mI->_window->getHeight());
		mI->_render->setCamera2d(mCameraTerrain);
		mI->_entity2dManager->renderEntities2d(0);

		// --- Layer 1 (gui) ---

		mI->_render->setViewPort2d(0, 0, mI->_window->getWidth(), mI->_window->getHeight());
		mI->_render->setCamera2d(mCameraGui);
		mI->_render->blitFillRectangle(10, 10, 240, 80, 128, 128, 128, 128);
		mI->_render->blitRectangle(10, 10, 240, 80, 255, 255, 255, 128);
		mI->_entity2dManager->renderEntities2d(1);

		mI->_render->endScene();	
	}

	// ----- Free -----

	mI->end();
	delete [] mUfos;

	return 0;
}
Exemple #18
0
/*
==================
Main
==================
*/
int IndieLib()			
{
    //Sets the working path as the 'exe' directory. All resource paths are relative to this directory
	if (!WorkingPathSetup::setWorkingPathFromExe(NULL)) {
		std::cout<<"\nUnable to Set the working path !";
	}
	
	// ----- IndieLib intialization -----

	CIndieLib *mI = CIndieLib::instance();
	if (!mI->init()) return 0;			

	// ----- Surface loading -----

	// Loading Background
	IND_Surface *mSurfaceBack = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mSurfaceBack, "../../resources/twist.jpg", IND_OPAQUE, IND_32)) return 0;

	// Loading draco
	IND_Surface *mSurfaceDraco = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mSurfaceDraco, "../../resources/draco.png", IND_ALPHA, IND_32)) return 0;

	// Font
	IND_Font *mFontSmall = IND_Font::newFont();
	if (!mI->_fontManager->add(mFontSmall, "../../resources/font_small.png", "../../resources/font_small.xml", IND_ALPHA, IND_32)) return 0;

	// ----- Font creation -----

	IND_Entity2d *mTextSmallWhite = IND_Entity2d::newEntity2d() ;					
	mI->_entity2dManager->add(mTextSmallWhite);				// Entity adding
	mTextSmallWhite->setFont(mFontSmall);					// Set the font into the entity
	mTextSmallWhite->setLineSpacing(18);
	mTextSmallWhite->setCharSpacing(-8);
	mTextSmallWhite->setPosition(5, 5, 1);
	mTextSmallWhite->setAlign(IND_LEFT);

	// ----- Create a grid for Draco IND_Surface -----

	mSurfaceDraco->setGrid(8, 8);

	// ----- Set the surfaces into 2d entities -----

	// Creating 2d entity for the background
	IND_Entity2d *mBack = IND_Entity2d::newEntity2d();					
	mI->_entity2dManager->add(mBack);						// Entity adding
	mBack->setSurface(mSurfaceBack);						// Set the surface into the entity

	// Creating 2d entity for the draco
	IND_Entity2d *mDraco = IND_Entity2d::newEntity2d();					
	mI->_entity2dManager->add(mDraco);						// Entity adding
	mDraco->setSurface(mSurfaceDraco);						// Set the surface into the entity

	// ----- Changing the attributes of the 2d entities -----

	// Background
	mBack->setHotSpot(0.5f, 0.5f);
	mBack->setPosition(400, 300, 0);
	mBack->setScale(1.7f, 1.7f);

	// Draco
	mDraco->setPosition(150, 50, 1);

	// ----- Main Loop -----

	int mNumBlocksX = mSurfaceDraco->getBlocksX();
	int mNumBlocksY = mSurfaceDraco->getBlocksY();
	int mWidthBlock = mSurfaceDraco->getWidthBlock();
	int mHeightBlock = mSurfaceDraco->getHeightBlock();
	bool mShowGrid = 0;
	float mAngle = 0;
	IND_Timer *mTimer = new IND_Timer();
	mTimer->start();
	float mT;
	char mText [2048];
	mText [0] = 0;

	while (!mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit())
	{
		// ----- Input update ----

		mI->_input->update();

		// ----- Text -----

		strcpy(mText, "Press space to see the grid in action. This is really cool, isn't it?");
		mTextSmallWhite->setText(mText);

		// ----- Input ----

		// Show / Hide the grid pressing "space"
		if (mI->_input->onKeyPress(IND_SPACE))
		{
			if (mShowGrid){
				mShowGrid = 0;
			}else{
				mShowGrid = 1;
			}
		}

		// ----- Updating entities attributes  -----

		mAngle += 0.1f;
		mBack->setAngleXYZ(0, 0, mAngle);

		// Update grid vertices for making a "wave" effect
		mT = mTimer->getTicks() / 1000.0f;
		
		for (int i = 1; i < mNumBlocksX; i++)
			for (int j = 1; j < mNumBlocksY; j++)
				mSurfaceDraco->setVertexPos (j, i, (int) ((j * mHeightBlock + cosf (mT * 10 + (i + j) / 2) * 5)), (int) ((i * mWidthBlock	+ sinf (mT * 10 + (i + j) / 2) * 5)));

		// ----- Render  -----

		mI->_render->beginScene();
		mI->_render->clearViewPort(60, 60, 60);
		mI->_entity2dManager->renderEntities2d();
		if (mShowGrid) mI->_entity2dManager->renderGridAreas(0, 0, 0, 255);
		mI->_render->endScene();	
	}

	// ----- Free -----

	mI->end();

	return 0;
}
Exemple #19
0
/* 
==================
Main
==================
*/
int IndieLib()
{
    //Sets the working path as the 'exe' directory. All resource paths are relative to this directory
	if (!WorkingPathSetup::setWorkingPathFromExe(NULL)) {
		std::cout<<"\nUnable to Set the working path !";
	}
	
	// ----- IndieLib intialization -----

	CIndieLib *mI = CIndieLib::instance();
	if ( !mI->init() ) return 0;									

	// ----- Surface loading -----

	// Loading Background
	IND_Surface *mSurfaceBoid = new IND_Surface();
	if ( !mI->_surfaceManager->add( mSurfaceBoid, "../res/boid.png", IND_ALPHA, IND_32) ) return 0;

	// ----- Set the surfaces into 2d entities ----
	BoidGame boidGame;
	BoidAgent *boid;
	
	for( int i = 0; i < 100; i++ ) {
		boid = boidGame.addBird();
		mI->_entity2dManager->add( boid );					// Entity adding
		boid->setSurface( mSurfaceBoid );					// Set the surface into the entity
	}

	while ( !mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit() )
	{
		// ----- Input update ----
		if ( mI->_input->onKeyPress( IND_Q ) ) {
			boidGame.decreaseAlignment();
		} else if ( mI->_input->onKeyPress( IND_W ) ) {
			boidGame.increaseAlignment();
		} else if ( mI->_input->onKeyPress( IND_A ) ) {
			boidGame.decreaseCohesion();
		} else if ( mI->_input->onKeyPress( IND_S ) ) {
			boidGame.increaseCohesion();
		} else if ( mI->_input->onKeyPress( IND_Z ) ) {
			boidGame.decreaseSeparation();
		} else if ( mI->_input->onKeyPress( IND_X ) ) {
			boidGame.increaseSeparation();
		}

		mI->_input->update();
		boidGame.update( mI->_render->getFrameTime() / 1000.0f );

		// ----- Render  -----
		mI->_render->beginScene();
		mI->_render->clearViewPort(255, 255, 255);
		mI->_entity2dManager->renderEntities2d();
		mI->_render->endScene();	
	}

	// ----- Free -----

	mI->end();

	return 0;
}
Exemple #20
0
/*
==================
Main
==================
*/
int IndieLib()
{
    //Sets the working path as the 'exe' directory. All resource paths are relative to this directory
	if (!WorkingPathSetup::setWorkingPathFromExe(NULL)) {
		std::cout<<"\nUnable to Set the working path !";
	}
	
	// ----- IndieLib intialization -----

	CIndieLib *mI = CIndieLib::instance();
	if (!mI->init()) return 0;		

	// ----- Surface loading -----

	// Loading draco
	IND_Surface *mSurfaceDraco = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mSurfaceDraco, "../../resources/draco.png", IND_ALPHA, IND_32)) return 0;

	// Loading gem (this image has a blue rectangle surronding it)
	IND_Surface *mSurfaceGem = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mSurfaceGem, "../../resources/gem_squared.png", IND_ALPHA, IND_32)) return 0;

	// Loading bug
	IND_Surface *mSurfaceBug = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mSurfaceBug, "../../resources/Enemy Bug.png", IND_ALPHA, IND_32)) return 0;

	// ----- Animation loading -----

	IND_Animation *mAnimationUfo = IND_Animation::newAnimation();
	if (!mI->_animationManager->addToSurface(mAnimationUfo, "../../resources/animations/ufo.xml", IND_ALPHA, IND_32)) return 0;

	// ----- Main Loop -----

	int mWidth, mHeight;
	float mAngle = 0.0f;
	float mHotSpotX, mHotSpotY;
	int mAxisCalX, mAxisCalY;
	IND_Matrix *mMatrix = new IND_Matrix();
	float mSpeed = 50;
	float mDelta;

	while (!mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit())
	{
		// ----- Input update ----

		mI->_input->update();

		// ----- Delta -----

		mDelta = mI->_render->getFrameTime() / 1000.0f;

		// ----- Render  -----

		mI->_render->beginScene();
		mI->_render->clearViewPort(60, 60, 60);


		// --------------------------------------------------------------------------------
		//					Blitting Draco directly (IND_Surface object) 
		// --------------------------------------------------------------------------------

		// 1) We apply the world space transformation (translation, rotation, scaling).
		// If you want to recieve the transformation in a single matrix you can pass
		// and IND_Matrix object by reference.

		mWidth = mSurfaceDraco->getWidth();
		mHeight = mSurfaceDraco->getHeight();
		mI->_render->setTransform2d(50,					// x pos
									70,					// y pos
									0,					// Angle x	
									0,					// Angle y
									0,					// Angle z
									1,					// Scale x
									1,					// Scale y
									0,					// Axis cal x
									0,					// Axis cal y
									0,					// Mirror x
									0,					// Mirror y
									mWidth,				// Width
									mHeight,			// Height
									mMatrix);			// Matrix in wich the transformation will be applied (optional)			
 
		// 2) We apply the color, blending and culling transformations.
		mI->_render->setRainbow2d(IND_ALPHA,								// IND_Type
									1,					// Back face culling 0/1 => off / on
									0,					// Mirror x
									0,					// Mirror y
									IND_FILTER_LINEAR,	// IND_Filter
									255,				// R Component	for tinting
									255,				// G Component	for tinting
									255,				// B Component	for tinting			
									255,				// A Component	for tinting
									0,					// R Component	for fading to a color		
									0,					// G Component	for fading to a color		
									0,					// B Component	for fading to a color			
									255,				// Amount of fading	
									IND_SRCALPHA,		// IND_BlendingType (source)
									IND_INVSRCALPHA);	// IND_BlendingType (destination)


		// 3) Blit the IND_Surface
		mI->_render->blitSurface(mSurfaceDraco);


		// --------------------------------------------------------------------------------
		//		Blitting Bug directly (IND_Surface object with a HotSpot and rotating)
		// --------------------------------------------------------------------------------

		// 1) We apply the world space transformation (translation, rotation, scaling).
		// If you want to recieve the transformation in a single matrix you can pass
		// and IND_Matrix object by reference.

		mAngle += mSpeed *mDelta;
		mHotSpotX = 0.5f;
		mHotSpotY = 0.5f;
		mWidth = mSurfaceBug->getWidth();
		mHeight = mSurfaceBug->getHeight();
		mAxisCalX = (int) (mHotSpotX * mWidth * -1);
		mAxisCalY = (int) (mHotSpotY * mHeight * -1);

		mI->_render->setTransform2d(500,				// x pos
									100,				// y pos
									0,					// Angle x	
									0,					// Angle y
									mAngle,				// Angle z
									1,					// Scale x
									1,					// Scale y
									mAxisCalX,			// Axis cal x
									mAxisCalY,			// Axis cal y
									0,					// Mirror x
									0,					// Mirror y
									mWidth,				// Width
									mHeight,			// Height
									mMatrix);			// Matrix in wich the transformation will be applied (optional)			
 
		// 2) We apply the color, blending and culling transformations.
		mI->_render->setRainbow2d(IND_ALPHA,			// IND_Type
									1,					// Back face culling 0/1 => off / on
									0,					// Mirror x
									0,					// Mirror y
									IND_FILTER_LINEAR,	// IND_Filter
									255,				// R Component	for tinting
									255,				// G Component	for tinting
									255,				// B Component	for tinting			
									255,				// A Component	for tinting
									0,					// R Component	for fading to a color		
									0,					// G Component	for fading to a color		
									0,					// B Component	for fading to a color			
									255,				// Amount of fading	
									IND_SRCALPHA,		// IND_BlendingType (source)
									IND_INVSRCALPHA);	// IND_BlendingType (destination)


		// 3) Blit the IND_Surface
		mI->_render->blitSurface(mSurfaceBug);


		// --------------------------------------------------------------------------------
		//				Blitting a region of Gem directly (IND_Surface region)
		// --------------------------------------------------------------------------------

		// 1) We apply the world space transformation (translation, rotation, scaling).
		// If you want to recieve the transformation in a single matrix you can pass
		// and IND_Matrix object by reference.

		mWidth = mSurfaceGem->getWidth();
		mHeight = mSurfaceGem->getHeight();
		mI->_render->setTransform2d(600,				// x pos
									200,				// y pos
									0,					// Angle x	
									0,					// Angle y
									0,					// Angle z
									1,					// Scale x
									1,					// Scale y
									0,					// Axis cal x
									0,					// Axis cal y
									0,					// Mirror x
									0,					// Mirror y
									mWidth,				// Width
									mHeight,			// Height
									mMatrix);			// Matrix in wich the transformation will be applied (optional)			
 
		// 2) We apply the color, blending and culling transformations.
		mI->_render->setRainbow2d(IND_ALPHA,								// IND_Type
									1,					// Back face culling 0/1 => off / on
									0,					// Mirror x
									0,					// Mirror y
									IND_FILTER_LINEAR,	// IND_Filter
									255,				// R Component	for tinting
									255,				// G Component	for tinting
									255,				// B Component	for tinting			
									255,				// A Component	for tinting
									0,					// R Component	for fading to a color		
									0,					// G Component	for fading to a color		
									0,					// B Component	for fading to a color			
									255,				// Amount of fading	
									IND_SRCALPHA,		// IND_BlendingType (source)
									IND_INVSRCALPHA);	// IND_BlendingType (destination)


		// 3) Blit the IND_Surface
		mI->_render->blitRegionSurface(mSurfaceGem, 10, 10, 70, 70);


		// --------------------------------------------------------------------------------
		//				Blitting a tiled region of Gem directly (IND_Surface wrap)
		// --------------------------------------------------------------------------------

		// 1) We apply the world space transformation (translation, rotation, scaling).
		// If you want to recieve the transformation in a single matrix you can pass
		// and IND_Matrix object by reference.

		mWidth = mSurfaceGem->getWidth();
		mHeight = mSurfaceGem->getHeight();
		mI->_render->setTransform2d(500,							// x pos
									350,				// y pos
									0,					// Angle x	
									0,					// Angle y
									0,					// Angle z
									1,					// Scale x
									1,					// Scale y
									0,					// Axis cal x
									0,					// Axis cal y
									0,					// Mirror x
									0,					// Mirror y
									mWidth,				// Width
									mHeight,			// Height
									mMatrix);			// Matrix in wich the transformation will be applied (optional)			
 
		// 2) We apply the color, blending and culling transformations.
		mI->_render->setRainbow2d(IND_ALPHA,								// IND_Type
									1,					// Back face culling 0/1 => off / on
									0,					// Mirror x
									0,					// Mirror y
									IND_FILTER_LINEAR,	// IND_Filter
									255,				// R Component	for tinting
									255,				// G Component	for tinting
									255,				// B Component	for tinting			
									255,				// A Component	for tinting
									0,					// R Component	for fading to a color		
									0,					// G Component	for fading to a color		
									0,					// B Component	for fading to a color			
									255,				// Amount of fading	
									IND_SRCALPHA,		// IND_BlendingType (source)
									IND_INVSRCALPHA);	// IND_BlendingType (destination)


		// 3) Blit the IND_Surface
		mI->_render->blitWrapSurface(mSurfaceGem, 200, 200, 0, 0);


		// --------------------------------------------------------------------------------
		//				Blitting a ufo animation directly (IND_Animation object)
		// --------------------------------------------------------------------------------

		// 1) We apply the world space transformation (translation, rotation, scaling).
		// If you want to recieve the transformation in a single matrix you can pass
		// and IND_Matrix object by reference.

		mWidth = mAnimationUfo->getActualSurface(0)->getWidth();
		mHeight= mAnimationUfo->getActualSurface(0)->getHeight();
		mI->_render->setTransform2d(650,								// x pos
									70,					// y pos
									0,					// Angle x	
									0,					// Angle y
									0,					// Angle z
									1,					// Scale x
									1,					// Scale y
									0,					// Axis cal x
									0,					// Axis cal y
									0,					// Mirror x
									0,					// Mirror y
									mWidth,				// Width
									mHeight,			// Height
									mMatrix);			// Matrix in wich the transformation will be applied (optional)			
 
		// 2) We apply the color, blending and culling transformations.
		mI->_render->setRainbow2d(IND_ALPHA,								// IND_Type
									1,					// Back face culling 0/1 => off / on
									0,					// Mirror x
									0,					// Mirror y
									IND_FILTER_LINEAR,	// IND_Filter
									255,				// R Component	for tinting
									255,				// G Component	for tinting
									255,				// B Component	for tinting			
									255,				// A Component	for tinting
									0,					// R Component	for fading to a color		
									0,					// G Component	for fading to a color		
									0,					// B Component	for fading to a color			
									255,				// Amount of fading	
									IND_SRCALPHA,		// IND_BlendingType (source)
									IND_INVSRCALPHA);	// IND_BlendingType (destination)


		// 3) Blit the IND_Animation looping
		if (mI->_render->blitAnimation(mAnimationUfo, 0, 0, 0, 0, 0, 0, 0, 0) == -1)
			mAnimationUfo->setActualFramePos (0, 0);

		mI->_render->endScene();	
	}

	// ----- Free -----

	mI->end();

	delete mMatrix;

	return 0;
}
/*
==================
Main
==================
*/
int IndieLib ()			
{
	// ----- IndieLib intialization -----

	CIndieLib *mI = CIndieLib::instance();
	if (!mI->init()) return 0;		
	
	// ----- Surface loading -----

	// Loading rabbit
	IND_Surface *mSurfaceRabbit = new IND_Surface();
	if (!mI->_surfaceManager->add(mSurfaceRabbit, "../../resources/rabbit.png", IND_ALPHA, IND_32)) return 0;

	// Font
	IND_Font *mFontSmall = new IND_Font();
	if (!mI->_fontManager->add(mFontSmall, "../../resources/font_small.png", "../../resources/font_small.xml", IND_ALPHA, IND_32)) return 0;

	// ----- Create rabbits -----
	
	CRabbit *mRabbits = new CRabbit[MAX_OBJECTS];
	
	int i;
	for (i = 0; i < MAX_OBJECTS; i++) mRabbits[i].init(mSurfaceRabbit, i);

	// ----- Font creation -----

	IND_Entity2d *mTextSmallWhite = new IND_Entity2d();					
	mI->_entity2dManager->add(mTextSmallWhite);			// Entity adding
	mTextSmallWhite->setFont(mFontSmall);				// Set the font into the entity
	mTextSmallWhite->setLineSpacing(18);
	mTextSmallWhite->setCharSpacing(-8);
	mTextSmallWhite->setPosition(5, 5, i);
	mTextSmallWhite->setAlign(IND_LEFT);
	
	// ----- Main Loop -----

	char mFpsString[128];
	char mFpsValueString[15];
	mFpsString [0] = 0;

	while (!mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit())
	{
		// ----- Input update ----

		mI->_input->update();

		// ----- Fps -----

		strcpy(mFpsString, "Fps: ");
		mI->_render->getFpsString(mFpsValueString);
		strcat(mFpsString, mFpsValueString);
		strcat(mFpsString, "\nPress space to toggle full screen");
		mTextSmallWhite->setText(mFpsString);	

		// ----- Game logic ----

		// Toogle full screen when pressing "space"
		if (mI->_input->onKeyPress(IND_SPACE)) mI->_render->toggleFullScreen();

		// Update rabbits position
		for (int i = 0; i < MAX_OBJECTS; i++) mRabbits[i].update();	

		// ----- Render -----

		mI->_render->beginScene();
		mI->_render->clearViewPort(60, 60, 60);
		mI->_entity2dManager->renderEntities2d();
		mI->_render->endScene();
	}

	// ----- Free -----

	mI->end();
	delete [] mRabbits;

	return 0;
}