⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graph.c

📁 TETRIS GAME, AUTO-PLAYER AND ARTIFICIAL INTELLIGENCY By Bluteau Thomas
💻 C
字号:
/************************/
/* Game Project for ACP */
/************************/

/***********************/
/*       TETRIS        */
/*    Thomas Bluteau   */
/***********************/


/*********************************************
  GRAPH.C is the library of all the functions 
  relating to  display, draw figures on screen.
*********************************************/

#include "CONST_DEFINE.h"
#include "function.h"


/*******
Is used to print the ground on the screen
	The updating of screen or SDL_Flip is not implement into and must be
	done to refresh the display
*******/
void drawGround(t_infos *infos)
{
	SDL_Rect base_square;
	int i,j;

	base_square.w = SQUARE-1;
	base_square.h = SQUARE-1;

	for(i=0;i<GRID_WIDTH;i++){					//Double loop to go trough the ground
		for(j=0;j<GRID_HEIGHT;j++)
			{
				base_square.x = (i*SQUARE)+1;
				base_square.y = (j*SQUARE)+1;	
				SDL_FillRect(infos->screen,&base_square, infos->ground[(i*GRID_HEIGHT)+j]);
			}
	}
}

void drawPrev(t_infos *infos,object_t prev_current)
{
{
	SDL_Rect base_square,mask;
	int i,j,couleur;

	base_square.w = SQUARE-1;
	base_square.h = SQUARE-1;
    
	for(i=0;i<prev_current.x;i++){					//Double loop to go trough the ground
		for(j=0;j<prev_current.y;j++)
			{
				base_square.x = ((i*SQUARE)+1)+(prev_current.position_X*SQUARE);
				base_square.y = ((j*SQUARE)+1)+(prev_current.position_Y*SQUARE);

				//SDL_FillRect(infos->screen,&base_square, prev_current.color*prev_current.form[i*prev_current.y + j]);
			}
	}
}		
}
/*******
Function used to put the grid
*******/
void trace_Grille(t_infos *infos, Uint32 pixel)
{
	int i;
	
	for(i=0;i<GRID_HEIGHT;i++)						//Horizontal Lines
		line(infos, 0,i*SQUARE,ABSMAX,1,pixel);
	
	for(i=0;i<GRID_WIDTH;i++)						//Vertical Lines
		line(infos,i*SQUARE, 0,ORDMAX,2,pixel);
}


/*******
Trace a horizontal or vertical line, depends on orient value.
Line starts at x,y coordinates and long of weidth
 sens:	if orient == 1 -> horizontal line;
		if orient == 2 -> vertical line
*******/
void line(t_infos *infos, int x, int y, int weidth, int orient, Uint32 pixel)
{
	int i;
	if(orient == 1) {
		for (i= 0;i< weidth; i++){
			putpixel(infos, x+i, y, pixel);
			SDL_UpdateRect(infos->screen, x+i, y, 1, 1);
		}
	} 
	else if (orient == 2) {
		for (i= 0;i< weidth; i++){
			putpixel(infos, x, y+i, pixel);
			SDL_UpdateRect(infos->screen, x, y+i, 1, 1);
		}
	}
}


/*******
Put a pixel on a given screen at the x,y coordinates with pixel color
*******/
void putpixel(t_infos *infos, int x, int y, Uint32 pixel)
{
    int bpp = infos->screen->format->BytesPerPixel;
    /* Here p is the address to the pixel we want to set */
    Uint8 *p = (Uint8 *)infos->screen->pixels + y * infos->screen->pitch + x * bpp;

    switch(bpp) {
    case 1:
        *p = pixel;
        break;

    case 2:
        *(Uint16 *)p = pixel;
        break;

    case 3:
        if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
            p[0] = (pixel >> 16) & 0xff;
            p[1] = (pixel >> 8) & 0xff;
            p[2] = pixel & 0xff;
        } else {
            p[0] = pixel & 0xff;
            p[1] = (pixel >> 8) & 0xff;
            p[2] = (pixel >> 16) & 0xff;
        }
        break;

    case 4:
        *(Uint32 *)p = pixel;
        break;
    }

}










⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -