Exemple #1
0
void drawTree(SDL_Simplewin *sw, node *tree,
                        fntrow fnt[FNTCHARS][FNTHEIGHT])
{
    cart parent, this;

    if(tree==NULL){
        return;
    }
    drawTree(sw, tree->c0, fnt);
    drawTree(sw, tree->c1, fnt);

    if(tree->y > 0){
        this = getTreeCoord(tree);
        parent = getTreeCoord(tree->parent);


        SDL_SetRenderDrawColor(sw->renderer, COL_TREE_GREEN, OPAQUE);
        SDL_RenderDrawLine(sw->renderer, parent.x, parent.y,
                                this.x, this.y);

        if(tree->chr){
            Neill_SDL_DrawChar(sw, fnt, tree->chr,
                                 this.x-(FNTWIDTH/2), this.y);
        } else {
            setRandColour(sw);
            Neill_SDL_RenderFillCircle(sw->renderer, this.x, this.y, CIRCRAD);
            SDL_SetRenderDrawColor(sw->renderer, COL_WHITE, OPAQUE);
            /*drawCirc(sw, this, CIRCRAD);*/
        }

    }
}
/* Display the maze in an SDL GUI */
void display_SDL(max_maze array, maze_dimensions dims){
	
	// Fit the maze to the window height by scaling each cell's dimensions
	int rectsize = WHEIGHT / dims.height; 
	int window_offset = (WWIDTH-WHEIGHT)/2;
	int cx=0, cy =0;
	
	SDL_Simplewin win;
	SDL_Rect rectangle;
	rectangle.w = rectsize;
	rectangle.h = rectsize;
	Neill_SDL_Init(&win);

	do {
		// Draw the array graphically.
		for (int i = 0; i < dims.height; ++i) {
			for (int j = 0; j < dims.width; ++j) {

				if ( array[i][j] == '#' ) {
					Neill_SDL_SetDrawColour(&win,255,255,255); // Set colour to WHITE
					
					// Draw rectangle for each array cell, centred in the window
					rectangle.x = (j * rectsize) + window_offset ;
					rectangle.y = i * rectsize;
					SDL_RenderFillRect(win.renderer, &rectangle);
				} 
				if ( array[i][j] == '.') {	
					Neill_SDL_SetDrawColour(&win,255,128,0); // Set colour to ORANGE

					cx = (j*rectsize) + window_offset + (rectsize/2);
					cy = (i*rectsize) + (rectsize/2);
					Neill_SDL_RenderFillCircle(win.renderer, cx, cy, RADIUS);
				}
			}
		}

		// Update window.
		SDL_RenderPresent(win.renderer);
		SDL_UpdateWindowSurface(win.win);
		Neill_SDL_Events(&win); 		// Check for user kill

		SDL_Delay(MILLISECONDDELAY); 	// Wait a short time

	} while(!win.finished);

	// Cleans up.
	atexit(SDL_Quit);
}