TapestryEngine

A 2D Platformer Game Engine
Log | Files | Refs

c5469d9b56e5ca42078edadacd36844e27d0a405.svn-base (3905B)


      1 #include "Utils.h"
      2 #include "Console.h"
      3 #include "MiscDraw.h"
      4 #include "DiagnosticDraw.h"
      5 #include "ActorCollision.h"
      6 #include "Input.h"
      7 #include "Actor.h"
      8 #include "sound.h"
      9 
     10 #include "Dialogue.h"
     11 
     12 #include "Loading.h"
     13 #include "Level.h"
     14 
     15 #include "BinaryTree.h" //remove later
     16 
     17 FILE _iob[] = { *stdin, *stdout, *stderr };
     18 
     19 extern "C" FILE * __cdecl __iob_func(void)
     20 {
     21 	return _iob;
     22 }
     23 
     24 int main(int argc, char *argv[])
     25 {
     26 	gTime = new Time();
     27 	gRandom = new Random();
     28 
     29 	TTF_Init();
     30 //	BinaryTree TestTree = BinaryTree(new Node(10, NULL));
     31 //	TestTree.Insert(5, NULL);
     32 //	TestTree.Insert(15, NULL);
     33 //	TestTree.Insert(7, NULL);
     34 //	TestTree.Insert(2, NULL);
     35 //	TestTree.Insert(20, NULL);
     36 //	TestTree.Insert(17, NULL);
     37 //	TestTree.Insert(35, NULL);
     38 //	TestTree.Insert(31, NULL);
     39 //	int s = TestTree.Size();
     40 
     41 //	Node** contents = TestTree.Dump();
     42 
     43 	//Node* tar = TestTree.Search(5);//->Delete();
     44 
     45 	//char buff1[256];
     46 	//memset(buff1, 0, sizeof(buff1));
     47 	//ReadBTree(&TestTree, buff1);
     48 	//tar->Delete();
     49 	//char buff2[256];
     50 	//memset(buff2, 0, sizeof(buff2));
     51 	//ReadBTree(&TestTree, buff2);
     52 
     53 //	Node* Tree = new Node();
     54 //	Tree->InsertNode()
     55 
     56 	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_AUDIO) != 0)
     57 	{
     58 		gCons->ConsPrintf("SDL_Init Error: %s\n", SDL_GetError());
     59 		SDL_Quit();
     60 		return 1;
     61 	}
     62 
     63 	Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048);
     64 //	Mix_Init(MIX_INIT_MP3);
     65 
     66 	if (TTF_Init() != 0)
     67 	{
     68 		gCons->ConsPrintf("TTF_Init Error: %s\n", TTF_GetError());
     69 		TTF_Quit();
     70 		SDL_Quit();
     71 		return 1;
     72 	}
     73 
     74 
     75 	SDL_Window* window = SDL_CreateWindow("Bandana Marathon", 10, 30, SCREEN_W, SCREEN_H, SDL_WINDOW_SHOWN);
     76 	if (window == NULL)
     77 	{
     78 		gCons->ConsPrintf("SDL_CreateWindow Error: %s", SDL_GetError());
     79 		SDL_Quit();
     80 		return 1;
     81 	}
     82 
     83 	SDL_Renderer* ren = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
     84 	if (ren == NULL)
     85 	{
     86 		gCons->ConsPrintf("SDL_CreateRenderer Error: %s", SDL_GetError());
     87 		SDL_Quit();
     88 		return 1;
     89 	}
     90 
     91 #ifdef DEBUG
     92 	SDL_Color fg = { 255, 255, 255 };
     93 	SDL_Color bg = { 0, 0, 255 };
     94 	gCons = new Console("ARIAL.TTF", 12, fg, bg);
     95 	//gCons = new Console("Tapestry.ttf", 16, fg, bg);
     96 #endif // DEBUG
     97 
     98 
     99 	Control ctrl = Control();
    100 
    101 	ContextManager ConMan = ContextManager("level_arid_land.json");
    102 
    103 	Level* lvl = new Level(ren, &ctrl);
    104 	ConMan.LogContext(lvl, "level");
    105 	//DiagnosticDraw* gDiagDraw = new DiagnosticDraw(ren, lvl->mCam);
    106 
    107 	Loading* load = new Loading(ren);
    108 	ConMan.LogContext(load, "load");
    109 	
    110 	MapTest* map_test = new MapTest(ren);
    111 	ConMan.LogContext(map_test, "map_test");
    112 
    113 	ConMan.LoadContext("map_test");
    114 	ConMan.ContextUpdate();
    115 	SDL_RenderPresent(ren);
    116 
    117 	//ConMan.LoadContext("load");
    118 	//ConMan.ContextUpdate();
    119 	//SDL_RenderPresent(ren);
    120 
    121 	//ConMan.LoadContext("level");
    122 
    123 	//Mix_Chunk* dhaka = LoadSound("Dhaka.mp3");
    124 	//Mix_Chunk* ftst = LoadSound("footstep.wav");
    125 
    126 	SDL_Event e;
    127 
    128 	//if (Mix_PlayingMusic() == false)
    129 	//{
    130 		//Mix_PlayMusic(dhaka, -1);
    131 		//Mix_Volume(1, 6);
    132 		//Mix_VolumeChunk(dhaka, 6);
    133 		//Mix_PlayChannel(1, dhaka, -1);
    134 
    135 	//}
    136 	bool quit = false;
    137 	while (!quit)
    138 	{
    139 		int CycleStart = GetRealTimeMS();
    140 		//srand(time(NULL));
    141 
    142 		SDL_RenderClear(ren);
    143 
    144 		ctrl.ProcessKeyboard();
    145 
    146 		ConMan.ContextUpdate();
    147 
    148 		//PrintBTree(&TestTree);
    149 
    150 #ifdef DEBUG
    151 		gCons->DrawConsole(ren); //Console is currently causing crashes for unknown reasons. No changes made to console system; very confusing
    152 #endif
    153 
    154 		SDL_RenderPresent(ren);
    155 
    156 		SDL_PollEvent(&e);
    157 
    158 		if (e.type == SDL_QUIT)
    159 		{
    160 			quit = true;
    161 		}
    162 
    163 		gTime->ProgressCycle();
    164 
    165 		int DeltaTime = (GetRealTimeMS() - CycleStart);
    166 		assert(DeltaTime >= 0);
    167 
    168 		int DelayTime = MS_PER_FRAME - DeltaTime;
    169 
    170 		if (DelayTime >= 0)
    171 		{
    172 			//gCons->ConsPrintf("Delay Time: %i \n", DelayTime);
    173 			SDL_Delay(DelayTime);
    174 		}
    175 		else
    176 		{
    177 			//gCons->ConsPrintf("Delay Time: %i FRAME DROP\n", DelayTime);
    178 		}
    179 	}
    180 
    181 	delete gCons;
    182 	SDL_DestroyWindow(window);
    183 	SDL_Quit();
    184 	return 0;
    185 }