liblashgame

Pathfinder and path decision making library for 2D tile game
git clone git://holbrook.no/liblashgame.git
Log | Files | Refs

lash_game_sprite.h (4183B)


      1 #ifndef LASH_GAME_SPRITE_SIMPLE_H_
      2 #define LASH_GAME_SPRITE_SIMPLE_H_
      3 
      4 #include <stdint.h>
      5 #include "liblashgame/lash_game_standard.h"
      6 
      7 enum states {
      8 			// direction
      9 			LASH_GAME_SPRITE_SIMPLE_STATE_STILL = (1 << 0),
     10 			LASH_GAME_SPRITE_SIMPLE_STATE_LEFT = (1 << 1),
     11 			LASH_GAME_SPRITE_SIMPLE_STATE_RIGHT = (1 << 2),
     12 			LASH_GAME_SPRITE_SIMPLE_STATE_UP = (1 << 3),
     13 			LASH_GAME_SPRITE_SIMPLE_STATE_DOWN = (1 << 4),
     14 			LASH_GAME_SPRITE_SIMPLE_STATE_RISE = (1 << 5),
     15 			LASH_GAME_SPRITE_SIMPLE_STATE_LOWER = (1 << 6),
     16 			// = (1 << 7)
     17 			
     18 			// movement types 
     19 			LASH_GAME_SPRITE_SIMPLE_STATE_WALKING = (1 << 8),
     20 			LASH_GAME_SPRITE_SIMPLE_STATE_RUNNING = (1 << 9),
     21 			LASH_GAME_SPRITE_SIMPLE_STATE_BOUNCING = (1 << 10),
     22 			// = (1 << 11)
     23 			// = (1 << 12)
     24 			// = (1 << 13)
     25 			// = (1 << 14)
     26 			// = (1 << 15)
     27 			
     28 			// posture types
     29 			LASH_GAME_SPRITE_SIMPLE_STATE_CROUCHING = (1 << 16),
     30 			LASH_GAME_SPRITE_SIMPLE_STATE_CRAWLING = (1 << 17),
     31 			LASH_GAME_SPRITE_SIMPLE_STATE_JUMPING = (1 << 18),
     32 			LASH_GAME_SPRITE_SIMPLE_STATE_FLYING = (1 << 19),
     33 			LASH_GAME_SPRITE_SIMPLE_STATE_SWIMMING = (1 << 20),
     34 			LASH_GAME_SPRITE_SIMPLE_STATE_CLIMBING = (1 << 21),
     35 			// = (1 << 22)
     36 			// = (1 << 23)
     37 			
     38 			// environment types
     39 			LASH_GAME_SPRITE_SIMPLE_STATE_IMMERSED = (1 << 24),  
     40 			LASH_GAME_SPRITE_SIMPLE_STATE_ENTERING = (1 << 25), // for swim, going into water, for jumping launching
     41 			LASH_GAME_SPRITE_SIMPLE_STATE_EXITING = (1 << 26),
     42 			LASH_GAME_SPRITE_SIMPLE_STATE_NOCONTROL = (1 << 27), // out of control; swimming = sinking, jumping = falling
     43 			LASH_GAME_SPRITE_SIMPLE_STATE_REBOUNDING = (1 << 28)
     44 			// = (1 << 29)
     45 			// = (1 << 30)
     46 			// = (1 << 31)
     47 			
     48 			
     49 		};
     50 		
     51 class Lash_Sprite_2D_Simple {
     52 	private:
     53 		lash_game_coords_float_t coords;
     54 		uint32_t w; // width in pixels
     55 		uint32_t h; // width in pixels
     56 		float v; // velocity
     57 		float rv; // radians direction of velocity
     58 		float a_init;
     59 		float a; // acceleration
     60 		float ra; // radians direction of acceleration
     61 		float m; // mass (kg)
     62 		float f; // friction
     63 		enum movements {
     64 			LASH_GAME_SPRITE_SIMPLE_MOVEMENT_LINEAR = (1 << 0),
     65 			LASH_GAME_SPRITE_SIMPLE_MOVEMENT_ARC = (1 << 1)
     66 		};
     67 		uint32_t state;
     68 		
     69 	public:
     70 		Lash_Sprite_2D_Simple();
     71 		Lash_Sprite_2D_Simple(const uint32_t initw, const uint32_t inith, const float inita, const float inca);
     72 		int init(const uint32_t initw, const uint32_t inith, const float inita, const float inca);
     73 		void clear();
     74 		int32_t getXPixels();
     75 		float getX();
     76 		void setX(const int32_t val);
     77 		void setX(const float val);
     78 		int32_t getYPixels();
     79 		float getY();
     80 		void setY(const int32_t val);
     81 		void setY(const float val);
     82 		void moveBy(const lash_game_coords_float_t addcoords);
     83 		void moveBy(float m, float r);
     84 		
     85 		int32_t getW();
     86 		int32_t getH();
     87 		void setResistance(float f);
     88 		float getResistance();
     89 		
     90 		void setAcceleration(float a, float r);
     91 		void setAccelerationX(float newa);
     92 		void setAccelerationY(float newa);
     93 		void getAcceleration(float *a, float *r, int noresistance);
     94 		
     95 		float getAccelerationX(int noresistance);
     96 		float getAccelerationY(int noresistance);
     97 		float getAccelerationRadians();
     98 		
     99 		void addAcceleration(float inca, float r);
    100 		void addAccelerationX(float inca);
    101 		void addAccelerationY(float inca);
    102 
    103 		float getVel();
    104 		void getVel(float *v, float *r);
    105 		float getVelRadians();		
    106 		float getVelX();
    107 		float getVelY();
    108 		
    109 		void addVel(float incv, float r);
    110 		void addVelX(float addx);
    111 		void addVelY(float addy);
    112 		
    113 		void setVelX(float newvx, int keepy);
    114 		void setVel(float v, float r);
    115 		void setVelY(float newvy, int keepx);
    116 		
    117 		int32_t getNextXPixels();
    118 		float getNextX();
    119 		int32_t getNextYPixels();
    120 		float getNextY();
    121 		void setMass(float newn);
    122 		float getMass();
    123 
    124 		void move();
    125 		void moveX();
    126 		void moveY();
    127 		void accelerate();
    128 		
    129 		void still();
    130 		int walkLeft(int resetvelocity = 0);
    131 		int walkRight(int resetvelocity = 0);
    132 		void stop();
    133 		
    134 		int jump();
    135 		int isJumping();
    136 		int isWalking(uint8_t state);
    137 		int isBouncing();
    138 		void land();
    139 		int bounce();
    140 		void launch();
    141 		void fall();
    142 		
    143 		void finish();
    144 		
    145 		void dumpState(char bitstring[]);
    146 		
    147 		void _old_land();
    148 };
    149 
    150 #endif // LASH_BALLRUNNER_SPRITE_H_