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
|
//////~///////
class bunny{
public:
//ints and bools etc///
SDL_Rect obscolbox;
void update_rect(int x,int y)
{
obscolbox.x=x;
obscolbox.y=y;
obscolbox.w=50;
obscolbox.h=50;
}
bunny()
{
int sex = (1+rand()%2);
if (sex == 2){female = true;}
start_pos_x = (40+rand()%540);
start_pos_y = (40+rand()%300);
int dir = (rand()%3);
if(dir==0){up=true;}
if(dir==1){down = true;}
if(dir==2){left = true;}
if(dir==3){right = true;}
update_rect(start_pos_x,start_pos_y);
}
bool bunny_collision(SDL_Rect B)
{
int leftA, leftB;
int rightA, rightB;
int topA, topB;
int bottomA, bottomB;
leftA = obscolbox.x;
rightA = obscolbox.x + obscolbox.w;
topA = obscolbox.y;
bottomA = obscolbox.y + obscolbox.h;
leftB = B.x;
rightB = B.x + B.w;
topB = B.y;
bottomB = B.y + B.h;
if( bottomA <= topB )
{
return false;
}
if( topA >= bottomB )
{
return false;
}
if( rightA <= leftB )
{
return false;
}
if( leftA >= rightB )
{
return false;
}
return true;
}
void new_direction()
{
int dir = 0;
dir = (1+rand()%5);
if(dir==1){up=true;}
if(dir==2){down = true;}
if(dir==3){left = true;}
if(dir==4){right = true;}
if(dir==5){still = true;}
}
bool check_pos()
{
if ((start_pos_x < 5)||(start_pos_x > 640-51)||(start_pos_y<5)||(start_pos_y>475-47)||(collided==true))
{
return true;
}
else
return false;
}
void roam_about()
{
//lots of directional if statements like the one below (if up is true...etc)
else if (right == true)
{
apply_surface(start_pos_x = start_pos_x +5,start_pos_y = start_pos_y,bunnysheet,screen,&clips[rightclips]);
rightclips++;
roamtime++;
if(rightclips == 9){rightclips = 6;}
if(check_pos()==true){right = false; roamtime = 0; left = true;}
else if(roamtime == 9){right = false; roamtime = 0; new_direction();}
}
update_rect(start_pos_x,start_pos_y);//<-updates rect position for object
collided = false;//<-most bunnies are rooted to the spot if i dont do this, but not all
}
};
///main///
//initialize stuff
bunny fatso;
bunny bugs;
vector<bunny>bunny_list;
bunny_list.push_back(fatso);
bunny_list.push_back(bugs);
for(int q = 0;q < 1000;q++)
{
bugs.roam_about();
fatso.roam_about();
//So the idea below is to go through each bunny and see whos colliding
//with the collision function, I was also hoping to use the numbers to
//check things against the two coliding bunny, one could be male and the
//other could be female (am gonna make if alpha bunny = true then beat
//up omega bunny, im gonna simulate their whole complex social structure
//:D)
for (int n =0;n<bunny_list.size();n++ )
for (int z =0;z<bunny_list.size();z++ )
{
bunny_list[n].bunny_collision(bunny_list[z].obscolbox);
}
//flipscreen stuff
|