void
step()
{
    canvas_clear(1);

    if (key_down(KEY_ESCAPE)) {
        CORE->running = 0;
    }

    if (key_pressed(KEY_RETURN)) {
        window_fullscreen_toggle();
    }

    player_step(&GAME->player,
                key_down(KEY_LEFT), key_down(KEY_RIGHT), key_pressed(KEY_UP));

    tilemap_draw(GAME->scene.tilemap);

    char buf[256];
    sprintf(buf, "%.3fms %.3f", CORE->perf_step * 1e3, CORE->time_delta);
    text_draw(buf, 0, 0, 2);
}
Beispiel #2
0
void
step()
{
    // printf("\nSTEP %d\n", PROGRAM->frame);
    draw_set(COLOR_BLACK);

    Entity *entity;
    memi i;

    player_step(GAME->player);

    //
    // Update entities
    //

    entity = GAME->entities;
    for (i = 0;
         i != GAME->entities_count;
         ++i, ++entity)
    {
        if (!equalf(entity->vx, 0, 0.1) || !equalf(entity->vy, 0, WORLD_COLLISION_EPSILON))
        {
            world_test_move(&GAME->world,
                            entity->collider,
                            entity->vx, entity->vy,
                            CollisionTestMask_All,
                            &collision,
                            on_collision);

            if (!equalf(collision.end_x, entity->collider->x, WORLD_COLLISION_EPSILON) ||
                !equalf(collision.end_y, entity->collider->y, WORLD_COLLISION_EPSILON))
            {
                world_move(&GAME->world,
                           entity->collider,
                           collision.end_x,
                           collision.end_y);
            }
        }
    }

    player_camera_step(GAME->player, &GAME->camera);

    PROGRAM->tx = -GAME->camera.x + (SCREEN_WIDTH >> 1);
    PROGRAM->ty = -GAME->camera.y + (SCREEN_HEIGHT >> 1);

    //
    // Update animations
    //

    if ((PROGRAM->frame % 3) == 0)
    {
        Animation *ani = GAME->animations;
        for (i = 0;
             i != GAME->animations_count;
             ++i, ++ani)
        {
            ani->sprite++;
            if (ani->sprite == ani->end) {
                ani->sprite = ani->begin;
            }
        }
    }

    //
    // Draw
    //

    tilemap_draw(res_level_0_layer1, res_image_set_main, 0, 0);

    Collider *collider;
    entity = GAME->entities;
    for (i = 0;
         i != GAME->entities_count;
         ++i, ++entity)
    {
        collider = entity->collider;
        rect_draw(v4i_make_size(roundf(collider->x - collider->w),
                                roundf(collider->y - collider->h),
                                collider->w * 2,
                                collider->h * 2), COLOR_SHADE_3);
//        image_set_draw(collider->x + entity->sprite_ox, collider->y + entity->sprite_oy,
//                 entity->animation->set,
//                 entity->animation->sprite,
//                 entity->animation->sprite_mode, 0);
    }

    //
    // Debug
    //

    debug_world_colliders_count(&GAME->world);

    PROGRAM->tx = 0;
    PROGRAM->ty = 0;
    debug_buttons(4, SCREEN_HEIGHT - res_icons->ch - 4);
    debug_fps(SCREEN_WIDTH - (7 * res_font->cw) - 4,
              SCREEN_HEIGHT - res_font->ch - 4,
              PROGRAM->time_step);
    debug_world_bucket_stats(&GAME->world, 4, 4);
    debug_world_bucket_cells(&GAME->world, SCREEN_WIDTH - 4 - 16, 4);
}