1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
|
/**
HXPA5v1_0_GameEngine
(HellfireXP's Allegro 5 version 1.0 Game Engine)
**/
#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>
#include <direct.h>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <iomanip>
#include <allegro5/allegro.h>
#include <allegro5/allegro_native_dialog.h>
#include <allegro5/allegro_ttf.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_primitives.h>
#include <allegro5/allegro_image.h>
#include <allegro5/allegro_audio.h>
#include <allegro5/allegro_acodec.h>
#define _WIN32_WINNT 0x0500
using namespace std;
ALLEGRO_DISPLAY *display = NULL;
ALLEGRO_FONT *graphicsFont;
ALLEGRO_EVENT_QUEUE *event_queue;
ALLEGRO_EVENT e;
ALLEGRO_TIMER *timer;
ALLEGRO_KEYBOARD_STATE keyState;
enum TEXT_ALIGN {LEFT,CENTER,RIGHT};
enum EVENT_LIST {NONE,BUTTON_LEFT_CLICK,BUTTON_RIGHT_CLICK,WINDOW_CLOSE};
/*****************************************
******************************************
************* MISC OBJECTS ***************
******************************************
*****************************************/
namespace obj{
class Color{
public:
ALLEGRO_COLOR Black, White, LightGray, DarkGray, Pink, Red, Maroon, Magenta,
Brown, Yellow, LightGreen, Green, DarkGreen, LightBlue, Blue, DarkBlue, Purple;
Color()
:Black(al_map_rgb(0,0,0)), White(al_map_rgb(255,255,255)),
LightGray(al_map_rgb(195,195,195)), DarkGray(al_map_rgb(127,127,127)),
Pink(al_map_rgb(255,174,201)), Red(al_map_rgb(255,0,0)), Maroon(al_map_rgb(136,0,21)),
Magenta(al_map_rgb(255,0,255)), Brown(al_map_rgb(185,122,87)), Yellow(al_map_rgb(255,255,0)),
LightGreen(al_map_rgb(128,255,128)), Green(al_map_rgb(0,255,0)),
DarkGreen(al_map_rgb(0,128,0)), LightBlue(al_map_rgb(128,128,255)),
Blue(al_map_rgb(0,0,255)), DarkBlue(al_map_rgb(0,0,128)), Purple(al_map_rgb(163,73,164))
{}
ALLEGRO_COLOR RGBA(int r=0, int g=0, int b=0, int a=255)
{
if (r < 0 || r > 255) r = 0;
if (g < 0 || g > 255) g = 0;
if (b < 0 || b > 255) b = 0;
if (a < 0 || a > 255) a = 255;
ALLEGRO_COLOR classCLR = al_map_rgba(r,g,b,a);
return classCLR;
}
};
class Font{
private:
bool VALID;
int Size;
TEXT_ALIGN Alignment;
ALLEGRO_COLOR Clr;
string Name;
public:
Font() :VALID(false), Size(12), Alignment(LEFT), Clr(al_map_rgb(0,0,0)), Name("arial.ttf") {}
void SetFont(string name, int size = 12, TEXT_ALIGN alignment = LEFT, ALLEGRO_COLOR clr = al_map_rgb(0,0,0))
{
VALID = false;
Size = size;
Alignment = alignment;
Clr = clr;
char * dir = _getcwd(NULL, 0);
stringstream ss;
ss << dir << "\\" << name;
string fPath = ss.str();
Name = fPath;
if (ifstream(fPath.c_str())) VALID = true;
}
string GetName() { return Name; }
ALLEGRO_COLOR GetColor() { return Clr; }
TEXT_ALIGN GetAlignment() { return Alignment; }
int GetSize() { return Size; }
bool IsValid() { return VALID; }
};
struct Point{
int X,Y;
Point(int X, int Y) :X(X),Y(Y) {}
Point() :X(0),Y(0) {}
};
struct Rect{
int X,Y,Width,Height;
Rect(int X, int Y, int Width, int Height) :X(X),Y(Y),Width(Width),Height(Height) {}
Rect() :X(0),Y(0),Width(10),Height(10) {}
};
struct Line{
int X1, Y1, X2, Y2;
Line(int X1, int Y1, int X2, int Y2) :X1(X1),Y1(Y1),X2(X2),Y2(Y2) {}
Line() :X1(0),Y1(0),X2(1),Y2(1) {}
};
struct Circle{
int centerX, centerY, Radius;
Circle(int centerX, int centerY, int Radius) :centerX(centerX),centerY(centerY),Radius(Radius) {}
Circle() :centerX(0),centerY(0),Radius(10) {}
};
class Timer{
public:
Timer() {}
void Set(double framesPerSecond)
{
timer = al_create_timer(1.0/framesPerSecond);
al_register_event_source(event_queue, al_get_timer_event_source(timer));
}
void Start() { al_start_timer(timer); }
void Stop() { al_stop_timer(timer); }
};
class Grid{
private:
int CellWidth, CellHeight, Columns, Rows;
public:
bool BuildGrid(int,int,int,int);
Grid() :CellWidth(32),CellHeight(32),Columns(5),Rows(5) {}
Grid(int cwidth, int cheight, int cols, int rows) { BuildGrid(cwidth,cheight,cols,rows); }
Point GetPoint(int);
int GetCell(Point);
int GetCellCount() { return (Columns * Rows); }
};
} //End of namespace obj
/*****************************************
******************************************
************ PRIMARY CLASSES *************
******************************************
*****************************************/
using namespace obj;
class Window{
public:
Point MOUSE;
Window() {}
bool Initialize(int,int,string,int,int,int);
void Refresh() { al_flip_display(); }
void Pause(double seconds) { al_rest(seconds); }
void Focus() { al_set_target_bitmap(al_get_backbuffer(display)); }
void Clear(ALLEGRO_COLOR);
void Text(string,Font,Point);
EVENT_LIST DoEvents();
void DrawPixel(Point, ALLEGRO_COLOR);
void DrawLine(Line, ALLEGRO_COLOR);
void DrawCircle(Circle, ALLEGRO_COLOR, bool);
void DrawRectangle(Rect, ALLEGRO_COLOR, bool);
void Destroy();
};
class Bitmap{
public:
ALLEGRO_BITMAP *tBmp;
void ImgLoad(string);
void Focus() { al_set_target_bitmap(tBmp); }
void ImgCreate(int,int);
void Draw(int,int,int);
void DrawRegion(int,int,int,int,int,int,int);
void Destroy();
void TransparentClr(ALLEGRO_COLOR);
int GetTileX(int,int);
int GetTileY(int,int,int);
};
class MusicBox{
private:
vector<string> mList;
ALLEGRO_SAMPLE *mSample;
ALLEGRO_SAMPLE *mbgSample;
ALLEGRO_SAMPLE_INSTANCE *mInstance;
int mLoaded;
int mBGLoaded;
public:
MusicBox() :mBGLoaded(false), mLoaded(-1) {}
void AddMusic(string);
void Play(int,bool);
void SetBGMusic(string);
void PlayBGMusic();
void Destroy();
};
class Engine{
public:
Engine() {}
void Randomize() { srand(time(0)); }
int Random(int,int);
string CStr(int);
string CenterText(string,int);
string Hex(int);
void HideConsole()
{
HWND hWnd = GetConsoleWindow();
ShowWindow( hWnd, SW_HIDE );
}
int GetScreenWidth() { return GetSystemMetrics(0); }
int GetScreenHeight() { return GetSystemMetrics(1); }
};
|