void initData(void) { /* lasttime = SystemGetElapsedTime(); */ game->pauseflag = PAUSE_GAME_RUNNING; game2->rules.speed = getSettingf("speed"); game2->rules.eraseCrashed = getSettingi("erase_crashed"); game2->rules.grid_size = getSettingi("grid_size"); game2->grid.width = game2->rules.grid_size; game2->grid.height = game2->rules.grid_size; /* time management */ game2->time.lastFrame = 0; game2->time.current = 0; game2->time.offset = SystemGetElapsedTime(); /* TODO: fix that */ game2->players = game->players; /* event management */ game2->events.next = NULL; /* TODO: free any old events that might have gotten left */ resetVideoData(); resetPlayerData(); initWalls(); }
void initGui() { menutime = SystemGetElapsedTime(); if(pCurrent == NULL) { pCurrent = *pMenuList; /* erstes Menu ist RootMenu - Default pCurrent */ pCurrent->iHighlight = 0; } }
int updateTime() { game2->time.lastFrame = game2->time.current; game2->time.current = SystemGetElapsedTime() - game2->time.offset; game2->time.dt = game2->time.current - game2->time.lastFrame; /* fprintf(stderr, "dt: %d\n", game2->time.dt); */ return game2->time.dt; }
int processEvent(GameEvent* e) { int value = 0; Data *data; if(game2->mode == GAME_SINGLE_RECORD) { writeEvent(e); } switch(e->type) { case EVENT_TURN_LEFT: data = game->player[e->player].data; if(data->speed > 0) { data->iposx = e->x; data->iposy = e->y; data->turn = TURN_LEFT; doTurn(data, e->timestamp); } break; case EVENT_TURN_RIGHT: data = game->player[e->player].data; if(data->speed > 0) { data->iposx = e->x; data->iposy = e->y; data->turn = TURN_RIGHT; doTurn(data, e->timestamp); } break; case EVENT_CRASH: data = game->player[e->player].data; data->posx = data->iposx = e->x; data->posy = data->iposy = e->y; sprintf(messages, "player %d crashed", e->player + 1); fprintf(stderr, "%s\n", messages); consoleAddLine(messages); crashPlayer(e->player); break; case EVENT_STOP: fprintf(stderr, "game stopped\n"); if(game2->mode == GAME_SINGLE_RECORD) { stopRecording(); game2->mode = GAME_SINGLE; } else if(game2->mode == GAME_PLAY) { stopPlaying(); game2->mode = GAME_SINGLE; } game->winner = e->player; sprintf(messages, "winner: %d", game->winner + 1); printf("%s\n", messages); consoleAddLine(messages); switchCallbacks(&pauseCallbacks); /* screenSaverCheck(0); */ stoptime = SystemGetElapsedTime(); game->pauseflag = PAUSE_GAME_FINISHED; value = 1; break; } free(e); return value; }
void drawPause(Visual *display) { char pause[] = "Game is paused"; char winner[] = "Player %d wins!"; char nowinner[] = "No one wins!"; char buf[100]; char *message; static float d = 0; static float lt = 0; float delta; int now; now = SystemGetElapsedTime(); delta = now - lt; lt = now; delta /= 500.0; d += delta; /* printf("%.5f\n", delta); */ if (d > 2 * PI) { d -= 2 * PI; } if ((game->pauseflag & PAUSE_GAME_FINISHED) && game->winner != -1) { if (game->winner >= -1) { float* player_color = gPlayerVisuals[game->winner].pColorAlpha; /* make the 'Player wins' message oscillate between white and the winning bike's color */ //TODO: check this glColor4f((player_color[0] + ((sinf(d) + 1) / 2) * (1 - player_color[0])), (player_color[1] + ((sinf(d) + 1) / 2) * (1 - player_color[1])), (player_color[2] + ((sinf(d) + 1) / 2) * (1 - player_color[2])), 1.0); message = buf; sprintf(message, winner, game->winner + 1); } else { //TODO:DONE redo for gles glColor4f(1.0, (sin(d) + 1) / 2, (sin(d) + 1) / 2,1.0f); message = nowinner; } } else { //TODO:DONE redo for gles glColor4f(1.0, (sin(d) + 1) / 2, (sin(d) + 1) / 2,1.0f); message = pause; } rasonly(gScreen); drawText(gameFtx, display->vp_w / 6, 20, display->vp_w / (6.0f / 4.0f * strlen(message)), message); }
void idlePause() { #ifdef SOUND soundIdle(); #endif /* if(SystemGetElapsedTime() - lasttime < 10) return; timediff(); */ doCameraMovement(); if(game->settings->screenSaver && stoptime != 0 && SystemGetElapsedTime() - stoptime > 2000) { initData(); stoptime = 0; switchCallbacks(&gameCallbacks); } SystemPostRedisplay(); }
void idlePause() { #ifdef __NETWORK__ int sockstat; #endif #ifdef SOUND soundIdle(); #endif #ifdef __NETWORK__ if( game2->mode == GAME_NETWORK_PLAY && serverstate == gameState ) { initTurnList(); stoptime = 0; switchCallbacks(&gameCallbacks); } else { if( game2->mode == GAME_NETWORK_PLAY && isConnected ) { sockstat = Net_checksocks(); if( sockstat != socksnotready ) { if( sockstat & tcpsockready ) handleServer(); } } } #endif /* if(SystemGetElapsedTime() - lasttime < 10) return; timediff(); */ doCameraMovement(); if(game->settings->screenSaver && stoptime != 0 && SystemGetElapsedTime() - stoptime > 2000) { initData(); stoptime = 0; switchCallbacks(&gameCallbacks); } SystemPostRedisplay(); }
void initData() { int i; /* colmap */ /* TODO: check if grid_size/colwidth has changed and * reallocate colmap accordingly */ colwidth = game->settings->grid_size; if(colmap != NULL) free(colmap); colmap = (unsigned char*) malloc(colwidth * game->settings->grid_size); for(i = 0; i < colwidth * game->settings->grid_size; i++) *(colmap + i) = 0; if(debugtex != NULL) free(debugtex); debugtex = (unsigned char*) malloc(4 * DEBUG_TEX_W * DEBUG_TEX_H); memset(debugtex, 0, 4 * DEBUG_TEX_W * DEBUG_TEX_H); ogl_debugtex = 0; /* lasttime = SystemGetElapsedTime(); */ game->pauseflag = 0; game2->rules.speed = game->settings->current_speed; game2->rules.eraseCrashed = game->settings->erase_crashed; /* time management */ game2->time.lastFrame = 0; game2->time.current = 0; game2->time.offset = SystemGetElapsedTime(); /* TODO: fix that */ game2->players = game->players; /* event management */ game2->events.next = NULL; /* TODO: free any old events that might have gotten left */ initPlayerData(); initClientData(); }
void drawCredits() { int time; int x, y; int h; int i; float colors[][3] = { { 1.0, 0.0, 0.0 }, { 1.0, 1.0, 1.0 } }; time = SystemGetElapsedTime() - coffset; glClearColor(.0, .0, .0, .0); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); rasonly(game->screen); h = game->screen->vp_h / (24 * 1.5); for(i = 0; i < time / 250; i++) { glColor3fv(colors[i % 2]); if(credits[i] == NULL) break; x = 10; y = game->screen->vp_h - 1.5 * h * (i + 1); drawText(gameFtx, x, y, h, credits[i]); } }
void enterGame(void) { /* called when game mode is entered */ updateSettingsCache(); SystemHidePointer(); // SystemWarpPointer(MOUSE_ORIG_X, MOUSE_ORIG_Y); game2->time.offset = SystemGetElapsedTime() - game2->time.current; Audio_EnableEngine(); // disable booster and cam offset { int i; for(i = 0; i < game->players; i++) { game->player[i].data->boost_enabled = 0; game->player[i].camera->movement[CAM_PHI_OFFSET] = 0; } } /* reset pause flag */ if (game->pauseflag != PAUSE_GAME_FINISHED) { game->pauseflag = PAUSE_GAME_RUNNING; } /* fprintf(stderr, "init game\n"); */ }
void Time_Idle(void) { game2->time.lastFrame = game2->time.current; game2->time.current = SystemGetElapsedTime() - game2->time.offset; game2->time.dt = game2->time.current - game2->time.lastFrame; /* fprintf(stderr, "dt: %d\n", game2->time.dt); */ }
void playerCamera(PlayerVisual *pV, Player *p) { float dest[3]; float tdest[3]; float phi, chi, r; float x, y; Camera *cam; Data *data; /* first, process all movement commands */ /* that means, check for mouse input mainly */ /* dt hack: the time since the last frame is not necessarily the game time, since the game maybe hasn't started yet, or was paused */ static int last=0; int dt; if(game2->time.dt == 0) { dt = SystemGetElapsedTime() - last; last = SystemGetElapsedTime(); } else { dt = game2->time.dt; } cam = p->camera; data = p->data; getPositionFromData(&x, &y, data); if(cam->type.freedom[CAM_FREE_R]) { if(gInput.mouse1 == 1) cam->movement[CAM_R] += (cam->movement[CAM_R]-CLAMP_R_MIN+1) * dt / 300.0f; if(gInput.mouse2 == 1) cam->movement[CAM_R] -= (cam->movement[CAM_R]-CLAMP_R_MIN+1) * dt / 300.0f; writeCamDefaults(cam, CAM_R); } if(cam->type.freedom[CAM_FREE_PHI]) { cam->movement[CAM_PHI] += - gInput.mousex * MOUSE_CX; writeCamDefaults(cam, CAM_CHI); } if(cam->type.freedom[CAM_FREE_CHI]) { cam->movement[CAM_CHI] += gInput.mousey * MOUSE_CY; writeCamDefaults(cam, CAM_PHI); } /* done with mouse movement, now clamp the camera to legal values */ clampCam(cam); phi = cam->movement[CAM_PHI] + cam->movement[CAM_PHI_OFFSET]; chi = cam->movement[CAM_CHI]; r = cam->movement[CAM_R]; /* if the cam is coupled to player movement, change the phi accordingly */ if(cam->type.coupled) { int time = game2->time.current - p->data->turn_time; if(time < TURN_LENGTH) { int dir, ldir; dir = p->data->dir; ldir = p->data->last_dir; if(dir == 1 && ldir == 2) dir = 4; if(dir == 2 && ldir == 1) ldir = 4; phi += ((TURN_LENGTH - time) * camAngles[ldir] + time * camAngles[dir]) / TURN_LENGTH; } else phi += camAngles[p->data->dir]; } /* position the camera */ dest[0] = x + r * cosf(phi) * sinf(chi); dest[1] = y + r * sinf(phi) * sinf(chi); dest[2] = r * cosf(chi); /* ok, now let's calculate the new camera destination coordinates */ /* also, perform some camera dependant movement */ switch(cam->type.type) { case CAM_TYPE_CIRCLING: /* Andi-cam */ cam->movement[CAM_PHI] += CAM_SPEED * game2->time.dt; tdest[0] = x; tdest[1] = y; tdest[2] = B_HEIGHT; break; case CAM_TYPE_FOLLOW: /* Mike-cam */ tdest[0] = x; tdest[1] = y; tdest[2] = B_HEIGHT; break; case CAM_TYPE_COCKPIT: /* 1st person */ tdest[0] = x + 4.0f * dirsX[ p->data->dir ] + 2.0f * cosf(phi); tdest[1] = y + 4.0f * dirsY[ p->data->dir ] + 2.0f * sinf(phi); tdest[2] = CAM_COCKPIT_Z; dest[0] = x + 4.0f * dirsX[ p->data->dir ] + 0.1f * cosf(phi); dest[1] = y + 4.0f * dirsY[ p->data->dir ] + 0.1f * sinf(phi); dest[2] = CAM_COCKPIT_Z + 0.1f; break; case CAM_TYPE_MOUSE: /* mouse camera */ tdest[0] = x; tdest[1] = y; tdest[2] = B_HEIGHT; break; } memcpy(cam->cam, dest, sizeof(cam->cam)); memcpy(cam->target, tdest, sizeof(cam->target)); }
void initCredits() { coffset = SystemGetElapsedTime(); }