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 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
|
class bunny
{
public:
SDL_Rect obscolbox;
int return_direction ()
//collision boxes keep up
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);
}
//set position of the bunny
void set_posx_posy(int posx,int posy)
{
start_pos_x = posx;
start_pos_y = posy;
}
//get position of da bunny
int getposx()
{
return start_pos_x;
}
int getposy()
{
return start_pos_y;
}
bool bunny_collision(SDL_Rect &A,SDL_Rect &B)
{
}
collided=true;
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()
//the basic bunny behaviour function
void roam_about()
{
if (still == true)
{
apply_surface(start_pos_x,start_pos_y,bunnysheet,screen,&clips[stillclips]);
stillclips++;
roamtime++;
if (stillclips == 23)
{
stillclips =12;
}
if(roamtime == 12)
{
still=false;
roamtime = 0;
new_direction();
}
}
//same as above for up down left and right, just had to cut them out//
}
//breeding sequence
else if (go_nest == true)
{
apply_surface(start_pos_x,start_pos_y,bunnysheet,screen,&clips[nestclips]);
nestclips++;
roamtime++;
if (nestclips == 47)
{
nestclips = 24;
pregnant =true;
}
if(roamtime == 23)
{
roamtime = 0;
go_nest = false;
new_direction();
}
}
//so a newly created bun hops out of a hole and runs left, hopefully
else if (hole_pop == true)
{
apply_surface(start_pos_x,start_pos_y,bunnysheet,screen,&clips[holeclips]);
holeclips++;
roamtime++;
if(holeclips==52)
{
holeclips = 48;
}
if(check_pos() == true)
{
roamtime = 0;
hole_pop = false;
new_direction();
}
}
collided = false;
}
};
int main( int argc, char* args[] )
{
//initialize stuffs
/there ere all the clip dimensions here, millions of em//
vector<bunny>bunny_list;
bunny_list.push_back(bunny());
bunny_list.push_back(bunny());
bunny_list.push_back(bunny());
bunny_list.push_back(bunny());
//units of .120 seconds passing, bunnies need time for a life span will change this near finish
int q=0;
for(q; q < 5000; q++)
{
//checks each bunny against a bunny
for (int n =0; n<bunny_list.size(); n++ )
{
bunny_list[n].update_rect(bunny_list[n].start_pos_x,bunny_list[n].start_pos_y);
if(bunny_list[n].pregnant==true)
{
bunny_list[n].babiesx=bunny_list[n].getposx();
bunny_list[n].babiesx=bunny_list[n].getposy();
bunny_list[n].gestation++;
}
else if(bunny_list[n].gestation == 100)
{
bunny_list[n].gestation = 0;
bunny_list[n].pregnant=false;
int x = bunny_list[n].babiesx;
int y = bunny_list[n].babiesy;
bunny_list.push_back(bunny());
bunny &neobun = bunny_list.back();
neobun.set_posx_posy(x,y);
neobun.roamtime=0;
int for_switch = neobun.return_direction();
switch(for_switch)
{
case(1):
bunny_list[n].up=false;
break;
case(2):
bunny_list[n].down=false;
break;
case(3):
bunny_list[n].right=false;
break;
case(4):
bunny_list[n].left=false;
break;
case(5):
bunny_list[n].still=false;
case(6):
bunny_list[n].go_nest=false;
}
neobun.hole_pop=true;
}
else
continue;
for (int z =0; z<bunny_list.size(); z++ )
{
if(n==z)
continue;
if((bunny_list[n].female==false)&&(bunny_list[z].female==false))
continue;
bunny_list[n].bunny_collision(bunny_list[n].obscolbox,bunny_list[z].obscolbox);
if(bunny_list[n].collided==true)
{
bunny_list[n].roamtime=0;
int for_switch = bunny_list[n].return_direction();
switch(for_switch)
{
case(1):
bunny_list[n].up=false;
break;
case(2):
bunny_list[n].down=false;
break;
case(3):
bunny_list[n].right=false;
break;
case(4):
bunny_list[n].left=false;
break;
case(5):
bunny_list[n].still=false;
case(6):
bunny_list[n].hole_pop=false;
}
bunny_list[n].go_nest=true;
break;
}
}
bunny_list[n].roam_about();
}
//apply_surface(240,230,bunnysheet,screen,&clips[48]);//for testing clips!!
SDL_Flip(screen);
SDL_FillRect(screen,&screen->clip_rect,SDL_MapRGB(screen->format,253,253,253));
SDL_Delay(120);
}
SDL_FreeSurface(bunnysheet);
}
|