bdb70fc76cf056ff538d1cac875bcce9afeae58d.svn-base (2973B)
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 FALL 11 46 #define JUMP_TO_FALL 13 47 #define RUN 20 48 #define RUN_DRAWN 25 49 #define IDLE_BEGIN 30 50 #define JUMP 40 51 #define WANDER 50 52 #define PURSUE 60 53 #define SWIM 110 54 #define TREAD 120 55 #define LOOK 121 56 #define EAT 122 57 #define SLEEP 123 58 #define PARTICLE 124 59 60 #define SWIM_LEFT 130 61 #define SWIM_RIGHT 131 62 #define SWIM_DOWN 132 63 #define SWIM_UP 133 64 65 #define RUN_LEFT 0x1 66 #define RUN_RIGHT 0x02 67 #define RUN_DOWN 0x003 68 #define RUN_UP 0x0004 69 70 #define WALK_LEFT 0x5 71 #define WALK_RIGHT 0x06 72 #define WALK_DOWN 0x007 73 #define WALK_UP 0x0008 74 75 #define GATE_UP 201 76 #define GATE_DOWN 202 77 #define GATE_LOWER 203 78 #define GATE_LOWER_BEGIN 204 79 #define GATE_RAISE 205 80 81 #define ALIVE 70 82 #define DEAD 80 83 84 #define SPLASH 90 85 #define HAZE 100 86 // 87 88 //This is a strange place for this stuff. Should maybe be its own ParticleTypeData.h 89 struct drift_data 90 { 91 int mXspd; 92 int mYspd; 93 }; 94 95 union ParticleTypeData 96 { 97 bool NoData; 98 drift_data drift; 99 }; 100 101 ParticleTypeData NullPTdata(); 102 // 103 104 class Time 105 { 106 public: 107 108 Time() : mCycle(0) {}; 109 110 int ProgressCycle() 111 { 112 mCycle = (mCycle + 1); 113 return mCycle; 114 } 115 116 int GetCurrentCycle() 117 { 118 return mCycle; 119 } 120 121 int GetCurrentMS() 122 { 123 return (mCycle*MS_PER_FRAME); 124 } 125 protected: 126 127 int mCycle; 128 }; 129 130 //int GetTimeF(); 131 int GetRealTimeMS(); 132 133 SDL_Surface* LoadSurfaceBMP(const char* filename); 134 135 TTF_Font* LoadFont(char* file, int ptsize); 136 137 cJSON * LoadJSON(const char* filename); 138 139 void PrintJSON(cJSON* json); 140 141 bool ReadBTree(Node* root, char* str); 142 143 void PrintBTree(Node* root); 144 145 float GetSign(float x); 146 147 bool DetectRectIntersect(SDL_Rect* r1, SDL_Rect* r2); 148 149 bool DetectCenterPointIntersect(SDL_Rect* zone, SDL_Rect* point); //Detects collision between a rectangle "zone" and the center of a rectangle "point" 150 151 int CalcDistance(int x1, int y1, int x2, int y2); 152 153 int EvenOutcomes(int NumberofOutcomes); 154 155 int RandRange(int min, int max); 156 157 bool IsEven(int i); 158 159 extern Time* gTime; 160 161 #endif