void display(SDL_Window* screen){ glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); detectcollision(); arrow.setbuffers(); arrow.draw(); int i; for(i=0; i<objectarray.size; i++){ objectarray.array[i].setbuffers(); objectarray.array[i].draw(); } glFlush(); SDL_GL_SwapWindow(screen); }
/* the code that runs in each thread */ void *animate(void *arg) { struct element *info = arg; /* point to info block */ int len = strlen(info->str)+2; /* +2 for padding */ int i; while( 1 ) { detectcollision(); usleep(info->delay*TUNIT); // Handle alive code if (info->alive) { // Handle player specific code, always alive if (info->type == 0) { scrtxtdraw(); pthread_mutex_lock(&movelock); eledraw(arg); pthread_mutex_unlock(&movelock); } // Handle saucer code else if (info->type == 1) { eledraw(arg); info->col++; // end of screen, escape and die if (info->col+len >= COLS) { pthread_mutex_lock(&escapelock); escape++; pthread_mutex_unlock(&escapelock); eleclear(arg, len); resetscr(arg); } } // Handle bullet code else { eleclear(arg,len); pthread_mutex_lock(&firelock); info->row--; eledraw(arg); // top of screen, escape and die if (info->row <=0) { eleclear(arg,len); resetbls(arg); } pthread_mutex_unlock(&firelock); } } // Handle not alive code, player is never here else { // Handle saucer code if (info->type == 1) { eleclear(arg,len); info->respawn--; if (!info->respawn) { info->alive=1; rowscrinit(arg); } } // Handle bullet code else if (info->type == 2) { eleclear(arg, len); } } } }