前些天,小编写的代码出了些错误,现在进行整改:
主要变化:少了RSA.h,多了font.cpp
整改代码如下:【尴尬】
font.h
#pragma once
#include <graphics.h>
namespace Font {
class Font
{
public:
Font(const TCHAR* cs);
Font(const int& a);
Font(const float& f);
~Font();
void draw(float cx, float cy);
void draw();
int height=20, weight=20;
float x=0, y=0;
TCHAR style[100] = _T("宋体");
TCHAR* s;
COLORREF color = RGB(0, 0, 0);
private:
};
};
font.cpp
#include "font.h"
#include <stdio.h>
#include <algorithm>
Font::Font::Font(const TCHAR* cs)
{
*s = *cs;
}
inline Font::Font::Font(const int& a)
{
_stprintf(s, _T("%d"), a);
}
Font::Font::Font(const float& f)
{
_stprintf(s, _T("%f"), f);
}
Font::Font::~Font()
{
}
inline void Font::Font::draw(float cx, float cy)
{
x = cx, y = cy;
draw();
}
inline void Font::Font::draw()
{
setbkmode(TRANSPARENT);
settextcolor(color);
settextstyle(weight, height, style);
outtextxy(x, y, s);
}
PNG.h
#pragma once
#include <conio.h>
#include <graphics.h>
//函数声明
// 载入PNG图并去透明部分
void drawAlpha(IMAGE* picture, int picture_x, int picture_y) //x为载入图片的X坐标,y为Y坐标
{
// 变量初始化
DWORD* dst = GetImageBuffer(); // GetImageBuffer()函数,用于获取绘图设备的显存指针,EASYX自带
DWORD* draw = GetImageBuffer();
DWORD* src = GetImageBuffer(picture); //获取picture的显存指针
int picture_width = picture->getwidth(); //获取picture的宽度,EASYX自带
int picture_height = picture->getheight(); //获取picture的高度,EASYX自带
int graphWidth = getwidth(); //获取绘图区的宽度,EASYX自带
int graphHeight = getheight(); //获取绘图区的高度,EASYX自带
int dstX = 0; //在显存里像素的角标
// 实现透明贴图 公式: Cp=αp*FP+(1-αp)*BP , 贝叶斯定理来进行点颜色的概率计算
for (int iy = 0; iy < picture_height; iy++)
{
for (int ix = 0; ix < picture_width; ix++)
{
int srcX = ix + iy * picture_width; //在显存里像素的角标
int sa = ((src[srcX] & 0xff000000) >> 24); //0xAArrggbb;AA是透明度
int sr = ((src[srcX] & 0xff0000) >> 16); //获取RGB里的R
int sg = ((src[srcX] & 0xff00) >> 8); //G
int sb = src[srcX] & 0xff; //B
if (ix >= 0 && ix <= graphWidth && iy >= 0 && iy <= graphHeight && dstX <= graphWidth * graphHeight)
{
dstX = (ix + picture_x) + (iy + picture_y) * graphWidth; //在显存里像素的角标
int dr = ((dst[dstX] & 0xff0000) >> 16);
int dg = ((dst[dstX] & 0xff00) >> 8);
int db = dst[dstX] & 0xff;
draw[dstX] = ((sr * sa / 255 + dr * (255 - sa) / 255) << 16) //公式: Cp=αp*FP+(1-αp)*BP ; αp=sa/255 , FP=sr , BP=dr
| ((sg * sa / 255 + dg * (255 - sa) / 255) << 8) //αp=sa/255 , FP=sg , BP=dg
| (sb * sa / 255 + db * (255 - sa) / 255); //αp=sa/255 , FP=sb , BP=db
}
}
}
}
//绘制透明图片
Rect.h
#include "Speed.h"
#pragma once
class Rect
{
public:
float x=0, y=0, top=0, bottom=0, right=0, left=0;
float r = 0;
float width=0, height=0;
bool input_completely = true;
inline Rect(const float& w = 0, const float& h = 0, const float& cx = 0, const float& cy = 0)
{
width = w, height = h;
x = cx, y = cy;
top = y - h / 2, bottom = y + h / 2;
right = x + w / 2, left = x = w / 2;
}
inline Rect(const Rect& r)
{
x = r.x, y = r.y;
width = r.width, height = r.height;
top = r.top, bottom = r.bottom;
right = r.right, left = r.left;
}
~Rect();
inline void set_position_center(const float& cx = 0, const float& cy = 0);
inline void set_position_left_top(const float& cleft = 0, const float& ctop = 0);
inline void set_position_left_bottom(const float& cleft = 0, const float& cbottom = 0);
inline void set_position_right_top(const float& cright = 0, const float& ctop = 0);
inline void set_position_right_bottom(const float& cright = 0, const float& cbottom = 0);
inline void set_rect(const float& w = 0, const float& h = 0);
inline Rect& operator=(const Rect& r);
//Rect& operator+=(const Speed& sp);
inline friend Rect& operator+(Rect r, const Speed& sp);
inline friend Rect& operator+(Rect r, const Speed_X& sx);
inline friend Rect& operator+(Rect r, const Speed_Y& sy);
inline friend Rect& operator-(Rect r, const Speed_X& sx);
inline friend Rect& operator-(Rect r, const Speed_Y& sy);
bool isCollide(const Rect& r);
bool isCollide_Circle(const Rect& rt);
bool isCollide_Circle(const Rect& rt, const float& cr);
bool isCollide_Circle(const Rect& rt, const float& cr, const float ccr);
private:
};
Rect.cpp
#include "Rect.h"
#include <algorithm>
#include<math.h>
Rect