Advertisement
Guest User

Untitled

a guest
May 28th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 16.78 KB | None | 0 0
  1. #if _DEBUG
  2. #pragma comment(lib, "alld.lib")
  3. #else
  4. #pragma comment(lib, "alleg.lib")
  5. #endif
  6.  
  7. #define MAXMETEOS 32
  8.  
  9. #include<allegro.h>
  10. #include<stdio.h>
  11.  
  12. class GameObject
  13. {
  14. public: //pozniej ma byc protected
  15.     int _x;
  16.     int _y;
  17.     int dmg;
  18.     char* _image;
  19.  
  20.     int _dir_x;
  21.     int _dir_y;
  22.  
  23.     virtual ~GameObject()
  24.     {
  25.     }
  26.  
  27.     virtual void refresh()=0;
  28. };
  29.  
  30. class meteoryt : public GameObject
  31. {
  32.     int r_x;
  33.     int r_y;
  34.     int last_tick_time;
  35.     int spddelay;
  36.     int *ig_time;
  37.  
  38. public:
  39.     BITMAP *_bmp;
  40.     bool isAlive;
  41.     bool move_tick;
  42.  
  43.     meteoryt(int x, int y, char* img,int* time_var)
  44.     {
  45.         spddelay=5;
  46.         last_tick_time=0;
  47.         move_tick=true;
  48.         ig_time=time_var;
  49.  
  50.         isAlive=1;
  51.         dmg=100;
  52.         _x=x;
  53.         _y=y;
  54.         _image=img;
  55.  
  56.         _bmp=load_bmp(_image,default_palette); //bitmapa meteor dla meteo
  57.  
  58.         _dir_x=1;
  59.         _dir_y=1;
  60.  
  61.         r_x=this->_x+400;
  62.         r_y=this->_y+400;
  63.     }
  64.     ~meteoryt()
  65.     {
  66.         destroy_bitmap(_bmp);
  67.     }
  68.  
  69.     void setTimeVar(int *var_ms)
  70.     {
  71.         ig_time=var_ms;
  72.     }
  73.  
  74.     void move()
  75.     {
  76.         //ograniczenie ekranu
  77.         if(this->_y>600) this->_y=-120;
  78.         if(this->_y<-120) this->_y=580;
  79.         if(this->_x>800) this->_x=-100;
  80.         if(this->_x<-100) this->_x=800;
  81.  
  82.         //meteor trajektoria X
  83.         if(move_tick)
  84.         {
  85.             if((this->_x>=100 || this->_x<=r_x) && this->_dir_x==1) ++this->_x;
  86.             if((this->_x>=100 || this->_x<=r_x) && this->_dir_x==-1) --this->_x;
  87.         }
  88.  
  89.         if(this->_x==100 || this->_x==r_x)
  90.         {
  91.             if(this->_dir_x==1)
  92.                 this->_dir_x=-1;
  93.             else
  94.                 this->_dir_x=1;
  95.         }
  96.         //meteor trajektoria Y
  97.         if(move_tick)
  98.         {
  99.             if((this->_y>=100 || this->_y<=r_y) && this->_dir_y==1) ++this->_y;
  100.             if((this->_y>=100 || this->_y<=r_y) && this->_dir_y==-1) --this->_y;
  101.         }
  102.  
  103.         if(this->_y==100 || this->_y==r_y)
  104.         {
  105.             if(this->_dir_y==1)
  106.                 this->_dir_y=-1;
  107.             else
  108.                 this->_dir_y=1;
  109.         }
  110.     }
  111.     //kolizja z nabojem
  112.     void gotHit(int x, int y, int size_x, int size_y, int &ptr)
  113.     {
  114.         if(x>=this->_x && x<=this->_x+size_x && y>=this->_y && y<=this->_y+size_y)
  115.         {
  116.             this->isAlive=0;
  117.             ptr+=100;
  118.         }
  119.     }
  120.     void refresh()
  121.     {
  122.         move_tick = false;
  123.         if(ig_time==NULL) move_tick=true;
  124.         else if(*ig_time - last_tick_time > spddelay)
  125.         {
  126.             last_tick_time= *ig_time;
  127.             move_tick= true;
  128.         }
  129.     }
  130.  
  131.     void set_spddelay(int ms)
  132.     {
  133.         spddelay=ms;
  134.     }
  135. };
  136.  
  137. class GameEngine
  138. {
  139. private:
  140.    
  141.     long speed;
  142.     volatile static int GameEngine::msec;
  143.     static bool GameEngine::isPaused;
  144.  
  145. public:
  146.     BITMAP* background;
  147.     BITMAP* bufor;
  148.     int g_time;
  149.  
  150.     void refresh();
  151.  
  152.     static void errMsg(char *err)
  153.     {
  154.         if (screen != NULL)
  155.         set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
  156.  
  157.         allegro_message(err);
  158.     }
  159.  
  160.     class window
  161.     {
  162.     public:
  163.         unsigned int width;
  164.         unsigned int height;
  165.         bool quit;
  166.         bool pause;
  167.         bool menu;
  168.         char* backGround;
  169.  
  170.         window(unsigned int w, unsigned int h, char* bg)
  171.         {
  172.             width=w;
  173.             height=h;
  174.             bool menu=true;
  175.             bool quit=false;
  176.             bool pause=false;
  177.             backGround=bg;
  178.         }
  179.  
  180.     }*mainWindow;
  181.  
  182.     class Time
  183.     {  
  184.         static void timer_handler()
  185.         {
  186.             if(!GameEngine::isPaused)
  187.             ++GameEngine::msec;
  188.         }
  189.         END_OF_FUNCTION(timer_handler)
  190.  
  191.         void init()
  192.         {
  193.             LOCK_VARIABLE(GameEngine::msec);
  194.             LOCK_FUNCTION(Time::timer_handler);
  195.             install_int(Time::timer_handler,1);
  196.             GameEngine::msec=0;
  197.         }
  198.  
  199.         void deinit()
  200.         {
  201.             remove_int(Time::timer_handler);
  202.         }
  203.  
  204.     public:
  205.  
  206.         void pause(){ GameEngine::isPaused=true; }
  207.         void unpause(){ GameEngine::isPaused=false; }
  208.  
  209.         void reset() { msec=0; }
  210.         int ms() { return msec; }
  211.         double sec() { return ( msec/1000.0f ); }
  212.         double min() { return ( msec/60000.0f ); }
  213.  
  214.         friend GameEngine;
  215.  
  216.     }*time;/* time passed since game's started */
  217.  
  218.     class Sound
  219.     {
  220.     private:
  221.         SAMPLE *sample[33];
  222.         int time_last_play[33];
  223.         int slen[33];
  224.  
  225.         void init()
  226.         {
  227.             for(int i=0;i<33;++i)
  228.             {
  229.                 time_last_play[i]=0;
  230.                 sample[i]=NULL;
  231.             }
  232.         }
  233.  
  234.         void deinit()
  235.         {
  236.             for(int i=0;i<33;++i)
  237.                 destroy_sample(sample[i]);
  238.         }
  239.  
  240.     public:
  241.  
  242.         void setVolume(unsigned char vol)
  243.         {
  244.             set_volume(vol,vol);
  245.         }
  246.  
  247.         SAMPLE* load_sound(char *path, int id=32)
  248.         {
  249.             destroy_sample(sample[id]);
  250.             try
  251.             {
  252.                 sample[id]=load_sample(path);
  253.                 if(sample[id]==NULL)
  254.                 {
  255.                     char err[128];
  256.                     sprintf(err,"nie udalo sie zaladowac dzwieku z pliku: %s",path);
  257.                     throw(err);
  258.                 }
  259.             }
  260.             catch(char *str)
  261.             {
  262.                 errMsg(str);
  263.             }
  264.             slen[id]=1000*(double((sample[id]->len * 8) / sample[id]->bits) / double(sample[id]->freq));
  265.             return sample[id];
  266.         }
  267.        
  268.         void play_sound(int id,int block_delay_ms=-1,int vol=255,int freq=1000,int pan=127,int loop=0)
  269.         {
  270.             int stime=0;
  271.             if(block_delay_ms>=0)
  272.                 stime=(slen[id]+block_delay_ms);
  273.             if(GameEngine::msec-time_last_play[id]>=stime)
  274.             {
  275.                 time_last_play[id]=GameEngine::msec;
  276.                 play_sample(sample[id],vol,pan,freq,loop);
  277.             }
  278.         }
  279.         void play_sound(char *path,int block_delay_ms=-1,int vol=255,int freq=1000,int pan=127,int loop=0)
  280.         {
  281.             int stime=0;
  282.             if(block_delay_ms>=0)
  283.             if(GameEngine::msec-time_last_play[32]>=stime)
  284.             {
  285.                 time_last_play[32]=GameEngine::msec;
  286.                 play_sample(load_sound(path),vol,pan,freq,loop);
  287.             }
  288.         }
  289.        
  290.         friend GameEngine;
  291.     }*sound;
  292.  
  293.     class Meteos
  294.     {
  295.     private:
  296.         int count;
  297.         meteoryt *meteo[MAXMETEOS];
  298.         BITMAP *bufor;
  299.         GameEngine *ge;
  300.  
  301.     public:
  302.         Meteos()
  303.         {
  304.             count=0;
  305.             for(int i=0;i<MAXMETEOS;++i)
  306.                 meteo[i]=NULL;
  307.         }
  308.  
  309.         void addMeteo(int x,int y,char *bmp,int *time_var=NULL)
  310.         {
  311.             if(time_var==NULL)
  312.                 meteo[count]=new meteoryt(x,y,bmp,&ge->g_time);
  313.             else
  314.                 meteo[count]=new meteoryt(x,y,bmp,time_var);
  315.            
  316.             masked_blit(meteo[count]->_bmp,screen,0,0,meteo[count]->_x,meteo[count]->_y,meteo[count]->_bmp->w,meteo[count]->_bmp->h);
  317.             blit(meteo[count]->_bmp,bufor,0,0,0,0,meteo[count]->_bmp->w,meteo[count]->_bmp->h);
  318.  
  319.             ++count;
  320.         }
  321.         int getCount()
  322.         {
  323.             return this->count;
  324.         }
  325.         void delMeteo(int id)
  326.         {
  327.             if(count>0)
  328.             {
  329.                 id%=count;
  330.                 delete meteo[id];
  331.                 for(int i=id;i<MAXMETEOS-1;++i)
  332.                 {
  333.                     meteo[i]=meteo[i+1];
  334.                 }
  335.                 meteo[MAXMETEOS-1]=NULL;
  336.                 --count;
  337.             }
  338.         }
  339.  
  340.         ~Meteos()
  341.         {
  342.             for(int i=0;i<count;++i)
  343.                 delete meteo[i];
  344.         }
  345.  
  346.         meteoryt* operator[](int i)
  347.         {
  348.             return meteo[i];
  349.         }
  350.  
  351.         void refreshAll()
  352.         {
  353.             for(int i=0;i<count;++i)
  354.                 meteo[i]->refresh();
  355.         }
  356.         friend GameEngine;
  357.     }meteo;
  358.  
  359.  
  360.     GameEngine(int w, int h, char *bg) : g_time(0)
  361.     {
  362.         allegro_init();
  363.         install_timer();
  364.  
  365.         time= new Time;
  366.         time->init();
  367.  
  368.         sound= new Sound;
  369.         sound->init();
  370.         speed=0;
  371.         install_keyboard();
  372.  
  373.         install_sound(DIGI_AUTODETECT,MIDI_AUTODETECT,"");
  374.         sound->setVolume(255);
  375.  
  376.         set_color_depth(16);
  377.  
  378.         mainWindow = new window(800,600,bg);
  379.         set_gfx_mode(GFX_AUTODETECT_WINDOWED, mainWindow->width, mainWindow->height, 0, 0);
  380.  
  381.         bufor = create_bitmap(800,600);
  382.         meteo.bufor=bufor;
  383.         meteo.ge=this;
  384.  
  385.         try
  386.         {
  387.             background=load_bmp(mainWindow->backGround, default_palette);
  388.             if(background==NULL)
  389.                 throw("nie udalo sie zaladowac tla");
  390.         }
  391.         catch(char *str)
  392.         {
  393.             errMsg(str);
  394.         }
  395.  
  396.     }
  397.  
  398.     ~GameEngine()
  399.     {
  400.         destroy_bitmap(bufor);
  401.  
  402.         destroy_bitmap(background);
  403.        
  404.         sound->deinit();
  405.         time->deinit();
  406.  
  407.         delete mainWindow;
  408.         delete time;
  409.  
  410.         allegro_exit();
  411.     }
  412.  
  413.     void decSpeed(){--speed;}
  414.     void incSpeed(){++speed;}
  415.     int getSpeed(){return speed;}
  416. };
  417. volatile int GameEngine::msec=0;
  418. bool GameEngine::isPaused = false;
  419.  
  420. class ship : public GameObject
  421. {
  422. public:
  423.     bool _ammo;
  424.     bool _underAttack;
  425.     ship(int x, int y, char* img)
  426.     {
  427.         _x=x;
  428.         _y=y;
  429.         _image=img;
  430.         _underAttack=0;
  431.         dmg=0;
  432.         _ammo=0;
  433.         _dir_x=0;
  434.         _dir_y=0;
  435.     }
  436.     ~ship()
  437.     {}
  438.     void refresh() // musi byc bo bys mial abstracta skoro gameobject to ma jako abstract ()=0 ;P
  439.     {}
  440. };
  441. class bullet
  442. {
  443. public:
  444.     int _x;
  445.     int _y;
  446.     char* _img;
  447.  
  448.     bullet(char* img)
  449.     {
  450.         _x=0;
  451.         _y=0;
  452.         _img=img;
  453.     }
  454.     ~bullet(){}
  455.  
  456.     void move(int x, int y)
  457.     {
  458.         this->_x=x+32;
  459.         this->_y=y;
  460.     }
  461.  
  462. } bullet("images/ship/fire.bmp");
  463. void GameEngine::refresh()
  464. {
  465.     g_time= time->ms();
  466.     meteo.refreshAll();
  467. }
  468.  
  469.  
  470. int main()
  471. {
  472.     GameEngine *ge= new GameEngine(800,600,"images/menu2.bmp");
  473.    
  474.     //glowne okno
  475.  
  476.     /* ladowanie dzwiekow */
  477.     ge->sound->load_sound("sounds/ale_urwal.wav",0);
  478.     ge->sound->load_sound("sounds/ale_to_bylo_dobre.wav",1);
  479.  
  480.     /* menu */
  481.     int klawisz=0;
  482.     BITMAP* play=load_bmp("images/menu/1.bmp", default_palette);
  483.     BITMAP* play2=load_bmp("images/menu/1b.bmp", default_palette);
  484.  
  485.     BITMAP* options=load_bmp("images/menu/2.bmp", default_palette);
  486.     BITMAP* options2=load_bmp("images/menu/2b.bmp", default_palette);
  487.  
  488.     BITMAP* load_game=load_bmp("images/menu/3.bmp", default_palette);
  489.     BITMAP* load_game2=load_bmp("images/menu/3b.bmp", default_palette);
  490.  
  491.     BITMAP* save_game=load_bmp("images/menu/4.bmp", default_palette);
  492.     BITMAP* save_game2=load_bmp("images/menu/4b.bmp", default_palette);
  493.  
  494.     BITMAP* read=load_bmp("images/menu/5.bmp", default_palette);
  495.     BITMAP* read2=load_bmp("images/menu/5b.bmp", default_palette);
  496.  
  497.     BITMAP* quit=load_bmp("images/menu/6.bmp", default_palette);
  498.     BITMAP* quit2=load_bmp("images/menu/6b.bmp", default_palette);
  499.     clear_to_color(screen, makecol(17,16,16));
  500.     //kursor
  501.     install_mouse();
  502.     enable_hardware_cursor();
  503.     select_mouse_cursor(MOUSE_CURSOR_ALLEGRO);
  504.  
  505.     show_mouse(screen);
  506.     while(ge->mainWindow->menu)
  507.     {
  508.         if(klawisz<2 && key[KEY_UP])
  509.         {
  510.             ++klawisz;
  511.         }
  512.         if(klawisz>0 && key[KEY_DOWN])
  513.         {
  514.             --klawisz;
  515.         }
  516.         if(mouse_y>84 && mouse_y<129)
  517.         {
  518.             if(mouse_b==1)
  519.             {
  520.                 ge->mainWindow->menu=0;
  521.                 ge->mainWindow->quit=0;
  522.                 break;
  523.             }
  524.             blit(play,screen,0,0,250,84,play->w,play->h);
  525.         }
  526.         else
  527.             blit(play2,screen,0,0,250,84,play2->w,play2->h);
  528.  
  529.         if(mouse_y>145 && mouse_y<190)
  530.             blit(options,screen,0,0,250,145,options->w,options->h);
  531.         else
  532.             blit(options2,screen,0,0,250,145,options2->w,options2->h);
  533.  
  534.         if(mouse_y>206 && mouse_y<251)
  535.             blit(load_game,screen,0,0,250,206,load_game->w,load_game->h);
  536.         else
  537.             blit(load_game2,screen,0,0,250,206,load_game2->w,load_game2->h);
  538.  
  539.         if(mouse_y>267 && mouse_y<312)
  540.             blit(save_game,screen,0,0,250,267,save_game->w,save_game->h);
  541.         else
  542.             blit(save_game2,screen,0,0,250,267,save_game2->w,save_game2->h);
  543.  
  544.         if(mouse_y>328 && mouse_y<373)
  545.             blit(read,screen,0,0,250,328,read->w,read->h);
  546.         else
  547.             blit(read2,screen,0,0,250,328,read2->w,read2->h);
  548.         //wyjscie z gry
  549.         if(mouse_y>389 && mouse_y<441)
  550.         {
  551.             blit(quit,screen,0,0,250,389,quit->w,quit->h);
  552.             if(mouse_b==1)
  553.             {
  554.                 ge->mainWindow->menu=0;
  555.                 ge->mainWindow->quit=1;
  556.             }
  557.         }
  558.         else
  559.             blit(quit2,screen,0,0,250,389,quit2->w,quit2->h);
  560.  
  561.         if(key[KEY_ESC]) break;
  562.     }
  563.     show_mouse(NULL);
  564.     /* koniec menu */
  565.     if(!ge->mainWindow->menu)
  566.     {
  567.         //czas
  568.         //float const &time = ge->time->sec(); <- bez sensu nie bedzie zwracac wartosci ;p
  569.         ge->mainWindow->backGround="images/background.bmp";
  570.         ge->background=load_bmp(ge->mainWindow->backGround, default_palette);
  571.         masked_blit(ge->background,screen,0,0,0,0,ge->background->w,ge->background->h);
  572.         //statek
  573.         ship SpaceShip(320,220,"images/ship.bmp");
  574.         BITMAP* ship=load_bmp(SpaceShip._image,default_palette);
  575.         masked_blit(ship,screen,0,0,SpaceShip._x,SpaceShip._y,ship->w,ship->h);
  576.         //ogien
  577.         BITMAP* fire=load_bmp("images/ship/0.bmp",default_palette);
  578.         //crash
  579.         BITMAP* crash=load_bmp("images/ship/crash.bmp",default_palette);
  580.  
  581.         //bufor
  582.         blit(ge->background,ge->bufor,0,0,0,0,ge->background->w,ge->background->h);
  583.         blit(ship,ge->bufor,0,0,0,0,ship->w,ship->h);
  584.         ge->meteo.addMeteo(100,140,"images/meteo.bmp"); //meteo[0]
  585.         ge->meteo.addMeteo(50,240,"images/meteo.bmp"); //meteo[1]
  586.         ge->meteo.addMeteo(150,440,"images/meteo.bmp"); //meteo[2]
  587.         ge->meteo.addMeteo(250,340,"images/meteo.bmp"); //meteo[3]
  588.         ge->meteo.addMeteo(400,400,"images/meteo.bmp"); //meteo[4]
  589.         //predkosci meteo
  590.         ge->meteo[0]->set_spddelay(5);
  591.  
  592.  
  593.         bool move_tick=false;
  594.         int spddelay = 5; // 5ms tick
  595.  
  596.         int gtime,prevgtime;
  597.         gtime=prevgtime=ge->time->ms();
  598.  
  599.         float time_a=ge->time->sec();
  600.         while(!ge->mainWindow->quit)
  601.         {
  602.             if(key[KEY_TAB])
  603.             {
  604.                 if(ge->mainWindow->pause==0)
  605.                     ge->mainWindow->pause=1;
  606.                 else
  607.                     ge->mainWindow->pause=0;
  608.             }
  609.             if(ge->mainWindow->pause==1)
  610.             {
  611.                 readkey();
  612.                 ge->mainWindow->pause=0;
  613.             }
  614.             //koniec gry
  615.             if(!ge->meteo[0]->isAlive && !ge->meteo[1]->isAlive && !ge->meteo[2]->isAlive && !ge->meteo[3]->isAlive && !ge->meteo[4]->isAlive)
  616.             {
  617.                 readkey();
  618.             }
  619.             ge->refresh(); //odswieza timery, pozycje
  620.  
  621.             move_tick = false;
  622.             if(ge->g_time-prevgtime> spddelay)
  623.             {
  624.                 prevgtime= ge->g_time;
  625.                 move_tick= true;
  626.             }
  627.  
  628.             if(key[KEY_RIGHT] || SpaceShip._dir_x==1)
  629.             {
  630.                 if(move_tick) ++SpaceShip._x;
  631.                 SpaceShip._dir_x=1;
  632.             }
  633.             if(key[KEY_LEFT] || SpaceShip._dir_x==-1)
  634.             {
  635.                 if(move_tick) --SpaceShip._x;
  636.                 SpaceShip._dir_x=-1;
  637.             }
  638.             if(key[KEY_DOWN] || SpaceShip._dir_y==-1)
  639.             {
  640.                 if(move_tick) ++SpaceShip._y;
  641.                 if(key[KEY_DOWN] && SpaceShip._dir_y==-1)
  642.                 {
  643.                     SpaceShip._dir_y=-1;
  644.                     SpaceShip._dir_x=0;
  645.                 }
  646.                 else
  647.                     SpaceShip._dir_y=-1;
  648.             }
  649.             if(key[KEY_UP] || SpaceShip._dir_y==1)
  650.             {
  651.                 if(move_tick) --SpaceShip._y;
  652.                 if(key[KEY_UP] && SpaceShip._dir_y==1)
  653.                 {
  654.                     SpaceShip._dir_y=1;
  655.                     SpaceShip._dir_x=0;
  656.                 }
  657.                 else
  658.                     SpaceShip._dir_y=1;
  659.             }
  660.             //ograniczenia ekranu
  661.             if(SpaceShip._y>600) SpaceShip._y=-120;
  662.             if(SpaceShip._y<-120) SpaceShip._y=580;
  663.             if(SpaceShip._x>800) SpaceShip._x=-100;
  664.             if(SpaceShip._x<-100) SpaceShip._x=800;
  665.  
  666.  
  667.             if(!ge->mainWindow->menu)
  668.             {
  669.                 ge->meteo[0]->move();
  670.                 ge->meteo[1]->move();
  671.                 ge->meteo[2]->move();
  672.                 ge->meteo[3]->move();
  673.                 ge->meteo[4]->move();
  674.             }
  675.  
  676.             blit(ge->background, ge->bufor,0,0,0,0,ge->background->w,ge->background->h);
  677.  
  678.             if(ge->meteo[0]->isAlive==1)
  679.             {
  680.                 masked_blit(ge->meteo[0]->_bmp,ge->bufor,0,0,ge->meteo[0]->_x,ge->meteo[0]->_y,ge->meteo[0]->_bmp->w,ge->meteo[0]->_bmp->h);
  681.             }
  682.             if(ge->meteo[1]->isAlive==1)
  683.             {
  684.                 masked_blit(ge->meteo[1]->_bmp,ge->bufor,0,0,ge->meteo[1]->_x,ge->meteo[1]->_y,ge->meteo[1]->_bmp->w,ge->meteo[1]->_bmp->h);
  685.             }
  686.             if(ge->meteo[2]->isAlive==1)
  687.             {
  688.                 masked_blit(ge->meteo[2]->_bmp,ge->bufor,0,0,ge->meteo[2]->_x,ge->meteo[2]->_y,ge->meteo[2]->_bmp->w,ge->meteo[2]->_bmp->h);
  689.             }
  690.             if(ge->meteo[3]->isAlive==1)
  691.             {
  692.                 masked_blit(ge->meteo[3]->_bmp,ge->bufor,0,0,ge->meteo[3]->_x,ge->meteo[3]->_y,ge->meteo[3]->_bmp->w,ge->meteo[3]->_bmp->h);
  693.             }
  694.             if(ge->meteo[4]->isAlive==1)
  695.             {
  696.                 masked_blit(ge->meteo[4]->_bmp,ge->bufor,0,0,ge->meteo[4]->_x,ge->meteo[4]->_y,ge->meteo[4]->_bmp->w,ge->meteo[4]->_bmp->h);
  697.             }
  698.  
  699.             if(key[KEY_UP])
  700.                 masked_blit(fire, ge->bufor,0,0,SpaceShip._x,SpaceShip._y,ship->w,ship->h);
  701.             else
  702.                 masked_blit(ship, ge->bufor,0,0,SpaceShip._x,SpaceShip._y,ship->w,ship->h);
  703.            
  704.             BITMAP* b=load_bmp(bullet._img,default_palette);
  705.            
  706.             //strzal
  707.             if(SpaceShip._ammo==1)
  708.             {
  709.                 masked_blit(b, ge->bufor,0,0,bullet._x,bullet._y,b->w,b->h);
  710.                 --bullet._y;
  711.             }
  712.             if(bullet._y<0)
  713.             {
  714.                 SpaceShip._ammo=0;
  715.                 bullet._x=0;
  716.                 bullet._y=0;
  717.             }
  718.             //detekcja kolizji z nabojem
  719.             if(SpaceShip._ammo==1)
  720.             {
  721.                 ge->meteo[0]->gotHit(bullet._x,bullet._y,77,72,SpaceShip.dmg);
  722.                 ge->meteo[1]->gotHit(bullet._x,bullet._y,77,72,SpaceShip.dmg);
  723.                 ge->meteo[2]->gotHit(bullet._x,bullet._y,77,72,SpaceShip.dmg);
  724.                 ge->meteo[3]->gotHit(bullet._x,bullet._y,77,72,SpaceShip.dmg);
  725.                 ge->meteo[4]->gotHit(bullet._x,bullet._y,77,72,SpaceShip.dmg);
  726.             }
  727.  
  728.             if(key[KEY_SPACE] && SpaceShip._ammo==0)
  729.             {
  730.                 SpaceShip._ammo=1;
  731.                 bullet.move(SpaceShip._x+32,SpaceShip._y);
  732.             }
  733.  
  734.             //zderzenie
  735.             for(int i=0; i<ge->meteo.getCount(); ++i)
  736.             {
  737.                 if(ge->time->sec()-time_a>2.0)
  738.                     SpaceShip._underAttack=0;
  739.  
  740.                 if(ge->meteo[i]->isAlive==1 && ge->meteo[i]->_y>=SpaceShip._y && ge->meteo[i]->_y<=SpaceShip._y+80 && ge->meteo[i]->_x>=SpaceShip._x && ge->meteo[i]->_x<=SpaceShip._x+76
  741.                 || ge->meteo[i]->isAlive==1 && SpaceShip._y>=ge->meteo[i]->_y && SpaceShip._y<=ge->meteo[i]->_y+72 && SpaceShip._x>=ge->meteo[i]->_x && SpaceShip._x<=ge->meteo[i]->_x+77)
  742.                 {
  743.                     ge->sound->play_sound(0,500);
  744.                
  745.                     if(SpaceShip._underAttack==0)
  746.                     {
  747.                         SpaceShip.dmg-=100;
  748.                         SpaceShip._underAttack=1;
  749.                         time_a=ge->time->sec();
  750.                     }
  751.  
  752.                     masked_blit(crash, ge->bufor,0,0,SpaceShip._x,SpaceShip._y,ship->w,ship->h);
  753.                     SpaceShip._dir_x=ge->meteo[i]->_dir_x;
  754.                     SpaceShip._dir_y=ge->meteo[i]->_dir_y;
  755.                 }
  756.                 else
  757.                 {
  758.                     masked_blit(ship, ge->bufor,0,0,SpaceShip._x,SpaceShip._y,ship->w,ship->h);
  759.                 }
  760.             }
  761.             textprintf(ge->bufor,font,20,20,makecol(255,255,128),"Punkty zycia : %d",SpaceShip.dmg);
  762.             blit(ge->bufor, screen, 0,0,0,0, 800,600);  
  763.             //wyjscie z gry
  764.             if(key[KEY_ESC])
  765.             {
  766.                 ge->mainWindow->quit=true;
  767.                 break;
  768.             }
  769.         }
  770.  
  771.         destroy_bitmap(ship);
  772.     }
  773.    
  774.     return 0;
  775. }
  776. END_OF_MAIN();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement