Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Includes----------------------------------------------
- #include <allegro.h>
- #include "Sys.h"
- #include "Player.h"
- #include "Stick.h"
- //Includes----------------------------------------------
- //Creating Class Objects--------------------------------
- Sys System;
- Player Player;
- Stick Stick;
- //Creating Class Objects--------------------------------
- int main()
- {
- System.Initilize(); //Initilizes Allegro.
- //Creating & loading bitmaps here, as they are a pain to pass from other functions.
- BITMAP *buffer = create_bitmap(640, 480);
- BITMAP *bmpTitleScreen = load_bitmap("resources/TitleScreen.bmp", NULL);
- BITMAP *bmpPlayer = load_bitmap("resources/PlayerSpriteHitbox.bmp", NULL);
- BITMAP *bmpGameBG = load_bitmap("resources/GameBG.bmp", NULL);
- BITMAP *bmpStick = load_bitmap("resources/StickHitbox.bmp", NULL);
- //Game Loop-----------------------------------------
- while (!key[KEY_ESC]) {
- while (System.getTitleScreen() == true) {
- System.Draw(buffer, bmpTitleScreen);
- if (key[KEY_ENTER]) {
- System.toggleTitleScreen();
- }}
- Player.CheckMovement();
- if (CheckCollision() == true) {Stick.GenerateNewCoords();}
- System.Draw(buffer, bmpGameBG);
- Stick.Draw(buffer, bmpStick);
- Player.Draw(buffer, bmpPlayer);
- blit(buffer, screen, 0, 0, 0, 0, 640, 480);
- clear_bitmap(buffer);
- }
- //Game Loop-----------------------------------------
- //Destroying Bitmaps--------------------------------
- destroy_bitmap(buffer);
- destroy_bitmap(bmpPlayer);
- destroy_bitmap(bmpTitleScreen);
- destroy_bitmap(bmpGameBG);
- destroy_bitmap(bmpStick);
- //Destroying Bitmaps--------------------------------
- }
- END_OF_MAIN()
- 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) {
- bool collision;
- if ( ( b1_x > b2_x + b2_w - 1 ) ||
- ( b1_y > b2_y + b2_h - 1 ) ||
- ( b2_x > b1_x + b1_w - 1 ) ||
- ( b2_y > b1_y + b1_h - 1 ) )
- { collision = false; return collision; }
- else { collision = false; return collision; }
- }
Advertisement
Add Comment
Please, Sign In to add comment