예제 #1
0
파일: main.cpp 프로젝트: luqui/soylent
void events() {
    SDL_Event e;

    Uint8* keys = SDL_GetKeyState(NULL);

    while (SDL_PollEvent(&e)) {
        if (e.type == SDL_KEYDOWN) {
            switch (e.key.keysym.sym) {
            case SDLK_ESCAPE:
                INIT.quit();
                exit(0);
                break;
            case SDLK_TAB:
                SDL_WM_ToggleFullScreen(SDL_GetVideoSurface());
                break;
            case SDLK_f:
                randomize_field();
                break;
            case SDLK_t:
                init_diffuse();
                break;
            case SDLK_r:
                init_react();
                break;
            case SDLK_RETURN:
                save_state();
                break;
            }
        }

        if (e.type == SDL_MOUSEMOTION) {
            int xcoord = int(e.motion.x / INIT.pixel_view().dim().x * GRIDW);
            int ycoord = int((INIT.pixel_view().dim().y - e.motion.y) / INIT.pixel_view().dim().y * GRIDH);
            if (xcoord >= 0 && xcoord < GRIDW && ycoord >= 0 && ycoord < GRIDH) {
                Cell& cell = GRID_FRONT[xcoord][ycoord];
                if (keys[SDLK_a]) {
                    cell.value[0] += DT;
                    if (cell.value[0] > 1) cell.value[0] = 1;
                }
                if (keys[SDLK_s]) {
                    cell.value[1] += DT;
                    if (cell.value[1] > 1) cell.value[1] = 1;
                }
                if (keys[SDLK_d]) {
                    cell.value[2] += DT;
                    if (cell.value[2] > 1) cell.value[2] = 1;
                }

            }
        }

        if (e.type == SDL_MOUSEBUTTONDOWN) {
            int xcoord = int(e.button.x / INIT.pixel_view().dim().x * GRIDW);
            int ycoord = int((INIT.pixel_view().dim().y - e.button.y) / INIT.pixel_view().dim().y * GRIDH);
            if (xcoord >= 0 && xcoord < GRIDW && ycoord >= 0 && ycoord < GRIDH) {
                modify_reaction(xcoord, ycoord);
            }
        }
    }
}
예제 #2
0
파일: main.cpp 프로젝트: luqui/soylent
void init() {
    INIT.init();

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0,GRIDW,0,GRIDH);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    reset_grid(&GRID_FRONT);
    reset_grid(&GRID_BACK);

    init_react();
    init_diffuse();

    randomize_field();
}
예제 #3
0
int main(int argc, const char *argv[])
{
	initialize_field(field);
	initialize_field(new_field);

	randomize_field(200);

	int it = 0;

	while (1) {
		clear();
		print_field();
		printf("Iteration: %d\n", ++it);
		step();
		usleep(100*1000);
	}

	return 0;
}