Example #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);
}
Example #2
0
void moveball(game *g) {
	int k; 
	ball *t = g->b;
	if((t->x == g->column && t->direcx == 1) || (t->x == 0 && t->direcx == -1)) {
		t->direcx *= -1;
	}
	if((t->x == 136 && t->direcx == 1) || (t->x == 5 && t->direcx == -1)) {
		t->direcx *= -1;
	}
	if(t->y == g->row && t->direcy == 1) {
		--g->lives;
		if(g->lives == 0) {
			g->exit = 1;
		}
		g->s->x = g->column/2 - 5;
		g->s->y = 3 * g->row / 4;
		g->s->columns = 12; 
		napms(1000);
		initball(g, g->lives);
		}
	if(t->y == 0 && t->direcy == -1) {
		t->direcy *= -1;
	}
	if(t->y == g->s->y - 1 && t->direcy == 1) {
		if(g->level == 1) {
			if(t->direcx == -1 && t->x > g->s->x && t->x <= g->s->x + 15)
				t->direcy *= -1;
			if(t->direcx == 1 && t->x >= g->s->x && t->x < g->s->x + 15)
				t->direcy *= -1;
		}
		if(g->level == 2) {
			if(t->direcx == -1 && t->x > g->s->x && t->x <= g->s->x + 10)
				t->direcy *= -1;
			if(t->direcx == 1 && t->x >= g->s->x && t->x < g->s->x + 10)
				t->direcy *= -1;
		}
		if(g->level == 3) {
			if(t->direcx == -1 && t->x > g->s->x && t->x <= g->s->x + 10)
				t->direcy *= -1;
			if(t->direcx == 1 && t->x >= g->s->x && t->x < g->s->x + 10)
				t->direcy *= -1;
		}
	}
	k = brickindex(g);
	if(k) 
		t->direcy *= -1;
	if((t->x == g->column && t->direcx == 1) || (t->x == 0 && t->direcx == -1)) {
		t->direcx *= -1;
	}	 
	if(t->y == 0 && t->direcy == -1) {
		t->direcy *= -1;
	}
	if(t->y == g->s->y - 1 && t->direcy == 1) {
		if(g->level == 1) {
			if(t->direcx == -1 && t->x > g->s->x && t->x <= g->s->x + 15)
				t->direcy *= -1;
			if(t->direcx == 1 && t->x >= g->s->x && t->x < g->s->x + 15)
				t->direcy *= -1;
		}
		if(g->level == 2) {
			if(t->direcx == -1 && t->x > g->s->x && t->x <= g->s->x + 10)
				t->direcy *= -1;
			if(t->direcx == 1 && t->x >= g->s->x && t->x < g->s->x + 10)
				t->direcy *= -1;
		}
		if(g->level == 3) {
			if(t->direcx == -1 && t->x > g->s->x && t->x <= g->s->x + 10)
				t->direcy *= -1;
			if(t->direcx == 1 && t->x >= g->s->x && t->x < g->s->x + 10)
				t->direcy *= -1;
		}
	}	
	if((t->x == 136 && t->direcx == 1) || (t->x == 5 && t->direcx == -1)) {
		t->direcx *= -1;
	}
	g->b->x += g->b->direcx;
	g->b->y += g->b->direcy;	
}