Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Object IDs
- enum IDS{PLAYER, FOOD, ENEMY, ENEMY2, ENEMY3, ENEMY4, ENEMY5, ENEMY6, ENEMY7, ENEMY8};
- const int WIDTH = 800;
- const int HEIGHT = 455;
- const int NUM_CARS = 18;
- const int NUM_CARS2 = 13;
- const int NUM_CARS3 = 18;
- const int NUM_CARS4 = 13;
- const int NUM_CARS5 = 18;
- const int NUM_CARS6 = 13;
- const int NUM_CARS7 = 18;
- const int NUM_CARS8 = 13;
- const int NUM_FOOD = 8;
- //Our Player
- class RoadBear
- {
- public:
- int ID;
- int x;
- int y;
- int lives;
- int speed;
- int boundx;
- int boundy;
- int score;
- RoadBear();
- void dibujar_oso(ALLEGRO_BITMAP *image);
- void mover_derecha();
- void mover_izquierda();
- void mover_arriba();
- void mover_abajo();
- };
- RoadBear::RoadBear(){
- x = 400;
- y = 455;
- ID = PLAYER;
- lives = 3;
- speed = 3;
- boundx = 0;
- boundy = 0;
- score = 0;
- }
- void RoadBear::dibujar_oso(ALLEGRO_BITMAP *image){
- al_draw_bitmap(image, x-23, y-30, 0);
- }
- void RoadBear::mover_derecha(){
- x += speed;
- if(x > 800)
- x = 800;
- }
- void RoadBear::mover_izquierda(){
- x -= speed;
- if(x < 0)
- x = 0;
- }
- void RoadBear::mover_arriba()
- {
- y -= speed;
- if(y < 0)
- y = 0;
- }
- void RoadBear::mover_abajo(){
- y += speed;
- if(y > HEIGHT)
- y = HEIGHT;
- }
- class Premio
- {
- public:
- int ID;
- int x;
- int y;
- int speed;
- bool live;
- int boundx;
- int boundy;
- Premio();
- void dibujar_premio(ALLEGRO_BITMAP *image11);
- void iniciar_premio();
- void actualizar_premio();
- void colision_premio(RoadBear &oso);
- };
- Premio::Premio(){
- ID = FOOD;
- live = false;
- speed = 2;
- boundx = 25;
- boundy = 25;
- }
- void Premio::dibujar_premio(ALLEGRO_BITMAP *image11){
- if(live)
- {
- al_draw_bitmap(image11, x-23, y-30, 0);
- }
- }
- void Premio::iniciar_premio(){
- live = true;
- x = WIDTH;
- y = 30 + rand()% (HEIGHT - 60);
- }
- void Premio::actualizar_premio(){
- if(live)
- {
- x -= speed;
- }
- }
- void Premio::colision_premio(RoadBear &oso){
- if(live)
- {
- if(x - boundx < oso.x + oso.boundx &&
- x + boundx > oso.x - oso.boundx &&
- y - boundy < oso.y + oso.boundy &&
- y + boundy > oso.y - oso.boundy)
- {
- oso.score++;
- live = false;
- }
- }
- }
- //Our Enemies
- class Coche{
- public:
- int ID;
- int x;
- int y;
- bool live;
- int speed;
- int boundx;
- int boundy;
- Coche();
- void dibujar_coche(ALLEGRO_BITMAP *image3);
- void iniciar_coche();
- void actualizar_coche();
- void colision_coche(RoadBear &oso);
- };
- Coche::Coche(){
- ID = ENEMY;
- live = false;
- speed = 10;
- boundx = 25;
- boundy = 25;
- }
- void Coche::dibujar_coche(ALLEGRO_BITMAP *image3){
- if(live)
- {
- al_draw_bitmap(image3, x-23, y-30, 0);
- }
- }
- void Coche::iniciar_coche(){
- live = true;
- x = WIDTH;
- y = 75 % (HEIGHT - 60);
- }
- void Coche::actualizar_coche(){
- if(live)
- {
- x -= speed;
- }
- }
- void Coche::colision_coche(RoadBear &oso){
- if(live)
- {
- if(x - boundx < oso.x + oso.boundx &&
- x + boundx > oso.x - oso.boundx &&
- y - boundy < oso.y + oso.boundy &&
- y + boundy > oso.y - oso.boundy)
- {
- oso.lives--;
- live = false;
- }
- }
- }
- class Coche2{
- public:
- int ID;
- int x;
- int y;
- bool live;
- int speed;
- int boundx;
- int boundy;
- Coche2();
- void dibujar_coche2(ALLEGRO_BITMAP *image4);
- void iniciar_coche2();
- void actualizar_coche2();
- void colision_coche2(RoadBear &oso);
- };
- Coche2::Coche2(){
- ID = ENEMY2;
- live = false;
- speed = 7;
- boundx = 25;
- boundy = 25;
- }
- void Coche2::dibujar_coche2(ALLEGRO_BITMAP *image4){
- if(live)
- {
- al_draw_bitmap(image4, x-23, y-30, 0);
- }
- }
- void Coche2::iniciar_coche2(){
- live = true;
- x = WIDTH;
- y = 115 % (HEIGHT - 60);
- }
- void Coche2::actualizar_coche2(){
- if(live)
- {
- x -= speed;
- }
- }
- void Coche2::colision_coche2(RoadBear &oso){
- if(live)
- {
- if(x - boundx < oso.x + oso.boundx &&
- x + boundx > oso.x - oso.boundx &&
- y - boundy < oso.y + oso.boundy &&
- y + boundy > oso.y - oso.boundy)
- {
- oso.lives--;
- live = false;
- }
- }
- }
- class Coche3{
- public:
- int ID;
- int x;
- int y;
- bool live;
- int speed;
- int boundx;
- int boundy;
- Coche3();
- void dibujar_coche3(ALLEGRO_BITMAP *image5);
- void iniciar_coche3();
- void actualizar_coche3();
- void colision_coche3(RoadBear &oso);
- };
- Coche3::Coche3(){
- ID = ENEMY3;
- live = false;
- speed = 10;
- boundx = 25;
- boundy = 25;
- }
- void Coche3::dibujar_coche3(ALLEGRO_BITMAP *image5){
- if(live)
- {
- al_draw_bitmap(image5, x-23, y-30, 0);
- }
- }
- void Coche3::iniciar_coche3(){
- live = true;
- x = WIDTH;
- y = 160 % (HEIGHT - 60);
- }
- void Coche3::actualizar_coche3(){
- if(live)
- {
- x -= speed;
- }
- }
- void Coche3::colision_coche3(RoadBear &oso){
- if(live)
- {
- if(x - boundx < oso.x + oso.boundx &&
- x + boundx > oso.x - oso.boundx &&
- y - boundy < oso.y + oso.boundy &&
- y + boundy > oso.y - oso.boundy)
- {
- oso.lives--;
- live = false;
- }
- }
- }
- class Coche4{
- public:
- int ID;
- int x;
- int y;
- bool live;
- int speed;
- int boundx;
- int boundy;
- Coche4();
- void dibujar_coche4(ALLEGRO_BITMAP *image6);
- void iniciar_coche4();
- void actualizar_coche4();
- void colision_coche4(RoadBear &oso);
- };
- Coche4::Coche4(){
- ID = ENEMY4;
- live = false;
- speed = 7;
- boundx = 25;
- boundy = 25;
- }
- void Coche4::dibujar_coche4(ALLEGRO_BITMAP *image6){
- if(live)
- {
- al_draw_bitmap(image6, x-23, y-30, 0);
- }
- }
- void Coche4::iniciar_coche4(){
- live = true;
- x = WIDTH;
- y = 195 % (HEIGHT - 60);
- }
- void Coche4::actualizar_coche4(){
- if(live)
- {
- x -= speed;
- }
- }
- void Coche4::colision_coche4(RoadBear &oso){
- if(live)
- {
- if(x - boundx < oso.x + oso.boundx &&
- x + boundx > oso.x - oso.boundx &&
- y - boundy < oso.y + oso.boundy &&
- y + boundy > oso.y - oso.boundy)
- {
- oso.lives--;
- live = false;
- }
- }
- }
- class Coche5{
- public:
- int ID;
- int x;
- int y;
- bool live;
- int speed;
- int boundx;
- int boundy;
- Coche5();
- void dibujar_coche5(ALLEGRO_BITMAP *image7);
- void iniciar_coche5();
- void actualizar_coche5();
- void colision_coche5(RoadBear &oso);
- };
- Coche5::Coche5(){
- ID = ENEMY5;
- live = false;
- speed = 10;
- boundx = 25;
- boundy = 25;
- }
- void Coche5::dibujar_coche5(ALLEGRO_BITMAP *image7){
- if(live)
- {
- al_draw_bitmap(image7, x-23, y-30, 0);
- }
- }
- void Coche5::iniciar_coche5(){
- live = true;
- x = WIDTH;
- y = 303 % (HEIGHT - 60);
- }
- void Coche5::actualizar_coche5(){
- if(live)
- {
- x -= speed;
- }
- }
- void Coche5::colision_coche5(RoadBear &oso){
- if(live)
- {
- if(x - boundx < oso.x + oso.boundx &&
- x + boundx > oso.x - oso.boundx &&
- y - boundy < oso.y + oso.boundy &&
- y + boundy > oso.y - oso.boundy)
- {
- oso.lives--;
- live = false;
- }
- }
- }
- class Coche6{
- public:
- int ID;
- int x;
- int y;
- bool live;
- int speed;
- int boundx;
- int boundy;
- Coche6();
- void dibujar_coche6(ALLEGRO_BITMAP *image8);
- void iniciar_coche6();
- void actualizar_coche6();
- void colision_coche6(RoadBear &oso);
- };
- Coche6::Coche6(){
- ID = ENEMY6;
- live = false;
- speed = 7;
- boundx = 25;
- boundy = 25;
- }
- void Coche6::dibujar_coche6(ALLEGRO_BITMAP *image8){
- if(live)
- {
- al_draw_bitmap(image8, x-23, y-30, 0);
- }
- }
- void Coche6::iniciar_coche6(){
- live = true;
- x = WIDTH;
- y = 339 % (HEIGHT - 60);
- }
- void Coche6::actualizar_coche6(){
- if(live)
- {
- x -= speed;
- }
- }
- void Coche6::colision_coche6(RoadBear &oso){
- if(live)
- {
- if(x - boundx < oso.x + oso.boundx &&
- x + boundx > oso.x - oso.boundx &&
- y - boundy < oso.y + oso.boundy &&
- y + boundy > oso.y - oso.boundy)
- {
- oso.lives--;
- live = false;
- }
- }
- }
- class Coche7{
- public:
- int ID;
- int x;
- int y;
- bool live;
- int speed;
- int boundx;
- int boundy;
- Coche7();
- void dibujar_coche7(ALLEGRO_BITMAP *image9);
- void iniciar_coche7();
- void actualizar_coche7();
- void colision_coche7(RoadBear &oso);
- };
- Coche7::Coche7(){
- ID = ENEMY7;
- live = false;
- speed = 10;
- boundx = 25;
- boundy = 25;
- }
- void Coche7::dibujar_coche7(ALLEGRO_BITMAP *image9){
- if(live)
- {
- al_draw_bitmap(image9, x-23, y-30, 0);
- }
- }
- void Coche7::iniciar_coche7(){
- live = true;
- x = WIDTH;
- y = 382 % (HEIGHT - 60);
- }
- void Coche7::actualizar_coche7(){
- if(live)
- {
- x -= speed;
- }
- }
- void Coche7::colision_coche7(RoadBear &oso){
- if(live)
- {
- if(x - boundx < oso.x + oso.boundx &&
- x + boundx > oso.x - oso.boundx &&
- y - boundy < oso.y + oso.boundy &&
- y + boundy > oso.y - oso.boundy)
- {
- oso.lives--;
- live = false;
- }
- }
- }
- class Coche8{
- public:
- int ID;
- int x;
- int y;
- bool live;
- int speed;
- int boundx;
- int boundy;
- Coche8();
- void dibujar_coche8(ALLEGRO_BITMAP *image10);
- void iniciar_coche8();
- void actualizar_coche8();
- void colision_coche8(RoadBear &oso);
- };
- Coche8::Coche8(){
- ID = ENEMY8;
- live = false;
- speed = 7;
- boundx = 25;
- boundy = 25;
- }
- void Coche8::dibujar_coche8(ALLEGRO_BITMAP *image10){
- if(live)
- {
- al_draw_bitmap(image10, x-23, y-30, 0);
- }
- }
- void Coche8::iniciar_coche8(){
- live = true;
- x = WIDTH;
- y = 390+25 % (HEIGHT - 60);
- }
- void Coche8::actualizar_coche8(){
- if(live)
- {
- x -= speed;
- }
- }
- void Coche8::colision_coche8(RoadBear &oso){
- if(live)
- {
- if(x - boundx < oso.x + oso.boundx &&
- x + boundx > oso.x - oso.boundx &&
- y - boundy < oso.y + oso.boundy &&
- y + boundy > oso.y - oso.boundy)
- {
- oso.lives--;
- live = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment