Beispiel #1
0
int main(){
    ball b;
    wall w[50];
    int i=0;
    for(;i<15;++i){
        w[i].y=15;
        w[i].x=10+i;
        w[i].flag=URWALL;
    }
    for(;i<30;++i){
        w[i].y=w[14].y+i-15;
        w[i].x=w[14].x;
        w[i].flag=WALL;
    }
    for(;i<50;++i){
        w[i].y=w[29].y;
        w[i].x=w[29].x+i-30;
        w[i].flag=DRWALL;
    }

    initscr();
    raw();
    keypad(stdscr,TRUE);
    noecho();
    curs_set(FALSE);

    initball(&b,DELAY,'O');
    b.direction_x=1;
    drawMap(w,50);

    timeout(DELAY);

    while(1){
        /* getmaxyx(stdscr,max_y,max_x); */
        /* clear(); */

        /* drawMap(NULL,0); */
        /* collision(&b); */
        drawball(&b);

        refresh();

        changedirection(&b);
        updateball(&b);
        /* ch=halfdelay(190); */
        if(quit)
            break;
    }

    endwin();
    exit(EXIT_SUCCESS);
}
Beispiel #2
0
int main(void) {

	//*uart_chan0_interruptenable |= INTERRUPTENABLE_ERBFI;

	//uint16_t* blip = _binary_blip_start;

	//for (int i = 0; i < sizeof(_binary_blip_start) / 2; i++) {
	//	*(sound_bank_0 + i) = *blip++;
	//}
	//*sound_channel_0_samplelength = sizeof(_binary_blip_start);
	//*sound_channel_master_config = 0xFFFF;
	//*sound_channel_master_volume = 0xFF99;
	//*sound_channel_0_volume = 0xFF22;
	//*sound_channel_0_config = 0xF9FF;

	FATFS fs;
	FRESULT result;
	result = pf_mount(&fs);
	util_printffresult(result);
	util_printfat(&fs);
	result = pf_open("test.txt");
	util_printffresult(result);
	char buf[64];
	uint16_t len;
	pf_read(buf, 63, &len);

	printf("read from file: %s\n", buf);

	image_loadimagefromfile(&fs, &pai, "pai.bz", true);
	image_loadimagefromfile(&fs, &ballimage, "ball.be", false);

	newball(&ball1, 0, 0, &ballimage);
	newball(&ball2, 50, 0, &ballimage);

	initvideo();

	machine_setinterruptmask(0);

	while (1) {

		if (fbready)
			continue;

		static uint16_t lastframe = 0;
		static uint16_t thisframe;

		uint16_t vidflags = video_register_flags;
		uint8_t port0 = input_port0;

		thisframe = video_register_frame;

		updateball(&ball1, thisframe, lastframe);
		updateball(&ball2, thisframe, lastframe);
		ballcollision(&ball1, &ball2);

		video_begin();
		video_clear(0xFFFF);
		video_blitimage_nocopy(pai.width, pai.height, 30, 30, pai.data);
		sprite_draw(ball1.sprite);
		sprite_draw(ball2.sprite);
		video_drawline(&vect);
		video_gputs("Hello World!", _binary_fontrom_start, 1, 1);

		lastframe = thisframe;
		video_commit();
		//video_flip();
		fbready = true;

	}

	printf("Shouldn't have got here!");

	while (1) {

	}

	return 0;

}
Beispiel #3
0
int playgame(short control)
{
    struct player p1 = {P1_Y, P1_X, 1, 0, 0, 35, 0};
    struct player p2 = {P2_Y, P2_X, 0, 0, 0, 40, 0};
    struct ball b = {B_Y, B_X, B_SPEED, B_DIRY, 1, 0};
    short gameover = 0;
    short bcounter = 0;
    short bbcounter = 0;
    short pcounter = 0;
    int c;

    while (!gameover) {
        /* Draw everything and pause for one tick. */
        drawpaddle(p1);
        drawpaddle(p2);
        drawnet();
        drawball(b);
        refresh();
        napms(SPEED);

        /* Get input. */
        control = controlpaddle(&p1, b, control);
        if (!control)
            break;
        controlpaddle(&p2, b, 0);
        if (pcounter++ == P_SPEED) {
            updatepaddle(&p1);
            updatepaddle(&p2);
            pcounter = 0;
        }
        if (bcounter++ == b.speed) {
            eraseball(b);
            if (updateball(&b, &p1, &p2) == 0) {
                bcounter = 0;
                if (bbcounter++ == 200 && b.speed > 1)
                    --b.speed;
            } else {
                bcounter = 0;
                bbcounter = 0;
                p1.y = P1_Y;
                p1.x = P1_X;
                p1.dir = 0;
                p2.y = P2_Y;
                p2.x = P2_X;
                p2.dir = 0;
                clear();
                drawpaddle(p1);
                drawpaddle(p2);
                drawnet();
                drawball(b);
                refresh();
                /* Wait for space or a mouse click */
                do {
                    c = getch();
                    napms(10);
                    if (c == 'q')
                        return 0;
                } while ((c != ' ') && (c != KEY_MOUSE));
                if (p1.score == 21) {
                    return 1;
                } else if (p2.score == 21) {
                    return 2;
                }
            }
        }
        napms(SPEED);
    }
    return 0;
}