回 帖 发 新 帖 刷新版面

主题:[原创]模拟烟花爆炸较果

   [b]下面程序在TC2.0下调式通过[/b]  
      小弟现丑了
     请各位大哥大姐指点
    
  付:请注意最后一个函数

/******************************************
    程序功能: 模似烟花爆炸较果
        作者: lirne
        时间: 06.04.14
        联系: liren0@126.com
*******************************************/

#include <graphics.h>
#include <math.h>
#include <stdlib.h>
#define SPEED 50          /*定义烟花运动的最大初速度*/
#define LTIME 30          /*定义烟花的最大生命值*/
#define MAX 40            /*定义烟花的最大个数*/
#define g 9.8             /*定义重力加速度*/

/*******定义烟花结构体类型*********/
struct yh{
    int x0,y0;             /*烟花的爆炸的坐标*/
    int x1,y1;             /*烟花某一时刻的坐标*/
    int v0;                /*初速度*/
    double t;
    int derc;               /*运动方向*/
    int ltime;               /*生命值*/
    int color;               /*颜色*/

};

struct yhs{
       int x;  /*烟花的爆炸的坐标和上面X0,Y0的值一样可去掉其一*/
       int y;
       int star_n;
       struct yh stars[MAX];
};


void star_init (struct yh *,int ,int);
void star_show (int,int,int,int);
void star_hind (struct yh *);
void star_next (struct yh *);

main(){
    int gd,gm;
    struct yhs star;
    int i;
    initgraph(&gd,&gm,"");


begin:

    star.x=100+random(440);      /* 随机生成烟花爆炸坐标*/
    star.y=100+random(280);
    star.star_n=random(MAX);
    for(i=0;i<star.star_n;i++)
    star_init(&star.stars[i],star.x,star.y);   /*初始化烟花*/
      while(!bioskey(1)){
           for(i=0;i<star.star_n;i++)
            star_show(star.stars[i].x1,star.stars[i].y1,
                 star.stars[i].color,star.stars[i].ltime);    /*显示烟花*/
            delay(10000);              /*显示延迟*/
              delay(10000);
            delay(10000);
              delay(10000);
       for(i=0;i<star.star_n;i++)
           star_show(star.stars[i].x1,star.stars[i].y1,
          BLACK,star.stars[i].ltime);/*隐藏烟花*/

        for(i=0;i<star.star_n;i++)
             star_next(&star.stars[i]);/* 计算下一步位置 */

        for(i=0;i<star.star_n;i++)
         if(star.stars[i].ltime>0)break;
         if(i>=star.star_n)goto begin;

     }
     closegraph();
}

/****初始化烟花*******/

void star_init(struct yh * sta,int x,int y){


    sta->x0=sta->x1=x;
    sta->y0=sta->y1=y;
    sta->v0=random(SPEED);
    sta->t=0;
    sta->derc=random(360);
    sta->ltime=random(LTIME);
    sta->color=random(16);
}

/*******显示/隐藏烟花*******/
void star_show(int x,int y,int color,int ltime){
  switch(ltime/10){         /*根据生命值显示烟花大小*/ 
    case 2:
         putpixel(x,y+2,color);
         putpixel(x,y-2,color);
           putpixel(x+2,y,color);
            putpixel(x-2,y,color);
         putpixel(x,y+3,color);


    case 1:
         putpixel(x-1,y,color);
        putpixel(x+1,y,color);
         putpixel(x,y-1,color);
          putpixel(x,y+1,color);
           putpixel(x,y+2,color);

    case 0:
         putpixel(x,y,color);

   }
}

/******计算烟花下一步的位置*******/

void star_next(struct yh * sta){

    sta->t+=0.1;
    sta->ltime-=1;
    sta->x1=sta->x0+sta->v0*cos(sta->derc/3.14)*sta->t;  /*平抛运动*/
    sta->y1=sta->y0+sta->v0*(-sin(sta->derc/3.14))      
    *sta->t+1/2.0*g*sta->t*sta->t;
       /*不知道为什么将这里的正佘弦中的弧度改为sta->derc/180*3.14 不行*/
}


回复列表 (共39个回复)

11 楼

我用的是VC,为什么说差一个头文件呀?
Cannot open include file: 'graphic.h': No such file or directory
请教哪位大侠我该怎么补上这个.h呢?

12 楼

可能是你TC下的驱动程序有误或者丢失了吧
也可能是TC的问题
我的TC在每次打开之后如果运行3~5次图形程序
也会出现那样的问题
要重启才行啊
所以说也郁闷啊

13 楼

VC6。0没有graphics.h这个头文件
这是一个古老的东西, VC已经丢弃了
你最好还是在TC下编译

14 楼


VC没有graphics.h这个头文件啊
你还是在TC下搞吧

兄弟
 物理学得不错吧

15 楼


VC没有graphics.h这个头文件啊
你还是在TC下搞吧

兄弟
 物理学得不错吧?

16 楼



[fly]SYRE  [/fly][em9]
[fly]JHD [/fly]

17 楼

哦,原来如此啊,那我去装个TC来试试

18 楼

回复第 10 楼
在main()函数中有一个语句:initgraph(&gd,&gm," ");是这样的,你应该把它改为你的turbo c中BGI的路径:如,initgraph(&gd,&gm,"D:\TC2");假如你的tc是在D盘的根目录的话。

19 楼

!!!惊叹!!  强人!

20 楼

顶,牛比

我来回复

您尚未登录,请登录后再回复。点此登录或注册