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
|
//main file
#include <iostream.h>
#include "initg.h"
#include "ball.h"
#include "bar.h"
#define G 2
//gravity
int chek_in(class bar &Ob_bar, class ball &Obj_b)
{
int left= Ob_bar.x- Ob_bar.wx/2,
rght= Ob_bar.x+ Ob_bar.wx/2,
y_dist= Ob_bar.y-Ob_bar.hy/2- (Obj_b.y+ Obj_b.r);//reverse Oy
if (left< Obj_b.x+Obj_b.r && Obj_b.x-Obj_b.r< rght)
{
if (-10< y_dist && y_dist<= 0)
{
Obj_b.y= Ob_bar.y- Ob_bar.hy/2- Obj_b.r;
Obj_b.vy= Ob_bar.vy;
}
else Obj_b.vy= G;
return 1;
}
Obj_b.vy= G;
return 0;
}
int main()
{
init_graph(); srand(time(NULL));
int posx= 240;
class bar bar0(posx , 479, 60, 10, -2);
class bar bar1(posx , 300, 60, 10, -2);
class bar bar2(posx , 100, 60, 10, -2);
class ball bll(posx , 200, 10, 0, 0);
class bar *ptobar[3];
ptobar[0]= &bar0; ptobar[1]= &bar1; ptobar[2]= &bar2;
int quit= 0; char c; int i;
while (!quit)
{
if (kbhit())
{
c= getch();
if (c== 27) quit= 1;
bll.setCord(c);
}
for (i= 0; i< 3; ++i)
if (chek_in( *ptobar[i], bll) ) break;
bll.move();
bar0.move();
bar1.move();
bar2.move();
delay(10);
}
return 0;
}
|