浪漫表白程序
作者:互联网
//686521686
#include<stdio.h>
#include<math.h>
#include<time.h>
#include<graphics.h>
#include<mmstream.h>
#pragma comment(lib,"winmm.lib") //多媒体设备头文件
#define PI 3.1415
#define num 13
#define WIDTH 960
#define HEIGHT 460
struct Fire
{
int x, y;
int cen_x, cen_y; //中心点坐标
int r; //当前绽放半径
int max_r; //最大半径
int width, height;
DWORD pixel[240][240];//图片像素数组
bool isShow; //烟花是否准备好
bool isDraw; //是否绘制烟花
}fire[num];
struct Jet//烟花弹
{
int x, y; //坐标
int hx, hy; //最高点
bool isLaunch;//烟花弹是否在发射中
IMAGE img[2];
byte n : 1;
}jet[num];
void initData(int i)
{
fire[i].cen_x = 120;
fire[i].cen_y = 120;
fire[i].max_r = 120;
fire[i].r = 0;
fire[i].width = 240;
fire[i].height = 240;
fire[i].isDraw = false;
fire[i].isShow = false;
return;
}
void welcome()
{
mciSendString(L"open ./res/nu5.mp3", 0, 0, 0);
mciSendString(L"play ./res/nu5.mp3", 0, 0, 0);//播放音乐
for (int i = 0; i < 50; ++i)
{
cleardevice();//清屏
int x =(int)( 500 + 180 * sin(2 * PI / 60 * i));
int y = (int)(200 + 180 * cos(2 * PI / 60 * i));
settextstyle(i, 0, L"楷体");//设置字体样式
settextcolor(RGB(0, 202, 0));
setbkmode(TRANSPARENT);
outtextxy(x, y, L"浪漫表白程序");
Sleep(20);
}
_gettch();
cleardevice();//清屏
settextstyle(25, 0, L"楷体");//设置字体样式
outtextxy(350, 100, L"我欲与君相知");
outtextxy(350, 150, L"长命无绝衰");
outtextxy(350, 200, L"山无棱");
outtextxy(350, 250, L"江水为竭");
outtextxy(350, 300, L"冬雷震震");
outtextxy(350, 350, L"夏雨雪");
outtextxy(350, 400, L"天地合");
outtextxy(350, 450, L"乃敢与君绝");
}
void loadImg()
{
//初始化绽放效果
IMAGE bloomImg, tImg;
loadimage(&bloomImg, L"./res/flower.png", 613, 163);
for (int i = 0; i < num; ++i)
{
initData(i);
SetWorkingImage(&bloomImg);
getimage(&tImg, i * 240, 0, 240, 240);
SetWorkingImage(&tImg);
for (int a = 0; a < 240; ++a)
{
for (int b = 0; b < 240; ++b)
{
fire[i].pixel[a][b] = getpixel(a, b);
}
}
}
//初始化烟花弹
IMAGE jetImg;
loadimage(&jetImg, L"./res/launch.png", 600, 140);
//putimage(0, 0, &jetImg);
SetWorkingImage(&jetImg);
for (int i = 0; i < num; ++i)
{
int n = rand() % 5;
getimage(&jet[i].img[0], n*60, 0, 60, 140);
getimage(&jet[i].img[1], n*60+300, 0, 60, 140);
jet[i].isLaunch = false;
}
SetWorkingImage();
}
//产生烟花弹
void createJet()
{
int i = rand() % num;
if (jet[i].isLaunch == false)
{
jet[i].x = rand() % (WIDTH-60);
jet[i].y = rand() % 150 + HEIGHT;
jet[i].hx = jet[i].x;
jet[i].hy=rand() % (HEIGHT / 3 * 2);
jet[i].isLaunch = true;
}
}
//发射烟花弹
void launch()
{
for (int i = 0; i < num; ++i)
{
if (jet[i].isLaunch)
{
putimage(jet[i].x, jet[i].y, &jet[i].img[jet[i].n],SRCINVERT);
//是否到达最高点
if (jet[i].y > jet[i].hy)
{
jet[i].y -= 5;
jet[i].n++;
}
putimage(jet[i].x, jet[i].y, &jet[i].img[jet[i].n], SRCINVERT);
if (jet[i].y <= jet[i].hy)
{
jet[i].isLaunch = false;
fire[i].x = jet[i].x;
fire[i].y = jet[i].y;
fire[i].isShow = true;
}
}
}
}
void bloom(DWORD* pMem)
{
for (int i = 0; i < num; ++i)
{
if (fire[i].isShow)
{
if (fire[i].r < fire[i].max_r)
{
fire[i].r++;
fire[i].isDraw = true;//可以开始绘制烟花了
}
if (fire[i].r >= fire[i].max_r)
{
//fire[i].isDraw = false;//结束
initData(i);
}
}
if (fire[i].isDraw)
{
//求当前半径下,圆上的每个点对应的弧度
for (double a = 0; a <= 2 * PI; a += 0.01)
{
int img_x =(int)( fire[i].cen_x + fire[i].r * cos(a));
int img_y =(int)( fire[i].cen_y + fire[i].r * sin(a));
if (img_x > 0 && img_x < fire[i].width && img_y>0 && img_y < fire[i].height)
{
//针对现在的绽放点,对应的屏幕坐标
int win_x =(int)( fire[i].x + fire[i].r * cos(a));
int win_y =(int)( fire[i].y + fire[i].r * sin(a));
if (win_x > 0 && win_x < WIDTH && win_y>0 && win_y < HEIGHT)
{
pMem[win_y * WIDTH + win_x] = BGR(fire[i].pixel[img_x][img_y]);
}
}
}
}
}
}
int main()
{
srand((unsigned)time(NULL) + clock());
initgraph(960, 640);
welcome();
loadImg();
DWORD* pMem = GetImageBuffer();//获取窗口的内存指针
while (1)
{
for (int i = 0; i < WIDTH; ++i)
{
for (int j = 0; j < 4; ++j)
{
int x = rand() % WIDTH;
int y = rand() % HEIGHT;
if (y < HEIGHT)
{
pMem[y * WIDTH + x] = BLACK;
}
}
}
createJet();
launch();
bloom(pMem);
Sleep(10);
}
closegraph();
}
#include<stdio.h>
#include<easyx.h> //easyx图形库,需要安装一下才能使用
#include<time.h>
#include<graphics.h>
#include<conio.h>
#include<mmsystem.h>
#pragma comment(lib,"winmm.lib")
#define STAR_NUM 520 //小星星数量
#define METEOR_NUM 99 //流星的数量
struct Star //小星星
{
int x;
int y;
COLORREF color; //颜色 unsigned int
int speed; //速度
}star[STAR_NUM];
struct Meteor //流星
{
int x;
int y;
int speed;
}meteor[METEOR_NUM];
IMAGE img[2];
//开始的表白界面,说出你的心里话
void loveYou()
{
//播放音乐
mciSendString(L"open ./images/浪漫空气.mp3 alias love", NULL, NULL, NULL);
mciSendString(L"play love", NULL, NULL, NULL);
//设置随机数种子
srand((unsigned)time(NULL));
//设置文字样式
settextstyle(40, 0, L"华文行楷");
//设置背景模式
setbkmode(TRANSPARENT);
//大家把想说的话,发到公屏上
while (!_kbhit()) //如果没有按键按下,就一直循环,否则退出循环
{
//清空屏幕
cleardevice();
//让文字居中显示
WCHAR title[] = L"阿珍我喜欢你♥";
int x = (getwidth() - textwidth(title)) / 2;
int y = 20;
//输出文字
outtextxy(x, y, title);
//设置文字颜色
settextcolor(RGB(rand() % 256, rand() % 256, rand() % 256));
outtextxy(200, 100, L"记得那是一个夏日的午后");
outtextxy(200, 150, L"你和我在那棵桃树下");
outtextxy(200, 200, L"请君入目,夜月皆无。");
outtextxy(200, 250, L"爱上你是我在这世界上做过的最容易的事");
outtextxy(200, 300, L"爱上你是我情非得已");
outtextxy(200, 350, L"我爱你就像风走了千万里从不问归期");
outtextxy(200, 400, L"那天你问我什么是爱情");
outtextxy(200, 450, L"我爱你像风走了八千里");
outtextxy(200, 500, L"");
outtextxy(200, 550, L"");
outtextxy(200, 600, L"---------------------------爱你的阿强");
for (int i = 0; i < 10; i++)
{
settextcolor(RGB(rand() % 256, rand() % 256, rand() % 256));
outtextxy(rand() % getwidth(), rand() % getheight(), L"♥");
}
Sleep(800);
}
cleardevice();
}
/***** 初始化小星星 ****/
void initStar(int i)
{
star[i].x = rand() % getwidth();
star[i].y = rand() % getheight();
star[i].speed = rand() % 4 + 1;
star[i].color = RGB(rand() % 256, rand() % 256, rand() % 256);
}
void drawStar()
{
for (int i = 0; i < STAR_NUM; i++)
{
putpixel(star[i].x, star[i].y, star[i].color);
}
}
void moveStar()
{
for (int i = 0; i < STAR_NUM; i++)
{
star[i].x += star[i].speed;
if (star[i].x > getwidth())
{
star[i].x = 0;
}
}
}
/***** 初始化流星 ****/
void loadImg()
{
loadimage(img, L"./images/1.jpg", 50, 50);
loadimage(img + 1, L"./images/2.jpg", 50, 50);
}
void initMeteor(int i)
{
meteor[i].x = rand() % (2 * getwidth()) - getwidth(); //[0-2400) - 1200 ->[-1200 - 1200)
meteor[i].y = rand() % 20 - 200; //[0-20) -> [-200,-180)
meteor[i].speed = rand() % 15 + 1;
}
//把流星贴出来
void drawMeteor()
{
for (int i = 0; i < METEOR_NUM; i++)
{
putimage(meteor[i].x, meteor[i].y, img + rand() % 2, SRCPAINT);
}
}
void moveMeteor()
{
for (int i = 0; i < METEOR_NUM; i++)
{
meteor[i].x += meteor[i].speed;
meteor[i].y += meteor[i].speed;
if (meteor[i].x >= getwidth() || meteor[i].y >= getheight())
{
initMeteor(i);
}
}
}
int main()
{
//1,创建图形窗口
initgraph(1200, 600);
loveYou();
loadImg();
for (int i = 0; i < STAR_NUM; i++)
{
initStar(i);
}
for (int i = 0; i < METEOR_NUM; i++)
{
initMeteor(i);
}
//双缓冲绘图
BeginBatchDraw();
while (true)
{
cleardevice();
drawStar();
moveStar();
drawMeteor();
moveMeteor();
FlushBatchDraw();
}
getchar(); //防止闪退
return 0;
}
标签:rand,jet,表白,int,程序,++,fire,浪漫,outtextxy 来源: https://blog.csdn.net/touso/article/details/117134568