extern State *update_free( State * const state , const double time ) { Entity * const player_entity = & state->player.entity; const TileType non_walkable = TILE_WALL; TileType dst_tile = update_entity( player_entity, & state->map, non_walkable, time ); const int current = tile_at( & state->map, player_entity->position ); if (current == TILE_TRAP) { die(state); } else if (current == TILE_TRADER) { change_state(state, STATE_TRADE); } else if (current == TILE_BOSS) { change_state(state, STATE_BOSS); } if (player_entity->position.x == state->map.width - 1) { state->current_level_no += 1; clean_map_data( & state-> map ); change_level( & state->map, state->current_level_no ); reset_entities( state ); player_entity->position.x = 0; player_entity->destination = player_entity->previous_position = player_entity->position; } for (int i = 0; i < state->enemies_count; i++) { Enemy *enemy = state->enemies + i; update_enemy( enemy, & state->map, time ); if ( POINT_EQ( state->player.entity.position , enemy->entity.position ) ) { die(state); } Boulder * b = boulder_at( state, enemy->entity.destination ); if ( b != NULL ) { cancel_move( & enemy->entity ); swap_enemy_direction( enemy ); } } for (int i = 0; i < state->boulders_count; i++) { Boulder *boulder = state->boulders + i; update_entity( & boulder->entity, & state->map, 0, time ); } return state; }
void update() { update_world(); for (int i = 0; i < 10; i++) { update_enemy(i); } }
int game_loop(){ unsigned redraw = 0; game_rect t; rect_Zero(&t); sprite_sheet = gamespr_create("ski1.bmp"); animation_init(); init_player(); start_new_game(0); while(!mainloop){ ALLEGRO_EVENT e; ALLEGRO_TIMEOUT timeout; int i; al_init_timeout(&timeout, 0.06); bool late = al_wait_for_event_until(g_queue, &e, &timeout); if(late){ switch(e.type){ case ALLEGRO_EVENT_DISPLAY_CLOSE: mainloop = 1; break; case ALLEGRO_EVENT_KEY_UP: player_poll_kbd_up(&e); break; case ALLEGRO_EVENT_KEY_DOWN: player_poll_kbd_dn(&e); break; case ALLEGRO_EVENT_TIMER: /* main clock updates 1/60ms (60FPS LOCK) */ if(e.timer.source == g_timer){ particle_list = particles_clean(particle_list, 0); particles_update(particle_list); player_update_screen(); player_update(&ski_player, &playfield); for(i = 1; i < MAX_SPRITES; i++){ update_enemy(i); } update_enemy_behavior(gobj_list, &playfield); redraw = 1; } /* update for the chronomenter run every 100ms only) */ if( e.timer.source == timer_chrono){ HUD_UpdateChrono(); DMSG("%d", al_get_timer_count(timer_chrono)); } break; } if( redraw == 1 && al_event_queue_is_empty(g_queue)){ redraw = 0; al_clear_to_color(WHITE_COLOR); particles_draw(NULL, particle_list); player_draw(ski_player.object->position.x, ski_player.object->position.y ); for(i = 1; i < MAX_OBJECTS; i++){ int enemy_type = gobj_list[i].type; draw_enemy(enemy_type, i, 0,0, gobj_list[i].position.x, gobj_list[i].position.y, 32,32); } HUD_create_stats_box(); al_flip_display(); } } } HUD_destroy(); unload_spritesheets(); window_deinit(); particle_list = particles_clean(particle_list, PARTICLES_ALL_CLEAN); return EXIT_SUCCESS; }