xemerau

main.cpp (Pickn' Sticks)

Sep 14th, 2011
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.18 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. int main()
  15. {
  16.     System.Initilize(); //Initilizes Allegro.
  17.  
  18.     //Creating & loading bitmaps here, as they are a pain to pass from other functions.
  19.     BITMAP *buffer = create_bitmap(640, 480);
  20.     BITMAP *bmpTitleScreen = load_bitmap("resources/TitleScreen.bmp", NULL);
  21.     BITMAP *bmpPlayer = load_bitmap("resources/PlayerSpriteHitbox.bmp", NULL);
  22.     BITMAP *bmpGameBG = load_bitmap("resources/GameBG.bmp", NULL);
  23.     BITMAP *bmpStick = load_bitmap("resources/StickHitbox.bmp", NULL);
  24.  
  25.  
  26.     //Game Loop-----------------------------------------
  27.     while (!key[KEY_ESC]) {
  28.          while (System.getTitleScreen() == true) {
  29.              System.Draw(buffer, bmpTitleScreen);
  30.  
  31.              if (key[KEY_ENTER]) {
  32.                  System.toggleTitleScreen();
  33.              }}
  34.  
  35.         Player.CheckMovement();
  36.         if (CheckCollision() == true) {Stick.GenerateNewCoords();}
  37.         System.Draw(buffer, bmpGameBG);
  38.         Stick.Draw(buffer, bmpStick);
  39.         Player.Draw(buffer, bmpPlayer);
  40.         blit(buffer, screen, 0, 0, 0, 0, 640, 480);
  41.         clear_bitmap(buffer);
  42.     }
  43.     //Game Loop-----------------------------------------
  44.  
  45.     //Destroying Bitmaps--------------------------------
  46.     destroy_bitmap(buffer);
  47.     destroy_bitmap(bmpPlayer);
  48.     destroy_bitmap(bmpTitleScreen);
  49.     destroy_bitmap(bmpGameBG);
  50.     destroy_bitmap(bmpStick);
  51.     //Destroying Bitmaps--------------------------------
  52. }
  53. END_OF_MAIN()
  54.  
  55.  
  56.  
  57. 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) {
  58.     bool collision;
  59.  
  60.     if (    ( b1_x > b2_x + b2_w - 1 ) ||
  61.             ( b1_y > b2_y + b2_h - 1 ) ||
  62.             ( b2_x > b1_x + b1_w - 1 ) ||
  63.             ( b2_y > b1_y + b1_h - 1 )  )
  64.             { collision = false; return collision; }
  65.  
  66.     else { collision = false; return collision; }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment