-
Notifications
You must be signed in to change notification settings - Fork 0
/
fish.h
148 lines (141 loc) · 2.33 KB
/
fish.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
static float t=0;
class Fish
{
float xpos;
float ypos;
float scalefactorx;
float scalefactory;
int flag;
float r,g,b;
float rem;
float range;
float resetx,resety;
public:
Fish()
{
xpos = rand() % 620;
ypos = rand() % 90;
resetx=1;
resety=0;
scalefactorx=4;
scalefactory=4;
flag=0;
r=((double) rand() / (RAND_MAX));
g=((double) rand() / (RAND_MAX));
b=((double) rand() / (RAND_MAX));
srand (time(NULL));
range = 360;
}
Fish(float x,float y)
{
xpos=x;
ypos=y;
resetx=x;
resety=y;
scalefactorx=4;
scalefactory=4;
flag=0;
r=((double) rand() / (RAND_MAX));
g=((double) rand() / (RAND_MAX));
b=((double) rand() / (RAND_MAX));
rem=y;
srand (time(NULL));
range=360;
}
Fish(float x,float y,float red,float green,float blue)
{
xpos=x;
ypos=y;
resetx=x;
resety=y;
scalefactorx=4;
scalefactory=4;
flag=0;
r=red;
g=green;
b=blue;
rem=y;
srand (time(NULL));
range=360;
}
void resetfish()
{
xpos=resetx;
ypos=resety;
r=((double) rand() / (RAND_MAX));
g=((double) rand() / (RAND_MAX));
b=((double) rand() / (RAND_MAX));
}
float getxpos(){return xpos;}
float getypos(){return ypos;}
void change_sf(float fx,float fy)
{
scalefactorx=fx;
scalefactory=fy;
}
void change_color(float red,float green,float blue)
{
g=green;
r=red;
b=blue;
}
void drawFish()
{
//head
glPushMatrix();
glTranslatef(xpos,ypos,0);
glScalef(scalefactorx,scalefactory,0);
glColor3f(r,g,b);
glBegin(GL_POLYGON);
glVertex2d(1,1);
glVertex2d(2,2);
glVertex2d(3,1);
glVertex2d(2,0);
glEnd();
//eyes
glColor3f(0.0f,0.0f,0.0f);
glBegin(GL_POLYGON);
glVertex2f(2,1);
glVertex2f(2,1.5);
glVertex2f(2.5,1.5);
glVertex2f(2.5,1);
glEnd();
//body
glColor3f(r,g,b);
glBegin(GL_POLYGON);
glVertex2f(1,1);
glVertex2f(0.7,1.5);
glVertex2f(0.5,1);
glVertex2f(0.7,0.5);
glEnd();
glPopMatrix();
}
void jump(float x, float theta, float r)
{
float xe = (x>r)? 0:x;
ypos = (rem+xe*tan(theta)*(1-(xe/r)));
}
void roam()
{
if(xpos>=620)
{
flag=1;
change_sf(-scalefactorx,scalefactory);
}
if(xpos<=0)
{
flag=0;
change_sf(-scalefactorx,scalefactory);
range= rand() % 620 + 1;
}
if(flag==0)
{
xpos = xpos+0.05;
jump(xpos,45,range);
}
if(flag==1)
{
xpos = xpos-0.05;
}
}
};