Beispiel #1
0
void LEVEL4(void){//レベル4に出る半分を埋め尽くす円
  if(a==4){//半分を埋め尽くす円
    newpen(win, 4);//色は青
    fillcirc(win, harf_x, harf_y, 200.0, 200.0);
    if(harf_x == 400){//右側の場合の当たり判定	   
      if( (200+5)*(200+5) >
	  (x-400)*(x-400)+(25-harf_y)*(25-harf_y) ){
	gclr(win);
	newpen(win, 1);
	drawstr(win, 150, 250, 24, 0.0, "GAMEOVER");
	msleep(time*30);
	exit(0);	 
      }
    }
    if(harf_x == 0){//左側の場合の当たり判定
      if( (200+5)*(200+5) >
	  (x-0)*(x-0)+(25-harf_y)*(25-harf_y) ){
	gclr(win);
	newpen(win, 1);
	drawstr(win, 150, 250, 24, 0.0, "GAMEOVER");
	msleep(time*30);
	exit(0);
      }
    }
    harf_y-=5;//落下速度
  }
}
Beispiel #2
0
static void remake_tree(int win, double order, double rt, double ra,
			double rnd, int bgcolor_r, int bgcolor_g,
			int bgcolor_b)
{
  Cdbl z2 = 0 + 0.9 * L / (1 - pow(rt, order + 1)) * I;
  Cdbl z1 = 0;
  int i;
  /* 背景色専用レイヤ */
  layer(win, 0, 2);
  for (i = 0; i < L; i++) {
    newrgbcolor(win, bgcolor_r + 128.0 * i / L,
		bgcolor_g + 128.0 * i / L, bgcolor_b + 128.0 * i / L);
    drawline(win, -L / 2, i, L / 2 - 1, i);
  }
  /* treeのマスク専用レイヤ */
  layer(win, 0, 4);
  gsetbgcolor(win, "#ffffff");
  gclr(win);
  newcolor(win, "#000000");
  btree(win, z1, z2, order, rt, ra, rnd);
  /* treeの専用レイヤ */
  layer(win, 0, 3);
  gsetbgcolor(win, "#003300");
  gclr(win);
  newgcfunction(win, GXandInverted);
  gputarea(win, -L / 2, 0, win, 4, -L / 2, 0, L / 2 - 1, L - 1);
  newgcfunction(win, GXcopy);
  newcolor(win, "white");
  drawstr(win, L / 2 - 180, 4, 14, 0, "Background Color: "
	  "#%02x%02x%02x", bgcolor_r, bgcolor_g, bgcolor_b);
}
Beispiel #3
0
void draw(void *_prms)
{
  param_set *p = (param_set *) _prms;
  int i;
  double psc = 2 * R / Hmax, vdistmax;

  gclr(*p->win);
  copylayer(*p->win, 2, 1);
  for (i = 0; i < DN; i++) {
    putimg24m(*p->win, x[i] - 4, y[i] - 4, 8, 8, Xpm_image_stone4);
  }
  copylayer(*p->win, 1, 0);

  gclr(*p->win2);
  vdistmax = vdist[0];
  for (i = 0; i < Hmax; i++) {
    if (vdistmax < vdist[i])
      vdistmax = vdist[i];
  }
  newcolor(*p->win2, "steelblue4");
  for (i = 0; i < Hmax; i++) {
    fillrect(*p->win2, psc * i, 0, psc, vdist[i] / vdistmax * R);
  }
  newcolor(*p->win2, "steelblue");
  for (i = 0; i < Hmax; i++) {
    drawrect(*p->win2, psc * i, 0, psc, vdist[i] / vdistmax * R);
  }
  copylayer(*p->win2, 1, 0);
}
Beispiel #4
0
int main()
{
  int win, win2, win3;
  double t = 0, h = 2 * M_PI / 100, quit = 0, run = 1;
  double clr2 = 0, clr3 = 0;
  double r[6] = { 0 };

  param_set prms = { &win, &win2, &win3, &F, &D, &B, &t, &h,
    &clr2, &clr3, &run, r
  };
  e_ctrl ctrls[] = {
    {"Force", &F, 0.1, &init, &prms},
    {"Dumping", &D, 0.01, &init, &prms},
    {"Nonlinear", &B, 0.1, &init, &prms},
    {"_Clear Phase", &clr2, 0, NULL, NULL},
    {"_Clear Poincare", &clr3, 0, NULL, NULL},
    {"_Run", &run, 0, NULL, NULL},
    {"_Quit", &quit, 0, NULL, NULL},
  };
  int cwin;
  cwin = init_ctrls(ctrls, 7);

  win = gopen(2 * WD + 2 * MG, HT);
  win2 = gopen(WD + MG, HT);
  win3 = gopen(WD + MG, HT);
  window(win, 0, -HT / 2, 2 * WD + 2 * MG, HT / 2 - 1);
  window(win2, -(MG + WD) / 2, -HT / 2, (WD + MG) / 2 - 1, HT / 2 - 1);
  window(win3, -(MG + WD) / 2, -HT / 2, (WD + MG) / 2 - 1, HT / 2 - 1);
  winname(win2, "Phase chart");
  winname(win3, "Poincare chart");
  layer(win, 0, 1);
  layer(win2, 0, 1);
  layer(win3, 0, 1);
  gsetbgcolor(win, ECTRL_BGCOLOR);
  gsetbgcolor(win2, ECTRL_FGCOLOR);
  gsetbgcolor(win3, ECTRL_FGCOLOR);
  newcolor(win, ECTRL_FGCOLOR);
  newcolor(win2, ECTRL_BGCOLOR);
  newcolor(win3, "red3");
  gclr(win2);
  gclr(win3);
  gsetnonblock(ENABLE);

  while (!quit) {
    int iscwin, type, button;
    double wx, wy;
    iscwin = ggetxpress(&type, &button, &wx, &wy);
    display_ctrls(cwin, ctrls, 7, wx, wy, iscwin, type, button);
    if (run) {
      rk4fixv6(duffing, t, r, h);
      t += h;
      draw(&prms);
    }
    msleep(5);
  }
  gcloseall();
  return 0;
}
Beispiel #5
0
void init(void *_prms)
{
  param_set *p = (param_set *) _prms;

  *p->t = 0;
  gclr(*p->win2);
  gclr(*p->win3);
  p->r[0] = 0;
  p->r[1] = 0;
  *p->run = 0;
}
Beispiel #6
0
int main()
{
    int win ;
    time_t time_now ;
    char d0[8],d1[8],d2[8],d3[8], t0[16] ;

    /* open a graphic window */
    win = gopen(FONTSIZE*24/2+4,FONTSIZE+4) ;
    /* set name of window */
    winname(win,"Simple Clock") ;
    /* configure layer */
    layer(win,0,1) ;
    /* display time... */
    while(1){
        time(&time_now) ;
        sscanf(ctime(&time_now),"%s %s %s %s %s",d0,d1,d2,t0,d3) ;
	gclr(win) ;
	drawstr(win,2,2,FONTSIZE,0,"%s %s %s %s %s",d0,d1,d2,t0,d3) ;
	copylayer(win,1,0) ;
	msleep(200) ;
    }
    /* close a graphic window */
    gclose(win) ;

    return(0) ;
}
Beispiel #7
0
void init(void *_prms)
{
  param_set *p = (param_set *) _prms;
  int i, j;

  *p->mid = (L + 1) / 2;	/* screen mid */
  for (i = 0; i < L + 2; i++)
    for (j = 0; j < L + 2; j++)
      grid[i][j] = 0;
  grid[(int) *p->mid][(int) *p->mid] = 1;

  if (*p->R >= L) {
    while (*p->R >= L - 1) {
      *p->R -= dR;
    }
  }
  *p->src_r = 0;
  *p->new_r = 1;
  *p->rem_r = 0;
  *p->reset = 0;
  layer(*p->win, 0, 2);
  gsetbgcolor(*p->win, ECTRL_BGCOLOR);
  newcolor(*p->win, "#303030");
  gclr(*p->win);
  fillarc(*p->win, *p->mid, *p->mid, *p->R / 2, *p->R / 2, 0, 360, 0);
  layer(*p->win, 0, 1);
  copylayer(*p->win, 2, 1);
  copylayer(*p->win, 1, 0);
}
Beispiel #8
0
int main()
{
    time_t time_now ;
    int win ;
    char d0[8],d1[8],d2[8],d3[8], t0[16] ;

    gsetinitialattributes(ENABLE,DOCK_APPLICATION) ;
    win = gopen(56,56) ;
    layer(win,0,1) ;
    while(1){
	time(&time_now) ;
	sscanf(ctime(&time_now),"%s %s %s %s %s\n",d0,d1,d2,t0,d3) ;
	gclr(win) ;
	newrgbcolor(win,0xff,0xff,0xff) ;
	drawstr(win,4,1, 8 ,0,"%s %s %s",d0,d1,d2) ;
	drawstr(win,4,46, 10 ,0,"%s",t0) ;
	gputimage(win,0,10,Ppmimage,PPM_WIDTH,PPM_HEIGHT,0) ;
	newrgbcolor(win,0x40,0x40,0x40) ;
	moveto(win,0,0) ;
	lineto(win,0,55) ;
	lineto(win,55,55) ;
	newrgbcolor(win,0xe7,0xe7,0xe7) ;
	lineto(win,55,0) ;
	lineto(win,0,0) ;
	copylayer(win,1,0) ;
	msleep(200) ;
    }
    gcloseall() ;
    return(0) ;
}
Beispiel #9
0
void init(void *_prms)
{
  param_set *p = (param_set *) _prms;
  int i, j;
  double th;

  layer(*p->win, 0, 4);		/* mask */
  gsetbgcolor(*p->win, "black");
  gclr(*p->win);
  newcolor(*p->win, "white");
  fillcirc(*p->win, 0, 0, R, R);
  newcolor(*p->win, "black");
  fillcirc(*p->win, *p->x0, 0, *p->IR, *p->IR);


  layer(*p->win, 0, 3);		/* image-mapped wall and colored vacuum */
  gsetbgcolor(*p->win, ECTRL_BGCOLOR);
  gclr(*p->win);
  for (i = 0; i < 2; i++)
    for (j = 0; j < 2; j++)
      putimg24(*p->win, (i - 1) * 200, (j - 1) * 200, 200, 200,
	       Xpm_image_slope);
  newgcfunction(*p->win, GXandInverted);
  gputarea(*p->win, -R, -R, *p->win, 4, -R, -R, R, R);

  layer(*p->win, 0, 2);		/* compose background image */
  gclr(*p->win);
  newgcfunction(*p->win, GXand);
  gputarea(*p->win, -R, -R, *p->win, 4, -R, -R, R, R);
  newgcfunction(*p->win, GXor);
  gputarea(*p->win, -R, -R, *p->win, 3, -R, -R, R, R);
  newgcfunction(*p->win, GXcopy);

  layer(*p->win, 0, 1);
  copylayer(*p->win, 2, 1);	/* copy background image */
  for (i = 0; i < N; i++) {
    th = drand48() * 2 * M_PI;
    x[i] = 0.95 * R * cos(th);
    y[i] = 0.95 * R * sin(th);
    vx[i] = (drand48() - 0.5) * Hmax;
    vy[i] = drand48() * Hmax * sin(drand48() * 2 * M_PI);
  }
  *p->run = 0;
  getstatis();
  draw(p);
}
Beispiel #10
0
void draw(void *_prms)
{
  param_set *p = (param_set *) _prms;
  static double y[2 * WD], v[2 * WD];
  int i;
  static int poincare = 0;

  for (i = 0; i < 2 * WD - 1; i++) {
    y[i] = y[i + 1];
    v[i] = v[i + 1];
  }
  y[2 * WD - 1] = p->r[0];
  v[2 * WD - 1] = p->r[1];

  /* y-t chart */
  gclr(*p->win);
  newcolor(*p->win, "gold");
  drawline(*p->win, MG, 0, 2 * WD + MG, 0);
  newcolor(*p->win, ECTRL_FGCOLOR);
  for (i = 0; i < 2 * WD; i++) {
    pset(*p->win, MG + i, y[i] * HT * SCY);
  }
  copylayer(*p->win, 1, 0);

  /* phase chart */
  if (*p->clr2 == 1) {
    gclr(*p->win2);
    *p->clr2 = 0;
  }
  for (i = 0; i < 2 * WD; i++) {
    pset(*p->win2, y[i] * HT * SCY, v[i] * SCV);
  }
  copylayer(*p->win2, 1, 0);

  /* poincare chart */
  if (*p->clr3 == 1) {
    gclr(*p->win3);
    *p->clr3 = 0;
  }
  if (poincare % 50 == 0) {
    pset(*p->win3, y[2 * WD - 1] * HT * SCY, v[2 * WD - 1] * SCV);
    copylayer(*p->win3, 1, 0);
  }
  poincare++;
}
Beispiel #11
0
void game(void){//ゲーム内容
  int j;
  
  gsetnonblock(ENABLE);//ノンブロッキングモードに
  while(1){	
    gclr(win);//画面消去
   
    //防護壁のx座標設定(レベル5になるまで値変化)
    defence_x=rand()%400;
    if(defence_x > 320){//x座標が340を超えたら340以下の数を減らす
      defence_x -= rand()%320;
    }
    LEVEL5();//レベル5の動作
    
    newpen(win, 1);
    level();// レベルの表記
    timecount();//時間の表記
    human();// 棒人間
    input();//入力待ち
    
    for(i=0; i<kosu; i++){
      j = rand() % 16;// 色はランダム
      if(j < 3) j = j + rand() % 10 + 3;//色は3〜15のどれか 
      if(a > 2){	 //レベル3、4でときどき黒になって消えて見える
	if(rand()%5 == 0) j = 0;
      }
      newpen(win, j);
      fillrect(win, x_sq[i], y_sq[i], w_sq[i], h_sq[i]);//四角	 
      fillcirc(win, x_circ[i], y_circ[i], r_circ[i], r_circ[i]);//円	        
      LEVEL4();//レベル4のみ出る円(半分を埋め尽くす円)
      
      //落下速度dx,dy
      y_sq[i] -= dy;
      y_circ[i] -= dy;
      
      LEVEL2();//レベル2以上で変化させる
    }
    atari();//当たり判定
    
    msleep(time);// 0.1秒止める
    
    count++;
    if(count/10 == 20*a){// カウント10回=約1秒とする
      dy += rand()%2+1;//速度変化は毎回変わる
      dx += rand()%2;//揺れる大きさ
      a++;//レベル
      kosu+=rand()%2+1;//増やす個数は毎回変わる 
      dh+=3;//通常四角の縦幅変化量
      dw+=3;//通常四角の横幅変化量
      dr+=3;//通常円の半径の変化量
    }
  }    
}
Beispiel #12
0
int main()
{
    int win;
    int cnt;
    float x_cen = X_CEN;
    float y_cen = Y_CEN;

    win = gopen(WIDTH,HEIGHT);

    puts("Move your mouse cursor on the window :-)");

    /* レイヤの設定をする */
    layer(win, 0,1);
    /* ノンブロックモードにする */
    gsetnonblock(ENABLE);

    cnt = 0;
    while ( 1 ) {
	int win_ev;	/* イベントのあったウィンドゥ番号 */
	int type, b;	/* イベントのタイプ,ボタン */
	float r, x, y;
	win_ev = ggetevent(&type,&b,&x,&y) ;
	if ( win_ev == win ) {
	    if ( type == MotionNotify ){
		x_cen = x;
		y_cen = y;
	    }
	    else if ( type == ButtonPress ) {
		break;
	    }
	}
	else {
	    int i;
	    if ( CNT_MAX <= cnt ) cnt = 0;
	    gclr(win);
	    for ( i=0 ; i < 4 ; i++ ) {
		r = pow((cnt+i*(CNT_MAX/4)) % CNT_MAX, 2)/DIV;
		drawcirc(win,x_cen,y_cen,r,r);
	    }
	    copylayer(win, 1,0);
	    msleep(20);
	    cnt++;
	}
    }
    gclose(win);

    return(0);
}
Beispiel #13
0
void draw(void *_prms)
{
  param_set *p = (param_set *) _prms;
  double x, y ; 
  double rad ;
  char tstr[20];

  rad = p->r[0];

  y = L*cos(rad)*SC; 
  x = L*sin(rad)*SC;
  gclr(*p->win);
  sprintf(tstr, "t = %.4f", *p->t);
  newrgbcolor(*p->win, 204,153, 0);
  fillrect(*p->win, -WD/2, -MG, WD, 18);
  newpen(*p->win, 1);
  moveto(*p->win, -x, 0);
  lineto(*p->win, x, 2*y);
  drawstr(*p->win, -WD/2+MG, HT-2*MG, 14, 0, tstr);
  copylayer(*p->win, 1, 0);
}
Beispiel #14
0
void draw(void *_prms)
{
  param_set *p = (param_set *) _prms;
  double maskx[4], masky[4];
  double rad;

  rad = *p->angle * M_PI / 180;
  maskx[0] = maskx[1] = *p->sx;
  maskx[2] = maskx[3] = *p->sx + 200;
  masky[0] = 0;
  masky[1] = masky[2] = 200;
  masky[3] = 200 * tan(*p->angle * M_PI / 180);

  gclr(*p->win);
  putimg24(*p->win, *p->sx, 0, 200, 200, Xpm_image_slope);
  newcolor(*p->win, ECTRL_BGCOLOR);
  fillpoly(*p->win, maskx, masky, 4, 0);
  putimg24m(*p->win, *p->bx - 10 * (sin(rad) + 1),
	    *p->by + 10 * (cos(rad) - 1), 20, 20, Xpm_image_stone10);
  newcolor(*p->win, ECTRL_FGCOLOR);
  drawline(*p->win, X0 + L, 0, X0 + L, 220);
  copylayer(*p->win, 1, 0);
}
Beispiel #15
0
void draw(void *_prms)
{
  param_set *p = (param_set *) _prms;
  int id, aggr = 0, this_r;
  int x, y, xnt, ynt, tk, key = 0;
  float tx[50000], ty[50000], th;

  for (;;) {
    if (*p->new_r) {
      *p->new_r = 0;
      *p->src_r += *p->r_inc;
      *p->rem_r = *p->src_r + *p->r_inc;
      if (*p->src_r >= (*p->R / 2)) {
	*p->run = 0;
	print_density(p);
	break;
      }
    }

    th = drand48() * 2.0 * M_PI;
    x = *p->src_r * cos(th) + *p->mid;
    y = *p->src_r * sin(th) + *p->mid;
    tk = 0;

    while (*p->run) {
      id = floor(drand48() * 4.0);
      xnt = (id == 0) ? x - 1 : (id == 1) ? x + 1 : x;
      ynt = (id <= 1) ? y : (id == 2) ? y - 1 : y + 1;
      tx[tk] = xnt;
      ty[tk] = ynt;
      this_r = hypot(xnt - *p->mid, ynt - *p->mid);

      if ((xnt < *p->mid - *p->R) || (xnt >= *p->mid + *p->R) ||
	  (ynt < *p->mid - *p->R) || (ynt >= *p->mid + *p->R) ||
	  (this_r > *p->rem_r)) {
	newcolor(*p->win, "red4");
	break;
      }
      /* seems to escape */
      if (grid[xnt - 1][ynt] == 1 || grid[xnt][ynt - 1] == 1 ||
	  grid[xnt][ynt + 1] == 1 || grid[xnt + 1][ynt] == 1) {
	aggr = 1;
	if (drand48() <= *p->agg_prob) {
	  grid[xnt][ynt] = 1;
	  if (this_r >= *p->src_r)
	    *p->new_r = 1;
	  layer(*p->win, 0, 2);
	  newcolor(*p->win, ECTRL_FGCOLOR);
	  pset(*p->win, xnt, ynt);
	  layer(*p->win, 0, 1);
	  newcolor(*p->win, "green3");
	}
	break;
      }				/* aggregate */
      if (aggr == 0) {
	x = xnt;
	y = ynt;
      }
      aggr = 0;
      tk++;
    }
    gclr(*p->win);
    copylayer(*p->win, 2, 1);
    newlinestyle(*p->win, LineSolid);
    drawpts(*p->win, tx, ty, tk - 1);
    newcolor(*p->win, "gray50");
    newlinestyle(*p->win, LineOnOffDash);
    drawarc(*p->win, *p->mid, *p->mid, *p->src_r, *p->src_r, 0, 360, 0);
    copylayer(*p->win, 1, 0);
    msleep(5);
    key = ggetch();
    if (key == 'q') {
      *p->run = 0;
      goto RET;
    }
  }
RET:
  ;				/* do nothing just return */
}
Beispiel #16
0
int main()
{
  int win, i, j, k, m, key = 0;
  int arp[5] = { 0, 3, 1, 4, 2 }, ars[7] = {
  0, 5, 3, 1, 6, 4, 2};
  double pentagon[3][5], septagon[3][7], parab[3][144], y;

  win = gopen(L, L);
  window(win, -L / 2, -L / 2, L / 2, L / 2);
  gsetbgcolor(win, ECTRL_BGCOLOR);
  newcolor(win, ECTRL_FGCOLOR);
  winname(win, "e_3d demo");
  layer(win, 0, 1);
  gsetnonblock(ENABLE);
  i = j = m = 0;

  for (i = 0; i < 144; i++) {
    y = L/(2*144.0)*i;
    parab[0][i] = 0;
    parab[1][i] = -y;
    parab[2][i] = 0.02*y*(L/2 - y);
  }

  while (key != 'q') {
    g3dsetangle(torad(40 * (1.5 + sin(j * 2 * M_PI / 30))),
		i * 2 * M_PI / 144);
    gclr(win);

    for (k = 0; k < 5; k++) {
      pentagon[0][k] =
	  L / 6 * cos(arp[k] * 2 * M_PI / 5 + m * 2 * M_PI / 50) + L / 5;
      pentagon[1][k] =
	  L / 6 * sin(arp[k] * 2 * M_PI / 5 + m * 2 * M_PI / 50) + L / 5;
      pentagon[2][k] = 0;
    }
    for (k = 0; k < 7; k++) {
      septagon[0][k] =
	  L / 6 * cos(ars[k] * 2 * M_PI / 7 + 2 * m * 2 * M_PI / 50) -
	  L / 5;
      septagon[1][k] = 0;
      septagon[2][k] =
	  L / 6 * sin(ars[k] * 2 * M_PI / 7 + 2 * m * 2 * M_PI / 50) +
	  L / 5;
    }
    newcolor(win, "lightsteelblue");
    newlinestyle(win, LineOnOffDash);
    for(k = 0; k < 6; k++) {
      drawline3d(win, -L/10*k, 0, 0,  -L/10*k, -L/2, 0);
      drawline3d(win, 0, -L/10*k, 0,  -L/2, -L/10*k, 0);
    }
    newlinestyle(win, LineSolid);
    newcolor(win, "red4");
    fillpoly3d(win, pentagon[0], pentagon[1], pentagon[2], 5, 0);
    newcolor(win, "green4");
    fillpoly3d(win, septagon[0], septagon[1], septagon[2], 7, 0);
    newcolor(win, ECTRL_FGCOLOR);
    drawarrow3d(win, 0, 0, 0, 0, 0, L / 3, 10, 6, 12);
    drawarrow3d(win, 0, 0, 0, 0, L / 3, 0, 10, 6, 12);
    drawarrow3d(win, 0, 0, 0, L / 3, 0, 0, 10, 6, 12);
    newcolor(win, "gold3");
    drawstr3d(win, 0, 0, L/3+10, FONTSET, 0, "z¼´");
    drawlines3d(win, parab[0], parab[1], parab[2], 144);
    y = L/(2*36.0)*(i%36);
    putimg24m3d(win, 0 - 6 *(-sin(_phi) - cos(_th)*cos(_phi)), 
                     -y - 6*(cos(_phi) - cos(_th)*sin(_phi)), 
                0.02*y*(L/2 - y) -6*sin(_th), 12, 12, Xpm_image_stone6);
    copylayer(win, 1, 0);
    i++;
    i %= 144;
    j++;
    j %= 30;
    m++;
    m %= 50;
    msleep(40);
    key = ggetch();
  }
  gcloseall();
  return 0;
}
Beispiel #17
0
void atari(void){//当たり判定
  //----------------四角の当たり判定-------------------
  for(i=0; i<kosu; i++){//通常の四角
    if(
       ( (x > x_sq[i] && x < x_sq[i]+w_sq[i]) &&
	 (25 > y_sq[i]-5 && 25 < y_sq[i]+h_sq[i]+5) ) ||
       
       ( (x_sq[i]-5 < x && x < x_sq[i]+w_sq[i]+5) &&
	 (y_sq[i] < 25 && 25 < y_sq[i]+h_sq[i]) ) ||
       
       ( (x_sq[i]-x)*(x_sq[i]-x)+
	 (y_sq[i]+w_sq[i]-25)*(y_sq[i]+w_sq[i]-25) < 25) ||
       
       ( (x_sq[i]+w_sq[i]-x)*(x_sq[i]+w_sq[i]-x)+
	 (y_sq[i]+h_sq[i]-25)*(y_sq[i]+h_sq[i]-25) < 25 ) 
       ){
      gclr(win);
      newpen(win, 1);
      drawstr(win, 150, 250, 24, 0.0, "GAMEOVER");
      msleep(time*30);
      exit(0);
    }  
  }
  //------------------ここまで---------------------
  
  //----------------丸の当たり判定--------------------
  for(i=0; i<kosu; i++){//通常の円
    if( (r_circ[i]+5)*(r_circ[i]+5) >
	(x-x_circ[i])*(x-x_circ[i])+(25-y_circ[i])*(25-y_circ[i]) ){
      gclr(win);
      newpen(win, 1);
      drawstr(win, 150, 250, 24, 0.0, "GAMEOVER");
      msleep(time*30);
      exit(0);	 
    }
  }
  
  //--------------ここまで-------------------------
  
  if(//左の四角
     ( (x > defence_x && x < defence_x+defence_w) &&
       (25 > defence_y-5 && 25 < defence_y+defence_h1+5) ) ||
     
     ( (defence_x-5 < x && x < defence_x+defence_w+5) &&
       (defence_y < 25 && 25 < defence_y+defence_h1) ) ||
     
     ( (defence_x-x)*(defence_x-x)+(defence_y-25)*(defence_y-25)
       < 25 ) ||
     
     ( (defence_x-x)*(defence_x-x)+
       (defence_y+defence_h1-25)*(defence_y+defence_h1-25) < 25 ) ||
     
     ( (defence_x+defence_w-x)*(defence_x+defence_w-x)+
       (defence_y-25)*(defence_y-25) < 25 ) ||
     
     ( (defence_x+defence_w-x)*(defence_x+defence_w-x)+
       (defence_y+defence_h1-25)*(defence_y+defence_h1-25) < 25 )
     ){
    gclr(win);
    newpen(win, 1);
    drawstr(win, 150, 250, 24, 0.0, "GAMEOVER");
    msleep(time*30);
    exit(0);
  } 
  
  if(//真ん中の四角
     ( (x > defence_x+40 && x < defence_x+40+defence_w) &&
       (25 > defence_y+60-5 && 25 < defence_y+60+defence_h2+5) ) ||
     
     ( (defence_x+40-5 < x && x < defence_x+40+defence_w+5) &&
       (defence_y+60 < 25 && 25 < defence_y+60+defence_h2) ) ||
     
     ( (defence_x+40-x)*(defence_x+40-x)+
       (defence_y+60-25)*(defence_y+60-25) < 25 ) ||
     
     ( (defence_x+40-x)*(defence_x+40-x)+
       (defence_y+60+defence_h2-25)*(defence_y+60+defence_h2-25)
       < 25 ) ||
     
     ( (defence_x+40+defence_w-x)*(defence_x+40+defence_w-x)+
       (defence_y+60-25)*(defence_y+60-25) < 25 ) ||
     
     ( (defence_x+40+defence_w-x)*(defence_x+40+defence_w-x)+
       (defence_y+60+defence_h2-25)*(defence_y+60+defence_h2-25)
       < 25 )
     ){
    gclr(win);
    newpen(win, 1);
    drawstr(win, 150, 250, 24, 0.0, "GAMEOVER");
    msleep(time*30);
    exit(0);
  } 
  
  if(//右の四角
     ( (x > defence_x+80 && x < defence_x+80+defence_w) &&
       (25 > defence_y-5 && 25 < defence_y+defence_h3+5) ) ||
     
     ( (defence_x+80-5 < x && x < defence_x+80+defence_w+5) &&
       (defence_y < 25 && 25 < defence_y+defence_h3) ) ||
     
     ( (defence_x+80-x)*(defence_x+80-x)+
       (defence_y-25)*(defence_y-25) < 25 ) ||
     
     ( (defence_x+80-x)*(defence_x+80-x)+
       (defence_y+defence_h3-25)*(defence_y+defence_h3-25) < 25 ) ||
     
     ( (defence_x+80+defence_w-x)*(defence_x+80+defence_w-x)+
       (defence_y-25)*(defence_y-25) < 25 ) ||
     
     ( (defence_x+80+defence_w-x)*(defence_x+80+defence_w-x)+
       (defence_y+defence_h3-25)*(defence_y+defence_h3-25) < 25 )
     ){
    gclr(win);
    newpen(win, 1);
    drawstr(win, 150, 250, 24, 0.0, "GAMEOVER");
    msleep(time*30);
    exit(0);
  } 
}
Beispiel #18
0
void LEVEL5(void){//レベル5の動作
  if(a==5){
    while(1){
      gclr(win);
      human();//棒人間
      input();//入力待ち
      
      newpen(win, 1);//色は白
      //防護壁表記
      fillrect(win,defence_x, defence_y, defence_w, defence_h1);
      fillrect(win,defence_x+40.0, defence_y+60.0, defence_w, defence_h2);
      fillrect(win,defence_x+80.0, defence_y, defence_w, defence_h3);
      defence_y -= 15.0;//速度
      
      atari();//当たり判定
      //一番下まで落ちたら    
      if(defence_y == 0){
	while(1){
	  gclr(win);//画面消去
	  human();//棒人間
	  input();//入力待ち
	  bougoheki();//防護壁	
	  atari();//当たり判定
	  newpen(win, 2);//太陽の色は赤で
	  fillcirc(win,all_x, all_y, 200, 200);//太陽
	  all_y-=5.0;//落下速度
	  
	  //太陽が防護壁に当たったら
	  if(all_y==280.0){
	    while(1){
	      gclr(win);//画面消去
	      human();//棒人間
	      input();//入力待ち
	      bougoheki();//防護壁
	      atari();//当たり判定
	      newpen(win, 2);//線は赤
	      
	      //太陽ぶつかった後の線
	      lastline();
	      msleep(time);
	      
	      if(explo_y1<0){//下に伸びた線が0以下になったら
		if(defence_x+40 < x && x < defence_x+80){//中にいれば
		  newpen(win, 1);
		  drawstr(win, 180, 250, 24, 0, "SAFE");
		  msleep(time*10);
		  gclr(win);
		  newpen(win, 1);
		  drawstr(win, 100, 300, 24, 0.0, "CONGRATULATIONS!");
		  drawstr(win, 170, 250, 24, 0.0, "CLEAR");
		  msleep(time*30);
		  exit(0);
		}
		else {//外にいれば
		  newpen(win, 1);
		  drawstr(win, 190, 250, 24, 0, "OUT");
		  msleep(time*10);
		  gclr(win);
		  newpen(win, 1);
		  drawstr(win, 150, 250, 24, 0.0, "GAMEOVER");
		  msleep(time*30);
		  exit(0);
		}
	      }
	    }
	  }
	  msleep(time);
	} 
      }
      msleep(time);   
    } 
  }
}
Beispiel #19
0
int main( int argc, char *argv[] )
{
    int ret = 1;
    int win_main, win_zoom, zoom_factor = 2;
    double p_x = -1, p_y = -1;
    unsigned char *zoom_buf = NULL;
    unsigned char *img_buf = NULL;
    int img_width, img_height, img_msk;
    int crosshairs = 1;

    if ( argc < 2 ) {
	fprintf(stderr,"[USAGE]\n");
	fprintf(stderr,"%s filename.png\n",argv[0]);
	return 1;
    }

    /* zoom ウィンドゥ用の画像バッファ */
    zoom_buf = (unsigned char *)malloc(ZOOMWN_WIDTH * ZOOMWN_HEIGHT * 4);
    if ( zoom_buf == NULL ) goto quit;

    //img_buf = readimage(NULL,argv[1],&img_width,&img_height,&img_msk);
    //img_buf = readimage("xbmtopbm",argv[1],&img_width,&img_height,&img_msk);
#ifdef USE_IMAGEMAGICK
    img_buf = readimage("convert",argv[1],&img_width,&img_height,&img_msk);
#else
    img_buf = readimage("pngtopnm",argv[1],&img_width,&img_height,&img_msk);
#endif
    if ( img_buf == NULL ) {
	fprintf(stderr,"ERROR: cannot read file\n");
	goto quit;
    }
    printf("mask value = %d\n",img_msk);

    /* 属性設定(左上を原点にする) */
    gsetinitialattributes(DISABLE, BOTTOM_LEFT_ORIGIN);
    /* ウィンドゥのオープン */
    win_zoom = gopen(ZOOMWN_WIDTH*2, ZOOMWN_HEIGHT);
    win_main = gopen(img_width, img_height);
    layer(win_zoom,0,1);

    /* メインウィンドゥへの画像の転送 */
    gclr(win_main);
    gputimage(win_main, 0,0, img_buf, img_width, img_height, img_msk);

    /* カーソル描画のために,XOR での描画functionに設定 */
    newgcfunction(win_main, GXxor);
    newcolor(win_main, "red");

#if 0	/* 保存のテスト */
    //writeimage(img_buf,img_width,img_height,img_msk,"pnmtopng",256,"hoge.png");
    //writeimage(img_buf,img_width,img_height,img_msk,NULL,256,"hoge.pam");
    gsaveimage( win_main,0,0,0,1999,1999,"pnmtopng",256,"capt0.png");
    {
	int im_w, im_h;
	unsigned char *im = ggetimage(win_main,0,0,0,1999,1999,&im_w,&im_h);
	writeimage(im_w,im_h,im,0,"pnmtopng",256,"capt.png");
	if ( im != NULL ) free(im);
    }
#endif

    /* メインループ */
    while ( 1 ) {
	int win_ev, type, b;
	int needs_redraw = 0;
	double x, y;
	win_ev = ggetevent(&type,&b,&x,&y) ;
	if ( type == EnterNotify ) {
	    fprintf(stderr,"event type = EnterNotify wid=%d\n",win_ev);
	}
	else if ( type == LeaveNotify ) {
	    fprintf(stderr,"event type = LeaveNotify wid=%d\n",win_ev);
	}
	else {
	    fprintf(stderr,"event type = %d wid=%d\n",type,win_ev);
	}
	if ( win_ev == win_main ) {
	    if ( type == MotionNotify || 
		 type == EnterNotify || type == LeaveNotify ) {
		if ( type == LeaveNotify ) {
		    x = -32000;  y = -32000;
		}
		if ( crosshairs ) {
		    /* crosshairs カーソルを消す */
		    drawline(win_main, 0,p_y, img_width,p_y);
		    drawline(win_main, p_x,0, p_x,img_height);
		    /* crosshairs カーソルを表示する */
		    drawline(win_main, 0,y, img_width,y);
		    drawline(win_main, x,0, x,img_height);
		}
		needs_redraw = 1;
		p_x = x;
		p_y = y;
	    }
	    else if ( type == ButtonPress ) {
		if ( b == 1 ) zoom_factor++;
		else if ( b == 3 ) zoom_factor--;
		needs_redraw = 1;
	    }
	}
	if ( type == KeyPress ) {
	    if ( b == 'q' ) goto quit;
	    else if ( b == '>' || b == '+' ) zoom_factor++;
	    else if ( b == '<' || b == '-' ) zoom_factor--;
	    else if ( b == ' ' ) {
		if ( crosshairs ) {
		    /* crosshairs カーソルを消す */
		    drawline(win_main, 0,p_y, img_width,p_y);
		    drawline(win_main, p_x,0, p_x,img_height);
		    crosshairs = 0;
		}
		else {
		    /* crosshairs カーソルを表示する */
		    drawline(win_main, 0,p_y, img_width,p_y);
		    drawline(win_main, p_x,0, p_x,img_height);
		    crosshairs = 1;
		}
	    }
	    needs_redraw = 1;
	}
	if ( needs_redraw ) {
	    if ( zoom_factor < 2 ) zoom_factor = 2;
	    else if ( 32 < zoom_factor ) zoom_factor = 32;
	    get_zoom_image(img_width, img_height,
			   img_buf, p_x, p_y, zoom_factor,
			   ZOOMWN_WIDTH, ZOOMWN_HEIGHT, zoom_buf);
	    gclr(win_zoom);
	    /* 普通のコピー */
	    newgcfunction(win_zoom, GXcopy);
	    gputimage(win_zoom, 0, 0, 
		      zoom_buf, ZOOMWN_WIDTH, ZOOMWN_HEIGHT, img_msk);
	    /* 反転コピー */
	    newgcfunction(win_zoom, GXcopyInverted);
	    gputarea(win_zoom, ZOOMWN_WIDTH, 0, 
		     win_zoom,1, 0,0,ZOOMWN_WIDTH-1, ZOOMWN_HEIGHT-1);
	    /* ズームウィンドゥで,文字列を反転描画する */
	    newgcfunction(win_zoom, GXinvert);
	    drawstr(win_zoom,2,14,14,0,
		    "%dx zoom pos=(%g,%g)\n",zoom_factor,p_x,p_y);
	    copylayer(win_zoom,1,0);
	}
    }

    ret = 0;
 quit:
    gcloseall();
    if ( img_buf != NULL ) free(img_buf);
    if ( zoom_buf != NULL ) free(zoom_buf);
    return ret;
}