TapestryEngine

A 2D Platformer Game Engine
Log | Files | Refs

8e814ec61bd836a85d906aefd7dd1addbfd38958.svn-base (3686B)


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