C++/SDL实现打砖块游戏——GraphicItem类(编写中)

太之初一 posted @ 2016年7月27日 09:30 in 未分类 with tags c++ sdl , 1002 阅读

GraphicItem是滑板、砖块、小球等类的基类。它包含着将一个图像部件渲染到屏幕上所需的基本信息。

以下代码中,各种get方法是我留下的坑,其实把geometry设为public就行了,但由于这是面向对象实习,我觉得一刀切全public可能会影响分数。。。于是。。。

class GraphicItem
{
public:
	GraphicItem(void);
	GraphicItem(SDL_Texture *t);
	~GraphicItem(void);

	// 具体使用哪个材质,由具体的类根据宏定义去选择
	virtual void set_texture(SDL_Texture **textures) = 0;

	SDL_Texture* get_texture();
	
	POINT speed;
	//POINT get_pos();
	// 几何信息的set和get
	void set_speed_x(int s);
	void set_speed_y(int s);
	void set_pos(int x, int y);
	void set_pos(POINT p);
	POINT get_pos();
	SDL_Rect get_geometry();
	void set_geometry(int x, int y, int w, int h);
	void set_geometry(SDL_Rect rect);
	void set_width(int w);

	virtual void update();

	// 获取图像的边界坐标
	int get_left_edge();
	int get_right_edge();
	int get_top_edge();
	int get_bottom_edge();
	// 获取图像的中点坐标
	int get_v_mid();
	int get_h_mid();
	SDL_Texture **textures;
protected:
	SDL_Texture *texture;
	SDL_Rect geometry;
	
};

对于一个可渲染的图像部件而言,需要有它的位置、大小、移动速度、当然还有贴图。对于砖块而言,速度当然是没有意义的。

类中的set_texture方法是一个纯虚函数,所以这个类是一个虚基类。之所以这样做,是因为我希望每个具体的图像部件知道自己所需的贴图在贴图列表中的索引。所以在具体的类中实现这个方法时,会提供宏定义的索引,上级对象只需提供贴图列表即可。

Avatar_small
AP SSC sa 2 Question 说:
2022年9月09日 03:11

SA-2 Exams called Summative Assignment-2 exams are known as Annual final public exams, every year those exams are held at the end of the academic session as Term-2 exams. Every State Board Telugu Medium, AP SSC sa 2 Question Paper English Medium & Urdu Medium Students can download the AP 10th Class SA 2 Model Paper 2023 Pdf with Answer Solutions designed by the Board based on the revised syllabus and curriculum.Class teachers and others have designed and suggested the AP 10th Class SA 2 Model Paper 2023 for all languages and subjects of the course for theory, objective,


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter