502509e254c16e83fd253447c08850cd220812d5.svn-base (3378B)
1 #ifndef UTILS_H 2 #define UTILS_H 3 4 //#define RELEASE 5 #define DEBUG 6 7 8 #include <vector> 9 #include <time.h> 10 #include <stdio.h> 11 #include <string.h> 12 #include <assert.h> 13 #include <stdarg.h> 14 #include <stdlib.h> 15 #include <math.h> 16 //#include <windows.h> 17 #include "cJSON.h" 18 #include "SDL.h" 19 #include "SDL_ttf.h" 20 #include "SDL_Mixer.h" 21 #include "BinaryTree.h" 22 23 //Terrain Defines 24 #define AIR 0x00 25 #define GROUND 0x01 26 #define PLATFORM 0x02 27 #define WATER 0x03 28 // 29 30 //Screen size defines //These must be a whole multiple of the camera size otherwise pixel stretching occurs 31 #define SCREEN_W 1344 32 #define SCREEN_H 756 33 // 34 35 //Direction Defines. Used by actor and terrain systems 36 #define DOWN 3 37 #define UP 2 38 #define LEFT 1 // must be 1 because of SDL draw function 39 #define RIGHT 0 // must be 0 because of SDL draw function 40 // 41 42 //Time Defines 43 #define MS_PER_FRAME 16 //this is normal speed 44 //#define MS_PER_FRAME 40 //useful slow speed 45 #define FRAMES_PER_SECOND (1/MS_PER_FRAME)*1000 //62.5 @16ms 46 47 #define CLOCKS_PER_FRAME (CLOCKS_PER_SEC/FRAMES_PER_SECOND) 48 // 49 50 51 //Actor State Defines 52 #define IDLE 10 53 #define IDLE_DRAWN 11 54 #define STUN 12 55 #define FALL 20 56 #define FALL_DRAWN 21 57 #define JUMP_TO_FALL 30 58 #define JUMP_TO_FALL_DRAWN 31 59 #define RUN 40 60 #define RUN_DRAWN 41 61 #define IDLE_BEGIN 50 62 #define IDLE_BEGIN_DRAWN 51 63 #define JUMP 60 64 #define JUMP_DRAWN 61 65 #define WANDER 70 66 #define PURSUE 80 67 #define SWIM 110 68 #define SWIM_BEGIN 111 69 #define TREAD 120 70 #define LOOK 121 71 #define EAT 122 72 #define SLEEP 123 73 #define PARTICLE 124 74 #define ATTACK 130 75 #define ALIVE 140 76 #define DEAD 150 77 #define DIE 151 78 79 #define SWIM_LEFT 160 80 #define SWIM_RIGHT 161 81 #define SWIM_DOWN 162 82 #define SWIM_UP 163 83 84 #define RUN_LEFT 0x1 85 #define RUN_RIGHT 0x02 86 #define RUN_DOWN 0x003 87 #define RUN_UP 0x0004 88 89 #define WALK_LEFT 0x5 90 #define WALK_RIGHT 0x06 91 #define WALK_DOWN 0x007 92 #define WALK_UP 0x0008 93 94 #define GATE_UP 201 95 #define GATE_DOWN 202 96 #define GATE_LOWER 203 97 #define GATE_LOWER_BEGIN 204 98 #define GATE_RAISE 205 99 100 #define SPLASH 90 101 #define HAZE 100 102 103 #define FADE_BLACK 210 104 #define FADE_RED 211 105 // 106 107 //This is a strange place for this stuff. Should maybe be its own ParticleTypeData.h 108 struct drift_data 109 { 110 int mXspd; 111 int mYspd; 112 }; 113 114 union ParticleTypeData 115 { 116 bool NoData; 117 drift_data drift; 118 }; 119 120 ParticleTypeData NullPTdata(); 121 // 122 123 //struct ActHandle 124 //{ 125 // int id; 126 //}; 127 128 typedef int ActHandle; 129 130 class Time 131 { 132 public: 133 134 Time() : mCycle(0) {}; 135 136 int ProgressCycle() 137 { 138 mCycle = (mCycle + 1); 139 return mCycle; 140 } 141 142 int GetCurrentCycle() 143 { 144 return mCycle; 145 } 146 147 int GetCurrentMS() 148 { 149 return (mCycle*MS_PER_FRAME); 150 } 151 protected: 152 153 int mCycle; 154 }; 155 156 class Random 157 { 158 public: 159 Random(); 160 161 int RandRange(int min, int max); 162 protected: 163 164 int mSeed; 165 }; 166 167 int GetRealTimeMS(); 168 169 SDL_Surface* LoadSurfaceBMP(const char* filename); 170 171 TTF_Font* LoadFont(char* file, int ptsize); 172 173 cJSON * LoadJSON(const char* filename); 174 175 void PrintJSON(cJSON* json); 176 177 float GetSign(float x); 178 179 bool DetectRectIntersect(SDL_Rect* r1, SDL_Rect* r2); 180 181 bool DetectCenterPointIntersect(SDL_Rect* zone, SDL_Rect* point); //Detects if the center of rectangle "point" is within rectangle "zone" 182 183 int CalcDistance(int x1, int y1, int x2, int y2); 184 185 int EvenOutcomes(int NumberofOutcomes); 186 187 bool IsEven(int i); 188 189 extern Time* gTime; 190 extern Random* gRandom; 191 192 #endif