-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrisbee.h
executable file
·199 lines (178 loc) · 6 KB
/
frisbee.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#ifndef __FRISBEE_H__
#define __FRISBEE_H__
#include "player.h"
class Frisbee
{
private:
bool caught;
double xpos, ypos;
int movex, movey;
int initx, inity;
int height;
double time;
float size;
int outone, outtwo;
public:
Frisbee(int x, int y) {
xpos = x;
ypos = y;
initx = x;
inity = y;
height = 0;
size = (float)(2.15);
caught = false;
time = 0.1;
outone = 0;
outtwo = 0;
movex = 0;
movey = 0;
}
void drawFrisbee(Window & window, int x, int y) {
//draw shadow
if(!caught && height>0) {
window.drawRectangleFilled(Style(Color(80,80,80,70), 5), (Field::realx(xpos,ypos)-x)-(6*2), (ypos-y)-size, (Field::realx(xpos,ypos)-x)+(6*2), (ypos-y)+size );
window.drawRectangleFilled(Style(Color(80,80,80,70), 5), (Field::realx(xpos,ypos)-x)-(5*2), (ypos-y)-(size*2),(Field::realx(xpos,ypos)-x)+(5*2), (ypos-y) +(size*2) );
}
//draw disc
window.drawRectangleFilled(Style(Color::WHITE, 5), (Field::realx(xpos,ypos)-x)-(6*2), (ypos-y)-size-height, (Field::realx(xpos,ypos)-x)+(6*2), (ypos-y)+size-height );
window.drawRectangleFilled(Style(Color::WHITE, 5), (Field::realx(xpos,ypos)-x)-(5*2), (ypos-y)-(size*2)-height,(Field::realx(xpos,ypos)-x)+(5*2), (ypos-y) +(size*2)-height );
}
void centerWindow(int & x, int & y, Window & window) {
//different speeds of centering
//if( Field::realx(xpos,ypos)+movex*50 < x+window.getWidth()/8 )
// x -= 6;
//if( Field::realx(xpos,ypos)+movex*50 > x+window.getWidth()*7/6)
// x +=6;
//if( ypos+movey*4 < y+window.getHeight()/8 )
// y -=6;
//if( ypos+movey*4 > y+window.getHeight()*7/8 )
// y +=6;
if( Field::realx(xpos,ypos)+movex*30 < x+window.getWidth()/6 )
x -= 3;
if( Field::realx(xpos,ypos)+movex*30 > x+window.getWidth()*5/6)
x +=3;
if( ypos+movey*30 < y+window.getHeight()/6 )
y -=3;
if( ypos+movey*30 > y+window.getHeight()*5/6 )
y +=3;
if( Field::realx(xpos,ypos)+movex*30 < x+window.getWidth()/5 )
x -= 4;
if( Field::realx(xpos,ypos)+movex*30 > x+window.getWidth()*4/5)
x +=4;
if( ypos+movey*30 < y+window.getHeight()/5 )
y -=4;
if( ypos+movey*30 > y+window.getHeight()*4/5 )
y +=4;
if( Field::realx(xpos,ypos)+movex*30 < x+window.getWidth()/3 )
x -=3;
if( Field::realx(xpos,ypos)+movex*30 > x+window.getWidth()*2/3)
x +=3;
if( ypos+movey*30 < y+window.getHeight()/3 )
y -=3;
if( ypos+movey*30 > y+window.getHeight()*2/3 )
y +=3;
}
void move(double direction, int power, double angle, int fieldw, int fieldh, int yard, int endzone, int init) {
//-1*v*sin(a)*t - projectile motion for two point on the line
//tempy = -1 * (power * sin(direction) * temptime) - ypos;
//v*cos(a)*t+w - projectile motion plus wind factor for two points
//tempx = power * cos(direction) * (temptime) + position;
if(!caught && height > 0) {
if(power >3)
height += (power* sin(angle)*time)-(power*sin(angle)*1.85);
else
height += (3* sin(angle)*time)-(2*sin(angle)*1.85);//(3*sin(angle)*1.85);//(sin(angle)*time)-
xpos += cos(direction)*power;
ypos += sin(direction)*power;
movex = cos(direction)*power;
movey = sin(direction)*power;
time += 0.027;
}
else {
movex = 0;
movey = 0;
}
//if out of bounds
if((xpos < yard+endzone+size*5 || xpos > fieldw-endzone-size*2 || ypos < yard+size*2 || ypos > fieldh-size*2)) {
if(height <= 0 && init) {
xpos = outone;
ypos = outtwo;
}
else if((xpos < yard+size*2 || xpos > fieldw-size*2 || ypos < yard+size*2 || ypos > fieldh-size*2)) {
if(height <= 0) {
xpos = outone;
ypos = outtwo;
}
}
}
else {
outone = xpos;
outtwo = ypos;
}
}
void restart() {
xpos = initx;
ypos = inity;
height = 0;
caught = false;
}
void drop() {
height = 0;
caught = false;
}
bool hasCaught(Player & guy, int defense) {
int guyx, guyy, guyh;
int rsize, csize;
guy.giveCords(guyx,guyy,csize,rsize,guyh);
if(height<50) {
//if within bounds of player
if( xpos>(guyx+csize/5) && xpos<(guyx+csize*4/5) &&
(ypos-height)>(guyy-guyh+rsize/12) && (ypos-height)<(guyy-guyh+rsize*21/22) ) {
//if( xpos>(guyx+csize/5) && xpos<(guyx+csize*4/5) && ypos>(guyy-csize) && ypos<(guyy+csize)
// && height > guyh && height < (guyh+rsize*2) ) {
if(height > 0 || defense) {
caught = true;
height = 35;
xpos = guyx+csize/2;
ypos = guyy+rsize/2+height;
time = 0.1;
return true;
}
}
}
return false;
}
void throwFrisbee() {
caught = false;
}
void drawArrow (Window & window, Player & guy, double x, double y, double i) {
Style ARROW = Style(Color::BLACK, 5);
x = (Field::realx(xpos,ypos)-x);
y = ypos - y;
window.drawLine(ARROW, x, y-height, x+(22*size)*cos(i), y+(22*size)*sin(i)-height);
window.drawTriangleFilled(ARROW, x+(22*size)*cos(i+.2), y+(22*size)*sin(i+.2)-height, x+(26*size)*cos(i), y+(26*size)*sin(i)-height, x+(22*size)*cos(i-.2), y+(22*size)*sin(i-.2)-height);
if( cos(i) < 0 )
guy.direc(false);
else
guy.direc(true);
}
int dist(Player & guy) {
int x,y;
int csize, rsize;
int junk;
guy.giveCords(x,y,csize,rsize, junk);
if(height<50)
return ( ((xpos-x-csize/2)*(xpos-x-csize/2)) + ((ypos-y-height-rsize/2)*(ypos-y-height-rsize/2)) );
else
return ( ((xpos-x-csize/2)*(xpos-x-csize/2)) + ((ypos-y-rsize/2)*(ypos-y-rsize/2)) );
}
void changeInit(int x, int y) {
initx = x;
inity = y;
}
void drawPixel(Window & window, int yard) {
window.drawRectangleFilled(Style(Color(255,100,150),3), window.getWidth()*3/4+(xpos-size*8)/yard, window.getHeight()-55+(ypos-size*8)/yard,
window.getWidth()*3/4+(xpos+size*8)/yard, window.getHeight()-55+(ypos+size*8)/yard);
}
};
#endif