int main(int argc, char* args[]) {

	//initialize SDL_ttf
	if (TTF_Init() == -1) {
		cerr << "TTF_Init: " << TTF_GetError() << endl;
//exit(2);
	}

	SDL_Texture* backGroundTexture; // the new SDL_Texture variable
	SDL_Texture* backimageTexture;
// *****************



	SDL_Init( SDL_INIT_EVERYTHING);

	//Create window
	g_pWindow = SDL_CreateWindow("Easy_Rider", SDL_WINDOWPOS_UNDEFINED,
	SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);

	//Create Renderer
	g_pRenderer = SDL_CreateRenderer(g_pWindow, -1, SDL_RENDERER_ACCELERATED);

	//Load image from specified path
	SDL_Surface* loadedSurface = IMG_Load("image/background.png");

	//Create texture from surface pixels
	backGroundTexture = SDL_CreateTextureFromSurface(g_pRenderer,
			loadedSurface);

	SDL_Surface* riderSurface = SDL_LoadBMP("image/rider.bmp");

	//Color key image
	SDL_SetColorKey(riderSurface, SDL_TRUE,
			SDL_MapRGB(riderSurface->format, 102, 204, 255));

	//Create texture from surface pixels
	backimageTexture = SDL_CreateTextureFromSurface(g_pRenderer, riderSurface);

	//SDL_Rect rectRider = {320, 0, riderSurface->w};

// flipping a image
	Text txt;
	txt.Init(g_pRenderer);

	SDL_RenderClear(g_pRenderer);


	bool gamerunning = true;
	SDL_Event event;

	//	game loop
	while (gamerunning) {

		if (SDL_PollEvent(&event)!= 0) {
			if (event.type == SDL_QUIT)
				gamerunning = false;
		}
			SDL_RenderClear(g_pRenderer);
					SDL_RenderCopy(g_pRenderer, backGroundTexture, 0, 0);
					txt.Draw(g_pRenderer);
			        txt.UpDate(event);
					SDL_RenderPresent(g_pRenderer);



	}

	SDL_RenderPresent(g_pRenderer);

	//SDL_Delay(2000);

	return 0;
}
Example #2
0
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	dInstance = hInstance;
	// Windows structure
	WNDCLASSEX wcex;
	ZeroMemory(&wcex, sizeof(wcex));

    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style          = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc    = WndProc;
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hInstance      = dInstance;
    wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
    wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName   = NULL;
    wcex.lpszClassName  = "gameDemoWindow";
    wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));

	// register a new type of window
	if (!RegisterClassEx(&wcex))
    {
        MessageBox(
        NULL,
        "Window Error",
        "Could not create window",
        NULL);
    }

	static TCHAR szWindowClass[] = "gameDemoWindow";
	static TCHAR szTitle[] = "Game Demo";

	hWnd = CreateWindow(
		szWindowClass,
		szTitle,
		WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, CW_USEDEFAULT,
		1920, 1080,
		NULL,
		NULL,
		dInstance,
		NULL);


	// Display the window
	ShowWindow(hWnd,nCmdShow);
	UpdateWindow(hWnd);

	int width;
	int height;
	bool windowed;

	

	
	//create engine, using MainCore
	MainCore* main_core = new MainCore();
	main_core->Startup(hWnd);

	//create pointer to access each core through MainCore
	AISystem* ai_core = main_core->GetAIManager();
	Sound* sound_core = main_core->GetAudioCoreSound();
	SoundEffect* sfx_core = main_core->GetAudioCoreSoundEffect();
	PhysicsInterface* physics_core = main_core->GetPhysicsManager();
	Input* input_core = main_core->GetInputManager();
	UI* ui_core = main_core->GetUIManager();
	ScriptingCore* script_core = main_core->GetScriptManager();
	EntityManager* entity_core = main_core->GetEntityManager();
	Clock* clock_manager = main_core->GetClock();

	width = script_core->width;
	height = script_core->height;
	windowed = true;
	Init(width, height);
	/*
	TO DO IN CASE 2
	setup UI and Graphics for game logic
	*/
	//load music stream
	sound_core->Load("Song1.ogg");
	//load sound effect
	sfx_core = new SoundEffect("Jump.wav"); //#5 to play
			
	//variables used for entity setups
	LPCSTR fileName;
	float pos[3];
	float rot[3];
	float scale[3];
	for(int i = 0; i < 3; i++)
	{
		pos[i] = 0;
		rot[i] = 0;
		scale[i] = .1;
	}
	rot[0] = 180;

	//setup for player
	//DO SOMETHING HERE
	Entity* player;
	player = new Entity;
	player->SetEntity("player", "player");
	//REPLACE 0'S WITH POSITION VALUES
	pos[0] = -3, pos[1] = 2.5, pos[2] = 20;
	scale[0] = .1, scale[1] = .1, scale[2] = .1; 
	player->agentData.setPosition(pos);
	player->agentData.setRotation(rot);
	player->agentData.setScale(scale);
	physics_core->setAABB(D3DXVECTOR3(-3, 2.5, 20), D3DXVECTOR3(-3.01, 2.51, 20.01), true, "player");
	ai_core->regeisterPlayer(&player->agentData);

	//setup for enemy
	//DO SOMETHING HERE
	Entity* enemy;
	enemy = new Entity;
	enemy->SetEntity("enemy", "basic");
	//REPLACE 0'S WITH POSITION VALUES
	pos[0] = -3, pos[1] = 2.5, pos[2] = 20;
	scale[0] = .1, scale[1] = .1, scale[2] = .1; 
	enemy->agentData.setPosition(pos);
	enemy->agentData.setRotation(rot);
	enemy->agentData.setScale(scale);
	physics_core->setAABB(D3DXVECTOR3(-3, 2.5, 20), D3DXVECTOR3(-3.01, 2.51, 20.01), true, "enemy");
	ai_core->registerAgent(&enemy->agentData); //look at removing the 0 here for a behavior isnt needed as AI sits, it automatically cycles through all states of an enemy already
			
			
	//setup for platforms
	//DO SOMETHING HERE
	Entity* platform;
	platform = new Entity;
	platform->SetEntity("platform", "platform");
	//REPLACE 0'S WITH POSITION VALUES
	pos[0] = 0, pos[1] = 0, pos[2] = 20; //THIS WILL MOST LIKELY BE REMOVED AS MULTIPLE PLATFORMS NEED DIFFERENT POSITION AND ROTATION VALUES, DO BEFORE RENDERING WHEN CREATEING MULTIPLES OF THIS MESH
	scale[0] = 100, scale[1] = .01, scale[2] = .1; 
	platform->agentData.setPosition(pos);
	platform->agentData.setRotation(rot);
	platform->agentData.setScale(scale);
	physics_core->setAABB(D3DXVECTOR3(0, 0, 20), D3DXVECTOR3(0.01, 0.01, 20.01), true,  "platform");
	
	//load the mesh model to use
	Meshes cube;
	cube.load_meshes("cube.X", pD3DDevice);
	//cube.set_meshes(pos, rot, scale);
	//camera setup
	//DO SOMETHING HERE
	Camera camera;
	camera.Init();
	camera.SetAR(width, height);
	
	//tex to use to write
	Text gText;
	D3DXCreateFont(pD3DDevice, 30, 0, FW_BOLD, 0, false, 
                  DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY,
                  DEFAULT_PITCH | FF_DONTCARE, TEXT("Times New Roman"), 
                  &pFont);
	gText.Init(22, pD3DDevice);

	//light setup
	//DO SOMETHING HERE
	//graphics_core->PointLight(
		//D3DXVECTOR3(/*FILL IN*/),	//position
		//D3DXCOLOR(1, 1, 1, 1),		//diffuse
		//D3DXCOLOR(1, 1, 1, 1));		//ambient
			
			
			
	/*
	TEST THIS CHANGE WHERE NEEDED IF NEEDED
	Z AXIS LOCKED AT 50 FOR PLAYER AND GAME OBJECTS
	Z AXIS LOCKED AT 10 FOR CAMERA
	X AXIS AT 100 FOR BASE LINE OF DEMO
	X AXIS MATCHING PLAYER FOR CAMERA
	Y AXIS AT 100 FOR BASE LINE OF DEMO
	Y AXIS + 25 ABOVE PLAYER
	*/
	//variables for game loop
	bool jump;
	jump = false;
	float time;
	int gameState = 1;
	/*
	gamestate to tell the engine what state the game is in. Menu, Game Logic, Credtis, etc.
	swtich cases to switch between the different states running the appropiate functions
	state 1 - Menu
	state 2 - Game Logic
	state 3 - Credits
	state 4 - shutdown application
	*/
	MSG  msg;
    msg.message = WM_NULL;
	char str[128];
	RECT rect;
	sound_core->Play(false);
	if(clock_manager->GetFPS() < 60)
	{
		while(msg.message != WM_QUIT)
		{
			// If there are Window messages then process them.
			if(PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
			{
		       TranslateMessage( &msg );
		        DispatchMessage( &msg );
			}
			// Otherwise, do animation/game stuff.
			else
	     {
				switch(gameState)
				{
				case (1)://menu state
					/*
					TO DO IN CASE 1
					setup menu with UI and Graphics
					update
					render
					loop till user input to change gamestate
					*/
					//DO SOMETHING HERE
					
					pD3DDevice->BeginScene();
					pD3DDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0) , 1.0f, 0);
				
					GetClientRect(hWnd, &rect);
					sprintf(str, "Engine Demo");
					pFont->DrawText(NULL, str, -1, &rect,
							DT_TOP | DT_CENTER | DT_NOCLIP , D3DCOLOR_ARGB(255, 
							255, 
							255, 
							255			
							));
					gText.DisplayText("Play Demo - (1)", width / 2, height * 0.25f, 50, 25, WHITE);
					gText.DisplayText("Credits - (2)", width / 2, height * 0.5f, 50, 25, WHITE);
					gText.DisplayText("Exit Demo - (3)", width / 2, height * 0.75f, 50, 25, WHITE);
					pD3DDevice->EndScene();
					pD3DDevice->Present(0, 0, 0, 0);
					main_core->Update(enemy, gameState);
					if(input_core->OnePressed())
					{
						gameState = 2;
					}

					if(input_core->TwoPressed())
					{
						gameState = 3;
					}

					if(input_core->ThreePressed())
					{
						gameState = 4;
					}

					break;
				case (2)://game logic state
					float temp[3];
					float temp2[3];
					player->agentData.getPosition(temp);
					if(temp[1] <= 101)
						jump = false;

					if(input_core->EscPressed()) gameState = 1;

					if(input_core->APressed())
					{
						player->agentData.getPosition(temp);
						player->agentData.getAcceleration(temp2);
						temp[0] -= .2f;
						player->agentData.setPosition(temp);
						sfx_core->Play();
						/*
						temp2[0] -= .1f;
						physics_core->setAccel(temp2, "player");
						D3DXVECTOR3 vec;
						vec = physics_core->getVel("player");
						player->agentData.setAcceleration(temp2);
						temp[0] += vec.x;
						temp[1] += vec.y;
						temp[2] += vec.z;
						player->agentData.setPosition(temp);
						*/
					}

					if(input_core->DPressed())
					{
						player->agentData.getPosition(temp);
						player->agentData.getAcceleration(temp2);
						temp[0] += .2f;
						player->agentData.setPosition(temp);
						sfx_core->Play();
						/*
						temp2[0] += .1f;
						physics_core->setAccel(temp2, "player");
						D3DXVECTOR3 vec;
						vec = physics_core->getVel("player");
						player->agentData.setAcceleration(temp2);
						temp[0] += vec.x;
						temp[1] += vec.y;
						temp[2] += vec.z;
						player->agentData.setPosition(temp);
						*/
					}

					if(!jump)
					{
						if(input_core->SpaceBar())
						{
							jump = true;
							player->agentData.getPosition(temp);
							player->agentData.getAcceleration(temp2);
							/*
							temp2[1] += 1.0f;
							physics_core->setAccel(temp2, "player");
							D3DXVECTOR3 vec;
							vec = physics_core->getVel("player");
							player->agentData.setAcceleration(temp2);
							temp[0] += vec.x;
							temp[1] += vec.y;
							temp[2] += vec.z;
							player->agentData.setPosition(temp);
							*/
						}
					}

					//update
					main_core->Update(enemy, gameState);

for(int i = 0; i < physics_core->Core._collisions->length();i++)
{
//Pop the next collision off the stack:
physics_core->Core._collisions->getNext();
msgbuffer << physics_core->Core._collisions->currentCollision.boxA_ID;
msgbuffer << " is colliding with ";
msgbuffer << physics_core->Core._collisions->currentCollision.boxB_ID;
msgbuffer << "!\n";

char * tempString = new char[msgbuffer.str().length() + 1];
strcpy(tempString, msgbuffer.str().c_str());
//Sample collision handling (this just prints which box ID's are colliding in the output window in visual studio)
OutputDebugString(tempString);
}
				
					if (Wireframe)
					{
						pD3DDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
					}
					else
					{
						pD3DDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
					}
					pD3DDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0) , 1.0f, 0);
					camera.dxSetProjection(pD3DDevice);
					camera.dxSetView(pD3DDevice);
					pD3DDevice->BeginScene();

					enemy->agentData.getPosition(pos);
					enemy->agentData.getScale(scale);
					enemy->agentData.getRotation(rot);
					cube.set_meshes(pos, rot, scale);
					cube.draw_meshes(pD3DDevice);

					player->agentData.getPosition(pos);
					player->agentData.getScale(scale);
					player->agentData.getRotation(rot);
					cube.set_meshes(pos, rot, scale);
					cube.draw_meshes(pD3DDevice);

					platform->agentData.getPosition(pos);
					platform->agentData.getScale(scale);
					platform->agentData.getRotation(rot);
					cube.set_meshes(pos, rot, scale);
					cube.draw_meshes(pD3DDevice);

					GetClientRect(hWnd, &rect);
					sprintf(str, "GSP 420 Running Demo");
					pFont->DrawText(NULL, str, -1, &rect,
							DT_TOP | DT_LEFT | DT_NOCLIP , D3DCOLOR_ARGB(255, 
							255, 
							255, 
							255			
							));
					pD3DDevice->EndScene();
					pD3DDevice->Present(0, 0, 0, 0);
					break;
				case (3)://credits state
					//setup credits with UI and Graphics
					//loop till gameState changes
					//update
					pD3DDevice->BeginScene();
					pD3DDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(122, 0, 0) , 1.0f, 0);
				
					GetClientRect(hWnd, &rect);

					pFont->DrawText(NULL, str, -1, &rect,
							DT_TOP | DT_CENTER | DT_NOCLIP , D3DCOLOR_ARGB(255, 
							255, 
							255, 
							255			
							));

					gText.DisplayText("CREDITS:", width / 2, 35, 50, 25, WHITE);

					for (int i = 0; i < AUTHORS; i++)
					{
						gText.DisplayText(authors[i], width / 2, i * 25 + 60, 100, 10, WHITE);
					}

				
					pD3DDevice->EndScene();
					pD3DDevice->Present(0, 0, 0, 0);
					main_core->Update(enemy, gameState);

					if(input_core->EscPressed()) gameState = 1;

					break;
				case (4):	//shutdown application
					//shutdown
					main_core->Shutdown();
					pD3DDevice->Release();
					pD3DObject->Release();
					//destroy application
					msg.message = WM_QUIT;
					break;
				}
			}	
		}
		return (int)msg.wParam;
	}
}
Example #3
0
    void TextInit(DWORD size, LPDIRECT3DDEVICE9 device) {

        text->Init(size, device);

    }