Pokitto Community Team / Pokitto_Game_Lost

Dependencies:   PokittoLib

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers playgame.h Source File

playgame.h

00001 /**************************************************************************/
00002 /*!
00003     @file     Playgame.h
00004     @author   WTW
00005 
00006     @section v0.4
00007     adding AreIntersecting function using collision detection
00008 
00009 */
00010 /**************************************************************************/
00011 #ifndef PLAYGAME_H
00012 #define PLAYGAME_H
00013 #include "Pokitto.h"
00014 #include <vector>
00015 #include "bullet.h"
00016 #include "aircraft.h "
00017 #include "palette.h "
00018 #define BULLET_AMOUNT_MAX_EASY 20
00019 #define BULLET_TIME_SPACE_EASY 100
00020 #define BULLET_AMOUNT_MAX_NORMAL 50
00021 #define BULLET_TIME_SPACE_NORMAL 50
00022 #define BULLET_AMOUNT_MAX_HARD 100
00023 #define BULLET_TIME_SPACE_HARD 20
00024 #define BULLET_AMOUNT_MAX_VHARD 200
00025 #define BULLET_TIME_SPACE_VHARD 10
00026 #define BULLET_AMOUNT_MAX_DEAD 300
00027 #define BULLET_TIME_SPACE_DEAD 5
00028 
00029 #define AIRCRAFT_X_OFFSET 7
00030 #define AIRCRAFT_Y_OFFSET 7
00031 #define BULLET_X_OFFSET 1
00032 #define BULLET_Y_OFFSET 1
00033 
00034 std::vector<bullet> vbullet;
00035 aircraft air1;
00036 int bullettimespace = 0;
00037 int bullet_amount_max = BULLET_AMOUNT_MAX_NORMAL;
00038 int bullet_time_space = BULLET_TIME_SPACE_NORMAL;
00039 uint32_t oldTime,finalTime;
00040 bool AreIntersecting(const aircraft & air, const bullet & bul);
00041 void playgame();
00042 
00043 bool AreIntersecting(const aircraft & air, const bullet & bul){ //using collision detection
00044     return
00045     !(
00046         (air.getTop() > bul.getBottom()) || (air.getLeft() > bul.getRight()) ||
00047         (air.getRight() < bul.getLeft()) || (air.getBottom() < bul.getTop())
00048     );
00049 }
00050 
00051 void playgame(){
00052 
00053     Pokitto::Display::load565Palette(playgame_pal);
00054     Pokitto::Display::invisiblecolor = PLAYGAME_INVISIBLE_COLOR;
00055 
00056     if (Pokitto::Core::update()) {
00057         //Pokitto::Display::print(0,0,"live");
00058         finalTime = Pokitto::Core::getTime()/1000 - oldTime/1000;
00059         //Pokitto::Display::print(25,0,finalTime);//show living time
00060         air1.move();
00061         air1.display();
00062         ++bullettimespace;
00063 
00064         if(bullettimespace == bullet_time_space){ //control bulltet object max amount
00065             if(vbullet.size() <= bullet_amount_max){
00066                 bullet *bl = new bullet(air1.getx()+AIRCRAFT_X_OFFSET, air1.gety()+AIRCRAFT_Y_OFFSET);
00067                 vbullet.push_back(*bl);
00068                 }
00069                 bullettimespace = 0;
00070         }
00071 
00072         for(std::vector<bullet>::iterator bull = vbullet.begin();  bull != vbullet.end(); ++bull){
00073             bull->move();
00074             bull->renew(air1.getx()+AIRCRAFT_X_OFFSET, air1.gety()+AIRCRAFT_Y_OFFSET);
00075             bull->display();
00076             if( AreIntersecting(air1, *bull)
00077                ){
00078                     gameConditon = 2;
00079                     bullettimespace = 0;
00080                     air1.clear();
00081                     vbullet.clear();
00082                     break;
00083             }
00084 
00085         }
00086     }
00087 }
00088 #endif