Advertisement
kevryan

Support code for Aidan's Cooler part in Contraption Maker

Apr 22nd, 2016
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 15.84 KB | None | 0 0
  1. // Code Excerpt #1
  2.  
  3. // Aidan's Cooler
  4. static cpVect aidansCoolerHandleVerts[4] = {cpvFtoI(5-16,22-16),cpvFtoI(9-16,25-16),cpvFtoI(27-16,8-16),cpvFtoI(25-16,6-16)};
  5. static cpVect aidansCoolerVertsInside[4] = {cpvFtoI(9-31.5f,18-28),cpvFtoI(12-31.5f,30-28),cpvFtoI(53-31.5f,30-28),cpvFtoI(53-31.5f,18-28)};
  6. static cpVect aidansCoolerVertsFront[4] = {cpvFtoI(5-31.5f,15-28),cpvFtoI(8-31.5f,39-28),cpvFtoI(57-31.5f,38-28),cpvFtoI(57-31.5f,15-28)};
  7. static cpVect aidansCoolerVertsRight[4] = {cpvFtoI(54-31.5f,15-28),cpvFtoI(54-31.5f,39-28),cpvFtoI(57-31.5f,38-28),cpvFtoI(57-31.5f,15-28)};
  8. static cpVect aidansCoolerVertsLeft[4] = {cpvFtoI(5-31.5f,15-28),cpvFtoI(8-31.5f,39-28),cpvFtoI(10-31.5f,39-28),cpvFtoI(7-31.5f,15-28)};
  9. static cpVect aidansCoolerVerts[4] = {cpvFtoI(11-31.5f,38-28),cpvFtoI(12-31.5f,50-28),cpvFtoI(54-31.5f,50-28),cpvFtoI(54-31.5f,38-28)};
  10.  
  11. static CMPartBodyDynamicDef aidansCoolerWheelBodyDef(2,CC_TO_TMPOINTINT32(16-31.5f,46-28), FLOAT_TO_INT32(1.5f), FLOAT_TO_INT32(7.8f), false,false,false, NULL);
  12. static CMPartBodyDynamicDef aidansCoolerHandleBodyDef(1,CC_TO_TMPOINTINT32(66-31.5f,9-28), FLOAT_TO_INT32(12), FLOAT_TO_INT32(7.8f), false,false,false, &aidansCoolerWheelBodyDef);
  13. static CMPartBodyDynamicDef aidansCoolerBodyDef(0,CC_TO_TMPOINTINT32(0.0f,0.0f), FLOAT_TO_INT32(68), FLOAT_TO_INT32(7.8f), false,false,false, &aidansCoolerHandleBodyDef);
  14.  
  15. static CMPartConstraintRotaryLimitJointDef aidansCoolerHandleRotaryConstraintDef(2,0,1, 0,TM_THREE_QUARTERS_PI, false,NULL);
  16. static CMPartConstraintPivotJointDef aidansCoolerHandleConstraintDef(1,1,0,CC_TO_TMPOINTINT32(58-31.5f,16-28),false,&aidansCoolerHandleRotaryConstraintDef);
  17. static CMPartConstraintPivotJointDef aidansCoolerConstraintDef(0,2,0,CC_TO_TMPOINTINT32(16-31.5f,46-28),false,&aidansCoolerHandleConstraintDef);
  18.  
  19. static CMPartShapeCircleDef aidansCoolerWheelShapeDef(5,CC_TO_TMPOINTINT32(0,0),2, SP_SOFT_STICKY,SP_SFX_SILENT, FLOAT_TO_INT32(5.5f), COL_GROUP_DEFAULT,COL_TYPE_DEFAULT,COL_LAYER_DEFAULT, false, NULL);
  20. static CMPartShapePolyDef aidansCoolerHandleShapeDef(4,zeroPoint,1, SP_SOFT_NORMAL,SP_SFX_SILENT, aidansCoolerHandleVerts,4, COL_GROUP_DEFAULT,COL_TYPE_DEFAULT,COL_LAYER_DEFAULT, false,&aidansCoolerWheelShapeDef);
  21. static CMPartShapePolyDef aidansCoolerInsideShapeDef(CONTAINER_SHAPE_ID,zeroPoint,0, SP_SENSOR,SP_SFX_SILENT, aidansCoolerVertsInside,4, COL_GROUP_DEFAULT,COL_TYPE_SENSOR_BEGIN_SEPARATE,COL_LAYER_DEFAULT, false,&aidansCoolerHandleShapeDef);
  22. static CMPartShapePolyDef aidansCoolerFrontShapeDef(3,zeroPoint,0, SP_SOFT_NORMAL,SP_SFX_HARD_SURFACE, aidansCoolerVertsFront,4, COL_GROUP_DEFAULT,COL_TYPE_DEFAULT,COL_LAYER_BOX_FRONT, false,&aidansCoolerInsideShapeDef);
  23. static CMPartShapePolyDef aidansCoolerRightShapeDef(2,zeroPoint,0, SP_SOFT_NORMAL,SP_SFX_HARD_SURFACE, aidansCoolerVertsRight,4, COL_GROUP_DEFAULT,COL_TYPE_DEFAULT,COL_LAYER_DEFAULT, false,&aidansCoolerFrontShapeDef);
  24. static CMPartShapePolyDef aidansCoolerLeftShapeDef(1,zeroPoint,0, SP_SOFT_NORMAL,SP_SFX_HARD_SURFACE, aidansCoolerVertsLeft,4, COL_GROUP_DEFAULT,COL_TYPE_DEFAULT,COL_LAYER_DEFAULT, false,&aidansCoolerRightShapeDef);
  25. static CMPartShapePolyDef aidansCoolerShapeDef(0,zeroPoint,0, SP_SOFT_NORMAL,SP_SFX_HARD_SURFACE, aidansCoolerVerts,4, COL_GROUP_DEFAULT,COL_TYPE_DEFAULT,COL_LAYER_DEFAULT, false,&aidansCoolerLeftShapeDef);
  26.  
  27. static CMPartAttachmentRopeDef aidansCoolerAttachmentDef(0,CC_TO_TMPOINTINT32(25-16,7-16),1,false,NULL);
  28.  
  29. static CMPartArtSpriteRectDef aidansCoolerWheelArtDef(3,BOX_FRONT_LAYER+1,2,2,"iceChestWheels",FLOAT_TO_INT32(20.0f),FLOAT_TO_INT32(20.0f),1,zeroPoint, true,true,false,true);
  30. static CMPartArtSpriteRectDef aidansCoolerHandleArtDef(2,BOX_FRONT_LAYER+1,1,1,"iceChestHandle",FLOAT_TO_INT32(32.0f),FLOAT_TO_INT32(32.0f),1,zeroPoint, true,true,false,true, 255, &aidansCoolerWheelArtDef);
  31. static CMPartArtSpriteRectDef aidansCoolerFlippedArtDef(1,BOX_FRONT_LAYER,0,0,"iceChestBodyNoIceFlipped",FLOAT_TO_INT32(63),FLOAT_TO_INT32(56),1,zeroPoint, true,true,false,false, 255, &aidansCoolerHandleArtDef);
  32. static CMPartArtSpriteRectDef aidansCoolerArtDef(0,BOX_FRONT_LAYER,0,0,"iceChestBodyNoIce",FLOAT_TO_INT32(63),FLOAT_TO_INT32(56),1,zeroPoint, true,true,false,false, 255, &aidansCoolerFlippedArtDef);
  33.  
  34.  
  35. //--------------------------------------------------------------------------------------------------------------------------------------------------
  36.  
  37. // Code Excerpt #2
  38.  
  39. // Some macros used above
  40. #define FLOAT_TO_INT32(flt)         ((int)((flt)*INT32_ONE_FLOAT))
  41. #define CC_TO_TMPOINTINT32(x,y)     TmPointInt32(FLOAT_TO_INT32(x),FLOAT_TO_INT32(y))
  42.  
  43.  
  44. //--------------------------------------------------------------------------------------------------------------------------------------------------
  45.  
  46. // Code Excerpt #3
  47.  
  48. // Constructor for Chipmunk dynamic body
  49. CMPartBodyDynamicDef(int id, TmPointInt32 pos, int mass, int density, bool noGravity=false, bool dampsRope=false, bool shouldSave=false, CMPartBodyDef *next=NULL);
  50.  
  51.  
  52. //--------------------------------------------------------------------------------------------------------------------------------------------------
  53.  
  54. // Code Excerpt #4
  55.  
  56. // Constructor for Chipmunk rotary limit joint
  57. CMPartConstraintRotaryLimitJointDef(int id, int body1Id, int body2Id, int minAngle, int maxAngle, bool shouldSave=false, CMPartConstraintDef *next=NULL);
  58.  
  59.  
  60. //--------------------------------------------------------------------------------------------------------------------------------------------------
  61.  
  62. // Code Excerpt #5
  63.  
  64. // Constructor for Chipmunk pivot joint
  65. CMPartConstraintPivotJointDef(int id, int body1Id, int body2Id, TmPointInt32 pivot, bool shouldSave=false, CMPartConstraintDef *next=NULL);
  66.  
  67.  
  68. //--------------------------------------------------------------------------------------------------------------------------------------------------
  69.  
  70. // Code Excerpt #6
  71.  
  72. // Collision Group (used by chipmunk in conjunction with shapes)
  73. #define COL_GROUP_DEFAULT                0       // Collides with everything
  74. #define COL_GROUP_WALL                   1
  75. #define COL_GROUP_GEAR                   2
  76. #define COL_GROUP_TOASTER                3
  77. #define COL_GROUP_BOBBER                 4
  78. #define COL_GROUP_FOCUS_LASER            5
  79. #define COL_GROUP_ARROW                  6
  80.  
  81. #define COL_GROUP_REMOTE_BOMB_PLUNGER   -1
  82.  
  83. // Collision Type (used by chipmunk in conjunction with shapes)
  84. #define COL_TYPE_DEFAULT                 0
  85. #define COL_TYPE_BEGIN                   1
  86. #define COL_TYPE_PRE                     2
  87. #define COL_TYPE_POST                    3
  88. #define COL_TYPE_SEPARATE                4
  89. #define COL_TYPE_SENSOR_BEGIN_SEPARATE   5
  90. #define COL_TYPE_SENSOR_PRE              6
  91. #define COL_TYPE_BEGIN_SEPARATE          7
  92. #define COL_TYPE_BEGIN_POST              8
  93. #define COL_TYPE_SENSOR_BEGIN            9
  94. #define COL_TYPE_BEGIN_PRE               10
  95.  
  96. // Collision Layer (used by chipmunk in conjunction with shapes)
  97. #define COL_LAYER_ALL               0xffffffff
  98.  
  99. #define COL_LAYER_SLED_FRONT        0x00000001     // Is part of default layers
  100. #define COL_LAYER_BOX_FRONT         0x00000002     // Doesn't collide with default (bit not set in default layers)
  101. #define COL_LAYER_LASER_IGNORE      0x00000002     //          "
  102. #define COL_LAYER_GEAR              0x00000004     //          "
  103. #define COL_LAYER_LASER_TRIGGER     0x00000008     //          "
  104. #define COL_LAYER_TOAST             0x00000010     //          "
  105. #define COL_LAYER_BOBBER            0x00000020     //          "
  106. #define COL_LAYER_LASER_SPLITTER    0x00000040     //          "
  107. #define COL_LAYER_DOG               0x00000080     //          "
  108. #define COL_LAYER_FORCE_FIELD       0x00000100     //          "
  109. #define COL_LAYER_LADDER            0x00000200     // Is part of default layers
  110.  
  111. #define COL_LAYER_PROJECTION        0x80000000     // Only used by the part that is being projected from
  112.  
  113. #define COL_LAYER_NON_DEFAULT       (COL_LAYER_BOX_FRONT|COL_LAYER_LASER_IGNORE|COL_LAYER_GEAR|COL_LAYER_LASER_TRIGGER|COL_LAYER_TOAST|COL_LAYER_BOBBER|COL_LAYER_LASER_SPLITTER|COL_LAYER_DOG|COL_LAYER_FORCE_FIELD|COL_LAYER_PROJECTION)
  114. #define COL_LAYER_DEFAULT           (COL_LAYER_ALL ^ COL_LAYER_NON_DEFAULT)
  115.  
  116. #define COL_LAYER_TT                (COL_LAYER_DEFAULT & ~COL_LAYER_SLED_FRONT)     // Collides with all default layers except for the sled front layer
  117.  
  118. #define COL_LAYER_LASER             (COL_LAYER_ALL ^ (COL_LAYER_BOX_FRONT|COL_LAYER_GEAR|COL_LAYER_LASER_SPLITTER))
  119.  
  120.  
  121. //--------------------------------------------------------------------------------------------------------------------------------------------------
  122.  
  123. // Code Excerpt #7
  124.  
  125. struct CpShapeProperty
  126. {
  127.    int e;         // Coefficient of restitution. (elasticity)
  128.    int uSliding;  // Coefficient of friction. (sliding)
  129.    int uRolling;  // Coeffience of friction. (rolling)
  130. };
  131.  
  132. #define SP_FIRST                    0
  133.  
  134. #define SP_VERY_BOUNCY_NONE         0
  135. #define SP_VERY_BOUNCY_SLICK        1
  136. #define SP_VERY_BOUNCY_NORMAL       2
  137. #define SP_VERY_BOUNCY_STICKY       3
  138. #define SP_VERY_BOUNCY_MED_STICKY   4
  139. #define SP_VERY_BOUNCY_VERY_STICKY  5
  140.  
  141. #define SP_BOUNCY_NONE              6
  142. #define SP_BOUNCY_SLICK             7
  143. #define SP_BOUNCY_NORMAL            8
  144. #define SP_BOUNCY_STICKY            9
  145. #define SP_BOUNCY_MED_STICKY        10
  146. #define SP_BOUNCY_VERY_STICKY       11
  147.  
  148. #define SP_NORMAL_NONE              12
  149. #define SP_NORMAL_SLICK             13
  150. #define SP_NORMAL_NORMAL            14
  151. #define SP_NORMAL_STICKY            15
  152. #define SP_NORMAL_MED_STICKY        16
  153. #define SP_NORMAL_VERY_STICKY       17
  154.  
  155. #define SP_SOFT_NONE                18
  156. #define SP_SOFT_SLICK               19
  157. #define SP_SOFT_NORMAL              20
  158. #define SP_SOFT_STICKY              21
  159. #define SP_SOFT_MED_STICKY          22
  160. #define SP_SOFT_VERY_STICKY         23
  161.  
  162. #define SP_VERY_SOFT_NONE           24
  163. #define SP_VERY_SOFT_SLICK          25
  164. #define SP_VERY_SOFT_NORMAL         26
  165. #define SP_VERY_SOFT_STICKY         27
  166. #define SP_VERY_SOFT_MED_STICKY     28
  167. #define SP_VERY_SOFT_VERY_STICKY    29
  168.  
  169. #define SP_NONE_NONE                30
  170. #define SP_NONE_SLICK               31
  171. #define SP_NONE_NORMAL              32
  172. #define SP_NONE_STICKY              33
  173. #define SP_NONE_MED_STICKY          34
  174. #define SP_NONE_VERY_STICKY         35
  175.  
  176. #define SP_MECHANICAL_TRAMPOLINE    36
  177.  
  178. #define SP_BALL_BASEBALL            37
  179. #define SP_BALL_BASKETBALL          38
  180. #define SP_BALL_BILLIARD            39
  181. #define SP_BALL_BOWLING             40
  182. #define SP_BALL_IRONBALL            41
  183. #define SP_BALL_SOCCER              42
  184. #define SP_BALL_BOUNCYBALL          43
  185. #define SP_BALL_TENNIS              44
  186. #define SP_BALL_MARBLE              45
  187.  
  188. #define SP_SENSOR                   46
  189. #define SP_SCRIPT_NON_SENSOR        47
  190.  
  191. #define SP_NORMAL_TRAMPOLINE        48
  192. #define SP_CONVEYOR_BELT            49
  193. #define SP_EGG                      50
  194. #define SP_CREATURE_TREADS          51
  195.  
  196. #define SP_ICE                      52
  197. #define SP_SNOW                     53
  198.  
  199. #define SP_SLED                     54
  200.  
  201. #define SP_BLOCK                    55
  202.  
  203. #define SP_LAST                     55
  204.  
  205.  
  206. //--------------------------------------------------------------------------------------------------------------------------------------------------
  207.  
  208. // Code Excerpt #8
  209.  
  210. struct CpShapeSfxProperty
  211. {
  212.    int mSfxResIndex;
  213.    int minVel;       // Minimun velocity for sfx to be played
  214.    char *desc;
  215. };
  216.  
  217. // These are the actual sfx
  218. #define CM_SFX_BASEBALL       0
  219. #define CM_SFX_BASKETBALL     1
  220. #define CM_SFX_BOUNCY_BALL    2
  221. #define CM_SFX_BOWLING_BALL   3
  222. #define CM_SFX_CANNONBALL     4
  223. #define CM_SFX_CARDBOARD      5
  224. #define CM_SFX_MARBLE         6
  225. #define CM_SFX_SOCCER_BALL    7
  226. #define CM_SFX_TENNIS_BALL    8
  227. #define CM_SFX_WOOD_CRATE     9
  228.  
  229. #define CM_SFX_NUM            10
  230.  
  231. // These are the types of sfx surfaces that are mapped to actual sfx
  232. #define SP_SFX_FIRST          0
  233.  
  234. #define SP_SFX_BASEBALL       0
  235. #define SP_SFX_BASKETBALL     1
  236. #define SP_SFX_BOUNCYBALL     2
  237. #define SP_SFX_BOWLING_BALL   3
  238. #define SP_SFX_CANNONBALL     4
  239. #define SP_SFX_CARDBOARD      5
  240. #define SP_SFX_MARBLE         6
  241. #define SP_SFX_SOCCER_BALL    7
  242. #define SP_SFX_TENNIS_BALL    8
  243. #define SP_SFX_WOOD_CRATE     9
  244. #define SP_SFX_HARD_SURFACE   10
  245. #define SP_SFX_SOFT_SURFACE   11
  246. #define SP_SFX_SILENT         12
  247.  
  248. #define SP_SFX_LAST           12
  249.  
  250.  
  251. //--------------------------------------------------------------------------------------------------------------------------------------------------
  252.  
  253. // Code Excerpt #9
  254.  
  255. // Constructor for Chipmunk circle collision shape
  256. CMPartShapeCircleDef(int id, TmPointInt32 pos, int bodyId, int shapeProperty, int shapeSfxProperty, int radius, int group=COL_GROUP_DEFAULT, int collisionType=COL_TYPE_DEFAULT, int layers=COL_LAYER_DEFAULT, bool shouldSave=false, CMPartShapeDef *next=NULL);
  257.  
  258.  
  259. //--------------------------------------------------------------------------------------------------------------------------------------------------
  260.  
  261. // Code Excerpt #10
  262.  
  263. // Constructor for Chipmunk polygon collision shape
  264. CMPartShapePolyDef(int id, TmPointInt32 pos, int bodyId, int shapeProperty, int shapeSfxProperty, cpVect *verts, int numVerts, int group=COL_GROUP_DEFAULT, int collisionType=COL_TYPE_DEFAULT, int layers=COL_LAYER_DEFAULT, bool shouldSave=false, CMPartShapeDef *next=NULL);
  265.  
  266.  
  267. //--------------------------------------------------------------------------------------------------------------------------------------------------
  268.  
  269. // Code Excerpt #11
  270.  
  271. // Constructor for a Rope attachment
  272. CMPartAttachmentRopeDef(int id, TmPointInt32 pos, int bodyLinkId, bool shouldSave=false, CMPartAttachmentDef *next=NULL);
  273.  
  274.  
  275. //--------------------------------------------------------------------------------------------------------------------------------------------------
  276.  
  277. // Code Excerpt #12
  278.  
  279. // Constructor for the sprites
  280. CMPartArtSpriteRectDef(int id, int layer, int posLinkId, int rotLinkId, const char *spriteName, int width, int height, int partAttachmentId=-1, TmPointInt32 pos=TmPointInt32(0,0), bool useFrameCache=false, bool usedForBb=true, bool shouldSave=false, bool shouldPostProcess=true, unsigned char opacity=255, CMPartArtDef *next=NULL);
  281.  
  282.  
  283. //--------------------------------------------------------------------------------------------------------------------------------------------------
  284.  
  285. // Code Excerpt #13
  286.  
  287. // These are the different Chipmunk routines that are called along with some of the surrounding code
  288.  
  289. // Dynamic Body
  290. cpVect gravity = getGravity();
  291. tmInt64 moment = computeMomentOfInertia(part);
  292. mCpBody = cpBodyNew(mMass, moment, gravity);
  293.  
  294. // Rotary Limit Constraint
  295. mCpConstraint = cpRotaryLimitJointNew(body1->mCpBody,body2->mCpBody,mMinAngle,mMaxAngle);
  296.  
  297. // Pivot Joint Constraint
  298. mCpConstraint = cpPivotJointNew(body1->mCpBody,body2->mCpBody,cpv(pivot.x+part->mPos.x,pivot.y+part->mPos.y));
  299.  
  300. // Circle Collision Shape
  301. mCpShape = cpCircleShapeNew(body->mCpBody, mRadius, cpv(pos.x,pos.y));
  302. mCpShape->shapeProperty = mShapeProperty;
  303. mCpShape->shapeSfxProperty = mShapeSfxProperty;
  304. mCpShape->e = defaultShapeProps[mShapeProperty].e;
  305. mCpShape->u = defaultShapeProps[mShapeProperty].uSliding;
  306. mCpShape->uRolling = defaultShapeProps[mShapeProperty].uRolling;
  307. mCpShape->group = mGroup;
  308. mCpShape->layers = mLayers;
  309. mCpShape->collision_type = mCollisionType;
  310. mCpShape->sensor = (mShapeProperty == SP_SENSOR);
  311. mCpShape->id = mId;
  312.  
  313. // Polygon Collision Shape
  314. mCpShape = cpPolyShapeNew(body->mCpBody, numVerts, verts, cpv(pos.x,pos.y));
  315. mCpShape->shapeProperty = mShapeProperty;
  316. mCpShape->shapeSfxProperty = mShapeSfxProperty;
  317. mCpShape->e = defaultShapeProps[mShapeProperty].e;
  318. mCpShape->u = defaultShapeProps[mShapeProperty].uSliding;
  319. mCpShape->uRolling = defaultShapeProps[mShapeProperty].uRolling;
  320. mCpShape->group = mGroup;
  321. mCpShape->layers = mLayers;
  322. mCpShape->collision_type = mCollisionType;
  323. mCpShape->sensor = (mShapeProperty == SP_SENSOR);
  324. mCpShape->id = mId;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement