📄 graphics.c
字号:
////////////////////////////////////////////////////////////////////////////////////////////
//Graphics.c 有关图像处理的功能
//
//注意!以下函数如无特殊说明,都只是把图像画在后台,没有显示出来
#include "Type.h"
extern BOOL IsStar(BYTE btContent);
extern BOOL IsBomb(BYTE btContent);
extern BOOL IsPlayer(BYTE btContent);
//得到玩家的点的颜色,返回值ret[0]-R ret[1]-G ret[2]-B, ret[3]未使用
DWORD Content2PlayerColor(BYTE btContent)
{
BYTE pbtRet[4];//ret[0]-R ret[1]-G ret[2]-B
*((DWORD*)pbtRet) = 0;
//红
if(btContent & 1)
{
pbtRet[0] = 0xFF;
}
if(btContent & 8)
{
pbtRet[0] -= (0xFF / 2);
}
//绿
if(btContent & 2)
{
pbtRet[1] = 0xFF;
}
if(btContent & 16)
{
pbtRet[1] -= (0xFF / 2);
}
//蓝
if(btContent & 4)
{
pbtRet[2] = 0xFF;
}
if(btContent & 32)
{
pbtRet[2] -= (0xFF / 2);
}
return *((DWORD*)pbtRet);
}
//清屏
void ClearScreen(SAppData* psApp)
{
IGRAPHICS_SetBackground(psApp->pIGraphics, 0, 0, 0);
IGRAPHICS_ClearViewport(psApp->pIGraphics);
}
//画出一个雷
void DrawBomb(SAppData* psApp,
BYTE btGridX, BYTE btGridY)//网格索引
{
AEECircle sCircle;
AEELine sLine;
AEEPoint pt;
//求出图形数据
//圆
sCircle.cx = btGridX * BLOCK_SIZE + (BLOCK_SIZE * 1 / 3);
sCircle.cy = btGridY * BLOCK_SIZE + (BLOCK_SIZE * 2 / 3);
sCircle.r = BLOCK_SIZE / 3;
//柄
sLine.sx = btGridX * BLOCK_SIZE + (BLOCK_SIZE - 2);
sLine.sy = btGridY * BLOCK_SIZE + 2;
sLine.ex = btGridX * BLOCK_SIZE + (BLOCK_SIZE / 2);
sLine.ey = btGridY * BLOCK_SIZE + (BLOCK_SIZE / 2);
//准备环境
IGRAPHICS_SetFillMode(psApp->pIGraphics, TRUE);
IGRAPHICS_SetFillColor(psApp->pIGraphics, 190, 136, 109, 0);
IGRAPHICS_SetColor(psApp->pIGraphics, 190, 136, 109, 0);
//画出圆
IGRAPHICS_DrawCircle(psApp->pIGraphics, &sCircle);
//画出柄
IGRAPHICS_DrawLine(psApp->pIGraphics, &sLine);
//画出像素点
IGRAPHICS_SetPointSize(psApp->pIGraphics, 2);
pt.x = sLine.sx;
pt.y = sLine.sy + 1;
IGRAPHICS_DrawPoint(psApp->pIGraphics, &pt);
}
//画出一颗星
void DrawStar(SAppData* psApp,
BYTE btGridX, BYTE btGridY)//网格索引
{
AEEPolygon sPolygon;
uint16 iOffsetX, iOffsetY;
//计算坐标
iOffsetX = BLOCK_SIZE * btGridX;
iOffsetY = BLOCK_SIZE * btGridY;
sPolygon.points = psApp->ps5Point;
sPolygon.len = 5;
sPolygon.points[0].x = iOffsetX + (BLOCK_SIZE / 2);
sPolygon.points[0].y = iOffsetY + 0;
sPolygon.points[1].x = iOffsetX + BLOCK_SIZE;//(BLOCK_SIZE * 2 / 3);
sPolygon.points[1].y = iOffsetY + BLOCK_SIZE;
sPolygon.points[2].x = iOffsetX + 0;
sPolygon.points[2].y = iOffsetY + (BLOCK_SIZE / 3);
sPolygon.points[3].x = iOffsetX + BLOCK_SIZE;
sPolygon.points[3].y = iOffsetY + (BLOCK_SIZE / 3);
sPolygon.points[4].x = iOffsetX + 0;//(BLOCK_SIZE / 3);
sPolygon.points[4].y = iOffsetY + BLOCK_SIZE;
//准备环境
IGRAPHICS_SetFillMode(psApp->pIGraphics, TRUE);
IGRAPHICS_SetFillColor(psApp->pIGraphics, 255, 255, 0, 0);
IGRAPHICS_SetColor(psApp->pIGraphics, 255, 255, 0, 0);
//画
IGRAPHICS_DrawPolygon(psApp->pIGraphics, &sPolygon);
}
//画出一个玩家
void DrawPlayer(SAppData* psApp,
BYTE btGridX, BYTE btGridY,//网格索引
BYTE btR, BYTE btG, BYTE btB)//颜色
{
AEECircle sCircle;
//准备环境
IGRAPHICS_SetFillMode(psApp->pIGraphics, TRUE);
IGRAPHICS_SetFillColor(psApp->pIGraphics, btR, btG, btB, 0);
IGRAPHICS_SetColor(psApp->pIGraphics, 255, 255, 255, 0);
//求出位置及尺寸
sCircle.cx = btGridX * BLOCK_SIZE + (BLOCK_SIZE / 2);
sCircle.cy = btGridY * BLOCK_SIZE + (BLOCK_SIZE / 2);
sCircle.r = BLOCK_SIZE / 2;
//画
IGRAPHICS_DrawCircle(psApp->pIGraphics, &sCircle);
}
//把后台的图像显示出来
void Disp(SAppData* psApp)
{
IGRAPHICS_Update(psApp->pIGraphics);
}
//刷屏,并显示出来
void RefurbishScreen(SAppData* psApp)
{
BYTE x, y;
DWORD dwRGB;
//清屏
ClearScreen(psApp);
//画出网格内容
for(x = 0; x < MAX_GRID; x++)
{
for(y = 0; y < MAX_GRID; y++)
{
if(IsStar(psApp->pbtGrid[x][y]))
{//是星
DrawStar(psApp, x, y);
}else
{
if(IsBomb(psApp->pbtGrid[x][y]))
{//有雷
DrawBomb(psApp, x, y);
}
if(IsPlayer(psApp->pbtGrid[x][y]))
{//有玩家在上面,看来是这个玩布下的
dwRGB = Content2PlayerColor(psApp->pbtGrid[x][y]);
DrawPlayer(psApp, x, y, ((BYTE*)&dwRGB)[0], ((BYTE*)&dwRGB)[1], ((BYTE*)&dwRGB)[2]);
}
}
}
}
//最后显示出来
Disp(psApp);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -