C++创意编程--基于EasyX库图形库--豌豆射手

刚开始接触图形库的时候做的一个小动图,算是致敬经典了吧。

为了留作纪念,决定把之前做的一些小玩意er搬到csdn上面来。

也给c++的一些初学者们提供一些有趣的编程实例。

1、图片素材

2、运行结果:

3、代码实例:

#include<graphics.h>
#include<conio.h>
#include<stdio.h>
using namespace std;

class p2 {
public:
	int size_x;
	int size_y;
	int init_x;
	int init_y;

	void _p2(int x1, int y1, int x2, int y2) {
		size_x = x1;
		size_y = y1;
		init_x = x2;
		init_y = y2;
	}
};
class p3 {
public:
	int size_x;
	int size_y;
	int init_x;
	int init_y;

	void _p3(int x1, int y1, int x2, int y2) {
		size_x = x1;
		size_y = y1;
		init_x = x2;
		init_y = y2;
	}
};

int main()
{
	p2 ptwo;
	p3 pthree;
	ptwo._p2(200, 200, 200, 200);
	pthree._p3(50, 50, 400, 250);
	IMAGE p2, p3;
	loadimage(&p2, "p2.png", ptwo.size_x, ptwo.size_y);
	loadimage(&p3, "p3.png", pthree.size_x, pthree.size_y);
	initgraph(800, 600);
	putimage(ptwo.init_x, ptwo.init_y, &p2);
	putimage(pthree.init_x, pthree.init_y, &p3);
	BeginBatchDraw();//开始批量绘制
	while (1)
	{
		cleardevice();
		putimage(ptwo.init_x, ptwo.init_y, &p2);
		pthree.init_x += 1;
		if (pthree.init_x == 750)
			pthree.init_x = 400;
		putimage(pthree.init_x, pthree.init_y, &p3);
		Sleep(10);
		FlushBatchDraw();//批量绘制
	}
	_getch();
	closegraph();
	return 0;
}

Guess you like

Origin blog.csdn.net/qq_51701007/article/details/121285451