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

        引言

        easyX是一个非常实用的底层图形库,但却不是实用的游戏库,所以小编为此写了一个轻量的游戏框架。

        一、C++编译器下载

        点击以下链接即可下载:

                Visual studio链接 :功能全面、主流 (ue4引擎的必要编译器)

                Dev c++链接 : 轻量、 占内存小

        二、easyX下载

                点击以下链接即可下载:

                EasyX链接

        三、框架代码

                font.h

#pragma once
#include "PNG.h"

namespace Font {
	const int SPACE = 100;

	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[SPACE] = _T("宋体");
		TCHAR* s;
		COLORREF color = RGB(0, 0, 0);

	private:

	};

	Font::Font(const TCHAR* cs)
	{
		*s = *cs;
	}

	inline Font::Font(const int& a)
	{
		_stprintf(s, _T("%d"), a);
	}

	inline Font::Font(const float& f)
	{
		_stprintf(s, _T("%f"), f);
	}

	Font::~Font()
	{
	}
	inline void Font::draw(float cx, float cy)
	{
		x = cx, y = cy;
		draw();
	}
	inline void Font::draw()
	{
		setbkmode(TRANSPARENT); 
		settextcolor(color);
		settextstyle(weight, height, style);
		outtextxy(x, y, s);
	}
};

 

PNG.h

#pragma once
#include <graphics.h>	
#include <conio.h>
#pragma comment( lib, "MSIMG32.LIB")
void transparentimage3(IMAGE* dstimg, int x, int y, IMAGE* srcimg) //新版png
{
    HDC dstDC = GetImageHDC(dstimg);
    HDC srcDC = GetImageHDC(srcimg);
    int w = srcimg->getwidth();
    int h = srcimg->getheight();
    BLENDFUNCTION bf = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
    AlphaBlend(dstDC, x, y, w, h, srcDC, 0, 0, w, h, bf);
}

/*
* 函数使用	transparentimage3(NULL, 220, 100, &picture[0]);//透明png

*/

               

Speed.h

#pragma once
class Speed
{
public:
	Speed(const float& vx = 0, const float& vy = 0);
	~Speed();
	void set_vx(const float& vx);
	void set_vy(const float& vy);
	void set_speed(const float& vx, const float& vy);
	void set_speed(const Speed& sp);
	void add_vx(const float& vx);
	void add_vy(const float& vy);
	void add_speed(const float& vx, const float& vy);
	void add_speed(const Speed& sp);
	float get_vx() const;
	float get_vy() const;
	Speed& operator=(const Speed& sp);
	Speed& operator+=(const Speed& sp);

private:
	float* Rvx = new float(0);
	float* Rvy = new float(0);
	

};

class Speed_X
	{
	public:
		Speed_X(const float& x=0);
		Speed_X(const Speed_X& sx);
		~Speed_X();

		float get_vx() const;

		Speed_X& operator=(const float& f);
		Speed_X& operator=(const Speed_X& sx);

		Speed_X& operator+=(const float& f);
		Speed_X& operator+=(const Speed_X& sx);


		Speed_X& operator-=(const float& f);
		Speed_X& operator-=(const Speed_X& sx);

		Speed_X& operator*=(const float& f);
		Speed_X& operator*=(const Speed_X& sx);

		Speed_X& operator/=(const float& f);
		Speed_X& operator/=(const Speed_X& sx);

		float vx;

	private:

	};

class Speed_Y
{
public:
	Speed_Y(const float& y=0);
	Speed_Y(const Speed_Y& sy);
	~Speed_Y();

	float get_vy() const;

	Speed_Y& operator=(const float& f);
	Speed_Y& operator=(const Speed_Y& sy);

	Speed_Y& operator+=(const float& f);
	Speed_Y& operator+=(const Speed_Y& sy);



	Speed_Y& operator-=(const float& f);
	Speed_Y& operator-=(const Speed_Y& sy);

	Speed_Y& operator*=(const float& f);
	Speed_Y& operator*=(const Speed_Y& sy);

	Speed_Y& operator/=(const float& f);
	Speed_Y& operator/=(const Speed_Y& sy);

	float vy;

private:

};

Speed.cpp

#include "Speed.h"

Speed::Speed(const float& vx, const float& vy)
{
	delete Rvy, Rvx;
	Rvx = new float(vx);
	Rvy = new float(vy);
}

Speed::~Speed()
{
	delete Rvy, Rvx;
}

void Speed::set_vx(const float& vx)
{
	delete Rvx;
	Rvx = new float(vx);
}

void Speed::set_vy(const float& vy)
{
	delete Rvy;
	Rvy = new float(vy);
}

void Speed::set_speed(const float& vx, const float& vy)
{
	delete Rvy, Rvx;
	Rvx = new floa
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值