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

刚整改完,小编突然发现sprite.h没有整改......

sprite.h

#pragma once
#include "Rect.h"
namespace Sprite {
	class Sprite
	{
	public:
		static Speed_X wvx;
		static Speed_Y wvy;

		virtual void draw() const = 0;
		virtual void update() const = 0;
		virtual void init() const = 0;
		//可以重构的内置虚函数

		virtual void MOVE();
		virtual void MOVE_X();
		virtual void MOVE_Y();
		//允许重构的内置移动函数

		void WORLD_MOVE();//世界移动函数


		Sprite(const float& w = 0, const float& h = 0, const float& cx = 0, const float& cy = 0);
		Sprite(const Rect& r);
		Sprite(const Sprite& spr);
		virtual ~Sprite();
		void set_rect(const Rect& r);
		void set_speed(const Speed& sp);
		void set_speed(const float& cvx, const float& cvy);
		void set_vx(const float& cvx);
		void set_vy(const float& cvy);
		void set_R(const float& r);
		void add_vx(const float& cvx);
		void add_vy(const float& cvy);
		void add_speed(const Speed& sp);
		void add_speed(const float& cvx, const float& cvy);
		void set_position(const float& x, const float& y);
		void set_position_left_top(const float& cleft, const float& ctop);
		void set_position_left_bottom(const float& cleft, const float& cbottom);
		void set_position_right_top(const float& cright, const float& ctop);
		void set_position_right_bottom(const float& cright, const float& cbottom);
		void change_input_completed();

		bool isCollide(const Sprite& spr);
		bool isCollide(const Rect& r);
		bool isCollide_circle(const Sprite& spr);
		bool isCollide_circle(const Rect& r);


		Rect get_rect() const;
		Speed get_speed() const;
		Speed_X get_vx() const;
		Speed_Y get_vy() const;
		Sprite& operator=(const Sprite& spr);
		Sprite& operator+=(const Speed& sp);
		Sprite& operator+=(const Speed_X& sx);
		Sprite& operator+=(const Speed_Y& sy);

		float& rvx = vx->vx;
		float& rvy = vy->vy;//速度的应用

		const float& x = rect->x, &y = rect ->y,
			&top = rect->top, &bottom = rect->bottom, &right = rect->right, &left = rect->left,
			&height = rect->height, &width = rect->width;

		float& r = rect->r;
		Rect& rect_ = *rect;

	protected:
		Rect* rect = new Rect();
		//Speed* speed = new Speed();
		Speed_X* vx = new Speed_X();
		Speed_Y* vy = new Speed_Y();

	};

	inline void Sprite::MOVE()
	{
		(*rect) = *rect + *vx;
		(*rect) = *rect + *vy;
	}

	inline void Sprite::MOVE_X()
	{
		(*rect) = *rect + *vx;
	}

	inline void Sprite::MOVE_Y()
	{
		(*rect) = *rect + *vy;
	}

	inline void Sprite::WORLD_MOVE()
	{
		(*rect) = (*rect) + wvx;
		(*rect) = (*rect) + wvy;
	}

	inline Sprite::Sprite(const float& w, const float& h, const float& cx, const float& cy)
	{
		(*rect).set_position_center(cx, cy);
		(*rect).set_rect(w, h);
		init();
	}

	inline Sprite::Sprite(const Rect& r)
	{
		(*rect) = r;
	}

	inline Sprite::Sprite(const Sprite& spr)
	{
		(*rect) = spr.get_rect();
		(*vx) = spr.get_vx();
		(*vy) = spr.get_vy();
	}

	inline Sprite::~Sprite()
	{
		delete rect, vx, vy;
	}

	inline void Sprite::set_rect(const Rect& r)
	{
		(*rect) = r;
	}

	inline void Sprite::set_speed(const Speed& sp)
	{
		(*vx) = sp.get_vx();
		(*vy) = sp.get_vy();
	}

	inline void Sprite::set_speed(const float& cvx, const float& cvy)
	{
		(*vx) = cvx;
		(*vy) = cvy;
	}

	inline void Sprite::set_vx(const float& cvx)
	{
		(*vx) = cvx;
	}

	inline void Sprite::set_vy(const float& cvy)
	{
		(*vy) = cvy;
	}

	inline void Sprite::set_R(const float& r)
	{
		rect->r = r;
	}

	inline void Sprite::add_vx(const float& cvx)
	{
		(*vx) = cvx;
	}

	inline void Sprite::add_vy(const float& cvy)
	{
		(*vy) = cvy;
	}

	inline void Sprite::add_speed(const Speed& sp)
	{
		(*vx) += sp.get_vx();
		(*vy) += sp.get_vy();
	}

	inline void Sprite::add_speed(const float& cvx, const float& cvy)
	{
		(*vx) += cvx;
		(*vy) += cvy;
	}

	inline void Sprite::set_position(const float& x, const float& y)
	{
		(*rect).set_position_center(x, y);
	}

	inline void Sprite::set_position_left_top(const float& cleft, const float& ctop)
	{
		rect->set_position_left_top(cleft, ctop);
	}

	inline void Sprite::set_position_left_bottom(const float& cleft, const float& cbottom)
	{
		rect->set_position_left_bottom(cleft, cbottom);
	}

	inline void Sprite::set_position_right_top(const float& cright, const float& ctop)
	{
		rect->set_position_right_top(cright, ctop);
	}

	inline void Sprite::set_position_right_bottom(const float& cright, const float& cbottom)
	{
		rect->set_position_left_bottom(cright, cbottom);
	}

	inline void Sprite::change_input_completed()
	{
		(*rect).input_completely = !((*rect).input_completely);
	}

	inline bool Sprite::isCollide(const Sprite& spr)
	{
		return (*rect).isCollide(spr.get_rect());
	}

	inline bool Sprite::isCollide(const Rect& r)
	{
		return (*rect).isCollide(r);
	}

	inline bool Sprite::isCollide_circle(const Sprite& spr)
	{
		return (*rect).isCollide_Circle(spr.get_rect());
	}

	inline bool Sprite::isCollide_circle(const Rect& r)
	{
		return (*rect).isCollide_Circle(r);
	}



	inline Rect Sprite::get_rect() const
	{
		return (*rect);
	}

	inline Speed Sprite::get_speed() const
	{
		return Speed((vx)->get_vx(), (vy)->get_vy());
	}

	inline Speed_X Sprite::get_vx() const
	{
		return (*vx);
	}

	inline Speed_Y Sprite::get_vy() const
	{
		return (*vy);
	}

	inline Sprite& Sprite::operator=(const Sprite& spr)
	{
		if (this != &spr)
		{
			this->set_rect(spr.get_rect());
			this->set_speed(spr.get_speed());
		}
		return *this;// TODO: 在此处插入 return 语句
	}

	inline Sprite& Sprite::operator+=(const Speed& sp)
	{
		*(this->rect) = *(this->rect) + sp;
		return *this;// TODO: 在此处插入 return 语句
	}

	inline Sprite& Sprite::operator+=(const Speed_X& sx)
	{
		*(this->rect) = *(this->rect) + sx;
		return *this;// TODO: 在此处插入 return 语句
	}

	inline Sprite& Sprite::operator+=(const Speed_Y& sy)
	{
		*(this->rect) = *(this->rect) + sy;
		return *this;// TODO: 在此处插入 return 语句
	}

	
}
/* Sprite(精灵类)继承模板
class object : public Sprite
	{
	public:
		object(const float& w = 0, const float& h = 0, const float& cx = 0, const float& cy = 0);
		object(const Rect& r);
		object(const Sprite& spr);

		~object();

		object& operator=(const object& spr);
		object& operator+=(const Speed& sp);
		object& operator+=(const Speed_X& sx);
		object& operator+=(const Speed_Y& sy);

	protected:
		

	private:
		
	};

	inline object::object(const float& w, const float& h, const float& cx, const float& cy) : Sprite(w, h, cx, cy)
	{}

	inline object::object(const Rect& r) : Sprite(r)
	{}

	inline object::object(const Sprite& spr) : Sprite(spr)
	{}

	object::~object()
	{
	}
	inline object& object::operator=(const object& spr)
	{
		if (this != &spr)
		{
			this->set_rect(spr.get_rect());
			this->set_speed(spr.get_speed());
		}
		return *this;// TODO: 在此处插入 return 语句
	}
	inline object& object::operator+=(const Speed& sp)
	{
		*(this->rect) = *(this->rect) + sp;
		return *this;// TODO: 在此处插入 return 语句
	}
	inline object& object::operator+=(const Speed_X& sx)
	{
		*(this->rect) = *(this->rect) + sx;
		return *this;// TODO: 在此处插入 return 语句
	}
	inline object& object::operator+=(const Speed_Y& sy)
	{
		*(this->rect) = *(this->rect) + sy;
		return *this;// TODO: 在此处插入 return 语句
	}
*/

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值