void available_levels(al_defs *al) { bool quit=false; level_list *list = get_level_list(); level_list_mem *p = list->first; level* l = NULL; while(!quit) { al_clear_to_color(al_map_rgb(0,0,0)); al_draw_text(al->logo_font,al_map_rgb(255,255,255),al->width/2, 20,ALLEGRO_ALIGN_CENTRE,"sokoban"); al_draw_text(al->menu_font,al_map_rgb(255,255,255), al->width/2, 160, ALLEGRO_ALIGN_CENTRE,"Select your level:"); al_draw_textf(al->menu_font, al_map_rgb(255,0,0), al->width/2, al->height/2, ALLEGRO_ALIGN_CENTRE, "%s", p->name); al_draw_text(al->hint_font, al_map_rgb(120, 120, 120), 10, al->height-30, ALLEGRO_ALIGN_LEFT, "Use arrows to navigate, ENTER to choose, Esc to return to the main screen"); al_flip_display(); ALLEGRO_EVENT ev; al_wait_for_event(al->queue, &ev); if(ev.type == ALLEGRO_EVENT_KEY_DOWN) { //printf("EVENT KEYCODE: %d\n",ev.keyboard.keycode); switch(ev.keyboard.keycode) { case ALLEGRO_KEY_ESCAPE: quit=true; break; case ALLEGRO_KEY_ENTER: do { if(l!=NULL) free_level(l); l = read_level(p->name); if(l==NULL) break; }while(play_level(al, l, p->name)); free_level(l); l=NULL; break; case ALLEGRO_KEY_LEFT: p=p->prev; break; case ALLEGRO_KEY_RIGHT: p=p->next; break; } } } }
void templateAppExit( void ) { free_level(); thread = THREAD_free( thread ); AUDIO_stop(); }
void l_arena_exit(void) { resetgamestatus(ARENA_MODE); #ifndef MSDOS_SUPPORTED_ANTIQUE free_level(Level); #endif Level = NULL; change_environment(E_CITY); }
/* Deallocate current dungeon */ void free_dungeon(void) { plv tlv; while (Dungeon != NULL) { tlv = Dungeon; Dungeon = Dungeon->next; free_level(tlv); } }
void l_house_exit(void) { if (optionp(CONFIRM)) { clearmsg(); if (cinema_confirm("You're about to step out of this abode.") != 'y') return; } #ifndef MSDOS_SUPPORTED_ANTIQUE free_level(Level); #endif Level = NULL; change_environment(Last_Environment); }
void l_tactical_exit(void) { if (optionp(CONFIRM)) { if (cinema_confirm("You're about to leave this place.") != 'y') return; } /* Free up monsters and items, and the level, if not SAVE_LEVELS */ free_level(Level); Level = NULL; if ((Current_Environment == E_TEMPLE) || (Current_Environment == E_TACTICAL_MAP) ) change_environment(E_COUNTRYSIDE); else change_environment(Last_Environment); }
int main(int argc, char *argv[]) { FILE *t; struct level *map; char level_name[LEVELNAMESZ]; int asset_width = 32, asset_height = 32, i; printf("Soko v1.0 by Boro Sitnikovski\n=============================\n"); if (argc > 1) { strncpy(level_name, argv[1], LEVELNAMESZ-1); } else { printf("Enter a valid level name (levels/*.dat): "); if (fgets(level_name, LEVELNAMESZ, stdin) == NULL) { printf("Enter a valid level, m8.\n"); return 0; } } /* remove newlines */ i = strlen(level_name) - 1; while (level_name[i] == '\r' || level_name[i] == '\n') i--; level_name[i+1] = '\0'; /* attempt to parse level */ map = read_level(level_name); if (map == NULL) { printf("Error: Cannot parse level.\n"); return 0; } /* parse assets */ t = fopen("assets.cfg", "r"); if (t) { fscanf(t, "%d %d", &asset_width, &asset_height); fclose(t); } /* main SDL loop */ sokosdl_main(map, asset_width, asset_height); /* release level */ free_level(&map); return 1; }
/* Deallocate current dungeon */ void free_dungeon(void) { #ifndef SAVE_LEVELS plv tlv; while (Dungeon != NULL) { tlv = Dungeon; Dungeon = Dungeon->next; free_level(tlv); } #else if (Dungeon != NULL) { sprintf(Str2,"om%d*.lev",Dungeon->environment); kill_levels(Str2); } #endif }
/* loads the city level */ void load_city(int populate) { int i,j; pml ml; char site; map *city; map *maze; initrand(E_CITY, 0); /* Get the hedge maze (which is in the city). */ maze = map_open(MAP_hedges); /* Choose a random level from it. */ map_setLevel(maze, random_range(map_getDepth(maze))); /* Get the city. */ city = map_open(MAP_city); map_setLevel(city,0); TempLevel = Level; if (ok_to_free(TempLevel)) { #ifndef SAVE_LEVELS free_level(TempLevel); #endif TempLevel = NULL; } #ifndef SAVE_LEVELS Level = ((plv) checkmalloc(sizeof(levtype))); #else msdos_changelevel(TempLevel,0,-1); Level = &TheLevel; #endif clear_level(Level); Level->depth = 0; Level->environment = E_CITY; /* WDT: Rampart, as a special case, has its width stored in a * global variable. */ WIDTH = Level->level_width = map_getWidth(city); LENGTH = Level->level_length = map_getLength(city); for(j=0; j<Level->level_length; j++) { for(i=0; i<Level->level_width; i++) { lset(i,j,SEEN); site = map_getSiteChar(city,i,j); switch(site) { /* case '@': Player.x = i; Player.y = j; Level->site[i][j].locchar = FLOOR; break; */ case 'g': Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = L_GARDEN; break; case 'y': Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = L_CEMETARY; break; case 'p': /* WDT: each of these places needs to be assigned * a function (or replaced with an 'x' in the map) */ case '!': case 'I': case 'E': case 'e': case 'x': assign_city_function(i,j); break; case 't': Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = L_TEMPLE; CitySiteList[L_TEMPLE-CITYSITEBASE][0] = TRUE; CitySiteList[L_TEMPLE-CITYSITEBASE][1] = i; CitySiteList[L_TEMPLE-CITYSITEBASE][2] = j; break; #if 0 /* WDT: HACK! The new city doesn't use portcullis traps, but has other * uses for 'T'. Um... I'd rather have a use for them (that's what * the jail is supposed to be), so this will stay only for now; with * any luck we'll have things fixed up before the next release. */ case 'T': Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = L_PORTCULLIS_TRAP; Level->site[i][j].aux = NOCITYMOVE; break; #endif /* end of hack */ case 'R': Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = L_RAISE_PORTCULLIS; Level->site[i][j].aux = NOCITYMOVE; break; case '7': Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = L_PORTCULLIS; Level->site[i][j].aux = NOCITYMOVE; break; case 'C': Level->site[i][j].locchar = OPEN_DOOR; Level->site[i][j].p_locf = L_COLLEGE; CitySiteList[L_COLLEGE-CITYSITEBASE][0] = TRUE; CitySiteList[L_COLLEGE-CITYSITEBASE][1] = i; CitySiteList[L_COLLEGE-CITYSITEBASE][2] = j; break; case 's': Level->site[i][j].locchar = OPEN_DOOR; Level->site[i][j].p_locf = L_SORCERORS; CitySiteList[L_SORCERORS-CITYSITEBASE][0] = TRUE; CitySiteList[L_SORCERORS-CITYSITEBASE][1] = i; CitySiteList[L_SORCERORS-CITYSITEBASE][2] = j; break; case 'M': Level->site[i][j].locchar = OPEN_DOOR; Level->site[i][j].p_locf = L_MERC_GUILD; CitySiteList[L_MERC_GUILD-CITYSITEBASE][0] = TRUE; CitySiteList[L_MERC_GUILD-CITYSITEBASE][1] = i; CitySiteList[L_MERC_GUILD-CITYSITEBASE][2] = j; break; case 'K': Level->site[i][j].locchar = OPEN_DOOR; Level->site[i][j].p_locf = L_MONASTERY; CitySiteList[L_MONASTERY-CITYSITEBASE][0] = TRUE; CitySiteList[L_MONASTERY-CITYSITEBASE][1] = i; CitySiteList[L_MONASTERY-CITYSITEBASE][2] = j; break; case 'c': Level->site[i][j].locchar = OPEN_DOOR; Level->site[i][j].p_locf = L_CASTLE; CitySiteList[L_CASTLE-CITYSITEBASE][0] = TRUE; CitySiteList[L_CASTLE-CITYSITEBASE][1] = i; CitySiteList[L_CASTLE-CITYSITEBASE][2] = j; break; case '?': { static int myI = -1, myJ; char site; if ( myI == -1 ) { /* If this is the first time we've seen the hedge maze, * set this as its corner. */ myI = i; myJ = j; } site = map_getSiteChar(maze, i - myI, j - myJ); mazesite(site,i,j,populate); } break; case 'P': Level->site[i][j].locchar = OPEN_DOOR; Level->site[i][j].p_locf = L_ORDER; CitySiteList[L_ORDER-CITYSITEBASE][0] = TRUE; CitySiteList[L_ORDER-CITYSITEBASE][1] = i; CitySiteList[L_ORDER-CITYSITEBASE][2] = j; break; case 'H': Level->site[i][j].locchar = OPEN_DOOR; Level->site[i][j].p_locf = L_CHARITY; CitySiteList[L_CHARITY-CITYSITEBASE][0] = TRUE; CitySiteList[L_CHARITY-CITYSITEBASE][1] = i; CitySiteList[L_CHARITY-CITYSITEBASE][2] = j; break; case 'h': Level->site[i][j].locchar = FLOOR; if (populate) make_horse(i,j); /* from village.c */ break; case 'j': Level->site[i][j].locchar = FLOOR; if (populate) make_justiciar(i,j); break; case 'J': Level->site[i][j].locchar = CLOSED_DOOR; Level->site[i][j].p_locf = L_JAIL; break; case 'A': Level->site[i][j].locchar = OPEN_DOOR; Level->site[i][j].p_locf = L_ARENA; CitySiteList[L_ARENA-CITYSITEBASE][0] = TRUE; CitySiteList[L_ARENA-CITYSITEBASE][1] = i; CitySiteList[L_ARENA-CITYSITEBASE][2] = j; break; case 'B': Level->site[i][j].locchar = OPEN_DOOR; Level->site[i][j].p_locf = L_BANK; CitySiteList[L_BANK-CITYSITEBASE][0] = TRUE; CitySiteList[L_BANK-CITYSITEBASE][1] = i; CitySiteList[L_BANK-CITYSITEBASE][2] = j; lset(i,j,STOPS); lset(i,j+1,STOPS); lset(i+1,j,STOPS); lset(i-1,j,STOPS); lset(i,j-1,STOPS); break; case 'i': Level->site[i][j].locchar = OPEN_DOOR; Level->site[i][j].p_locf = L_TOURIST; CitySiteList[L_TOURIST-CITYSITEBASE][1] = i; CitySiteList[L_TOURIST-CITYSITEBASE][2] = j; lset(i,j,STOPS); lset(i,j+1,STOPS); lset(i+1,j,STOPS); lset(i-1,j,STOPS); lset(i,j-1,STOPS); break; case 'X': Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = L_COUNTRYSIDE; CitySiteList[L_COUNTRYSIDE-CITYSITEBASE][0] = TRUE; CitySiteList[L_COUNTRYSIDE-CITYSITEBASE][1] = i; CitySiteList[L_COUNTRYSIDE-CITYSITEBASE][2] = j; break; case 'v': Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = L_VAULT; Level->site[i][j].aux = NOCITYMOVE; lset(i,j,SECRET); break; case 'S': Level->site[i][j].locchar = FLOOR; Level->site[i][j].aux = NOCITYMOVE; lset(i,j,SECRET); break; case 'G': Level->site[i][j].locchar = FLOOR; if (populate) { make_site_monster(i,j,GUARD); Level->site[i][j].creature->aux1 = i; Level->site[i][j].creature->aux2 = j; } break; case 'u': Level->site[i][j].locchar = FLOOR; if (populate) make_minor_undead(i,j); break; case 'U': Level->site[i][j].locchar = FLOOR; if (populate) make_major_undead(i,j); break; case 'V': Level->site[i][j].showchar = WALL; Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = L_VAULT; if (populate) make_site_treasure(i,j,5); Level->site[i][j].aux = NOCITYMOVE; lset(i,j,SECRET); break; case '%': Level->site[i][j].showchar = WALL; Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = L_TRAP_SIREN; if (populate) make_site_treasure(i,j,5); Level->site[i][j].aux = NOCITYMOVE; lset(i,j,SECRET); break; case '$': Level->site[i][j].locchar = FLOOR; if (populate) make_site_treasure(i,j,5); break; case '2': Level->site[i][j].locchar = ALTAR; Level->site[i][j].p_locf = L_ALTAR; Level->site[i][j].aux = ODIN; break; case '3': Level->site[i][j].locchar = ALTAR; Level->site[i][j].p_locf = L_ALTAR; Level->site[i][j].aux = SET; break; case '4': Level->site[i][j].locchar = ALTAR; Level->site[i][j].p_locf = L_ALTAR; Level->site[i][j].aux = ATHENA; break; case '5': Level->site[i][j].locchar = ALTAR; Level->site[i][j].p_locf = L_ALTAR; Level->site[i][j].aux = HECATE; break; case '6': Level->site[i][j].locchar = ALTAR; Level->site[i][j].p_locf = L_ALTAR; Level->site[i][j].aux = DESTINY; break; case '^': Level->site[i][j].showchar = WALL; Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = TRAP_BASE+random_range(NUMTRAPS); lset(i,j,SECRET); break; case '"': Level->site[i][j].locchar = HEDGE; break; case '~': Level->site[i][j].locchar = WATER; Level->site[i][j].p_locf = L_WATER; break; case '=': Level->site[i][j].locchar = WATER; Level->site[i][j].p_locf = L_MAGIC_POOL; break; case '*': Level->site[i][j].locchar = WALL; Level->site[i][j].aux = 10; break; case '#': Level->site[i][j].locchar = WALL; Level->site[i][j].aux = 500; break; case 'T':/* currently meaningless in large city map. */ case '>': /* currently meaningless outside of maze.*/ case '.': Level->site[i][j].locchar = FLOOR; break; case ',': Level->site[i][j].showchar = WALL; Level->site[i][j].locchar = FLOOR; Level->site[i][j].aux = NOCITYMOVE; lset(i,j,SECRET); break; case '-': case 'D': /* WDT: should all Ds be changed to -, or should D be given * special treatment? */ Level->site[i][j].locchar = CLOSED_DOOR; break; case '1': Level->site[i][j].locchar = STATUE; break; default: printf("\nOops... missed a case [%d,%d]: '%c' (%d)\n", i,j,site,site); morewait(); } if (loc_statusp(i,j,SEEN)) { if (loc_statusp(i,j,SECRET)) Level->site[i][j].showchar = WALL; else Level->site[i][j].showchar = Level->site[i][j].locchar; } } } map_close(maze); map_close(city); City = Level; /* make all city monsters asleep, and shorten their wakeup range to 2 */ /* to prevent players from being molested by vicious monsters on */ /* the streets */ for(ml=Level->mlist; ml!=NULL; ml=ml->next) { m_status_reset(ml->m,AWAKE); ml->m->wakeup = 2; } initrand(E_RESTORE, 0); }
void templateAppDraw( void ) { if( game_state == 2 ) { free_level(); load_level(); } glClearColor( 1.0f, 1.0f, 1.0f, 1.0f ); glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT ); GFX_set_matrix_mode( PROJECTION_MATRIX ); GFX_load_identity(); GFX_set_perspective( 80.0f, ( float )viewport_matrix[ 2 ] / ( float )viewport_matrix[ 3 ], 0.1f, 50.0f, -90.0f ); GFX_set_matrix_mode( MODELVIEW_MATRIX ); GFX_load_identity(); /* Linearly interpolate the accelerometer values to get a smooth transition. */ next_accelerometer.x = accelerometer.x * 0.1f + next_accelerometer.x * 0.9f; next_accelerometer.y = accelerometer.y * 0.1f + next_accelerometer.y * 0.9f; /* Assign the current Y rotation of the accelerometer to the Z rotation of the camera, * multiplied by the accelerometer sensitivity factor. */ rotz += next_accelerometer.y * sensitivity; /* The forward vector of the ball. */ vec3 forward = { 0.0f, 1.0f, 0.0f }, /* The current direction vector of the ball. Basically, this is the forward vector rotated by the cameraÕs Z rotation. */ direction; /* If the game is running, let the user move the ball. */ if( !game_state ) { /* Pre-calculate a few variables before rotating the forward vector by the cameraÕs Z rotation. */ float r = rotz * DEG_TO_RAD, c = cosf( r ), s = sinf( r ); /* Rotate the forward vector and store the result into the direction variable. Because both vectors are already normalized, thereÕs no need to re-normalize them again. */ direction.x = c * forward.y - s * forward.x; direction.y = s * forward.y + c * forward.x; float speed = CLAMP( ( -next_accelerometer.x * sensitivity ) * ball_speed, -ball_speed, ball_speed ); /* Assign the direction vector multiplied by the current speed to the angular velocity of the ball. */ player->btrigidbody->setAngularVelocity( btVector3( direction.x * speed, direction.y * speed, 0.0f ) ); /* Activate the rigid body to make sure that the angular velocity will be applied. */ player->btrigidbody->setActivationState( ACTIVE_TAG ); } next_eye.x = player->location.x + distance * cosf( rotx * DEG_TO_RAD ) * sinf( rotz * DEG_TO_RAD ); next_eye.y = player->location.y - distance * cosf( rotx * DEG_TO_RAD ) * cosf( rotz * DEG_TO_RAD ); next_eye.z = player->location.z + distance * sinf( rotx * DEG_TO_RAD ); player->location.z += player->dimension.z; btVector3 p1( player->location.x, player->location.y, player->location.z ), p2( next_eye.x, next_eye.y, next_eye.z ); ClosestNotMeRayResultCallback back_ray( player->btrigidbody, p1, p2 ); dynamicsworld->rayTest( p1, p2, back_ray ); if( back_ray.hasHit() ) { back_ray.m_hitNormalWorld.normalize(); next_eye.x = back_ray.m_hitPointWorld.x() + ( back_ray.m_hitNormalWorld.x() * 0.1f ); next_eye.y = back_ray.m_hitPointWorld.y() + ( back_ray.m_hitNormalWorld.y() * 0.1f ); next_eye.z = back_ray.m_hitPointWorld.z() + ( back_ray.m_hitNormalWorld.z()* 0.1f ); } eye.x = next_eye.x * 0.05f + eye.x * 0.95f; eye.y = next_eye.y * 0.05f + eye.y * 0.95f; eye.z = next_eye.z * 0.05f + eye.z * 0.95f; /* Calculate the direction vector from the player to the current eye location. */ vec3_diff( &direction, &player->location, &eye ); /* Normalize the direction vector. */ vec3_normalize( &direction, &direction ); AUDIO_set_listener( &eye, &direction, &up ); GFX_look_at( &eye, &player->location, &up ); build_frustum( frustum, GFX_get_modelview_matrix(), GFX_get_projection_matrix() ); unsigned int i = 0; while( i != obj->n_objmesh ) { OBJMESH *objmesh = &obj->objmesh[ i ]; objmesh->distance = sphere_distance_in_frustum( frustum, &objmesh->location, objmesh->radius ); if( objmesh->distance && objmesh->visible ) { GFX_push_matrix(); /* Check if the current objmesh name contains Ògem.Ó * If yes, donÕt ask Bullet for the transformation matrix and handle the position and * rotation manually. */ if( strstr( objmesh->name, "gem" ) ) { GFX_translate( objmesh->location.x, objmesh->location.y, objmesh->location.z ); objmesh->rotation.z += 1.0f; GFX_rotate( objmesh->rotation.z, 0.0f, 0.0f, 1.0f ); } else if( objmesh->btrigidbody ) { mat4 mat; objmesh->btrigidbody->getWorldTransform().getOpenGLMatrix( ( float * )&mat ); memcpy( &objmesh->location, ( vec3 * )&mat.m[ 3 ], sizeof( vec3 ) ); GFX_multiply_matrix( &mat ); } else { GFX_translate( objmesh->location.x, objmesh->location.y, objmesh->location.z ); } OBJ_draw_mesh( obj, i ); GFX_pop_matrix(); } ++i; } dynamicsworld->stepSimulation( 1.0f / 60.0f ); GFX_set_matrix_mode( PROJECTION_MATRIX ); GFX_load_identity(); float half_width = ( float )viewport_matrix[ 2 ] * 0.5f, half_height = ( float )viewport_matrix[ 3 ] * 0.5f; GFX_set_orthographic_2d( -half_width, half_width, -half_height, half_height ); GFX_rotate( -90.0f, 0.0f, 0.0f, 1.0f ); GFX_translate( -half_height, -half_width, 0.0f ); GFX_set_matrix_mode( MODELVIEW_MATRIX ); GFX_load_identity(); vec4 font_color = { 0.0f, 0.0f, 0.0f, 1.0f }; char gem_str [ MAX_CHAR ] = {""}, time_str [ MAX_CHAR ] = {""}, level_str[ MAX_CHAR ] = {""}; if( game_state ) { sprintf( level_str, "Level Clear!" ); FONT_print( font_big, viewport_matrix[ 3 ] * 0.5f - FONT_length( font_big, level_str ) * 0.5f + 4.0f, viewport_matrix[ 2 ] - font_big->font_size * 1.5f - 4.0f, level_str, &font_color ); /* Yellow. */ font_color.x = 1.0f; font_color.y = 1.0f; font_color.z = 0.0f; FONT_print( font_big, viewport_matrix[ 3 ] * 0.5f - FONT_length( font_big, level_str ) * 0.5f, viewport_matrix[ 2 ] - font_big->font_size * 1.5f, level_str, &font_color ); } font_color.x = 0.0f; font_color.y = 0.0f; font_color.z = 0.0f; sprintf( gem_str, "Gem Points:%02d", gem_points ); sprintf( time_str, "Game Time:%02.2f", game_time * 0.1f ); FONT_print( font_small, viewport_matrix[ 3 ] - FONT_length( font_small, gem_str ) - 6.0f, ( font_small->font_size * 0.5f ), gem_str, &font_color ); FONT_print( font_small, 8.0f, ( font_small->font_size * 0.5f ), time_str, &font_color ); font_color.x = 1.0f; font_color.y = 1.0f; font_color.z = 0.0f; FONT_print( font_small, viewport_matrix[ 3 ] - FONT_length( font_small, gem_str ) - 8.0f, ( font_small->font_size * 0.5f ), gem_str, &font_color ); FONT_print( font_small, 6.0f, ( font_small->font_size * 0.5f ), time_str, &font_color ); if( !game_state ) game_time += SOUND_get_time( background_sound ); }
void templateAppDraw( void ) { if( game_state == 2 ) { free_level(); load_level(); } glClearColor( 1.0f, 1.0f, 1.0f, 1.0f ); glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT ); GFX_set_matrix_mode( PROJECTION_MATRIX ); GFX_load_identity(); GFX_set_perspective( 80.0f, ( float )viewport_matrix[ 2 ] / ( float )viewport_matrix[ 3 ], 0.1f, 50.0f, 0.0f ); GFX_set_matrix_mode( MODELVIEW_MATRIX ); GFX_load_identity(); if(turn_left()) { next_rotz+=1.2; } if(turn_right()) { next_rotz-=1.2; } vec3 forward = { 0.0f, 1.0f, 0.0f },direction; if( !game_state ) { //Pre-calculate a few variables before rotating the forward vector by the camera's Z rotation. float r = rotz * DEG_TO_RAD, c = cosf( r ), s = sinf( r ); //Rotate the forward vector and store the result into the direction variable. Because //both vectors are already normalized, there's no need to re-normalize them one more time. direction.x = c * forward.y - s * forward.x; direction.y = s * forward.y + c * forward.x; //Calculate the current angular velocity that is relevant to the //accelerometer value that we are using as the force factor. //Then clamp the result to make sure that the speed is between the minimum and //maximum ball speed thresholds. float speed = CLAMP( -maximum_speed, -maximum_speed, maximum_speed ); player->btrigidbody->setAngularVelocity( btVector3( direction.x * speed,direction.y * speed,0.0f ) ); //Activate the rigid body to make sure that the angular velocity will be applied. player->btrigidbody->setActivationState( ACTIVE_TAG ); } /* if( view_delta.x || view_delta.y ) { if( view_delta.x ) next_rotz -= view_delta.x; if( view_delta.y ) { next_roty += view_delta.y; next_roty = CLAMP( next_roty, -180.0f, -90.0f ); } view_delta.x = view_delta.y = 0.0f; } if( move_delta.z ) { vec3 direction; float r = rotz * DEG_TO_RAD, c = cosf( r ), s = sinf( r ); direction.x = s * move_delta.y + c * move_delta.x; direction.y = c * move_delta.y - s * move_delta.x; player->btrigidbody->setAngularVelocity( 2*btVector3( -direction.y * ( move_delta.z * 6.7f ), -direction.x * ( move_delta.z * 6.7f ), 0.0f ) ); player->btrigidbody->setActivationState( ACTIVE_TAG ); }*/ //console_print("player_x: %3.f player_y: %3.f\n",player->location.x,player->location.y); next_eye.x = player->location.x + distance * cosf( roty * DEG_TO_RAD ) * sinf( rotz * DEG_TO_RAD ); next_eye.y = player->location.y - distance * cosf( roty * DEG_TO_RAD ) * cosf( rotz * DEG_TO_RAD ); next_eye.z = player->location.z + distance * sinf( roty * DEG_TO_RAD ); btVector3 p1( player->location.x, player->location.y, player->location.z ), p2( next_eye.x, next_eye.y, next_eye.z ); ClosestNotMeRayResultCallback back_ray( player->btrigidbody, p1, p2 ); dynamicsworld->rayTest( p1, p2, back_ray ); if( back_ray.hasHit() ) { back_ray.m_hitNormalWorld.normalize(); next_eye.x = back_ray.m_hitPointWorld.x() + ( back_ray.m_hitNormalWorld.x() * 0.1f ); next_eye.y = back_ray.m_hitPointWorld.y() + ( back_ray.m_hitNormalWorld.y()* 0.1f ); next_eye.z = back_ray.m_hitPointWorld.z() + ( back_ray.m_hitNormalWorld.z()* 0.1f ); } roty = roty * 0.9f + next_roty * 0.1f; rotz = rotz * 0.9f + next_rotz * 0.1f; eye.x = eye.x * 0.95f + next_eye.x * 0.05f; eye.y = eye.y * 0.95f + next_eye.y * 0.05f; eye.z = eye.z * 0.95f + next_eye.z * 0.05f; player->location.z += player->dimension.z * 0.5f; /* * needed for directional audio */ vec3 player_location={player->location.x,player->location.y,player->location.z}; AUDIO_set_listener( &eye, &player_location, &up ); GFX_look_at( &eye, &player->location, &up ); build_frustum( frustum, GFX_get_modelview_matrix(), GFX_get_projection_matrix() ); unsigned int i = 0; while( i != obj->n_objmesh ) { OBJMESH *objmesh = &obj->objmesh[ i ]; objmesh->distance = sphere_distance_in_frustum( frustum, &objmesh->location, objmesh->radius ); if( objmesh->distance && objmesh->visible ) { GFX_push_matrix(); if( strstr( objmesh->name, "gem" ) ) { GFX_translate( objmesh->location.x, objmesh->location.y, objmesh->location.z ); objmesh->rotation.z += 1.0f; GFX_rotate( objmesh->rotation.z, 0.0f, 0.0f, 1.0f ); } else if( objmesh->btrigidbody ) { mat4 mat; objmesh->btrigidbody->getWorldTransform().getOpenGLMatrix( ( float * )&mat ); memcpy( &objmesh->location, ( vec3 * )&mat.m[ 3 ], sizeof( vec3 ) ); GFX_multiply_matrix( &mat ); } else { GFX_translate( objmesh->location.x, objmesh->location.y, objmesh->location.z ); } OBJ_draw_mesh( obj, i ); GFX_pop_matrix(); } ++i; } if(!game_state ) { dynamicsworld->stepSimulation( 1.0f / 60.0f ); } GFX_set_matrix_mode( PROJECTION_MATRIX ); GFX_load_identity(); float half_width = ( float )viewport_matrix[ 2 ] * 0.5f, half_height = ( float )viewport_matrix[ 3 ] * 0.5f; GFX_set_orthographic_2d( -half_width, half_width, -half_height, half_height ); GFX_rotate( 0.0f, 0.0f, 0.0f, 1.0f ); GFX_translate( -half_width, -half_height, 0.0f ); GFX_set_matrix_mode( MODELVIEW_MATRIX ); GFX_load_identity(); vec4 font_color = { 0.0f, 0.0f, 0.0f, 1.0f }; char gem_str [ MAX_CHAR ] = {""}, time_str [ MAX_CHAR ] = {""}, level_str[ MAX_CHAR ] = {""}, pause_str [ MAX_CHAR ] = {""}; if( game_state == 3 ) { sprintf( pause_str, "Touch to Resume" ); FONT_print( font_big, viewport_matrix[ 2 ] * 0.5f - FONT_length( font_big, pause_str ) * 0.5f + 4.0f, viewport_matrix[ 3 ] * 0.7f - font_big->font_size * 1.5f - 4.0f, pause_str, &font_color ); /* Yellow. */ font_color.x = 1.0f; font_color.y = 1.0f; font_color.z = 0.0f; FONT_print( font_big, viewport_matrix[ 2 ] * 0.5f - FONT_length( font_big, pause_str ) * 0.5f, viewport_matrix[ 3 ] * 0.7f - font_big->font_size * 1.5f, pause_str, &font_color ); } if( game_state == 1 ) { sprintf( level_str, "Level Clear!" ); FONT_print( font_big, viewport_matrix[ 2 ] * 0.5f - FONT_length( font_big, level_str ) * 0.5f + 4.0f, viewport_matrix[ 3 ] - font_big->font_size * 1.5f - 4.0f, level_str, &font_color ); /* Yellow. */ font_color.x = 1.0f; font_color.y = 1.0f; font_color.z = 0.0f; FONT_print( font_big, viewport_matrix[ 2 ] * 0.5f - FONT_length( font_big, level_str ) * 0.5f, viewport_matrix[ 3 ] - font_big->font_size * 1.5f, level_str, &font_color ); } font_color.x = 0.0f; font_color.y = 0.0f; font_color.z = 0.0f; sprintf( gem_str, "Gem Points:%02d", gem_points ); sprintf( time_str, "Game Time:%02.2f", game_time * 0.1f ); FONT_print( font_small, viewport_matrix[ 2 ] - FONT_length( font_small, gem_str ) - 6.0f, ( font_small->font_size * 0.5f ), gem_str, &font_color ); FONT_print( font_small, 8.0f, ( font_small->font_size * 0.5f ), time_str, &font_color ); font_color.x = 1.0f; font_color.y = 1.0f; font_color.z = 0.0f; FONT_print( font_small, viewport_matrix[ 2 ] - FONT_length( font_small, gem_str ) - 8.0f, ( font_small->font_size * 0.5f ), gem_str, &font_color ); FONT_print( font_small, 6.0f, ( font_small->font_size * 0.5f ), time_str, &font_color ); if( !game_state ) game_time += SOUND_get_time( background_sound ); }
/* loads the house level into Level*/ void load_house(int kind, int populate) { map *home; int i,j; char site; int stops; TempLevel = Level; initrand(Current_Environment, Player.x + Player.y + hour()*10); if (ok_to_free(TempLevel)) { #ifndef SAVE_LEVELS free_level(TempLevel); #endif TempLevel = NULL; } #ifndef SAVE_LEVELS Level = ((plv) checkmalloc(sizeof(levtype))); #else msdos_changelevel(TempLevel,0,-1); Level = &TheLevel; #endif clear_level(Level); switch(kind) { case E_HOUSE: home = map_open(MAP_house); break; case E_MANSION: home = map_open(MAP_mansion); break; default: case E_HOVEL: home = map_open(MAP_hovel); break; } Level->level_width=map_getWidth(home); Level->level_length=map_getLength(home); map_setLevel(home, 0); stops = 0; for(j=0;j<Level->level_length;j++) { for(i=0;i<Level->level_width;i++) { if (kind == E_HOVEL) Level->site[i][j].lstatus = SEEN; else Level->site[i][j].lstatus = 0; Level->site[i][j].roomnumber = RS_CORRIDOR; Level->site[i][j].p_locf = L_NO_OP; site = map_getSiteChar(home,i,j); switch(site) { case 'N': Level->site[i][j].locchar = FLOOR; Level->site[i][j].roomnumber = RS_BEDROOM; if (random_range(2) && populate) make_house_npc(i,j); break; case 'H': Level->site[i][j].locchar = FLOOR; Level->site[i][j].roomnumber = RS_BEDROOM; if (random_range(2) && populate) make_mansion_npc(i,j); break; case 'D': Level->site[i][j].locchar = FLOOR; Level->site[i][j].roomnumber = RS_DININGROOM; break; case '.': Level->site[i][j].locchar = FLOOR; if (stops) { lset(i,j,STOPS); stops = 0; } break; case 'c': Level->site[i][j].locchar = FLOOR; Level->site[i][j].roomnumber = RS_CLOSET; break; case 'G': Level->site[i][j].locchar = FLOOR; Level->site[i][j].roomnumber = RS_BATHROOM; break; case 'B': Level->site[i][j].locchar = FLOOR; Level->site[i][j].roomnumber = RS_BEDROOM; break; case 'K': Level->site[i][j].locchar = FLOOR; Level->site[i][j].roomnumber = RS_KITCHEN; break; case 'S': Level->site[i][j].locchar = FLOOR; Level->site[i][j].showchar = WALL; lset(i,j,SECRET); Level->site[i][j].roomnumber = RS_SECRETPASSAGE; break; case '3': Level->site[i][j].locchar = SAFE; Level->site[i][j].showchar = WALL; lset(i,j,SECRET); Level->site[i][j].p_locf = L_SAFE; break; case '^': Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = TRAP_BASE+random_range(NUMTRAPS); break; case 'P': Level->site[i][j].locchar = PORTCULLIS; Level->site[i][j].p_locf = L_PORTCULLIS; break; case 'R': Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = L_RAISE_PORTCULLIS; break; case 'p': Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = L_PORTCULLIS; break; case 'T': Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = L_PORTCULLIS_TRAP; break; case 'X': Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = L_HOUSE_EXIT; stops = 1; break; case '#': Level->site[i][j].locchar = WALL; switch (kind) { case E_HOVEL: Level->site[i][j].aux = 10; break; case E_HOUSE: Level->site[i][j].aux = 50; break; case E_MANSION: Level->site[i][j].aux = 150; break; } break; case '|': Level->site[i][j].locchar = OPEN_DOOR; Level->site[i][j].roomnumber = RS_CORRIDOR; lset(i,j,STOPS); break; case '+': Level->site[i][j].locchar = CLOSED_DOOR; Level->site[i][j].roomnumber = RS_CORRIDOR; Level->site[i][j].aux = LOCKED; lset(i,j,STOPS); break; case 'd': Level->site[i][j].locchar = FLOOR; Level->site[i][j].roomnumber = RS_CORRIDOR; if (populate) make_site_monster(i,j,DOBERMAN); break; case 'a': Level->site[i][j].locchar = FLOOR; Level->site[i][j].roomnumber = RS_CORRIDOR; Level->site[i][j].p_locf = L_TRAP_SIREN; break; case 'A': Level->site[i][j].locchar = FLOOR; Level->site[i][j].roomnumber = RS_CORRIDOR; if (populate) make_site_monster(i,j,AUTO_MINOR); /* automaton */ break; } Level->site[i][j].showchar = ' '; } } map_close(home); initrand(E_RESTORE, 0); }