Esempio n. 1
0
void notmain() {
  led_init();
  gpio_init();
  gfx_init();

  unsigned int index = 0;
  char line[60];
  line[0] = 0;
  
  gpio_set_input(GPIO_PIN23);
  gpio_set_input(GPIO_PIN24);
  gpio_set_pullup(GPIO_PIN23);
  gpio_set_pullup(GPIO_PIN24);
  //  while (1) {}
  while (1) {
    wait_for_clock();
    line[index] = '+';
    line[++index] = 0;
    gfx_clear();
    gfx_draw_string(0xFFFFFFFF, 20, 20, "Button pushes: ");
    gfx_draw_string(0xFFFFFFFF, 210, 20, line);
    gfx_draw();
  }
  
  while (1) {
    unsigned char ch = 0;
    int pinval;

    wait_for_clock();
    pinval = gpio_pin_read(GPIO_PIN24);
    if (pinval != 0) {
      //continue;
    }    

    int i;
    for (i = 0; i < 8; i++) {
      wait_for_clock();
      ch |= gpio_pin_read(GPIO_PIN24) << i;
    }

    wait_for_clock();
    wait_for_clock();

    ch = 'z'; //lookup_table[ch];
    if (index < LINE_SIZE) {
      line[index] = ch;
      line[index++] = 0;
    }
    gfx_clear();
    gfx_draw_string(0xFFFFFFFF, 20, 20, line);
    gfx_draw();
  }
 
}
Esempio n. 2
0
int main(int argc, char **argv) {
	Gfx gfx;
	Model model;
	
	if(argc != 2) {
		printf("Invalid count of arguments!\nUsage %s FILENAME\n", argv[0]);
		return 1;
	}

	if(load_map(argv[1], &model))
		return 1;
	model_static_field(&model);
	gfx_init(&gfx, model.w, model.h);
	double t = SDL_GetTicks()/1000.-0.016;
	while(1) {
		int i;
		int nsteps = 5;

		if(gfx_event(&gfx) < 0)
			break;

		double dt = SDL_GetTicks()/1000.-t;
		dt = 0.06;
		if(nsteps < dt*C/DX*5) {
			nsteps = dt*C/DX*5+0.5;
			printf("nsteps %d\n", nsteps);
			if(nsteps > 30)
				nsteps = 30;
		}

		for(i = 0; i < nsteps; i++)
			model_update(&model, dt/nsteps);
		
		double rho = 0;
		int x, y;
		for(x = 0; x < model.w; x++) {
			for(y = 0; y < model.h; y++) {
				rho += model.rho[y*model.w+x];
			}
		}		
		double tdt = SDL_GetTicks()/1000.-t;
		t = SDL_GetTicks()/1000.;
		printf("%f fps aval = %g\n", 1./tdt, model.phi[model.tp][model.h/2*model.w+model.w*8/10-2]);
		gfx_draw(&gfx, &model);
	}

	gfx_deinit(&gfx);
	model_free(&model);

	return 0;
}
Esempio n. 3
0
void draw_then_sleep(struct gfx_state *s, struct gamestate *g)
{
    gfx_draw(s, g);
    /* Have a fixed time for each turn to animate (160 default) */
    gfx_sleep(160 / g->opts->grid_width);
}
Esempio n. 4
0
int main(int argc, char **argv)
{
    struct gamestate *g = gamestate_init(argc, argv);
    struct gfx_state *s;

    if (g->opts->interactive)
        s = gfx_init(g);

    int game_running = true;
    while (game_running) {

        if (g->opts->interactive)
            gfx_draw(s, g);

get_new_key:;
        int direction = dir_invalid;
        int value = !g->opts->ai ? gfx_getch(s) : ai_move(g);
        switch (value) {
            case 'h':
            case 'a':
                direction = dir_left;
                break;
            case 'l':
            case 'd':
                direction = dir_right;
                break;
            case 'j':
            case 's':
                direction = dir_down;
                break;
            case 'k':
            case 'w':
                direction = dir_up;
                break;
            case 'q':
                game_running = false;
                break;
            default:
                goto get_new_key;
        }

        /* Game will only end if 0 moves available */
        if (game_running) {
            gamestate_tick(s, g, direction, g->opts->animate && g->opts->interactive
                    ? draw_then_sleep : NULL);

            int spawned;
            for (spawned = 0; spawned < g->opts->spawn_rate; spawned++)
                gamestate_new_block(g);

            if (gamestate_end_condition(g)) {
                game_running = false;
            }
        }
    }

    if (g->opts->interactive) {
        // gfx_getch(s);   // getch here would be good,
                         // need an exit message for each graphical output
        gfx_destroy(s);
    }

    printf("%ld\n", g->score);
    gamestate_clear(g);
    return 0;
}