Advertisement
Guest User

AY

a guest
May 9th, 2010
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 16.38 KB | None | 0 0
  1. //#include <fstream>
  2. #include <time.h>
  3. #include <SDL.h>
  4. #include <SDL_ttf.h>
  5. //#include <Windows.h>
  6. #include <iostream>
  7. #include <sstream>
  8. using namespace std;
  9. SDL_Surface *screen;
  10.  
  11. string bts(bool b)
  12. {
  13. if(b)
  14. return "True";
  15. return "False";
  16. }
  17.  
  18. void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination ) {
  19.     //Make a temporary rectangle to hold the offsets
  20.     SDL_Rect offset;
  21. //Give the offsets to the rectangle
  22. offset.x = x; offset.y = y;
  23. //Blit the surface
  24. SDL_BlitSurface( source, NULL, destination, &offset ); }
  25.  
  26.  
  27. string is(int m)
  28. {
  29. stringstream bob;
  30. bob<<m;
  31. return bob.str();
  32. }
  33.  
  34. int zcheck(int ch)
  35. {
  36. if(ch<0){return 0;}
  37. else{return ch;}
  38. }
  39. /*
  40. void em(string txt)
  41. {
  42. MessageBox(0,txt.c_str(),"Azjherben",0);
  43. }*/
  44. int fomap = 0;
  45. void applysurface(int x,int y,SDL_Surface *source)
  46. {
  47. SDL_Rect offset;
  48. offset.x = x;
  49. offset.y = y;
  50. SDL_BlitSurface( source, NULL, screen, &offset );
  51. }
  52.  
  53. SDL_Surface *load_image( std::string filename )
  54. {
  55. SDL_Surface *loadedImage = SDL_LoadBMP( filename.c_str() );
  56. loadedImage = SDL_DisplayFormat( loadedImage );
  57. Uint32 colorkey = SDL_MapRGB( loadedImage->format, 255, 255, 255);
  58. SDL_SetColorKey( loadedImage, SDL_SRCCOLORKEY, colorkey );
  59. return loadedImage;
  60. }
  61.  
  62.  
  63. Uint32 getacolor(int r,int g,int b) //gets a color and returns handle
  64. {
  65. return SDL_MapRGB(screen->format,r,g,b);
  66. }
  67.  
  68. void applyapixel(int x,int y,Uint32 color)
  69. {
  70. SDL_Rect off;
  71. off.x = x;
  72. off.y = y;
  73. off.w = 1;
  74. off.h = 1;
  75. SDL_FillRect(screen,&off,color);
  76. }
  77.  
  78. int rcs = 0;
  79. int rq = 0;
  80. int randa(int min,int max)
  81. {
  82. if(rq > 10000000)
  83. {
  84. rq = 1;
  85. }
  86. srand((time(NULL)*rcs)+rq);
  87. int diff = max-min;
  88. int reta = rand() %diff;
  89. //em("Max is "+is(max)+" min is "+is(min)+". Number gened is "+is(reta+min));
  90. rcs=reta+min;
  91. rq+=21728;
  92. return reta+min;
  93. }
  94.  
  95. SDL_Event event;
  96.  
  97. int lightr = 255;
  98. int lightg = 255;
  99. int lightb = 255;
  100.  
  101. class food
  102. {
  103. public:
  104. int x,y;
  105. bool u;
  106. void show();
  107. };
  108.  
  109. void food::show()
  110. {
  111. applyapixel(x,y,getacolor(255,255,0));
  112. applyapixel(x,y+1,getacolor(255,255,0));
  113. applyapixel(x+1,y,getacolor(255,255,0));
  114. applyapixel(x+1,y+1,getacolor(255,255,0));
  115. }
  116.  
  117. food foods[600];
  118.  
  119. void makefood(int x,int y)
  120. {
  121. for(int qr = 0; qr<600; qr++)
  122. {
  123. if(foods[qr].u == false)
  124. {
  125. fomap += 1;
  126. foods[qr].u = true;
  127. foods[qr].x = x;
  128. foods[qr].y = y;
  129. return;
  130. }
  131. }
  132. }
  133.  
  134. class cell
  135. {
  136. public:
  137. int x,y,r,g,b,food,waitforkids,sff,fff,use,ka,po,pfc,pff,phold,kanwait,ckw,por,pog,pob,dr;
  138. bool dead,eats,conz,ec;
  139. void makefood();
  140. void produce();
  141. void dieout();
  142. void starv();
  143. void show();
  144. void canna();
  145. void checkandeat();
  146. void pop();
  147. };
  148.  
  149. void cell::show()
  150. {
  151. if(use !=-1){
  152. //em("Showing... "+is(r)+" "+is(g)+" "+is(b));
  153. applyapixel(x,y,getacolor(r,g,b));
  154. if(ckw > 1){ckw -= 1;}
  155. }}
  156.  
  157. int foodat(int ax,int ay)
  158. {
  159. for(int nf = 0; nf<1000; nf++)
  160. {
  161. if(foods[nf].x == ax && foods[nf].y == ay)
  162. {
  163. if(foods[nf].u == true)
  164. {
  165. return nf;
  166. }
  167. }
  168. }
  169. return -1;
  170. }
  171.  
  172. void cell::checkandeat()
  173. {
  174. if(eats == true)
  175. {
  176.  
  177. int fae = -1;
  178. bool taf = false;
  179.  
  180.  
  181. if(foodat(x+1,y) != -1 ){po += pff; fae = foodat(x+1,y); fomap -= 1; foods[fae].u = false; food+=fff; foods[fae].x = -1; foods[fae].y = -1; return; taf = true;}
  182. if(foodat(x,y+1) != -1){po += pff; fae = foodat(x,y+1); fomap -= 1;  foods[fae].u = false; food+=fff; foods[fae].x = -1; foods[fae].y = -1; return; taf = true;}
  183. if(foodat(x+1,y+1) != -1){po += pff; fae = foodat(x+1,y+1); fomap -= 1;  foods[fae].u = false; food+=fff; foods[fae].x = -1; foods[fae].y = -1; return; taf = true;}
  184. if(foodat(x+2,y+2) != -1){po += pff; fae = foodat(x+2,y+2); fomap -= 1;  foods[fae].u = false; food+=fff; foods[fae].x = -1; foods[fae].y = -1; return; taf = true;}
  185. if(foodat(x+2,y+1) != -1){po += pff; fae = foodat(x+2,y+1); fomap -= 1;  foods[fae].u = false; food+=fff; foods[fae].x = -1; foods[fae].y = -1; return; taf = true;}
  186. if(foodat(x+1,y+2) != -1){po += pff; fae = foodat(x+1,y+2); fomap -= 1;  foods[fae].u = false; food+=fff; foods[fae].x = -1; foods[fae].y = -1; return; taf = true;}
  187. if(foodat(x+2,y) != -1){po += pff; fae = foodat(x+2,y); fomap -= 1;  foods[fae].u = false; food+=fff; foods[fae].x = -1; foods[fae].y = -1; return; taf = true;}
  188. if(foodat(x,y+2) != -1){po += pff; fae = foodat(x,y+2); fomap -= 1;  foods[fae].u = false; food+=fff; foods[fae].x = -1; foods[fae].y = -1; return; taf = true;}
  189. if(foodat(x,y-1) != -1){po += pff; fae = foodat(x,y-1); fomap -= 1;  foods[fae].u = false; food+=fff; foods[fae].x = -1; foods[fae].y = -1; return; taf = true;}
  190. if(foodat(x-1,y) != -1){po += pff; fae = foodat(x-1,y); fomap -= 1;  foods[fae].u = false; food+=fff; foods[fae].x = -1; foods[fae].y = -1; return; taf = true;}
  191. if(foodat(x-1,y-1) != -1){po += pff; fae = foodat(x-1,y-1); fomap -= 1;  foods[fae].u = false; food+=fff; foods[fae].x = -1; foods[fae].y = -1; return; taf = true;}
  192.  
  193.  
  194.  
  195. }
  196. }
  197.  
  198. const int maxcells = 1000;
  199. int timetowait = 2;
  200. cell cells[maxcells];
  201.  
  202.  
  203. bool nocellat(int ax,int ay)
  204. {
  205. for(int nc = 0; nc<maxcells; nc++)
  206. {
  207. if(cells[nc].x == ax && cells[nc].y == ay)
  208. {
  209. return false;
  210. }
  211. else{
  212. }
  213. }
  214. return true;
  215. }
  216.  
  217. class pots
  218. {
  219. public:
  220. int xx,yy,ro,used,r,g,b;
  221. void show();
  222. void remove();
  223. };
  224.  
  225. bool rper(int percent)
  226. {
  227. int rrp = randa(0,100);
  228. for(int rcrp = 0; rcrp<percent; rcrp++)
  229. {
  230. if(rrp == rcrp){return true;}
  231. }
  232. return false;
  233. }
  234.  
  235. pots poops[200];
  236.  
  237. void pots::remove()
  238. {
  239. if(ro < 1){used = false;}
  240. else{
  241. ro -= 1;}
  242. }
  243.  
  244. void pots::show()
  245. {
  246. if(used == true)
  247. {
  248. applyapixel(xx,yy,getacolor(r,g,b));
  249. applyapixel(xx,yy+1,getacolor(r,g,b));
  250. applyapixel(xx+1,yy,getacolor(r,g,b));
  251. applyapixel(xx+1,yy+1,getacolor(r,g,b));
  252. }
  253. }
  254.  
  255. void makepo(int x,int y,int rat,int r,int g,int b)
  256. {
  257. for(int poche = 0; poche<200; poche++)
  258. {
  259. if(poops[poche].used == false)
  260. {
  261. poops[poche].used = true;
  262. poops[poche].ro = rat*10;
  263. poops[poche].xx = x;
  264. poops[poche].yy = y;
  265. poops[poche].r = r;
  266. poops[poche].g = g;
  267. poops[poche].b = b;
  268. }
  269. }
  270. }
  271.  
  272. void cell::pop()
  273. {
  274. if(po > phold)
  275. {
  276. makepo(x,y,po,por,pog,pob);
  277. po = 0;
  278. }
  279. }
  280.  
  281. int cellat(int ax,int ay)
  282. {
  283. for(int nc = 0; nc<maxcells; nc++)
  284. {
  285. if(cells[nc].x == ax && cells[nc].y == ay)
  286. {
  287. return nc;
  288. }
  289. }
  290. return -1;
  291. }
  292.  
  293. void cell::canna()
  294. {
  295. if(conz != false){
  296. if(ckw < 2){
  297. int ccel = -1;
  298.  
  299. for(int vx = 0; vx<6; vx++)
  300. {
  301. for(int vy = 0; vy<6; vy++)
  302. {
  303. if(cellat(x+vx-3,y+vy-3)!=-1){ccel = cellat(x+vx-3,y+vy-3);}
  304. }
  305. }
  306.  
  307. if(ka<-100)
  308. {
  309. ka = 0;
  310. }
  311.  
  312. if(ccel !=-1)
  313. {
  314. //if(cells[ccel].conz != true)
  315. //{
  316. if(ccel != use){
  317. int tqf = (((cells[ccel].food)/2)-ka);
  318. po += pfc;
  319. food += tqf;
  320. cells[ccel].dead = true;
  321. cells[ccel].use = -1;
  322. ckw = kanwait;
  323. //}
  324. }
  325. }
  326. }}
  327. }
  328.  
  329.  
  330. void makeacell(int x,int y,int r,int g,int b,int w,int s,bool eats,int faw,bool e,int k,int qpfc,int qpff,int qphold,int canawt,
  331. int por,int pog,int pob,int dnarepair)
  332. {
  333. for(int chk = 0; chk<maxcells; chk++)
  334. {
  335. if (cells[chk].use == -1)
  336. {
  337. if(nocellat(x,y)){
  338. cells[chk].use = chk;
  339. cells[chk].dead = false;
  340. cells[chk].x = x;
  341. cells[chk].y = y;
  342. cells[chk].r = r;
  343. cells[chk].g = g;
  344. cells[chk].b = b;
  345. cells[chk].waitforkids = w;
  346. cells[chk].sff = s;
  347. cells[chk].food = s;
  348. cells[chk].eats = eats;
  349. cells[chk].conz = e;
  350. cells[chk].ka = k;
  351. cells[chk].kanwait = canawt;
  352.  
  353. cells[chk].pfc = qpfc;
  354. cells[chk].pff = qpff;
  355. cells[chk].po = 0;
  356. cells[chk].por = por;
  357. cells[chk].pog = pog;
  358. cells[chk].pob = pob;
  359.  
  360. cells[chk].dr = dnarepair;
  361.  
  362. if(eats == false){faw = 0;}
  363. cells[chk].fff = faw;
  364. return;
  365. }
  366. }
  367. }
  368. }
  369.  
  370. void cell::dieout()
  371. {
  372. if(use != -1)
  373. {
  374. if(rper(1))
  375. {
  376. if(rper(50)){
  377. dead = true;
  378. use = -1;
  379. //em("Cell died.");
  380. }}
  381. }
  382. }
  383.  
  384. void cell::makefood()
  385. {
  386. if(use != -1)
  387. {
  388.  
  389.  
  390. int ivr = 255-r;
  391. int ivg = 255-g;
  392. int ivb = 255-b;
  393.  
  394.  
  395. if(ivr > lightr){ivr = lightr;}
  396. if(ivg > lightg){ivg = lightg;}
  397. if(ivb > lightb){ivb = lightb;}
  398.  
  399.  
  400. food += (ivr+ivg+ivb)/10;
  401.  
  402. //em("Produced "+is((ivr+ivg+ivb)/10)+" units of food. "+is(lightr)+" "+is(lightg)+" "+is(lightb));
  403.  
  404. }
  405. }
  406.  
  407. void cell::starv()
  408. {
  409. if(use!=-1)
  410. {
  411. food -= 20;
  412. if(dr>0)
  413. {
  414. food-=4;
  415. }
  416. if(food < 5)
  417. {
  418. dead = true;
  419. use = -1;
  420. }
  421. }
  422. }
  423.  
  424.  
  425.  
  426. void cell::produce()
  427. {
  428. if(use!=-1)
  429. {
  430. if(food > waitforkids)
  431. {
  432. food -= 1000+zcheck(sff);
  433. if(food > 5)
  434. {
  435.  
  436. int v = 100;
  437. if(dr == 1){v = 2;}
  438.  
  439. int pr,pg,pb;
  440.  
  441. if(rper(v)){
  442. pr = r+randa(-10,10);
  443. pg = g+randa(-10,10);
  444. pb = b+randa(-10,10);
  445. }
  446. else{
  447. pr = r;
  448. pg = g;
  449. pb = b;
  450. }
  451.  
  452. if(pr < 1){pr = abs(pr)+1;}
  453. if(pg < 1){pg = abs(pg)+1;}
  454. if(pb < 1){pb = abs(pb)+1;}
  455.  
  456. if(pr > 254){pr = 253;}
  457. if(pg > 254){pg = 253;}
  458. if(pb > 254){pb = 253;} // :D
  459.  
  460. int px = x+randa(-5,5);
  461. int py = y+randa(-5,5);
  462.  
  463. if(px < 1){px = 1;}
  464. if(py < 1){py = 1;}
  465.  
  466. if(px > 498){px = 497;}
  467. if(py > 498){py = 497;}
  468.  
  469. int st = sff + randa(-10,10);
  470. int wfk = waitforkids + randa(-10,10);  //second gene to go in
  471. //em(is(wfk));
  472. int ffa = fff + randa(-10,10);
  473.  
  474. if(rper(4) && dr == 0){ if(rper(4)){  dr = 1; food -= 400;}}
  475. if(rper(1) && rper(5) && rper(5) && dr == 1){dr = 0;}
  476.  
  477. int kat =  + randa(-10,10);
  478.  
  479. if(eats == false){if(randa(0,300) == 50){eats=true; ffa = 100; fff = 100;}}
  480. if(eats == true){if(randa(0,300) == 50){eats=false; ffa = 0; fff = 0;}}
  481.  
  482. if(conz == false){if(randa(0,300) == 50){conz=true; ka = 10; ka = 10;}}
  483. if(conz == true){if(randa(0,300) == 50){conz=false; ka = 0; ka = 0;}}
  484.  
  485. makeacell(px,py,pr,pg,pb,wfk,st,eats,ffa,conz,kat,pfc,pff,phold,kanwait,por,pog,pob,dr);
  486. }
  487. }
  488. }
  489. }
  490.  
  491. void drawspectrum()
  492. {
  493. for(int dsx = 0; dsx<255; dsx++)
  494. {
  495. for(int dsy = 0; dsy<10; dsy++)
  496. {
  497. applyapixel(dsx,dsy,getacolor(256,dsx,256));
  498. }
  499. for(int dsy = 0; dsy<10; dsy++)
  500. {
  501. applyapixel(dsx,dsy+10,getacolor(256,256,dsx));
  502. }
  503. for(int dsy = 0; dsy<10; dsy++)
  504. {
  505. applyapixel(dsx,dsy+20,getacolor(dsx,256,256));
  506. }
  507. for(int dsy = 0; dsy<10; dsy++)
  508. {
  509. applyapixel(dsx,dsy+30,getacolor(dsx,dsx,dsx));
  510. }
  511. }
  512. }
  513.  
  514. Uint32 get_pixel32( SDL_Surface *surface, int x, int y )
  515. {
  516.     //Convert the pixels to 32 bit
  517.     Uint32 *pixels = (Uint32 *)surface->pixels;
  518.  
  519.     //Get the requested pixel
  520.     return pixels[ ( y * surface->w ) + x ];
  521. }
  522.  
  523.  
  524. int main ( int argc, char** argv )
  525. {
  526.  
  527.  
  528.  
  529.     SDL_Init( SDL_INIT_EVERYTHING );   //Inital Init
  530.     screen = SDL_SetVideoMode(500,500,32,0); //500 by 500 screen
  531.  
  532.  
  533. SDL_Rect txt;//hello
  534. txt.x = 400;
  535. txt.y = 100;
  536. txt.w = 1;
  537. txt.h = 1;
  538.  
  539.  
  540.  TTF_Init();
  541.     TTF_Font* tmpfont = NULL;
  542.      tmpfont = TTF_OpenFont("a.ttf", 18);
  543.     // if(tmpfont == NULL){em("Font did not load.");}
  544.     SDL_Color black = {0,0,0};
  545.  
  546.  
  547.  
  548. for(int aset = 0; aset<maxcells; aset++)
  549. {
  550. cells[aset].use = -1;
  551. cells[aset].dead = true;
  552. }
  553. //makeacell(300,201,255,0,0,1500,400,false,100,false,10,25,20,35,50,169,39,19,1);
  554. //makeacell(300,200,255,0,0,1500,400,false,100,false,10,25,20,35,50,169,39,19,1);
  555.  
  556.  
  557. //makeacell(125,201,0,255,0,1000,200,false,100,true,10,25,20,35,5,169,39,19,0);
  558. //makeacell(125,200,0,255,0,1000,200,false,100,true,10,25,20,35,5,169,39,19,0);
  559.  
  560.  
  561. /*
  562. makeacell(100,200,0,255,0,800,200,true);
  563. makeacell(300,200,0,0,255,800,200,true);
  564. makeacell(100,201,0,255,0,800,200,true);
  565. makeacell(300,201,0,0,255,800,200);            //tests for color
  566. makeacell(200,350,150,150,150,800,200);
  567. makeacell(200,351,150,150,150,800,200);
  568. */
  569.  
  570.  
  571.  
  572.  
  573. /*
  574. makeacell(100,200,0,255,0,1200);
  575. makeacell(300,200,0,255,0,600);                  //tests for waitforkid values
  576.  
  577. makeacell(100,201,0,255,0,1200);
  578. makeacell(300,201,0,255,0,600);
  579. *///int size; char * memblock;
  580. string fir,fig,fib,fdata;
  581. int posf = 0;
  582. int numberfound = 0;
  583. int positions[100];
  584. int ptrk = 0;
  585.  
  586.  
  587. /*
  588. ifstream file("startcell.txt", ios::in|ios::binary|ios::ate);
  589. if(file.is_open())
  590. {
  591.  
  592.  
  593.  
  594.     size = file.tellg();
  595.     memblock = new char [size];
  596.     file.seekg (0, ios::beg);
  597.  
  598.  
  599.     for(int sizecheck = 0; sizecheck<size; sizecheck++){
  600.     file.read (memblock, 1);
  601.     if(memblock!=NULL && memblock!="" && memblock!=" "){
  602.     fdata += memblock;
  603.     }
  604.     }
  605.  
  606.  
  607. for(int p = 0; p<100; p++){positions[p] = -1;}
  608.  
  609. while(!(posf>fdata.length()))
  610. {
  611. if(fdata.substr(posf,1) == "|")
  612. {
  613. positions[ptrk] = posf;
  614. //em("Positions["+is(ptrk)+"] = "+is(posf));
  615. ptrk++;
  616. numberfound++;
  617. }
  618. posf++;
  619. }
  620. }
  621. else{
  622.  
  623. //em("Couldn't find cell start data, defaulting.");
  624.  
  625. makeacell(100,200,1,255,1,1500,400,false,100,false,10,25,20,35,50,169,39,19,0);
  626. makeacell(100,201,1,255,1,1500,400,false,100,false,10,25,20,35,50,169,39,19,0);
  627.  
  628. }
  629.  
  630. file.close();
  631. string fwa,fsf;
  632. fir = fdata.substr(0,positions[0]);
  633. fig = fdata.substr(positions[0]+1,positions[1]-positions[0]-1);
  634. fib = fdata.substr(positions[1]+1,positions[2]-positions[1]-1);
  635. fwa = fdata.substr(positions[2]+1,positions[3]-positions[2]-1);
  636. fsf = fdata.substr(positions[3]+1,positions[4]-positions[3]-1);
  637.  
  638.  
  639.  
  640.  
  641. makeacell(100,200,atoi(fir.c_str()),atoi(fig.c_str()),atoi(fib.c_str()),atoi(fwa.c_str()),atoi(fsf.c_str()),false,100,false,10,25,20,35,50,169,39,19,0);
  642. makeacell(100,201,atoi(fir.c_str()),atoi(fig.c_str()),atoi(fib.c_str()),atoi(fwa.c_str()),atoi(fsf.c_str()),false,100,false,10,25,20,35,50,169,39,19,0);
  643. */
  644.  
  645. makeacell(100,201,0,255,0,1400,400,false,100,false,10,25,20,35,50,169,39,19,0);
  646. makeacell(100,200,0,255,0,1400,400,false,100,false,10,25,20,35,50,169,39,19,0);
  647.  
  648.  
  649.  
  650.     // program main loop
  651.     bool done = false;
  652.     while (!done)
  653.     {
  654.         while(SDL_PollEvent(&event)) //run though events
  655.         {
  656.             if(event.type == SDL_QUIT) //if the user wants to quit
  657.             {
  658.                 done = true;
  659.             }
  660.             if(event.type == SDL_MOUSEBUTTONDOWN)
  661.             {
  662.                 if(event.button.button == SDL_BUTTON_LEFT)
  663.                 {
  664.                     if(cellat(event.motion.x,event.motion.y) == -1)
  665.                     {
  666.                     Uint32 clickcolor = get_pixel32(screen,event.motion.x,event.motion.y);
  667.                     Uint8 ra,ga,ba;
  668.                     SDL_GetRGB(clickcolor,screen->format,&ra,&ga,&ba);
  669.                     lightr = ra;
  670.                     lightg = ga;
  671.                     lightb = ba;
  672.                     }
  673.                     else{
  674.                     int cnum = cellat(event.motion.x,event.motion.y);
  675.                     /*em("Clicked cell number: "+is(cnum)+" has "+is(cells[cnum].food)+
  676.                     " food. || Genes || Wfk: "+is(cells[cnum].waitforkids)+" Sff: "+is(cells[cnum].sff)+ " Red: "+is(cells[cnum].r)+" Green: "+is(cells[cnum].g)+
  677.                     " Blue: "+is(cells[cnum].b)+" fff: "+is(cells[cnum].fff)+" ka: "+is(cells[cnum].ka)+" pfc: "+is(cells[cnum].pfc)+" pff: "+is(cells[cnum].pff)+
  678.                     " phold: "+is(cells[cnum].phold)+" kwy: "+is(cells[cnum].kanwait)+" conz: "+bts(cells[cnum].conz)+" eats: "+bts(cells[cnum].eats)+ " por: "+is(cells[cnum].por)
  679.                     +" pog: "+is(cells[cnum].pog)+" pob: "+is(cells[cnum].pob)+" dr: "+is(cells[cnum].dr) );*/
  680.                     }
  681.  
  682.                 }
  683.                  if(event.button.button == SDL_BUTTON_RIGHT)
  684.                 {
  685.  
  686.                         makefood(event.motion.x,event.motion.y);
  687.                 }
  688.             }
  689.         }
  690.         //start draws
  691.  
  692.         // DRAWING ENDS HERE
  693.  
  694.  
  695. if(fomap < 500){
  696. makefood(randa(0,500),randa(0,500));
  697. makefood(randa(0,500),randa(0,500));
  698. makefood(randa(0,500),randa(0,500));
  699. makefood(randa(0,500),randa(0,500));
  700. makefood(randa(0,500),randa(0,500));
  701. }
  702. else{
  703. }
  704. //make a random food
  705.  
  706.  
  707. SDL_FillRect(screen,&screen->clip_rect,getacolor(lightr,lightg,lightb));
  708. drawspectrum();
  709. int hgfd = 0;
  710. for(int fud = 0; fud<600; fud++)
  711. {
  712. if(foods[fud].u == true)
  713. {
  714. hgfd += 1;
  715. foods[fud].show();
  716. }
  717. }
  718. for(int pud = 0; pud<200; pud++){
  719. if(poops[pud].used == true)
  720. {
  721. poops[pud].show();
  722. poops[pud].remove();
  723. }
  724. }
  725. int hgce = 0;
  726.  
  727. int hgdr = 0;
  728. for(int showcells = 0; showcells<maxcells; showcells++)
  729. {
  730. if(cells[showcells].use != -1){
  731. cells[showcells].produce();
  732. cells[showcells].makefood();
  733. cells[showcells].show();
  734. cells[showcells].checkandeat();
  735. cells[showcells].dieout();
  736. cells[showcells].canna();
  737. cells[showcells].pop();
  738. cells[showcells].starv();
  739. hgce += 1;
  740. if(cells[showcells].dr > 0){hgdr++;}
  741. }
  742. }
  743.  
  744.  
  745. string ah = "Cells: "+is(hgce);
  746. SDL_Surface* tp = TTF_RenderText_Solid(tmpfont, ah.c_str(), black);
  747. apply_surface(350,100,tp,screen);
  748.  
  749. string at = "Food cubes: "+is(hgfd);
  750. SDL_Surface* to = TTF_RenderText_Solid(tmpfont, at.c_str(), black);
  751. apply_surface(350,120,to,screen);
  752.  
  753. string aq = "Cells with dr: "+is(hgdr);
  754. SDL_Surface* tq = TTF_RenderText_Solid(tmpfont, aq.c_str(), black);
  755. apply_surface(350,140,tq,screen);
  756.  
  757.         // finally, update the screen :)
  758.         SDL_Flip(screen);
  759.         SDL_Delay(timetowait/2);
  760.        // Sleep(timetowait/2);
  761.     } // end main loop
  762.  
  763.  
  764.     // all is well ;)
  765.     return 0;
  766. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement