xemerau

Untitled

Sep 14th, 2011
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.57 KB | None | 0 0
  1. //Includes----------------------------------------------
  2. #include <allegro.h>
  3. #include "Sys.h"
  4. #include "Player.h"
  5. #include "Stick.h"
  6. //Includes----------------------------------------------
  7.  
  8. //Creating Class Objects--------------------------------
  9. Sys System;
  10. Player Player;
  11. Stick Stick;
  12. //Creating Class Objects--------------------------------
  13.  
  14. //Misc Functions----------------------------------------
  15. bool CheckCollision (int b1_x, int b1_y, int b1_w, int b1_h, int b2_x, int b2_y, int b2_w, int b2_h) {
  16.  
  17.     if (    ( b1_x > b2_x + b2_w - 1 ) ||
  18.             ( b1_y > b2_y + b2_h - 1 ) ||
  19.             ( b2_x > b1_x + b1_w - 1 ) ||
  20.             ( b2_y > b1_y + b1_h - 1 )  )
  21.             {return false;}
  22.  
  23.    else {return true;}
  24. }
  25. //Misc Functions----------------------------------------
  26.  
  27.  
  28. int main()
  29. {
  30.     System.Initilize(); //Initilizes Allegro.
  31.  
  32.     //Creating & loading bitmaps & samples here, as they are a pain to pass from other functions.
  33.     BITMAP *buffer = create_bitmap(640, 480);
  34.     BITMAP *bmpTitleScreen = load_bitmap("resources/TitleScreen.bmp", NULL);
  35.     BITMAP *bmpPlayer = load_bitmap("resources/PlayerSprite.bmp", NULL);
  36.     BITMAP *bmpGameBG = load_bitmap("resources/GameBG.bmp", NULL);
  37.     BITMAP *bmpStick = load_bitmap("resources/Stick.bmp", NULL);
  38.     SAMPLE *wavBackingMusic = load_sample("resources/AfterTheRain_Moosader.wav");
  39.  
  40.  
  41.     //Game Loop-----------------------------------------
  42.     while (!key[KEY_ESC]) {
  43.          while (System.getTitleScreen() == true) {
  44.              System.Draw(buffer, bmpTitleScreen);
  45.  
  46.              if (key[KEY_ENTER]) {
  47.                  System.toggleTitleScreen();
  48.              }
  49.          }
  50.  
  51.         play_sample(wavBackingMusic, 255, 128, 1000, true);
  52.         Player.CheckMovement();
  53.         if (CheckCollision(Player.ReturnX(), Player.ReturnY(), Player.ReturnBBw(), Player.ReturnBBh(), Stick.ReturnX(), Stick.ReturnY(), Stick.ReturnBBw(), Stick.ReturnBBh()) == true) {Stick.GenerateNewCoords();}
  54.         System.Draw(buffer, bmpGameBG);
  55.         Stick.Draw(buffer, bmpStick);
  56.         Player.Draw(buffer, bmpPlayer);
  57.         blit(buffer, screen, 0, 0, 0, 0, 640, 480);
  58.         clear_bitmap(buffer);
  59.     }
  60.     //Game Loop-----------------------------------------
  61.  
  62.     //Destroying Bitmaps & Samples--------------------------------
  63.     destroy_bitmap(buffer);
  64.     destroy_bitmap(bmpPlayer);
  65.     destroy_bitmap(bmpTitleScreen);
  66.     destroy_bitmap(bmpGameBG);
  67.     destroy_bitmap(bmpStick);
  68.     destroy_sample(wavBackingMusic);
  69.     //Destroying Bitmaps & Samples--------------------------------
  70. }
  71. END_OF_MAIN()
Advertisement
Add Comment
Please, Sign In to add comment