TapestryEngine

A 2D Platformer Game Engine
Log | Files | Refs

f5e7c090d18d14e5102d9282859c8b166685c4a5.svn-base (3434B)


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