Пример #1
0
int main()
{
    int exit = 0;
    MAP* map = load_map("zaza.wad");
    VEC2F vp = vec2f(-6.f, -232.f);
    float ang = 1.6, move_speed = 200.f, rot_speed = 2.5f;
    
    init();

    int i;    
    for(i = 0; i < RANDOM_COLOR_NUM; ++i)
      random_colors[i] = makecol(rand() % 156 + 100, rand() % 156 + 100, rand() % 156 + 100);
    
    clock_t last_clock = clock();
    
    int baz = 0;
    
    while(!exit)
    {
        clock_t now = clock();
        float dt = (float)(now - last_clock) / CLOCKS_PER_SEC;
        last_clock = now;
        
        VEC2F view_dir = vec2f(cos(ang), sin(ang));
        VEC2F view_dir_norm = vec2f(-view_dir.y, view_dir.x);
        
        if(key[KEY_ESC]) exit = 1;
        if(key[KEY_S]) vp = vec2f_sum(vp, vec2f_uscale(view_dir, -move_speed * dt));
        if(key[KEY_W]) vp = vec2f_sum(vp, vec2f_uscale(view_dir, move_speed * dt));
        if(key[KEY_A]) vp = vec2f_sum(vp, vec2f_uscale(view_dir_norm, -move_speed * dt));
        if(key[KEY_D]) vp = vec2f_sum(vp, vec2f_uscale(view_dir_norm, move_speed * dt));
        if(key[KEY_LEFT]) ang -= rot_speed * dt;
        if(key[KEY_RIGHT]) ang += rot_speed * dt;
        
        //printf("(%f, %f) %f | %d\n", vp.x, vp.y, ang, mouse_x / 2);
        
        
        clear_to_color(buffer, makecol(64, 64, 64));
        
        SECTOR* s = find_sector(map, map->node_num - 1, vp);
        float h = s->floor_height - 45;
        
        int i = 0;
        
        for(i = 0; i < H_RES; ++i)
        {
            float t = i - H_RES / 2;
            float u = FOCAL_DIST;
            
            VEC2F ray_dir = vec2f_sum(vec2f_uscale(view_dir, u), vec2f_uscale(view_dir_norm, t)); //vec2f(view_dir.x * FOCAL_DIST + view_dir_norm.x * t, view_dir.y * FOCAL_DIST + view_dir_norm.y * t);
            float ray_len = sqrt(ray_dir.x * ray_dir.x + ray_dir.y * ray_dir.y);
            ray_dir.x /= ray_len;
            ray_dir.y /= ray_len;
            
            int minh = 0;
            int maxh = SCREEN_H;
            
            render_col(buffer, map, map->node_num - 1, vp, h, ray_dir, i, &minh, &maxh);
            printf("\n");
            //line(buffer, SCREEN_W / 2, SCREEN_H / 2, SCREEN_W / 2 + ray_dir.x * 200, SCREEN_H / 2 + ray_dir.y * 200, makecol(255, 255, 255));
        }

        
        
        if(key[KEY_TAB])
        for(i = 0; i < map->seg_num; ++i)
        {
            VERTEX v1t = map->vertexes[map->segs[i].v1_idx];
            VERTEX v2t = map->vertexes[map->segs[i].v2_idx];
            VEC2F v1 = vec2f(v1t.x, v1t.y);
            VEC2F v2 = vec2f(v2t.x, v2t.y);
            VEC2F mid = vec2f((v1.x + v2.x) / 2, (v1.y + v2.y) / 2);
            
            VEC2F n = normalized_normal(vec2f_diff(v2, v1));
            float scl = 1.f / 2.f;
            
            line(buffer, v1.x*scl + SCREEN_W / 2,
                         v1.y*scl + SCREEN_H / 2,
                         v2.x*scl + SCREEN_W / 2,
                         v2.y*scl + SCREEN_H / 2, makecol(255, 255, 255));
            circlefill(buffer, (int)vp.x*scl + SCREEN_W/2, (int)vp.y*scl +SCREEN_H/2, 3, makecol(255, 255, 255));
            
            
            line(buffer, SCREEN_W/2+ mid.x*scl,
                        SCREEN_H/2 +  mid.y*scl,
                        SCREEN_W/2+ (mid.x + n.x * 10)*scl,
                        SCREEN_H/2+ (mid.y + n.y * 10)*scl, makecol(255, 255, 255));
            
            
            line(buffer, SCREEN_W/2+vp.x*scl,
                        SCREEN_H/2+vp.y*scl,
                        SCREEN_W/2+(vp.x+view_dir.x*100)*scl,
                        SCREEN_H/2+(vp.y+view_dir.y*100)*scl, makecol(255, 255, 255));
        }
        
        //
        
        draw_sprite(buffer, mouse_sprite, mouse_x, mouse_y);
        blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
    }
    
    destroy_map(map);
    deinit();
    return 0;
}END_OF_MAIN()
Пример #2
0
int merger_destroy_map( lua_State *L )
{
   destroy_map( );
   
   return 0;
}