int main(int argc, char** argv) { (void) argc; (void) argv; /*srand(time(NULL));*/ #ifdef WIN32 { LARGE_INTEGER divisor; QueryPerformanceFrequency(&divisor); clockDivisor = divisor.QuadPart; } #else clockDivisor = CLOCKS_PER_SEC; #endif printf("Starting\nClock divisor: %lu\n", clockDivisor); struct graphics g = { #ifdef SHOWKEYS .width = 100, .height = 100, #else .width = 1200, .height = 900, #endif }; initiateGraphics(&g, "Test window"); if(!g.window) goto CLEANUP; /*thread t;*/ /*newThread(test, NULL, &t);*/ clockType frameStart, frameEnd, gameStart; getClockTime(&frameStart); initLogic(); loadEntities(); loadTileTextures(); initializeWorld(); initializeBullets(); initializeItems(); initializeItemFunctions(); luaStart(); getClockTime(&gameStart); while(1){ cameraTick(); renderGraphics(&g); oldMouseState = mouseState; mouseState = SDL_GetMouseState(&mouseX, &mouseY); if(oldMouseState != mouseState){ mouseEvent(); } for(SDL_Event event; SDL_PollEvent(&event);){ switch(event.type){ case SDL_QUIT: goto CLEANUP; case SDL_KEYDOWN: case SDL_KEYUP: if(event.key.keysym.scancode == 0x14) goto CLEANUP; //TODO keyEvent(event.key); break; } } getClockTime(&frameEnd); frameTime = getDiffClock(frameStart, frameEnd); appTime = getDiffClock(gameStart, frameEnd); frameStart = frameEnd; gameUpdate(); } CLEANUP: luaEnd(); uninitializeItems(); uninitializeItemFunctions(); uninitializeBullets(); uninitializeWorld(); unloadTileTextures(); unloadEntities(); destroyGraphics(&g); return 0; } float normalRandomFloat(){ return ((float) rand()) / ((float) RAND_MAX); } float randomFloat(float a, float b){ float diff = b - a; return a + normalRandomFloat() * diff; }
int main(){ int xposS = 370; char c; //user input int xdist = 0, ydist =0; int dx = 1; int Bnum = 0; int posB[2][10] = {0}; unsigned int i, j; gfx_open(SIZEX, SIZEY, "Space Invaders"); //open window initializeBullets(posB); while(true){ gfx_clear(); //clear screen dispScore(); uShooter(xposS); drawAliens(xdist, ydist); if(gfx_event_waiting()){ //if true c = gfx_wait(); //find choice if (c == 'b'){ xposS-=10; if (xposS <= 0) xposS = 0; }else if (c == 'n'){ xposS +=10; if (xposS >= SIZEX-30) xposS = SIZEX-30; }else if (c == ' '){ for(i=0; i<10; i++){ if(posB[0][i] == -1){ posB[0][i] = drawBullet(xposS); posB[1][i] = YPOS; } } }else if (c == 'q') return 0; else continue; } xdist+=dx; if(xdist>=370 || xdist <=-100){ dx*=-1; } if(xdist == 370 || xdist ==-100){ ydist +=5; } if(ydist == 225) return 0; //change lives num for(j=0; j<10; j++){ if(posB[0][j] != -1){ moveBullet(posB, j); } checkBullet(posB,j); } usleep(25000); gfx_flush(); } }