#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "GrWin.h"

int lighthouse(int a, int b){

	a=12;
	b=100;
	GWsrect(a+1,b,a+8,b+30,7);
	GWsrect(a-1,b+30,a+10,b+40,7);
	GWscircle(a+3,b+40,a+6.5,b+45,15);
	GWxpie(a-1,b+40,a+10,b+50,0.0,0.5,4);
	
	return (0);
};              /*灯台を描く関数*/
/*-------------------------------------------------------------*/
float boat(int p,int q){

	p=180;
	q=50;
	GWsrect(p,q+20,p+15,q+25,7);
	GWsrect(p+12.5,q+25,p+14,q+27,7);
	GWsrect(p+5.5,q+21.5,p+6.5,q+23.5,4);
	GWsrect(p+9.5,q+21.5,p+10.5,q+23.5,4);
	GWsrect(p,q+15,p+15,q+20,4);
	GWxpie(p-5,q+15,p+5,q+25,0.5,0.25,4);
	GWxpie(p+10,q+15,p+20,q+25,0.75,0.25,4);
	p-=0.5;


  return 0;
};           /*船を描く*/
/*------------------------------------------------------------*/
int main()
{
  int a, b, c, f, p, q;
  float x, y, dx, dy, dp;

  GWopen(0);
  GWindow(0.0, 0.0, 200.0, 200.0);

  x=180.0; y=100.0; /* 最初の位置 */
  dx=2.0; dy=3.9;
  c=15;/* ステップごとの進行速度 */
  f=19;

  while(1) {
  	if((x <= 10.0)||(y < 100)) {
      /* 左の壁に当たったら消滅 */
    	GWleave();
    };
    x-=dx; /* x 軸方向にワンステップ進む */

  	if(x >= 180.0){
  		dy-=0.2;
  		c=111330;
  	}else if(x >= 160.0){
  		dy-=0.1;
  		c=111335;
  	}else if(x >= 140.0){
		dy-=0.1;
  		c=111340;
  	}else if(x >= 120.0){
  		dy-=0.1;
  		c=111340;
  	}else if(x >= 100.0){
  		dy-=0.1;
  		c=111345;
  	}else if(x >= 80.0){
		dy-=0.1;
  		c=111350;
  	}else if(x >= 40.0){
  		dy-=0.1;
  		c=11250;
  	}else if(x >= 30.0){
  		dy-=0.2;
  		c=11200;
    };

    y+=dy; /* y 軸方向にワンステップ進む */
  	GWsrect(0,0,250,100,16);
	GWsrect(0,100,250,200,19);
    GWscircle(x, y, x+15, y+20.0, c);
	GWxpie(-50,120,50,70,0.0,0.25,3);
  	lighthouse(a, b);
	boat(p, q);
  	GWsleep(200);
    GWclear(-1); 
   	if(x <= 30){
  		GWsrect(0,100,250,200,0);
   		GWsrect(0,0,250,100,16);
		GWxpie(-50,120,50,70,0.0,0.25,3);
   		lighthouse(a, b);
   		boat(p, q);
   		GWsetpxl(10,190,15);
   		GWsetpxl(40,180,15);
   		GWsetpxl(60,190,15);
   		GWsetpxl(90,120,15);
   		GWsetpxl(110,150,15);
   		GWsetpxl(120,180,15);
   		GWsetpxl(170,140,15);
   		GWsetpxl(190,110,15);
   		GWsetpxl(110,130,15);
   		GWsetpxl(120,150,15);
   		GWsetpxl(170,130,15);
   		GWsetpxl(190,190,15);
   		return 0;
  	};
  };
  return 0;
}
