C++(easyX)的游戏引擎制作(整改)

本文档记录了对之前使用C++和easyX开发的游戏引擎的错误整改过程,主要改动包括移除RSA.h引用,新增font.cpp文件。整改后的代码包括font.h, font.cpp, PNG.h, Rect.h/cpp, Speed.h/cpp/x/y.cpp, sprite.h及world_func.h等,调整了代码组织结构。" 112361525,10535223,机械制图基础知识:图线和尺寸标注详解,"['CAD', '绘图软件', '工程制图', '尺寸规范', '图线标准']
摘要由CSDN通过智能技术生成

前些天,小编写的代码出了些错误,现在进行整改:

主要变化:少了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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值