Glaas2

objects

Jun 13th, 2012
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.26 KB | None | 0 0
  1. //Object IDs
  2. enum IDS{PLAYER, FOOD, ENEMY, ENEMY2, ENEMY3, ENEMY4, ENEMY5, ENEMY6, ENEMY7, ENEMY8};
  3.  
  4. const int WIDTH = 800;
  5. const int HEIGHT = 455;
  6. const int NUM_CARS = 18;
  7. const int NUM_CARS2 = 13;
  8. const int NUM_CARS3 = 18;
  9. const int NUM_CARS4 = 13;
  10. const int NUM_CARS5 = 18;
  11. const int NUM_CARS6 = 13;
  12. const int NUM_CARS7 = 18;
  13. const int NUM_CARS8 = 13;
  14. const int NUM_FOOD = 8;
  15.  
  16. //Our Player
  17. class RoadBear
  18. {
  19.     public:
  20.     int ID;
  21.     int x;
  22.     int y;
  23.     int lives;
  24.     int speed;
  25.     int boundx;
  26.     int boundy;
  27.     int score;
  28.    
  29.     RoadBear();
  30.     void dibujar_oso(ALLEGRO_BITMAP *image);
  31.     void mover_derecha();
  32.     void mover_izquierda();
  33.     void mover_arriba();
  34.     void mover_abajo();
  35. };
  36.  
  37. RoadBear::RoadBear(){
  38.     x = 400;
  39.     y = 455;
  40.     ID = PLAYER;
  41.     lives = 3;
  42.     speed = 3;
  43.     boundx = 0;
  44.     boundy = 0;
  45.     score = 0;                            
  46. }
  47.  
  48. void RoadBear::dibujar_oso(ALLEGRO_BITMAP *image){
  49.      al_draw_bitmap(image, x-23, y-30, 0);
  50. }
  51.  
  52. void RoadBear::mover_derecha(){
  53.      x += speed;
  54.     if(x > 800)
  55.         x = 800;
  56.      }
  57.  
  58. void RoadBear::mover_izquierda(){
  59.      x -= speed;
  60.     if(x < 0)
  61.         x = 0;
  62.      }
  63.  
  64. void RoadBear::mover_arriba()
  65. {
  66.      y -= speed;
  67.     if(y < 0)
  68.         y = 0;
  69.  }
  70.  
  71. void RoadBear::mover_abajo(){
  72.      y += speed;
  73.     if(y > HEIGHT)
  74.         y = HEIGHT;
  75.      }
  76.  
  77. class Premio
  78. {
  79.     public:
  80.     int ID;
  81.     int x;
  82.     int y;
  83.     int speed;
  84.     bool live;
  85.     int boundx;
  86.     int boundy;
  87.    
  88.     Premio();
  89.     void dibujar_premio(ALLEGRO_BITMAP *image11);
  90.     void iniciar_premio();
  91.     void actualizar_premio();
  92.     void colision_premio(RoadBear &oso);
  93.    
  94. };
  95.  
  96. Premio::Premio(){
  97.       ID = FOOD;
  98.       live = false;
  99.       speed = 2;
  100.       boundx = 25;
  101.       boundy = 25;
  102. }
  103.  
  104. void Premio::dibujar_premio(ALLEGRO_BITMAP *image11){
  105.      if(live)
  106.         {
  107.              al_draw_bitmap(image11, x-23, y-30, 0);
  108.         }
  109. }
  110.      
  111. void Premio::iniciar_premio(){
  112.      live = true;
  113.      x = WIDTH;
  114.      y = 30 + rand()% (HEIGHT - 60);
  115. }
  116.      
  117. void Premio::actualizar_premio(){
  118.      if(live)
  119.         {
  120.             x -= speed;
  121.         }
  122. }
  123.  
  124. void Premio::colision_premio(RoadBear &oso){
  125.      if(live)
  126.         {
  127.             if(x - boundx < oso.x + oso.boundx &&
  128.                 x + boundx > oso.x - oso.boundx &&
  129.                 y - boundy < oso.y + oso.boundy &&
  130.                 y + boundy > oso.y - oso.boundy)
  131.             {
  132.                 oso.score++;
  133.                 live = false;
  134.             }
  135.         }
  136. }
  137.  
  138. //Our Enemies
  139. class Coche{
  140.       public:
  141.       int ID;
  142.       int x;
  143.       int y;
  144.       bool live;
  145.       int speed;
  146.       int boundx;
  147.       int boundy;
  148.      
  149.       Coche();
  150.       void dibujar_coche(ALLEGRO_BITMAP *image3);
  151.       void iniciar_coche();
  152.       void actualizar_coche();
  153.       void colision_coche(RoadBear &oso);
  154. };
  155.  
  156. Coche::Coche(){
  157.       ID = ENEMY;
  158.       live = false;
  159.       speed = 10;
  160.       boundx = 25;
  161.       boundy = 25;
  162. }
  163.  
  164. void Coche::dibujar_coche(ALLEGRO_BITMAP *image3){
  165.      if(live)
  166.         {
  167.              al_draw_bitmap(image3, x-23, y-30, 0);
  168.         }
  169. }
  170.      
  171. void Coche::iniciar_coche(){
  172.      live = true;
  173.      x = WIDTH;
  174.      y = 75 % (HEIGHT - 60);
  175. }
  176.      
  177. void Coche::actualizar_coche(){
  178.      if(live)
  179.         {
  180.             x -= speed;
  181.         }
  182. }
  183.  
  184. void Coche::colision_coche(RoadBear &oso){
  185.      if(live)
  186.         {
  187.             if(x - boundx < oso.x + oso.boundx &&
  188.                 x + boundx > oso.x - oso.boundx &&
  189.                 y - boundy < oso.y + oso.boundy &&
  190.                 y + boundy > oso.y - oso.boundy)
  191.             {
  192.                 oso.lives--;
  193.                 live = false;
  194.             }
  195.         }
  196. }
  197.  
  198. class Coche2{
  199.       public:
  200.       int ID;
  201.       int x;
  202.       int y;
  203.       bool live;
  204.       int speed;
  205.       int boundx;
  206.       int boundy;
  207.      
  208.       Coche2();
  209.       void dibujar_coche2(ALLEGRO_BITMAP *image4);
  210.       void iniciar_coche2();
  211.       void actualizar_coche2();
  212.       void colision_coche2(RoadBear &oso);
  213. };
  214.  
  215. Coche2::Coche2(){
  216.       ID = ENEMY2;
  217.       live = false;
  218.       speed = 7;
  219.       boundx = 25;
  220.       boundy = 25;
  221. }
  222.  
  223. void Coche2::dibujar_coche2(ALLEGRO_BITMAP *image4){
  224.      if(live)
  225.         {
  226.              al_draw_bitmap(image4, x-23, y-30, 0);
  227.         }
  228. }
  229.      
  230. void Coche2::iniciar_coche2(){
  231.      live = true;
  232.      x = WIDTH;
  233.      y = 115 % (HEIGHT - 60);
  234. }
  235.      
  236. void Coche2::actualizar_coche2(){
  237.      if(live)
  238.         {
  239.             x -= speed;
  240.         }
  241. }
  242.  
  243. void Coche2::colision_coche2(RoadBear &oso){
  244.      if(live)
  245.         {
  246.             if(x - boundx < oso.x + oso.boundx &&
  247.                 x + boundx > oso.x - oso.boundx &&
  248.                 y - boundy < oso.y + oso.boundy &&
  249.                 y + boundy > oso.y - oso.boundy)
  250.             {
  251.                 oso.lives--;
  252.                 live = false;
  253.             }
  254.            
  255.         }
  256. }
  257.  
  258. class Coche3{
  259.       public:
  260.       int ID;
  261.       int x;
  262.       int y;
  263.       bool live;
  264.       int speed;
  265.       int boundx;
  266.       int boundy;
  267.      
  268.       Coche3();
  269.       void dibujar_coche3(ALLEGRO_BITMAP *image5);
  270.       void iniciar_coche3();
  271.       void actualizar_coche3();
  272.       void colision_coche3(RoadBear &oso);
  273. };
  274.  
  275. Coche3::Coche3(){
  276.       ID = ENEMY3;
  277.       live = false;
  278.       speed = 10;
  279.       boundx = 25;
  280.       boundy = 25;
  281. }
  282.  
  283. void Coche3::dibujar_coche3(ALLEGRO_BITMAP *image5){
  284.      if(live)
  285.         {
  286.              al_draw_bitmap(image5, x-23, y-30, 0);
  287.         }
  288. }
  289.      
  290. void Coche3::iniciar_coche3(){
  291.      live = true;
  292.      x = WIDTH;
  293.      y = 160 % (HEIGHT - 60);
  294. }
  295.      
  296. void Coche3::actualizar_coche3(){
  297.      if(live)
  298.         {
  299.             x -= speed;
  300.         }
  301. }
  302.  
  303. void Coche3::colision_coche3(RoadBear &oso){
  304.      if(live)
  305.         {
  306.             if(x - boundx < oso.x + oso.boundx &&
  307.                 x + boundx > oso.x - oso.boundx &&
  308.                 y - boundy < oso.y + oso.boundy &&
  309.                 y + boundy > oso.y - oso.boundy)
  310.             {
  311.                 oso.lives--;
  312.                 live = false;
  313.             }
  314.        
  315.         }
  316. }
  317.  
  318. class Coche4{
  319.       public:
  320.       int ID;
  321.       int x;
  322.       int y;
  323.       bool live;
  324.       int speed;
  325.       int boundx;
  326.       int boundy;
  327.      
  328.       Coche4();
  329.       void dibujar_coche4(ALLEGRO_BITMAP *image6);
  330.       void iniciar_coche4();
  331.       void actualizar_coche4();
  332.       void colision_coche4(RoadBear &oso);
  333. };
  334.  
  335. Coche4::Coche4(){
  336.       ID = ENEMY4;
  337.       live = false;
  338.       speed = 7;
  339.       boundx = 25;
  340.       boundy = 25;
  341. }
  342.  
  343. void Coche4::dibujar_coche4(ALLEGRO_BITMAP *image6){
  344.      if(live)
  345.         {
  346.              al_draw_bitmap(image6, x-23, y-30, 0);
  347.         }
  348. }
  349.      
  350. void Coche4::iniciar_coche4(){
  351.      live = true;
  352.      x = WIDTH;
  353.      y = 195 % (HEIGHT - 60);
  354. }
  355.      
  356. void Coche4::actualizar_coche4(){
  357.      if(live)
  358.         {
  359.             x -= speed;
  360.         }
  361. }
  362.  
  363. void Coche4::colision_coche4(RoadBear &oso){
  364.      if(live)
  365.         {
  366.             if(x - boundx < oso.x + oso.boundx &&
  367.                 x + boundx > oso.x - oso.boundx &&
  368.                 y - boundy < oso.y + oso.boundy &&
  369.                 y + boundy > oso.y - oso.boundy)
  370.             {
  371.                 oso.lives--;
  372.                 live = false;
  373.             }
  374.            
  375.         }
  376. }
  377.  
  378. class Coche5{
  379.       public:
  380.       int ID;
  381.       int x;
  382.       int y;
  383.       bool live;
  384.       int speed;
  385.       int boundx;
  386.       int boundy;
  387.      
  388.       Coche5();
  389.       void dibujar_coche5(ALLEGRO_BITMAP *image7);
  390.       void iniciar_coche5();
  391.       void actualizar_coche5();
  392.       void colision_coche5(RoadBear &oso);
  393. };
  394.  
  395. Coche5::Coche5(){
  396.       ID = ENEMY5;
  397.       live = false;
  398.       speed = 10;
  399.       boundx = 25;
  400.       boundy = 25;
  401. }
  402.  
  403. void Coche5::dibujar_coche5(ALLEGRO_BITMAP *image7){
  404.      if(live)
  405.         {
  406.              al_draw_bitmap(image7, x-23, y-30, 0);
  407.         }
  408. }
  409.      
  410. void Coche5::iniciar_coche5(){
  411.      live = true;
  412.      x = WIDTH;
  413.      y = 303 % (HEIGHT - 60);
  414. }
  415.      
  416. void Coche5::actualizar_coche5(){
  417.      if(live)
  418.         {
  419.             x -= speed;
  420.         }
  421. }
  422.  
  423. void Coche5::colision_coche5(RoadBear &oso){
  424.      if(live)
  425.         {
  426.             if(x - boundx < oso.x + oso.boundx &&
  427.                 x + boundx > oso.x - oso.boundx &&
  428.                 y - boundy < oso.y + oso.boundy &&
  429.                 y + boundy > oso.y - oso.boundy)
  430.             {
  431.                 oso.lives--;
  432.                 live = false;
  433.             }
  434.            
  435.         }
  436. }
  437.  
  438. class Coche6{
  439.       public:
  440.       int ID;
  441.       int x;
  442.       int y;
  443.       bool live;
  444.       int speed;
  445.       int boundx;
  446.       int boundy;
  447.      
  448.       Coche6();
  449.       void dibujar_coche6(ALLEGRO_BITMAP *image8);
  450.       void iniciar_coche6();
  451.       void actualizar_coche6();
  452.       void colision_coche6(RoadBear &oso);
  453. };
  454.  
  455. Coche6::Coche6(){
  456.       ID = ENEMY6;
  457.       live = false;
  458.       speed = 7;
  459.       boundx = 25;
  460.       boundy = 25;
  461. }
  462.  
  463. void Coche6::dibujar_coche6(ALLEGRO_BITMAP *image8){
  464.      if(live)
  465.         {
  466.              al_draw_bitmap(image8, x-23, y-30, 0);
  467.         }
  468. }
  469.      
  470. void Coche6::iniciar_coche6(){
  471.      live = true;
  472.      x = WIDTH;
  473.      y = 339 % (HEIGHT - 60);
  474. }
  475.      
  476. void Coche6::actualizar_coche6(){
  477.      if(live)
  478.         {
  479.             x -= speed;
  480.         }
  481. }
  482.  
  483. void Coche6::colision_coche6(RoadBear &oso){
  484.      if(live)
  485.         {
  486.             if(x - boundx < oso.x + oso.boundx &&
  487.                 x + boundx > oso.x - oso.boundx &&
  488.                 y - boundy < oso.y + oso.boundy &&
  489.                 y + boundy > oso.y - oso.boundy)
  490.             {
  491.                 oso.lives--;
  492.                 live = false;
  493.             }
  494.            
  495.         }
  496. }
  497.  
  498. class Coche7{
  499.       public:
  500.       int ID;
  501.       int x;
  502.       int y;
  503.       bool live;
  504.       int speed;
  505.       int boundx;
  506.       int boundy;
  507.      
  508.       Coche7();
  509.       void dibujar_coche7(ALLEGRO_BITMAP *image9);
  510.       void iniciar_coche7();
  511.       void actualizar_coche7();
  512.       void colision_coche7(RoadBear &oso);
  513. };
  514.  
  515. Coche7::Coche7(){
  516.       ID = ENEMY7;
  517.       live = false;
  518.       speed = 10;
  519.       boundx = 25;
  520.       boundy = 25;
  521. }
  522.  
  523. void Coche7::dibujar_coche7(ALLEGRO_BITMAP *image9){
  524.      if(live)
  525.         {
  526.              al_draw_bitmap(image9, x-23, y-30, 0);
  527.         }
  528. }
  529.      
  530. void Coche7::iniciar_coche7(){
  531.      live = true;
  532.      x = WIDTH;
  533.      y = 382 % (HEIGHT - 60);
  534. }
  535.      
  536. void Coche7::actualizar_coche7(){
  537.      if(live)
  538.         {
  539.             x -= speed;
  540.         }
  541. }
  542.  
  543. void Coche7::colision_coche7(RoadBear &oso){
  544.      if(live)
  545.         {
  546.             if(x - boundx < oso.x + oso.boundx &&
  547.                 x + boundx > oso.x - oso.boundx &&
  548.                 y - boundy < oso.y + oso.boundy &&
  549.                 y + boundy > oso.y - oso.boundy)
  550.             {
  551.                 oso.lives--;
  552.                 live = false;
  553.             }
  554.            
  555.         }
  556. }
  557.  
  558. class Coche8{
  559.       public:
  560.       int ID;
  561.       int x;
  562.       int y;
  563.       bool live;
  564.       int speed;
  565.       int boundx;
  566.       int boundy;
  567.      
  568.       Coche8();
  569.       void dibujar_coche8(ALLEGRO_BITMAP *image10);
  570.       void iniciar_coche8();
  571.       void actualizar_coche8();
  572.       void colision_coche8(RoadBear &oso);
  573. };
  574.  
  575. Coche8::Coche8(){
  576.       ID = ENEMY8;
  577.       live = false;
  578.       speed = 7;
  579.       boundx = 25;
  580.       boundy = 25;
  581. }
  582.  
  583. void Coche8::dibujar_coche8(ALLEGRO_BITMAP *image10){
  584.      if(live)
  585.         {
  586.              al_draw_bitmap(image10, x-23, y-30, 0);
  587.         }
  588. }
  589.      
  590. void Coche8::iniciar_coche8(){
  591.      live = true;
  592.      x = WIDTH;
  593.      y = 390+25 % (HEIGHT - 60);
  594. }
  595.      
  596. void Coche8::actualizar_coche8(){
  597.      if(live)
  598.         {
  599.             x -= speed;
  600.         }
  601. }
  602.  
  603. void Coche8::colision_coche8(RoadBear &oso){
  604.      if(live)
  605.         {
  606.             if(x - boundx < oso.x + oso.boundx &&
  607.                 x + boundx > oso.x - oso.boundx &&
  608.                 y - boundy < oso.y + oso.boundy &&
  609.                 y + boundy > oso.y - oso.boundy)
  610.             {
  611.                 oso.lives--;
  612.                 live = false;
  613.             }
  614.            
  615.         }
  616. }
Advertisement
Add Comment
Please, Sign In to add comment