|
Post by thepinkpowerranger on Feb 19, 2009 19:00:53 GMT 12
|
|
MagmarFire
Brilliant member
Always thinking of you...
Posts: 648
|
Post by MagmarFire on Mar 5, 2009 15:41:25 GMT 12
#include <allegro.h> #include <iostream> #include <cmath> #include <ctime> #include <cmath> #include <string> #include <sstream> #include <cstdlib> #define pi 3.1415926535 #define null NULL #define SCREEN_W 640 #define SCREEN_H 480 #include "allegset.h" #include "HUD_outline.h" using namespace std;
int HP_divisor = 5; // Draws the line for when the siren sounds. int sleep = 30; // Sets the amount of time // in the interval between // each while loop iteration. int FPS = 100 / sleep;
//*************************************************** // Player Class // The class containing all the information that will // be used in the HUD. //***************************************************
class Player { private: int HP, MP, maxHP, maxMP, tempHP, frame; bool recoil; BITMAP *face; // We'll need to allocate new memory later! public: Player() // Player's default constructor. { HP = 120; maxHP = 120; maxMP = 100; MP = 100; face = NULL; tempHP = HP; face = null; frame = 1; recoil = false; face = load_bitmap("I:\\Dev-Cpp\\High Health.bmp",null); } int getHP() {return HP;} int getMP() {return MP;} int getmaxHP() {return maxHP;} int getmaxMP() {return maxMP;} void addmaxHP(int x) {maxHP += x;} void addHP(int x) {HP += x;} //void damage_check(int, int); // Void version of damage_check BITMAP * damage_check(int,int); // Bitmap version of damage_check BITMAP * get_face() {return face;} // An accessor that returns // the bitmap of the player's // face. }; // End class definition.
BITMAP * Player::damage_check(int currentHP, int beforeHP) { bool damage = false; // Initialize the damage flag to false. // If you want to add a pause to it, just // use a reference variable and an if // statement for this flag only.
if (currentHP >= beforeHP) damage = false; else if (currentHP < beforeHP && HP > 0) { damage = true; recoil = true; frame = 1; } if (damage == false && recoil == false) { if (currentHP > this->maxHP / HP_divisor) // If you have more than a fifth of your max HP left... this->face = load_bitmap("I:\\Dev-Cpp\\High Health.bmp",null); // ...you're good to go! else // If not... this->face = load_bitmap("I:\\Dev-Cpp\\Low Health.bmp",null); // ...you're screwed. } else if (recoil == true && frame % 17 != 0) // If damage IS taken... { this->face = load_bitmap("I:\\Dev-Cpp\\Damage.bmp",null); // All hail the animation frame++; // that is pretty much the return this->face; // main reason why I wrote // this program to begin with! } if (frame % 17 == 0) { frame = 1; recoil = false; } return this->face; // Return the appropriate face. }
//******************************************* // SAMPLES, BITMAPS, AND PROTOTYPES //*******************************************
BITMAP *buffer = NULL; BITMAP *enemy = null; SAMPLE *F = null; SAMPLE *song = null; SAMPLE *siren = null; int hexa(int); // Function prototypes int hex_to_HP(int); void face_change(); void siren_check(Player, int &, int); void HUD_filter(int &,int &,bool &,int,int,double, Player);
int main(int argc, char *argv[]) { int seed = time(0); srand(seed); alleg_setup(); // A shorthand function I created that sets up default Allegro configurations. Player Sora; buffer = create_bitmap(640,480); enemy = load_bitmap("I:\\Dev-Cpp\\Enemy.bmp",null); F = load_sample("I:\\F!.wav"); song = load_sample("I:\\dearlybelovedreprise.wav"); siren = load_sample("I:\\Crappy KH Low Health.wav");
int arc1 = 0, arc2 = 0; int bigrad = 65, smallrad = 50; // Radii of the arcs in the HUD. // Prefered bigrad:smallrad ratio = 1.25:1 int HUDx = 570, // The HUD's center coordinates. HUDy = SCREEN_H / 2 + 170; int HP = Sora.getHP(), maxHP = Sora.getmaxHP(), MP = Sora.getMP(), maxMP = Sora.getmaxMP(); int tempHP = HP; // tempHP will hold the original HP; this is for checking // to see if the player takes damage at all during each // of the HUD's iterations. int rest_request = 300; /* HUD FILTER VARIABLES */ int alpha = 0; // Sets the alpha value for the HUD filter. int red_rest = 0; // Sets the time value for the filter's flash. bool fade_flag = false; // If this is false and the other conditions are met, // the filter will grow redder and redder. while (!key[KEY_ESC]) { // Variable reassignments. tempHP = HP; HP = Sora.getHP(); maxHP = Sora.getmaxHP(); MP = Sora.getMP(); maxMP = Sora.getmaxMP(); if (key[KEY_RIGHT]) Sora.addmaxHP(1); if (key[KEY_LEFT]) Sora.addmaxHP(-1); if (key[KEY_UP]) { Sora.addHP(-3); //play_sample(F,255,150,1000,0); } else if (key[KEY_DOWN]) Sora.addHP(3); else if (key[KEY_U]) { HP += 2; } else if (key[KEY_D]) { HP -= 2; while (key[KEY_D]) {} } if (key[KEY_M]) MP += 1; else if (key[KEY_N]) MP -= 1; if (key[KEY_P]) { while (key[KEY_P]) {} play_sample(song,255,150,1000,0); } siren_check(Sora,rest_request,sleep); if (HP < 0) HP = 0; acquire_screen(); //Begin the screen acquirement. draw_sprite(buffer,Sora.damage_check(HP,tempHP),(HUDx - Sora.get_face()->w / 2), (HUDy - Sora.get_face()->h / 2)); HUD_filter(red_rest,alpha,fade_flag,HUDx,HUDy,smallrad,Sora); drawHUD(hex_to_HP(maxHP - 60),bigrad,smallrad,buffer,hex_to_HP(HP - 60), MP,maxMP,HUDx,HUDy); // We want degrees, not hexes! blit(buffer,screen,0,0,0,0,640,480); release_screen(); // Release what has been acquired for the screen. rest(sleep); clear_bitmap(buffer); } destroy_bitmap(buffer); return 0; } END_OF_MAIN();
int hex_to_HP(int HP) { return 3 * HP; } END_OF_FUNCTION(); void siren_check(Player object, int &rest_request, int rest_main) { if (object.getHP() <= object.getmaxHP() / HP_divisor) // Checks to see if the player's HP is less than { // one-fifth-max. if (rest_request % 270 == 0) // Make sure the mod-divisor is a multiple of the sleep // variable! { play_sample(siren,255,150,1000,0); rest_request = 0; rest_request += rest_main; } else rest_request += rest_main; } } END_OF_FUNCTION(); void HUD_filter(int &red_rest, int &alpha, bool &flag, int HUDx, int HUDy, double radius, Player persona) { if (persona.getHP() <= persona.getmaxHP() / HP_divisor) { drawing_mode(DRAW_MODE_TRANS, buffer,0,0); // Allows us to edit the alpha channel. set_trans_blender(195,0,0,alpha); circlefill(buffer,HUDx,HUDy,radius,makecol(95,0,0)); // I can make this an image if I want to, right? drawing_mode(DRAW_MODE_SOLID,buffer,0,0); if (alpha < 155 && flag == false) // If the filter's alpha value is less than or equal to 255... alpha += 10; // ...make its appearance more defined. else if (alpha >= 155 && flag == false) // If not... { flag = true; alpha -= 10; // ...have it grow fainter. } else if (flag == true && alpha > 75) // Time to go back to square one... alpha -= 10; else if (flag == true && alpha <= 75) flag = false;
else // If you're in good health, everything's back to normal! { alpha = 0; flag = false; } } } END_OF_FUNCTION();
...
Well, it's better than having absolutely nothing on my Clipboard, I guess... >.>''
|
|
|
Post by thedarkfiddler on Mar 6, 2009 0:03:46 GMT 12
RPPZBM21
|
|
|
Post by RobSp1derp1g on Mar 6, 2009 1:14:37 GMT 12
Clear out the windows
|
|
|
Post by tyrannosaurusalan on Mar 6, 2009 2:07:53 GMT 12
cheese steak jimmy's
|
|
|
Post by thedarkfiddler on Mar 6, 2009 2:07:53 GMT 12
Elves have four stages of inebriation: 1. I think I'm better than you. 2. I *know* I'm better than you. 3. I'm immortal. 4. Hey baby, wanna make a half-elf?
|
|
|
Post by thedarkfiddler on Mar 6, 2009 2:38:57 GMT 12
|
|
|
Post by RobSp1derp1g on Mar 6, 2009 3:06:00 GMT 12
^^^ that was (and still is) an Age of Empires II cheat code
travel at the speed of light
|
|
|
Post by tyrannosaurusalan on Mar 6, 2009 16:23:56 GMT 12
^^^ that was (and still is) an Age of Empires II cheat code travel at the speed of light True, I play the game, my brother had torrented the game and I'm a bit of a cheat. z8.invisionfree.com/_kab
|
|
MagmarFire
Brilliant member
Always thinking of you...
Posts: 648
|
Post by MagmarFire on Mar 7, 2009 8:30:47 GMT 12
play_sample(pain1,255,150,1000,0);
Huh, hibernation didn't delete it? Odd. O.o
|
|
|
Post by cascade88 on Jul 4, 2009 15:56:52 GMT 12
|
|