TapestryEngine

A 2D Platformer Game Engine
Log | Files | Refs

df3e306d07ba9ca033ef49e9ba9dc75f80fa3b21.svn-base (2936B)


      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 //struct ActHandle
    105 //{
    106 //	int id;
    107 //};
    108 
    109 typedef int ActHandle;
    110 
    111 class Time
    112 {
    113 public:
    114 
    115 	Time() : mCycle(0) {};
    116 
    117 	int ProgressCycle()
    118 	{
    119 		mCycle = (mCycle + 1);
    120 		return mCycle;
    121 	}
    122 
    123 	int GetCurrentCycle()
    124 	{
    125 		return mCycle;
    126 	}
    127 
    128 	int GetCurrentMS()
    129 	{
    130 		return (mCycle*MS_PER_FRAME);
    131 	}
    132 protected:
    133 
    134 	int mCycle;
    135 };
    136 
    137 int GetRealTimeMS();
    138 
    139 SDL_Surface* LoadSurfaceBMP(const char* filename);
    140 
    141 TTF_Font* LoadFont(char* file, int ptsize);
    142 
    143 cJSON * LoadJSON(const char* filename);
    144 
    145 void PrintJSON(cJSON* json);
    146 
    147 float GetSign(float x);
    148 
    149 bool DetectRectIntersect(SDL_Rect* r1, SDL_Rect* r2);
    150 
    151 bool DetectCenterPointIntersect(SDL_Rect* zone, SDL_Rect* point); //Detects if the center of rectangle "point" is within rectangle "zone"
    152 
    153 int CalcDistance(int x1, int y1, int x2, int y2);
    154 
    155 int EvenOutcomes(int NumberofOutcomes);
    156 
    157 int RandRange(int min, int max);
    158 
    159 bool IsEven(int i);
    160 
    161 extern Time* gTime;
    162 
    163 #endif