TapestryEngine

A 2D Platformer Game Engine
Log | Files | Refs

76622bf9e4d03d6b92424d74749ae7bf41f1eda7.svn-base (1503B)


      1 #ifndef PHYSICS_H
      2 #define PHYSICS_H
      3 
      4 #include "Utils.h"
      5 #include "Console.h"
      6 
      7 class Spring
      8 {
      9 public:
     10 
     11 	Spring() : mSpringK(0), mNeutral(0) {}
     12 
     13 	Spring(int* pos, float* vel, float k,  int n, float damp = 1, int Vmax = 0, int Amax = 0, int ExMax = 0);
     14 
     15 	int ZeroNeutralAxis();
     16 
     17 	float CalcAccel();
     18 
     19 	bool CalcVelocity();
     20 
     21 protected:
     22 	
     23 	int* mPos;
     24 	float* mVelocity;
     25 	int mMaxVel;
     26 	int mMaxAccel;
     27 	int mMaxExten;
     28 	float mSpringK;
     29 	float mDamper;
     30 	int   mNeutral;
     31 };
     32 
     33 class PhysicsManager
     34 {
     35 public:
     36 
     37 	PhysicsManager() : mGravAccel(0) {}
     38 
     39 	PhysicsManager(float GravAccel, float BouyancyK, int* pos, float* Xvel, float* Yvel, bool Grav = true);
     40 
     41 	int ZeroBouyantSurface()
     42 	{
     43 		return mBouyancy.ZeroNeutralAxis();
     44 	}
     45 
     46 	bool SetFloating(bool state)
     47 	{
     48 		return mFloating = state;
     49 	}
     50 
     51 	bool Floating()
     52 	{
     53 		return mFloating;
     54 	}
     55 
     56 	bool SetGravity(bool state)
     57 	{
     58 		return mGravity = state;
     59 	}
     60 
     61 	bool Gravity()
     62 	{
     63 		return mGravity;
     64 	}
     65 
     66 	Spring* GetBouyancy()
     67 	{
     68 		return &mBouyancy;
     69 	}
     70 
     71 	bool ApplyGravity()
     72 	{
     73 		if (mGravity == true)
     74 		{
     75 			*mYvel += mGravAccel;
     76 			//gCons->ConsPrintf("Gravity Applied!\n");
     77 			return true;
     78 		}
     79 		else
     80 		{
     81 			return false;
     82 		}
     83 	}
     84 
     85 	bool ApplyBouyancy()
     86 	{
     87 		if (mFloating == true)
     88 		{
     89 			mBouyancy.CalcVelocity();
     90 			return true;
     91 		}
     92 		else
     93 		{
     94 			return false;
     95 		}
     96 	}
     97 
     98 	bool ApplyPhysics()
     99 	{
    100 		ApplyGravity();
    101 		ApplyBouyancy();
    102 		
    103 		return true;
    104 	}
    105 
    106 protected:
    107 
    108 	float* mYvel;
    109 	float* mXvel;
    110 	bool mGravity;
    111 	float mGravAccel;
    112 	bool mFloating;
    113 	Spring mBouyancy;
    114 
    115 };
    116 
    117 #endif
    118