| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 783 人关注过本帖
标题:VC++烟花
取消只看楼主 加入收藏
RobinWang
Rank: 3Rank: 3
来 自:北京
等 级:论坛游侠
帖 子:69
专家分:121
注 册:2013-5-31
结帖率:50%
收藏
 问题点数:0 回复次数:0 
VC++烟花
#include <graphics.h>
#include <conio.h>
#include <iostream.h>
#include <math.h>
#include <time.h>
#include <stdio.h>
#include <Mmsystem.h>        
#pragma comment ( lib, "Winmm.lib" )
#define NUM        13
struct FIRE
{
int max_r;               
int x, y;            
int cen_x, cen_y;   
int width, height;        
int xy[240][240];   
bool show;               
bool draw;               
DWORD t1, t2, dt;        
int r;               
int counter;            
}Fire[NUM];
struct JET
{
int x, y;               
int hx, hy;               
int height;               
DWORD t1, t2, dt;        
IMAGE img[2];            
byte n : 1;            
bool shoot;               
}Jet[NUM];
struct HAPPY
{
int x, y;
IMAGE img;
}Happy[NUM];
struct WISH
{
int x, y;
DWORD t1, t2, dt;
IMAGE img;
int speed;
byte dir : 1;
}Wish;
void Init( int );
void Load();
void Shoot();               
void Chose( DWORD& );        
void Wishing();
void clear( int _x[], int _y[])
{
for ( int i = 0; i < 900; i ++ )
{
_x[i] = rand() % 1200;
_y[i] = rand() % 800;
}
}
void main()
{
initgraph( 1200, 700 );
srand( time(0) );
setfont( 26, 0, "华文" );
setcolor( YELLOW );
outtextxy( 520, 100, "北华大学Robin制作 .... ^_^ ");
Load();
for ( int i = 0; i < NUM; i++ )
Init( i );
int _x[900], _y[900];
setfillstyle( 0 );
int drt[16] = { 5, 5, 5, 5, 5, 6, 25, 25, 25, 25, 55, 55, 55, 55, 55 };
DWORD t1 = timeGetTime();
mciSendString( "open ./fire/bk.mp3 alias bk", 0, 0, 0 );
mciSendString( "play bk repeat", 0, 0, 0 );
BeginBatchDraw();
while ( !kbhit() )
{
Sleep( 2 );
clear( _x, _y );
for ( int clr = 0; clr < 900; clr++ )
bar( _x[clr], _y[clr], _x[clr] + 1, _y[clr] + 1);
Chose( t1 );
Shoot();
Wishing();
for ( int i = 0; i < NUM; i++ )
{
Fire[i].t2 = timeGetTime();
}
for ( i = 0; i < NUM; i++ )
{
if ( Fire[i].t2 - Fire[i].t1 > Fire[i].dt && Fire[i].show == true )
{
if ( Fire[i].r < Fire[i].max_r )
{
Fire[i].r++;
Fire[i].dt = drt[Fire[i].r / 10];
Fire[i].draw = true;
}
if ( Fire[i].r >= Fire[i].max_r - 1 )
{
Fire[i].counter++;
Fire[i].draw = false;
}
if ( Fire[i].counter > 17 )
Init( i );
Fire[i].t1 = Fire[i].t2;
}
}
for ( i = 0; i < NUM; i++ )
{
if ( Fire[i].draw )
{
for ( double a = 0; a <= 6.28; a += 0.01 )
{
int x1 = (int)( Fire[i].cen_x + Fire[i].r * cos(a) );        //
int y1 = (int)( Fire[i].cen_y - Fire[i].r * sin(a) );
if ( x1 >0 && x1 < Fire[i].width && y1 > 0 && y1 < Fire[i].height )
putpixel( Fire[i].x - Fire[i].cen_x + x1, Fire[i].y - Fire[i].cen_y + y1 , Fire[i].xy[x1][y1] );
}
Fire[i].draw = false;
}
}
FlushBatchDraw();
}
}
// 重置烟花参数
void Init( int i )
{
int r[13] = { 120, 120, 155, 123, 130, 147, 138, 138, 130, 135, 140, 132, 155 };
int x[13] = { 120, 120, 110, 117, 110, 93, 102, 102, 110, 105, 100, 108, 110 };
int y[13] = { 120, 120, 85, 118, 120, 103, 105, 110, 110, 120, 120, 104, 85 };
Fire[i].x = 0;
Fire[i].y = 0;
Fire[i].width  = 240;
Fire[i].height = 240;
Fire[i].max_r  = r[i];
Fire[i].cen_x  = x[i];
Fire[i].cen_y  = y[i];
Fire[i].show   = false;
Fire[i].dt = 5;
Fire[i].t1 = timeGetTime();
Fire[i].r  = 0;
Fire[i].counter = 0;
Jet[i].x = -240;
Jet[i].y = -240;
Jet[i].hx = -240;
Jet[i].hy = -240;
Jet[i].height = 0;
Jet[i].t1 = timeGetTime();
Jet[i].dt = rand() % 10;
Jet[i].n = 0;
Jet[i].shoot = false;
}
void Load()
{
IMAGE fm, gm;
loadimage( &fm, "./fire/flower.jpg", 3120, 240 );
for ( int i = 0; i < 13; i++ )
{
SetWorkingImage( &fm );
getimage( &gm, i * 240, 0, 240, 240 );
SetWorkingImage( &gm );
for ( int a = 0; a < 240; a++ )
for ( int b = 0; b < 240; b++ )
Fire[i].xy[a][b] = getpixel( a, b );
}
IMAGE sm;
loadimage( &sm, "./fire/shoot.jpg", 200, 50 );
for ( i = 0; i < 13; i++ )
{
SetWorkingImage( &sm );
int n = rand() % 5;
getimage( &Jet[i].img[0], n * 20, 0, 20, 50 );
getimage( &Jet[i].img[1], (n + 5) * 20, 0, 20, 50 );
}
IMAGE hm;
loadimage( &hm, "./fire/happy.jpg", 689, 115 );
SetWorkingImage( &hm );
for ( i = 0; i < 13; i++ )
{
Happy[i].x = i * 90;
Happy[i].y = rand() % 100 + 500;
getimage( &Happy[i].img, i * 53, 0, 53, 115 );
}
Wish.x = 0;
Wish.y = 100;
Wish.t1 = timeGetTime();
Wish.dt = 46;
Wish.dir = 0;
Wish.speed = rand() % 8 + 1;
loadimage( &Wish.img, "./fire/yaojing.jpg", 490, 100 );
putimage( Wish.x, Wish.y, &Wish.img, SRCINVERT );
SetWorkingImage();
}
void Chose( DWORD& t1 )
{
DWORD t2 = timeGetTime();
if ( t2 - t1 > 50 )
{
int n = rand() % 20;
if ( n < 13 && Jet[n].shoot == false && Fire[n].show == false )
{
Jet[n].x  = rand() % 1200;
Jet[n].y  = rand() % 100 + 600;
Jet[n].hx = Jet[n].x;
Jet[n].hy = rand() % 400;
Jet[n].height = Jet[n].y - Jet[n].hy;
Jet[n].shoot = true;
putimage( Jet[n].x, Jet[n].y, &Jet[n].img[Jet[n].n], SRCINVERT );
char c1[50], c2[30], c3[30];
sprintf( c1, "open ./fire/shoot.wav alias s%d", n );
sprintf( c2, "play s%d", n );
sprintf( c3, "close n%d", n );
mciSendString( c3, 0, 0, 0 );
mciSendString( c1, 0, 0, 0 );
mciSendString( c2, 0, 0, 0 );
}
t1 = t2;
}
}
void Shoot()
{
IMAGE yaojing;
for ( int i = 0; i < 13; i++ )
{
Jet[i].t2 = timeGetTime();
if ( Jet[i].t2 - Jet[i].t1 > Jet[i].dt && Jet[i].shoot == true )
{
putimage( Jet[i].x, Jet[i].y, &Jet[i].img[Jet[i].n], SRCINVERT );
if ( Jet[i].y > Jet[i].hy )
{
Jet[i].n++;
Jet[i].y -= 3;
}
putimage( Jet[i].x, Jet[i].y, &Jet[i].img[Jet[i].n], SRCINVERT );
if ( (Jet[i].y - Jet[i].hy) * 4 < Jet[i].height )   
Jet[i].dt = 10;
if ( Jet[i].y <= Jet[i].hy )
{
char c1[50], c2[30], c3[30];
sprintf( c1, "open ./fire/bomb.wav alias n%d", i );
sprintf( c2, "play n%d", i );
sprintf( c3, "close s%d", i );
mciSendString( c3, 0, 0, 0 );
mciSendString( c1, 0, 0, 0 );
mciSendString( c2, 0, 0, 0 );
putimage( Jet[i].x, Jet[i].y, &Jet[i].img[Jet[i].n], SRCINVERT );
Fire[i].x = Jet[i].hx;
Fire[i].y = Jet[i].hy;
Fire[i].show = true;
Jet[i].shoot = false;
putimage( Happy[i].x, Happy[i].y, &Happy[i].img, SRCINVERT );
}
Jet[i].t1 = Jet[i].t2;
}
}
}
void Wishing()
{
Wish.t2 = timeGetTime();
if ( Wish.t2 - Wish.t1 > Wish.dt )
{
putimage( Wish.x, Wish.y, &Wish.img, SRCINVERT );
Wish.t1 = Wish.t2;
if ( Wish.dir == 0 )
Wish.x += Wish.speed;
else
Wish.y -= Wish.speed;
putimage( Wish.x, Wish.y, &Wish.img, SRCINVERT );
if ( Wish.x > 1200 || Wish.y < 0 )
{
Wish.dir = rand() % 2;
if ( Wish.dir == 0 )
{
Wish.y = rand() % 600;
Wish.x = -490;
Wish.speed = rand() % 7 + 1;
}
else
{
Wish.speed = rand() % 7 + 1;
Wish.x = rand() % 700;
Wish.y = 700;
}
}
}
}
搜索更多相关主题的帖子: comment counter include 
2013-05-31 18:28
快速回复:VC++烟花
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021721 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved