From ff9b00848aa601cfd921b7074584e54e31d20782 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Mon, 5 Oct 2015 08:39:39 -0400 Subject: better Makefile --- src/main.cpp | 240 ----------------------------------------------------------- 1 file changed, 240 deletions(-) delete mode 100644 src/main.cpp (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp deleted file mode 100644 index fdb7d32..0000000 --- a/src/main.cpp +++ /dev/null @@ -1,240 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#define TICKS_PER_SEC 20 -#define MSEC_PER_TICK (1000/TICKS_PER_SEC) - -SDL_Window *window = NULL; -SDL_Surface *renderSurface = NULL; -SDL_GLContext mainGLContext = NULL; - -bool gameRunning = true; - -World *currentWorld=NULL; -Player *player; - -std::vectorentity; -std::vectornpc; -std::vectorbuild; - -int mx, my; -FILE* names; - -Mix_Music *music; -Mix_Chunk *horn; - -extern void initEverything(void); - -void logic(); -void render(); -void mainLoop(void); - -unsigned int millis(void){ - std::chrono::system_clock::time_point now=std::chrono::system_clock::now(); - return std::chrono::duration_cast(now.time_since_epoch()).count(); -} - -int main(int argc, char *argv[]){ - // Initialize SDL - if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0){ - std::cout << "SDL was not able to initialize! Error: " << SDL_GetError() << std::endl; - return -1; - } - atexit(SDL_Quit); - // Initialize SDL_image - if(!(IMG_Init(IMG_INIT_PNG|IMG_INIT_JPG)&(IMG_INIT_PNG|IMG_INIT_JPG))){ - std::cout<<"Could not init image libraries!\n"<= millis()){ - logic(); - prevTime = millis(); - } - - player->loc.y+=player->vel.y*deltatime; - player->loc.x+=(player->vel.x*player->speed)*deltatime; - for(int i=0;i<=entity.size();i++){ - entity[i]->loc.x += entity[i]->vel.x * deltatime; - entity[i]->loc.y += entity[i]->vel.y * deltatime; - if(entity[i]->vel.x<0)entity[i]->left=true; - if(entity[i]->vel.x>0)entity[i]->left=false; - } - - if(++debugDiv==20){ - fps=1000/deltatime; - debugDiv=0; - }else if(!(debugDiv%10)){ - debugY = player->loc.y; - } - - render(); -} - -void render(){ - //a matrix is a blank canvas for the computer to draw on, the matrices are stored in a "stack" - //GL_PROJECTION has 2 matrices - //GL_MODELVIEW has 32 matrices - glMatrixMode(GL_PROJECTION); //set the matrix mode as projection so we can set the ortho size and the camera settings later on - glPushMatrix(); //push the matrix to the top of the matrix stack - glLoadIdentity(); //replace the entire matrix stack with the updated GL_PROJECTION mode - glOrtho(player->loc.x-SCREEN_WIDTH/2,player->loc.x+SCREEN_WIDTH/2,0,SCREEN_HEIGHT,-1,1); - glMatrixMode(GL_MODELVIEW); //set the matrix to modelview so we can draw objects - glPushMatrix(); //push the matrix to the top of the matrix stack - glLoadIdentity(); //replace the entire matrix stack with the updated GL_MODELVIEW mode - glPushMatrix(); //basically here we put a blank canvas (new matrix) on the screen to draw on - glPushAttrib( GL_DEPTH_BUFFER_BIT | GL_LIGHTING_BIT ); - glClear(GL_COLOR_BUFFER_BIT); //clear the matrix on the top of the stack - - /************************** - **** RENDER STUFF HERE **** - **************************/ - - currentWorld->draw(&player->loc); // Draw the world around the player - glColor3ub(0,0,0); - player->near=true; - player->draw(); // Draw the player - player->inv->draw(); - - ui::draw(); // Draw any UI elements if they need to be - - if(ui::debug){ - ui::setFontSize(16); - ui::putText(player->loc.x-SCREEN_WIDTH/2,SCREEN_HEIGHT-ui::fontSize,"FPS: %d\nG:%d\nRes: %ux%u\nE: %d\nPOS: (x)%+.2f\n (y)%+.2f\nQc: %u", - fps,player->ground,SCREEN_WIDTH,SCREEN_HEIGHT,entity.size(),player->loc.x,debugY,player->qh.current.size()); - } - - /************************** - **** CLOSE THE LOOP **** - **************************/ - mx = ui::mouse.x + player->loc.x; - my = ui::mouse.y; - my = 720 - my; - mx -= (SCREEN_WIDTH/2); - glColor3ub(255,255,255); - glBegin(GL_TRIANGLES); - glVertex2i(mx,my); - glVertex2i(mx+HLINE*3.5,my); - glVertex2i(mx,my-HLINE*3.5); - glEnd(); - - glPopMatrix(); //take the matrix(s) off the stack to pass them to the renderer - SDL_GL_SwapWindow(window); //give the stack to SDL to render it -} - -void logic(){ - ui::handleEvents(); - currentWorld->detect(player); - for(int i=0;i<=entity.size();i++){ - if(entity[i]->alive&&entity[i]->type == NPCT){ - entity[i]->wander((rand()%120 + 30), &entity[i]->vel); - if( pow((entity[i]->loc.x - player->loc.x),2) + pow((entity[i]->loc.y - player->loc.y),2) <= pow(40*HLINE,2)){ - if(mx >= entity[i]->loc.x && mx <= entity[i]->loc.x + entity[i]->width && my >= entity[i]->loc.y && my <= entity[i]->loc.y + entity[i]->width){ - entity[i]->near=true; - if(SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(SDL_BUTTON_RIGHT)){ - entity[i]->interact(); - std::cout <<"["< "<< entity[i]->name << ", " << (std::string)(entity[i]->gender == MALE ? "Male" : "Female") << std::endl; - //Mix_PlayChannel( -1, horn, 0); - } - }else entity[i]->near=false; - } - } - } -} -- cgit v1.2.3