TapestryEngine

A 2D Platformer Game Engine
Log | Files | Refs

24d887981e0541248730f6dec827eff8ffbed726.svn-base (3187B)


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