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