xemerau

main.cpp (Pickn' Sticks(revised))

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