示例#1
0
static int	init_texture(t_env *env)
{
	textures_load(env, 0, "textures/wall0.xpm");
	textures_load(env, 1, "textures/wall1.xpm");
	textures_load(env, 2, "textures/wall2.xpm");
	textures_load(env, 3, "textures/wall3.xpm");
	textures_load(env, 4, "textures/wall4.xpm");
	textures_load(env, 5, "textures/wall5.xpm");
	textures_load(env, 6, "textures/wall6.xpm");
	textures_load(env, 7, "textures/wall7.xpm");
	textures_load(env, 8, "textures/wall8.xpm");
	textures_load(env, 9, "textures/wall9.xpm");
	env->ev_textures = 0;
	env->frame = 0;
	env->ev_frame = 0;
	env->size_line = -1;
	return (1);
}
示例#2
0
文件: main.c 项目: Anz/ztg_old
int main(int argc, char* argv[]) {
    printf("hello combine\n");

    SDL_Surface* window;
    SDL_Event event;
    bool running = true;

    // create window
    int width =  480, height = 360;
    SDL_Init(SDL_INIT_VIDEO);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    window = SDL_SetVideoMode(width, height, 24, SDL_OPENGL | SDL_GL_DOUBLEBUFFER);

    // init render
    render_init();

    // load all textures
    void* textures = textures_load("img");

    // scene
    scene_t scene;
    scene_init(&scene);

    sprite_t draft;
    sprite_init(&draft, map_get(textures, "draft"));
    draft.layer = 60;

    sprite_t hud;
    sprite_init(&hud, map_get(textures, "draft"));
    hud.x = (hud.texture->width - width) / 2.0f;
    hud.y = (height - hud.texture->height) / 2.0f;

    // player
    player_t player;
    player_init(&player, &scene, textures, -50, -40);

    scene.space = array_add(scene.space, &draft);

    scene.hud = array_add(scene.hud, &hud);

    level_load(&scene, textures, "cave.lvl");

    float counter = 0;

    int speed = 0;

    // main
    while (running) {
        while (SDL_PollEvent(&event)) {
            switch (event.type) {
                case SDL_QUIT: running = false; break;
                case SDL_KEYUP:
                case SDL_KEYDOWN: {
                    switch(event.key.keysym.sym) {
                        case SDLK_a: { if (speed == -1) { speed = 0; } else { speed = -1; }  break; }
                        case SDLK_d: { if (speed == 1) { speed = 0; } else { speed = 1; } break; }
                        default: break;
                    }
                }
            }
        }

        player_move(&player, speed * 2);

        if (running) {
            render(&scene, &player.camera);
            SDL_GL_SwapBuffers();
        }
        draft.rotation += 0.5f;
        draft.transparency = sin(counter) / 2.0f + 0.5f;

        counter += 0.05f;
    }

    // clean up
    scene_release(&scene);
    textures_release(textures);
    SDL_Quit();

    return 0;
}