Advertisement
Guest User

Untitled

a guest
Nov 6th, 2012
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.51 KB | None | 0 0
  1. #include <SDL.h>
  2. #include <SDL_ttf.h>
  3.  
  4. class instructions
  5. {
  6.  
  7. public:
  8.  
  9.  
  10. void apply(int srcX,int srcY,int x,int y,int w,int h,SDL_Surface *source,SDL_Surface *destination)
  11. {
  12.  
  13. SDL_Rect set;
  14. set.x=x;
  15. set.y=y;
  16. set.w=w;
  17. set.h=h;
  18.  
  19. SDL_Rect src;
  20. src.x=srcX;
  21. src.y=srcY;
  22. src.w=w;
  23. src.h=h;
  24.  
  25. SDL_BlitSurface(source,&src,destination,&set);
  26.  
  27. }
  28.  
  29.  
  30. void give(int x,int y,int w,int h,SDL_Rect &fake)
  31. {
  32. fake.x=x;
  33. fake.y=y;
  34. fake.w=w;
  35. fake.h=h;
  36. }
  37.  
  38.  
  39.  
  40.  
  41. bool CheckCollision(float Ax,float Ay,float Aw,float Ah,
  42. float Bx,float By,float Bw,float Bh)
  43.  
  44. {
  45.  
  46. if(Ay+Ah<By)
  47. return false;
  48.  
  49. else if(Ay>By+Bh)
  50. return false;
  51.  
  52. else if(Ax+Aw<Bx)
  53. return false;
  54.  
  55. else if(Ax>Bx+Bw)
  56. return false;
  57.  
  58.  
  59. return true;
  60.  
  61. }
  62.  
  63.  
  64. int showmenu(SDL_Surface *screen,TTF_Font *font)
  65. {
  66.  
  67. int x,y;
  68. const int NUMMENU=2;
  69. const char *labels[NUMMENU]={"Continue","Exit"};
  70. SDL_Surface *menus[NUMMENU];
  71.  
  72. bool selected[NUMMENU]={0,0};
  73. SDL_Color color[2]={{255,255,255},{255,0,0}};
  74.  
  75. menus[0]=TTF_RenderText_Solid(font,labels[0],color[0]);
  76. menus[1]=TTF_RenderText_Solid(font,labels[1],color[0]);
  77.  
  78. SDL_Rect pos[NUMMENU];
  79. pos[0].x=screen->clip_rect.w/2 - menus[0]->clip_rect.w/2;
  80. pos[0].y=screen->clip_rect.h/2 - menus[0]->clip_rect.h;
  81. pos[1].x=screen->clip_rect.w/2 - menus[0]->clip_rect.w/2;
  82. pos[1].y=screen->clip_rect.h/2 + menus[0]->clip_rect.h;
  83.  
  84. SDL_FillRect(screen,&screen->clip_rect,SDL_MapRGB(screen->format,0x200,0x200,0x255));
  85.  
  86. SDL_Event event;
  87. while(true)
  88. {
  89.  
  90. while(SDL_PollEvent(&event))
  91. {
  92. switch(event.type)
  93. {
  94. case SDL_QUIT:
  95. for(int i=0;i<NUMMENU;i++)
  96. {
  97. SDL_FreeSurface(menus[i]);
  98. }
  99. return 1;
  100.  
  101. case SDL_MOUSEMOTION:
  102. x=event.motion.x;
  103. y=event.motion.y;
  104. for(int i=0;i<NUMMENU;i++)
  105. {
  106. if(x>=pos[i].x && x<=pos[i].x+pos[i].w && y>=pos[i].y && y<=pos[i].y+pos[i].h)
  107. {
  108. if(!selected[i])
  109. {
  110. selected[i]=1;
  111. SDL_FreeSurface(menus[i]);
  112. menus[i]=TTF_RenderText_Solid(font,labels[i],color[1]);
  113.  
  114. }
  115. }
  116.  
  117. else
  118. {
  119. if(selected[i])
  120. {
  121. selected[i]=0;
  122. SDL_FreeSurface(menus[i]);
  123. menus[i]=TTF_RenderText_Solid(font,labels[i],color[0]);
  124. }
  125.  
  126. }
  127.  
  128. }
  129. break;
  130.  
  131. case SDL_MOUSEBUTTONDOWN:
  132. x=event.button.x;
  133. y=event.button.y;
  134.  
  135. for(int i=0;i<NUMMENU;i++)
  136. {
  137. if(x>=pos[i].x && x<=pos[i].x+pos[i].w && y>=pos[i].y && y<=pos[i].y+pos[i].h)
  138. {
  139. for(int j=0;j<NUMMENU;j++)
  140. SDL_FreeSurface(menus[j]);
  141.  
  142. return i;
  143. }
  144. }
  145. break;
  146.  
  147. case SDL_KEYDOWN:
  148. switch(event.key.keysym.sym)
  149. {
  150. case SDLK_ESCAPE:
  151. for(int i=0;i<NUMMENU;i++)
  152. SDL_FreeSurface(menus[i]);
  153.  
  154. return 0;
  155. }
  156.  
  157. }
  158.  
  159. }
  160.  
  161. for(int i=0;i<NUMMENU;i++)
  162. SDL_BlitSurface(menus[i],NULL,screen,&pos[i]);
  163.  
  164.  
  165. SDL_Flip(screen);
  166.  
  167. }
  168.  
  169. }
  170.  
  171.  
  172.  
  173. int showmenu1(SDL_Surface *screen,TTF_Font *font)
  174. {
  175.  
  176. int x,y;
  177. const int NUMMENU=3;
  178. const char *labels[NUMMENU]={"Start","Rules","Exit"};
  179. SDL_Surface *menus[NUMMENU];
  180.  
  181. bool selected[NUMMENU]={0,0,0};
  182. SDL_Color color[2]={{255,255,255},{255,0,0}};
  183.  
  184. menus[0]=TTF_RenderText_Solid(font,labels[0],color[0]);
  185. menus[1]=TTF_RenderText_Solid(font,labels[1],color[0]);
  186. menus[2]=TTF_RenderText_Solid(font,labels[2],color[0]);
  187.  
  188. SDL_Rect pos[NUMMENU];
  189. pos[0].x=screen->clip_rect.w/2 - menus[0]->clip_rect.w/2;
  190. pos[0].y=screen->clip_rect.h/3 - menus[0]->clip_rect.h;
  191. pos[1].x=screen->clip_rect.w/2 - menus[0]->clip_rect.w/2;
  192. pos[1].y=screen->clip_rect.h/3 + menus[0]->clip_rect.h;
  193. pos[2].x=screen->clip_rect.w/2 - menus[0]->clip_rect.w/2;
  194. pos[2].y=screen->clip_rect.h/2 + menus[0]->clip_rect.h;
  195.  
  196. SDL_FillRect(screen,&screen->clip_rect,SDL_MapRGB(screen->format,0x200,0x200,0x255));
  197.  
  198. SDL_Event event;
  199. while(true)
  200. {
  201.  
  202. while(SDL_PollEvent(&event))
  203. {
  204. switch(event.type)
  205. {
  206. case SDL_QUIT:
  207. for(int i=0;i<NUMMENU;i++)
  208. {
  209. SDL_FreeSurface(menus[i]);
  210. }
  211. return 2;
  212.  
  213. case SDL_MOUSEMOTION:
  214. x=event.motion.x;
  215. y=event.motion.y;
  216. for(int i=0;i<NUMMENU;i++)
  217. {
  218. if(x>=pos[i].x && x<=pos[i].x+pos[i].w && y>=pos[i].y && y<=pos[i].y+pos[i].h)
  219. {
  220. if(!selected[i])
  221. {
  222. selected[i]=1;
  223. SDL_FreeSurface(menus[i]);
  224. menus[i]=TTF_RenderText_Solid(font,labels[i],color[1]);
  225.  
  226. }
  227. }
  228.  
  229. else
  230. {
  231. if(selected[i])
  232. {
  233. selected[i]=0;
  234. SDL_FreeSurface(menus[i]);
  235. menus[i]=TTF_RenderText_Solid(font,labels[i],color[0]);
  236. }
  237.  
  238. }
  239.  
  240. }
  241. break;
  242.  
  243. case SDL_MOUSEBUTTONDOWN:
  244. x=event.button.x;
  245. y=event.button.y;
  246.  
  247. for(int i=0;i<NUMMENU;i++)
  248. {
  249. if(x>=pos[i].x && x<=pos[i].x+pos[i].w && y>=pos[i].y && y<=pos[i].y+pos[i].h)
  250. {
  251. for(int j=0;j<NUMMENU;j++)
  252. SDL_FreeSurface(menus[j]);
  253.  
  254. return i;
  255. }
  256. }
  257. break;
  258.  
  259. case SDL_KEYDOWN:
  260. switch(event.key.keysym.sym)
  261. {
  262. case SDLK_ESCAPE:
  263. for(int i=0;i<NUMMENU;i++)
  264. SDL_FreeSurface(menus[i]);
  265.  
  266. return 0;
  267. }
  268.  
  269. }
  270.  
  271. }
  272.  
  273. for(int i=0;i<NUMMENU;i++)
  274. SDL_BlitSurface(menus[i],NULL,screen,&pos[i]);
  275.  
  276.  
  277. SDL_Flip(screen);
  278.  
  279. }
  280.  
  281. }
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289. int rules(SDL_Surface *screen,TTF_Font *font)
  290. {
  291.  
  292. int x,y;
  293. const int NUMMENU=5;
  294. const char *labels[NUMMENU]={"Start","1)If you fell down.You loose.","2)Putting the down button you change","some of the background",
  295. "3)You try to go to the other side"};
  296. SDL_Surface *menus[NUMMENU];
  297.  
  298. bool selected[NUMMENU]={0,0,0,0,0};
  299. SDL_Color color[2]={{255,255,255},{255,0,0}};
  300.  
  301. menus[0]=TTF_RenderText_Solid(font,labels[0],color[0]);
  302. menus[1]=TTF_RenderText_Solid(font,labels[1],color[0]);
  303. menus[2]=TTF_RenderText_Solid(font,labels[2],color[0]);
  304. menus[3]=TTF_RenderText_Solid(font,labels[3],color[0]);
  305. menus[4]=TTF_RenderText_Solid(font,labels[4],color[0]);
  306.  
  307.  
  308. SDL_Rect pos[NUMMENU];
  309. pos[0].x=screen->clip_rect.w/2 - menus[0]->clip_rect.w/2;
  310. pos[0].y=screen->clip_rect.h/1.5 + menus[0]->clip_rect.h;
  311. pos[1].x=screen->clip_rect.w/6 - menus[0]->clip_rect.w;
  312. pos[1].y=screen->clip_rect.h/4 - menus[0]->clip_rect.h;
  313. pos[2].x=screen->clip_rect.w/6 - menus[0]->clip_rect.w;
  314. pos[2].y=screen->clip_rect.h/3 - menus[0]->clip_rect.h;
  315. pos[3].x=screen->clip_rect.w/4 - menus[0]->clip_rect.w;
  316. pos[3].y=screen->clip_rect.h/2.6 - menus[0]->clip_rect.h;
  317. pos[4].x=screen->clip_rect.w/6 - menus[0]->clip_rect.w;
  318. pos[4].y=screen->clip_rect.h/2 - menus[0]->clip_rect.h;
  319.  
  320.  
  321.  
  322.  
  323. SDL_FillRect(screen,&screen->clip_rect,SDL_MapRGB(screen->format,0x200,0x200,0x255));
  324.  
  325. SDL_Event event;
  326.  
  327. while(true)
  328. {
  329.  
  330. while(SDL_PollEvent(&event))
  331. {
  332. switch(event.type)
  333. {
  334. case SDL_QUIT:
  335. for(int i=0;i<NUMMENU;i++)
  336. {
  337. SDL_FreeSurface(menus[i]);
  338. }
  339. return 1;
  340.  
  341. case SDL_MOUSEMOTION:
  342. x=event.motion.x;
  343. y=event.motion.y;
  344.  
  345. if(x>=pos[0].x && x<=pos[0].x+pos[0].w && y>=pos[0].y && y<=pos[0].y+pos[0].h)
  346. {
  347. if(!selected[0])
  348. {
  349. selected[0]=1;
  350. SDL_FreeSurface(menus[0]);
  351. menus[0]=TTF_RenderText_Solid(font,labels[0],color[1]);
  352.  
  353. }
  354. }
  355.  
  356. else
  357. {
  358. if(selected[0])
  359. {
  360. selected[0]=0;
  361. SDL_FreeSurface(menus[0]);
  362. menus[0]=TTF_RenderText_Solid(font,labels[0],color[0]);
  363. }
  364.  
  365. }
  366.  
  367. break;
  368.  
  369. case SDL_MOUSEBUTTONDOWN:
  370. x=event.button.x;
  371. y=event.button.y;
  372.  
  373.  
  374. if(x>=pos[0].x && x<=pos[0].x+pos[0].w && y>=pos[0].y && y<=pos[0].y+pos[0].h)
  375. {
  376. SDL_FreeSurface(menus[0]);
  377. return 0;
  378. }
  379. break;
  380.  
  381. case SDL_KEYDOWN:
  382. switch(event.key.keysym.sym)
  383. {
  384. case SDLK_ESCAPE:
  385. SDL_FreeSurface(menus[0]);
  386. return 0;
  387. }
  388.  
  389. }
  390.  
  391. }
  392.  
  393. for(int i=0;i<NUMMENU;i++)
  394. SDL_BlitSurface(menus[i],NULL,screen,&pos[i]);
  395.  
  396.  
  397. SDL_Flip(screen);
  398.  
  399. }
  400.  
  401. }
  402.  
  403.  
  404.  
  405.  
  406. int win(SDL_Surface *screen,TTF_Font *font)
  407. {
  408.  
  409. int x,y;
  410. const int NUMMENU=2;
  411. const char *labels[NUMMENU]={"Exit","You Won!!!"};
  412. SDL_Surface *menus[NUMMENU];
  413.  
  414. bool selected[NUMMENU]={0,0};
  415. SDL_Color color[2]={{255,255,255},{255,0,0}};
  416.  
  417. menus[0]=TTF_RenderText_Solid(font,labels[0],color[0]);
  418. menus[1]=TTF_RenderText_Solid(font,labels[1],color[0]);
  419.  
  420.  
  421. SDL_Rect pos[NUMMENU];
  422. pos[0].x=screen->clip_rect.w/2 - menus[0]->clip_rect.w/2;
  423. pos[0].y=screen->clip_rect.h/1.5 + menus[0]->clip_rect.h;
  424. pos[1].x=screen->clip_rect.w/2 - menus[0]->clip_rect.w;
  425. pos[1].y=screen->clip_rect.h/4 - menus[0]->clip_rect.h;
  426.  
  427.  
  428.  
  429.  
  430.  
  431. SDL_FillRect(screen,&screen->clip_rect,SDL_MapRGB(screen->format,0x200,0x200,0x255));
  432.  
  433. SDL_Event event;
  434.  
  435. while(true)
  436. {
  437.  
  438. while(SDL_PollEvent(&event))
  439. {
  440. switch(event.type)
  441. {
  442. case SDL_QUIT:
  443. for(int i=0;i<NUMMENU;i++)
  444. {
  445. SDL_FreeSurface(menus[i]);
  446. }
  447. return 0;
  448.  
  449. case SDL_MOUSEMOTION:
  450. x=event.motion.x;
  451. y=event.motion.y;
  452.  
  453. if(x>=pos[0].x && x<=pos[0].x+pos[0].w && y>=pos[0].y && y<=pos[0].y+pos[0].h)
  454. {
  455. if(!selected[0])
  456. {
  457. selected[0]=1;
  458. SDL_FreeSurface(menus[0]);
  459. menus[0]=TTF_RenderText_Solid(font,labels[0],color[1]);
  460.  
  461. }
  462. }
  463.  
  464. else
  465. {
  466. if(selected[0])
  467. {
  468. selected[0]=0;
  469. SDL_FreeSurface(menus[0]);
  470. menus[0]=TTF_RenderText_Solid(font,labels[0],color[0]);
  471. }
  472.  
  473. }
  474.  
  475. break;
  476.  
  477. case SDL_MOUSEBUTTONDOWN:
  478. x=event.button.x;
  479. y=event.button.y;
  480.  
  481.  
  482. if(x>=pos[0].x && x<=pos[0].x+pos[0].w && y>=pos[0].y && y<=pos[0].y+pos[0].h)
  483. {
  484. SDL_FreeSurface(menus[0]);
  485. return 0;
  486. }
  487. break;
  488.  
  489. case SDL_KEYDOWN:
  490. switch(event.key.keysym.sym)
  491. {
  492. case SDLK_ESCAPE:
  493. SDL_FreeSurface(menus[0]);
  494. return 0;
  495. }
  496.  
  497. }
  498.  
  499. }
  500.  
  501. for(int i=0;i<NUMMENU;i++)
  502. SDL_BlitSurface(menus[i],NULL,screen,&pos[i]);
  503.  
  504.  
  505. SDL_Flip(screen);
  506.  
  507. }
  508.  
  509. }
  510.  
  511.  
  512. int loose(SDL_Surface *screen,TTF_Font *font)
  513. {
  514.  
  515. int x,y;
  516. const int NUMMENU=2;
  517. const char *labels[NUMMENU]={"Exit","You Lost!!!"};
  518. SDL_Surface *menus[NUMMENU];
  519.  
  520. bool selected[NUMMENU]={0,0};
  521. SDL_Color color[2]={{255,255,255},{255,0,0}};
  522.  
  523. menus[0]=TTF_RenderText_Solid(font,labels[0],color[0]);
  524. menus[1]=TTF_RenderText_Solid(font,labels[1],color[0]);
  525.  
  526.  
  527. SDL_Rect pos[NUMMENU];
  528. pos[0].x=screen->clip_rect.w/2 - menus[0]->clip_rect.w/2;
  529. pos[0].y=screen->clip_rect.h/1.5 + menus[0]->clip_rect.h;
  530. pos[1].x=screen->clip_rect.w/2 - menus[0]->clip_rect.w;
  531. pos[1].y=screen->clip_rect.h/4 - menus[0]->clip_rect.h;
  532.  
  533.  
  534.  
  535.  
  536.  
  537. SDL_FillRect(screen,&screen->clip_rect,SDL_MapRGB(screen->format,0x200,0x200,0x255));
  538.  
  539. SDL_Event event;
  540.  
  541. while(true)
  542. {
  543.  
  544. while(SDL_PollEvent(&event))
  545. {
  546. switch(event.type)
  547. {
  548. case SDL_QUIT:
  549. for(int i=0;i<NUMMENU;i++)
  550. {
  551. SDL_FreeSurface(menus[i]);
  552. }
  553. return 0;
  554.  
  555. case SDL_MOUSEMOTION:
  556. x=event.motion.x;
  557. y=event.motion.y;
  558.  
  559. if(x>=pos[0].x && x<=pos[0].x+pos[0].w && y>=pos[0].y && y<=pos[0].y+pos[0].h)
  560. {
  561. if(!selected[0])
  562. {
  563. selected[0]=1;
  564. SDL_FreeSurface(menus[0]);
  565. menus[0]=TTF_RenderText_Solid(font,labels[0],color[1]);
  566.  
  567. }
  568. }
  569.  
  570. else
  571. {
  572. if(selected[0])
  573. {
  574. selected[0]=0;
  575. SDL_FreeSurface(menus[0]);
  576. menus[0]=TTF_RenderText_Solid(font,labels[0],color[0]);
  577. }
  578.  
  579. }
  580.  
  581. break;
  582.  
  583. case SDL_MOUSEBUTTONDOWN:
  584. x=event.button.x;
  585. y=event.button.y;
  586.  
  587.  
  588. if(x>=pos[0].x && x<=pos[0].x+pos[0].w && y>=pos[0].y && y<=pos[0].y+pos[0].h)
  589. {
  590. SDL_FreeSurface(menus[0]);
  591. return 0;
  592. }
  593. break;
  594.  
  595. case SDL_KEYDOWN:
  596. switch(event.key.keysym.sym)
  597. {
  598. case SDLK_ESCAPE:
  599. SDL_FreeSurface(menus[0]);
  600. return 0;
  601. }
  602.  
  603. }
  604.  
  605. }
  606.  
  607. for(int i=0;i<NUMMENU;i++)
  608. SDL_BlitSurface(menus[i],NULL,screen,&pos[i]);
  609.  
  610.  
  611. SDL_Flip(screen);
  612.  
  613. }
  614.  
  615. }
  616.  
  617.  
  618.  
  619.  
  620.  
  621.  
  622. };
  623.  
  624. SDL_Surface *screen=NULL;
  625.  
  626. SDL_Surface *text=NULL;
  627.  
  628. SDL_Surface *pause=NULL;
  629.  
  630. SDL_Surface *heroe=NULL;
  631. SDL_Surface *imagebackground=NULL;
  632.  
  633.  
  634. SDL_Event event;
  635. bool run=true;
  636.  
  637.  
  638. int srcX1=0;
  639. int srcY1=0;
  640.  
  641. int dstX1=5;
  642. int dstY1=930;
  643.  
  644.  
  645. int ScreenWidth=1000;
  646. int ScreenHeight=1000;
  647.  
  648.  
  649.  
  650. int main(int argc, char** argv)
  651. {
  652.  
  653. SDL_Init(SDL_INIT_EVERYTHING);
  654. TTF_Init();
  655.  
  656. SDL_WM_SetCaption("Space game",NULL);
  657.  
  658. screen=SDL_SetVideoMode(1000,1000,32,SDL_SWSURFACE);
  659.  
  660.  
  661. instructions instr;
  662.  
  663. TTF_Font *font=TTF_OpenFont("256BYTES.ttf",80);
  664. TTF_Font *font1=TTF_OpenFont("256BYTES.ttf",60);
  665. TTF_Font *font2=TTF_OpenFont("256BYTES.ttf",100);
  666.  
  667. SDL_Color col{80,10,10};
  668. text=TTF_RenderText_Solid(font,"GOOD\n\n\nLUCK !!!",col);
  669.  
  670.  
  671. heroe=SDL_LoadBMP("myheroe.bmp");
  672. imagebackground=SDL_LoadBMP("bg.bmp");
  673. pause=SDL_LoadBMP("pause.bmp");
  674.  
  675.  
  676. SDL_SetColorKey(heroe,SDL_SRCCOLORKEY,SDL_MapRGB(heroe->format,0xff,0xff,0xff));
  677.  
  678.  
  679. Uint32 backround=SDL_MapRGB(screen->format,0x00,0xff,0xff);
  680. Uint32 color=SDL_MapRGB(screen->format,0x00,0x00,0xff);
  681. Uint32 color1=SDL_MapRGB(screen->format,0x100,0x255,0x100);
  682.  
  683.  
  684.  
  685. SDL_Rect obstacle,obstacle1,obstacle2,obstacle3,obstacle4,obstacle5,obstacle6,obstacle7,bad;
  686. instr.give(150,960,80,40,obstacle);
  687. instr.give(370,960,130,40,obstacle1);
  688. instr.give(530,960,130,40,obstacle2);
  689. instr.give(460,920,110,40,obstacle3);
  690. instr.give(800,960,190,40,obstacle4);
  691. instr.give(865,920,60,40,obstacle5);
  692.  
  693. instr.give(1110,690,100,40,obstacle6);
  694. instr.give(1140,400,360,40,obstacle7);
  695.  
  696. instr.give(250,960,40,40,bad);
  697.  
  698.  
  699. const int speed=6;
  700. SDL_Rect camera;
  701. instr.give(0,0,1000,1000,camera);
  702.  
  703. bool up=false;
  704. bool down=true;
  705. bool right=false;
  706. bool left=false;
  707. bool changeColor=false;
  708. bool makePause=false;
  709.  
  710.  
  711. int k;
  712. k=instr.showmenu1(screen,font);
  713.  
  714. if(k==1)
  715. {
  716. int r;
  717. r=instr.rules(screen,font1);
  718.  
  719. if(r==1)
  720. run=false;
  721. }
  722.  
  723. else if(k==2)
  724. run=false;
  725.  
  726.  
  727.  
  728. while(run)
  729. {
  730. if(SDL_PollEvent(&event))
  731. {
  732. switch(event.type)
  733. {
  734. case SDL_QUIT:
  735. run=false;
  736. break;
  737.  
  738. case SDL_KEYDOWN:
  739. switch(event.key.keysym.sym)
  740. {
  741.  
  742. case SDLK_DOWN:
  743. changeColor=true;
  744. break;
  745.  
  746. case SDLK_UP:
  747. up=true;
  748. down=false;
  749. break;
  750.  
  751. case SDLK_RIGHT:
  752. right=true;
  753. break;
  754.  
  755. case SDLK_LEFT:
  756. left=true;
  757. break;
  758.  
  759.  
  760.  
  761. case SDLK_ESCAPE:
  762. int i;
  763. i=instr.showmenu(screen,font);
  764. if(i==1)
  765. run=false;
  766.  
  767. break;
  768.  
  769. }
  770. break;
  771.  
  772. case SDL_KEYUP:
  773. switch(event.key.keysym.sym)
  774. {
  775.  
  776. case SDLK_DOWN:
  777. changeColor=false;
  778. break;
  779.  
  780. case SDLK_UP:
  781. up=false;
  782. down=true;
  783. break;
  784.  
  785. case SDLK_RIGHT:
  786. right=false;
  787. break;
  788.  
  789. case SDLK_LEFT:
  790. left=false;
  791. break;
  792.  
  793.  
  794.  
  795. }
  796. break;
  797.  
  798. case SDL_MOUSEBUTTONDOWN:
  799. makePause=true;
  800. break;
  801.  
  802.  
  803.  
  804. }
  805.  
  806.  
  807. }
  808.  
  809.  
  810.  
  811.  
  812.  
  813. ///////////////////////////////////
  814. ///////////////////////////////////
  815. ///////////////////////////////////
  816. ///////////////////////////////////
  817. ///////////////////////////////////
  818.  
  819.  
  820.  
  821. if(makePause==true)
  822. {
  823.  
  824. int x,y;
  825.  
  826. x=event.motion.x;
  827. y=event.motion.y;
  828. if(x>900 && x<900+pause->w && y>2 && 2+2+pause->h)
  829. {
  830. int i;
  831. i=instr.showmenu(screen,font);
  832. if(i==1)
  833. run=false;
  834. }
  835.  
  836. }
  837.  
  838. makePause=false;
  839.  
  840.  
  841.  
  842.  
  843. if(changeColor==true)
  844. {
  845. backround=SDL_MapRGB(screen->format,0x80,0x80,0x20);
  846. }
  847.  
  848.  
  849.  
  850.  
  851. if(up==true && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle.x,obstacle.y,obstacle.w,obstacle.h)==true)
  852. && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle1.x,obstacle1.y,obstacle1.w,obstacle1.h)==true)
  853. && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle2.x,obstacle2.y,obstacle2.w,obstacle2.h)==true)
  854. && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle3.x,obstacle3.y,obstacle3.w,obstacle3.h)==true)
  855. && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle4.x,obstacle4.y,obstacle4.w,obstacle4.h)==true)
  856. && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle5.x,obstacle5.y,obstacle5.w,obstacle5.h)==true)
  857. && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle6.x,obstacle6.y,obstacle6.w,obstacle6.h)==true)
  858. && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle7.x,obstacle7.y,obstacle7.w,obstacle7.h)==true))
  859. {
  860. dstY1-=2;
  861.  
  862.  
  863. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle.x,obstacle.y,obstacle.w,obstacle.h)==true)
  864. dstY1+=2;
  865.  
  866. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle1.x,obstacle1.y,obstacle1.w,obstacle1.h)==true)
  867. dstY1+=2;
  868.  
  869. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle2.x,obstacle2.y,obstacle2.w,obstacle2.h)==true)
  870. dstY1+=2;
  871.  
  872. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle3.x,obstacle3.y,obstacle3.w,obstacle3.h)==true)
  873. dstY1+=2;
  874.  
  875. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle4.x,obstacle4.y,obstacle4.w,obstacle4.h)==true)
  876. dstY1+=2;
  877.  
  878. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle5.x,obstacle5.y,obstacle5.w,obstacle5.h)==true)
  879. dstY1+=2;
  880.  
  881. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle6.x,obstacle6.y,obstacle6.w,obstacle6.h)==true)
  882. dstY1+=2;
  883.  
  884. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle7.x,obstacle7.y,obstacle7.w,obstacle7.h)==true)
  885. dstY1+=2;
  886.  
  887.  
  888.  
  889. }
  890.  
  891. if(down==true && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle.x,obstacle.y,obstacle.w,obstacle.h)==true)
  892. && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle1.x,obstacle1.y,obstacle1.w,obstacle1.h)==true)
  893. && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle2.x,obstacle2.y,obstacle2.w,obstacle2.h)==true)
  894. && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle3.x,obstacle3.y,obstacle3.w,obstacle3.h)==true)
  895. && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle4.x,obstacle4.y,obstacle4.w,obstacle4.h)==true)
  896. && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle5.x,obstacle5.y,obstacle5.w,obstacle5.h)==true)
  897. && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle6.x,obstacle6.y,obstacle6.w,obstacle6.h)==true)
  898. && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle7.x,obstacle7.y,obstacle7.w,obstacle7.h)==true))
  899. {
  900. dstY1+=2;
  901.  
  902.  
  903. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle.x,obstacle.y,obstacle.w,obstacle.h)==true)
  904. dstY1-=2;
  905.  
  906. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle1.x,obstacle1.y,obstacle1.w,obstacle1.h)==true)
  907. dstY1-=2;
  908.  
  909. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle2.x,obstacle2.y,obstacle2.w,obstacle2.h)==true)
  910. dstY1-=2;
  911.  
  912. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle3.x,obstacle3.y,obstacle3.w,obstacle3.h)==true)
  913. dstY1-=2;
  914.  
  915. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle4.x,obstacle4.y,obstacle4.w,obstacle4.h)==true)
  916. dstY1-=2;
  917.  
  918. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle5.x,obstacle5.y,obstacle5.w,obstacle5.h)==true)
  919. dstY1-=2;
  920.  
  921. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle6.x,obstacle6.y,obstacle6.w,obstacle6.h)==true)
  922. dstY1-=2;
  923.  
  924. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle7.x,obstacle7.y,obstacle7.w,obstacle7.h)==true)
  925. dstY1-=2;
  926.  
  927. }
  928.  
  929. if(right==true && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle.x,obstacle.y,obstacle.w,obstacle.h)==true)
  930. && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle1.x,obstacle1.y,obstacle1.w,obstacle1.h)==true)
  931. && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle2.x,obstacle2.y,obstacle2.w,obstacle2.h)==true)
  932. && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle3.x,obstacle3.y,obstacle3.w,obstacle3.h)==true)
  933. && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle4.x,obstacle4.y,obstacle4.w,obstacle4.h)==true)
  934. && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle5.x,obstacle5.y,obstacle5.w,obstacle5.h)==true)
  935. && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle6.x,obstacle6.y,obstacle6.w,obstacle6.h)==true)
  936. && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle7.x,obstacle7.y,obstacle7.w,obstacle7.h)==true))
  937. {
  938. dstX1++;
  939.  
  940. camera.x+=speed;
  941. if(camera.x>=5550)
  942. camera.x=0;
  943.  
  944.  
  945. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle.x,obstacle.y,obstacle.w,obstacle.h)==true)
  946. dstX1-=1;
  947.  
  948. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle1.x,obstacle1.y,obstacle1.w,obstacle1.h)==true)
  949. dstX1-=1;
  950.  
  951. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle2.x,obstacle2.y,obstacle2.w,obstacle2.h)==true)
  952. dstX1-=1;
  953.  
  954. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle3.x,obstacle3.y,obstacle3.w,obstacle3.h)==true)
  955. dstX1-=1;
  956.  
  957. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle4.x,obstacle4.y,obstacle4.w,obstacle4.h)==true)
  958. dstX1-=1;
  959.  
  960. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle5.x,obstacle5.y,obstacle5.w,obstacle5.h)==true)
  961. dstX1-=1;
  962.  
  963. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle6.x,obstacle6.y,obstacle6.w,obstacle6.h)==true)
  964. dstX1-=1;
  965.  
  966. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle7.x,obstacle7.y,obstacle7.w,obstacle7.h)==true)
  967. dstX1-=1;
  968.  
  969. }
  970.  
  971. if(left==true && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle.x,obstacle.y,obstacle.w,obstacle.h)==true)
  972. && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle1.x,obstacle1.y,obstacle1.w,obstacle1.h)==true)
  973. && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle2.x,obstacle2.y,obstacle2.w,obstacle2.h)==true)
  974. && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle3.x,obstacle3.y,obstacle3.w,obstacle3.h)==true)
  975. && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle4.x,obstacle4.y,obstacle4.w,obstacle4.h)==true)
  976. && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle5.x,obstacle5.y,obstacle5.w,obstacle5.h)==true)
  977. && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle6.x,obstacle6.y,obstacle6.w,obstacle6.h)==true)
  978. && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle7.x,obstacle7.y,obstacle7.w,obstacle7.h)==true))
  979. {
  980. dstX1--;
  981.  
  982. camera.x-=speed;
  983. if(camera.x<=0)
  984. camera.x=5550;
  985.  
  986.  
  987.  
  988. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle.x,obstacle.y,obstacle.w,obstacle.h)==true)
  989. dstX1+=1;
  990.  
  991. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle1.x,obstacle1.y,obstacle1.w,obstacle1.h)==true)
  992. dstX1+=1;
  993.  
  994. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle2.x,obstacle2.y,obstacle2.w,obstacle2.h)==true)
  995. dstX1+=1;
  996.  
  997. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle3.x,obstacle3.y,obstacle3.w,obstacle3.h)==true)
  998. dstX1+=1;
  999.  
  1000. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle4.x,obstacle4.y,obstacle4.w,obstacle4.h)==true)
  1001. dstX1+=1;
  1002.  
  1003. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle5.x,obstacle5.y,obstacle5.w,obstacle5.h)==true)
  1004. dstX1+=1;
  1005.  
  1006. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle6.x,obstacle6.y,obstacle6.w,obstacle6.h)==true)
  1007. dstX1+=1;
  1008.  
  1009. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle7.x,obstacle7.y,obstacle7.w,obstacle7.h)==true)
  1010. dstX1+=1;
  1011.  
  1012.  
  1013.  
  1014. }
  1015.  
  1016.  
  1017. /////////////////////////
  1018. /////////////////////////
  1019.  
  1020. if(dstX1<0)
  1021. {
  1022. dstX1=0;
  1023.  
  1024. }
  1025.  
  1026. if(dstY1<0)
  1027. {
  1028. dstY1=0;
  1029. }
  1030.  
  1031.  
  1032. /////////////////////////
  1033. /////////////////////////
  1034.  
  1035. if(dstX1+heroe->w > ScreenWidth)
  1036. {
  1037. dstX1=ScreenWidth-heroe->w;
  1038.  
  1039. }
  1040.  
  1041. if(dstY1+heroe->h > ScreenHeight)
  1042. {
  1043. dstY1=ScreenHeight-heroe->h;
  1044.  
  1045. }
  1046.  
  1047.  
  1048.  
  1049.  
  1050. if(up==true && (dstY1+heroe->h < 900) )
  1051. {
  1052. down=true;
  1053. up=false;
  1054. }
  1055.  
  1056.  
  1057. /////////////////////////////////
  1058. /////////////////////////////////
  1059.  
  1060. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,bad.x,bad.y,bad.w,bad.h)==true)
  1061. {
  1062. int l;
  1063. l=instr.loose(screen,font2);
  1064.  
  1065. if(l==0)
  1066. run=false;
  1067. }
  1068.  
  1069. /////////////////////////////////
  1070. /////////////////////////////////
  1071. if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle7.x-5,obstacle7.y-5,obstacle7.w-5,obstacle7.h-5)==true)
  1072. {
  1073. int w;
  1074. w=instr.win(screen,font2);
  1075.  
  1076. if(w==0)
  1077. run=false;
  1078. }
  1079. //////////////
  1080. SDL_FillRect(screen,&screen->clip_rect,backround);
  1081.  
  1082. SDL_BlitSurface(imagebackground,&camera,screen,NULL);
  1083.  
  1084. SDL_FillRect(screen,&obstacle,color);
  1085. SDL_FillRect(screen,&obstacle1,color);
  1086. SDL_FillRect(screen,&obstacle2,color);
  1087. SDL_FillRect(screen,&obstacle3,color);
  1088. SDL_FillRect(screen,&obstacle4,color);
  1089. SDL_FillRect(screen,&obstacle5,color);
  1090. SDL_FillRect(screen,&obstacle6,color);
  1091. SDL_FillRect(screen,&obstacle7,color);
  1092.  
  1093. SDL_FillRect(screen,&bad,color1);
  1094.  
  1095.  
  1096. instr.apply(srcX1, srcY1, 900, 2, pause->w,pause->h, pause, screen);
  1097.  
  1098.  
  1099. instr.apply(srcX1, srcY1, dstX1, dstY1, heroe->w,heroe->h, heroe, screen);
  1100.  
  1101.  
  1102.  
  1103.  
  1104. SDL_BlitSurface(text,NULL,screen,NULL);
  1105.  
  1106.  
  1107.  
  1108. SDL_Flip(screen);
  1109. }
  1110.  
  1111. SDL_FreeSurface(text);
  1112. TTF_CloseFont(font);
  1113.  
  1114. TTF_Quit();
  1115. SDL_Quit();
  1116. return 0;
  1117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement