c++实现图形编程

1.传奇动态小界面

素材:链接:https://pan.baidu.com/s/1qLAuEH4mO4sWYj50e6ppyw 密码:fria

#include<stdio.h>
#include<graphics.h>
#include<conio.h>
//#include<MMSystem.h>
#include <mmsystem.h>
#pragma comment(lib,"winmm.lib")
IMAGE img[24];


void loadResource()
{
	char filename[20] = "";
	for(int i = 0; i<24 ; i++)
	{
		if(i < 10)
		{
			sprintf(filename,"00%d.bmp",i);
		}
		else
		{
			sprintf(filename,"0%d.bmp",i);
		}
		loadimage(&img[i],filename);
	}
}
void putimageMyWindows()
{
	
		initgraph(570,650);
		
		int i = 0;

		mciSendString("open 传奇霸业.mp3 alias song",0,0,0);
		mciSendString("play song repeat",0,0,0);
		
	while(!_kbhit() )//1
	{
		putimage(0,0,&img[i]);
		Sleep(50);
		i++;

		if(i == 24)
			i = 0;
	}
	closegraph();
}

int main()
{
	loadResource();
	putimageMyWindows();
	return 0;
}
2.不知火舞的动态图
链接:https://pan.baidu.com/s/1BK_4o7lefwKwRI_IbAk9_Q 密码:ropi

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
IMAGE background,mm[16],mmy[16];
int imgNum = 0;
void loadResource()
{
	
	loadimage(&background,"background.jpg");
	char filenamebk[20] = "";
	char filenameym[20] = "";
	for(int i= 0 ;i <16 ;i++)
	{
		if(i < 9)
		{
			sprintf(filenamebk,"10%d.bmp",i+1);
			loadimage(&mm[i] , filenamebk);
			sprintf(filenameym,"10d%y.bmp",i+1);
			loadimage(&mmy[i],filenameym);
		}
		else
		{
			sprintf(filenamebk,"1%d.bmp",i+1);
			loadimage(&mm[i] , filenamebk);
			sprintf(filenameym,"1d%y.bmp",i+1);
			loadimage(&mmy[i],filenameym);
		}
	}
	
}
int startX = 410, startY = 300;
void putimageMyWindows()
{
	initgraph(640,480);
	int i = 0;
	while(1)
	{
		
		putimage(0,0,&background);
		putimage(410,300,&mmy[i],SRCAND);
		putimage(410,300,&mm[i],SRCPAINT);
		Sleep(50);
		i++;
		if(i == 16)
			i = 0;

	}
	
	closegraph();
}

int main()
{
	loadResource();
	putimageMyWindows();
	return 0;
}

3.c++实现键盘控制人物行走

W,A,S,D,Q,E,Z,X实现8个方向行走 素材:链接:https://pan.baidu.com/s/1jT0k8lGE5Y-1mrNMv6iftg 密码:7922

#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<stdlib.h>

IMAGE background,boy1,boy2;
int startX = 95 , startY=450;
int imgNum = 0;

void loadResource()
{
	loadimage(&background , "background.jpg");
	loadimage(&boy1,"boy1.bmp");
	loadimage(&boy2,"boy2.bmp");
}

void putimageFirstImg()
{
	initgraph(1024,768);
	putimage(0,0,&background); // 70
					// 992 / 8
	putimage(startX,startY,70,124,&boy2,70*imgNum,124*2,SRCAND);
	putimage(startX,startY,70,124,&boy1,70*imgNum,124*2,SRCPAINT);
}

void key_down()
{
	int user = _getch();
	switch(user)
	{
	case 'w':
	case 'W':
	case 72:
		BeginBatchDraw();
		putimage(0,0,&background);
		putimage(startX,startY,70,124,&boy2,70 * imgNum,124*3,SRCAND);
		putimage(startX,startY,70,124,&boy1,70 * imgNum,124*3,SRCPAINT);
		startY -= 10;
		imgNum++;
		if(imgNum == 4)
		{
			imgNum = 0;
		}
		EndBatchDraw();
		break;
	
	
	case 'S': 
	case 's':
	case 80:
		BeginBatchDraw();
		putimage(0,0,&background);
		putimage(startX,startY,70,124,&boy2,70 * imgNum,124*0,SRCAND);
		putimage(startX,startY,70,124,&boy1,70 * imgNum,124*0,SRCPAINT);
		startY += 10;
		imgNum++;
		if(imgNum == 4)
		{
			imgNum = 0;
		}
		EndBatchDraw();

		break;
	



	case 'a':
	case 'A':
	case 75:
		BeginBatchDraw();
		putimage(0,0,&background);
		putimage(startX,startY,70,124,&boy2,70 * imgNum,124*1,SRCAND);
		putimage(startX,startY,70,124,&boy1,70 * imgNum,124*1,SRCPAINT);
		startX -= 10;
		imgNum++;
		if(imgNum == 4)
		{
			imgNum = 0;
		}
		EndBatchDraw();

		break;

	case 'd':
	case 'D':
	case 77:
		BeginBatchDraw();
		putimage(0,0,&background);
		putimage(startX,startY,70,124,&boy2,70 * imgNum,124*2,SRCAND);
		putimage(startX,startY,70,124,&boy1,70 * imgNum,124*2,SRCPAINT);
		startX += 10;
		imgNum++;
		if(imgNum == 4)
		{
			imgNum = 0;
		}
		EndBatchDraw();

			
		break;

	case 'e':
	case 'E':
	case 45:
		BeginBatchDraw();
		putimage(0,0,&background);
		putimage(startX,startY,70,124,&boy2,70 * imgNum,124*7,SRCAND);
		putimage(startX,startY,70,124,&boy1,70 * imgNum,124*7,SRCPAINT);
		startX += 10;
		startY -= 10;
		imgNum++;
		if(imgNum == 4)
		{
			imgNum = 0;
		}
		EndBatchDraw();

			
		break;
	case 'q':
	case 'Q':
		BeginBatchDraw();
		putimage(0,0,&background);
		putimage(startX,startY,70,124,&boy2,70 * imgNum,124*6,SRCAND);
		putimage(startX,startY,70,124,&boy1,70 * imgNum,124*6,SRCPAINT);
		startX -= 10;
		startY -= 10;
		imgNum++;
		if(imgNum == 4)
		{
			imgNum = 0;
		}
		EndBatchDraw();
		break;

	case 'z':
	case 'Z':
		BeginBatchDraw();
		putimage(0,0,&background);
		putimage(startX,startY,70,124,&boy2,70 * imgNum,124*4,SRCAND);
		putimage(startX,startY,70,124,&boy1,70 * imgNum,124*4,SRCPAINT);
		startX -= 10;
		startY += 10;
		imgNum++;
		if(imgNum == 4)
		{
			imgNum = 0;
		}
		EndBatchDraw();
		break;

	case 'X':
	case 'x':
		BeginBatchDraw();
		putimage(0,0,&background);
		putimage(startX,startY,70,124,&boy2,70 * imgNum,124*5,SRCAND);
		putimage(startX,startY,70,124,&boy1,70 * imgNum,124*5,SRCPAINT);
		startX += 10;
		startY += 10;
		imgNum++;
		if(imgNum == 4)
		{
			imgNum = 0;
		}
		EndBatchDraw();
		break;
	}
	


}
int main()
{
	loadResource();
	putimageFirstImg();
	
	
	
	//system("pause");
	while(1)
	{
		key_down();
	}
	return 0;
}


阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zzb2019/article/details/79682613
想对作者说点什么? 我来说一句

C++游戏与图形编程基础 第2版

2016年09月21日 86.42MB 下载

c++游戏与图形编程(第二版)

2018年01月08日 86.42MB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭