Dumb-ways-to-memorize
2D game
dumb_physics.h
Go to the documentation of this file.
1 #ifndef __DUMB_PHYSICS__H
2 #define __DUMB_PHYSICS__H
3 
4 #include "entity.h"
5 
6 /** Defines the Preset Physics values */
7 typedef enum
8 {
10  PHYSICS_BASE_FRICTION = 1, /**< An enum constant representing the physics base friction option */
11  PHYSICS_BASE_SPEED_X = 5, /**< An enum constant representing the physics base speed in x direction */
12  PHYSICS_BASE_SPEED_Y = 10, /**< An enum constant representing the physics base speed in y direction */
13  PHYSICS_MAX_SPEED = 16, /**< An enum constant representing the physics maximum speed */
16 
17 //typedef struct physics_s physics_t;
18 
19 //struct physics_s
20 //{
21 // int dummy_var;
22 //};
23 
24 /**
25  * Executes physics.
26  * RunTime O( n(n+1)/2 )
27  * Applies velocity, acceleration, gravity, and friction.
28  * Limits velocity, acceleration, and sets bounds.
29  *
30  * @author Anthony Rios
31  * @date 3/20/2016
32  */
33 void RunPhysics();
34 
35 /**
36  * Check collision between entities. (AABB)
37  *
38  * @param [in,out] self If non-null, the class instance that this method operates on.
39  * @param [in,out] other If non-null, the other.
40  *
41  * @return An int 1 if colliding, 0 if not.
42  *
43  * @author Anthony Rios
44  * @date 3/20/2016
45  */
46 int CheckCollision(entity_t *self, entity_t *other);
47 
48 /**
49  * Executes the collision operation.
50  * Place self farthest x or y away from other, vice versa.
51  * And negative the velocity to half of orginal collision vel, for bounce back.
52  *
53  * @param [in,out] self If non-null, the class instance that this method operates on.
54  * @param [in,out] other If non-null, the other.
55  *
56  * @author Anthony Rios
57  * @date 3/20/2016
58  */
59 void DoCollision(entity_t *self, entity_t *other);
60 
61 /**
62  * Applies the speed limit to vector a, defined by physics max speed.
63  *
64  * @param [in,out] a If non-null, the vec2_t to process.
65  *
66  * @author Anthony Rios
67  * @date 3/29/2016
68  */
69 void ApplySpeedLimit(vec2_t *a);
70 
71 /**
72  * Applies the bounds to specified ent, defined by the screen dimensions.
73  *
74  * @param [in,out] ent If non-null, the ent.
75  *
76  * @author Anthony Rios
77  * @date 3/29/2016
78  */
79 void ApplyBounds(entity_t * ent);
80 
81 /**
82  * Applies the friction to vector a, for the nonzero values.
83  * Uses Physics_base_friction for friction coefficient.
84  *
85  * @param [in,out] a If non-null, the vec2_t to process.
86  *
87  * @author Anthony Rios
88  * @date 3/29/2016
89  */
90 void ApplyFriction(vec2_t *a);
91 
92 
93 #endif
physics_laws_t
Definition: dumb_physics.h:7
void ApplyBounds(entity_t *ent)
Definition: dumb_physics.c:168
int CheckCollision(entity_t *self, entity_t *other)
Definition: dumb_physics.c:57
void ApplyFriction(vec2_t *a)
Definition: dumb_physics.c:194
void RunPhysics()
Definition: dumb_physics.c:9
void ApplySpeedLimit(vec2_t *a)
Definition: dumb_physics.c:162
void DoCollision(entity_t *self, entity_t *other)
Definition: dumb_physics.c:75
Definition: globals.h:19