Moving and Flying Springs

Version:

2.0

Added on:

06 Mar 2020 18:14

Tags:

Description:
Moving and flying springs, like the ones in JJ1. For the moving spring, just use a regular spring event. (it will work as a red spring no matter what)

The flying one behaves as a butterfly. So put Area IDs to indicate its direction and speed. Please make sure the Keep X option for the spring is checked for this one. Otherwise it won't move.
  1. //moving spring
  2.  
  3. void onLevelLoad() {
  4.  
  5.   jjObjectPresets[OBJECT::REDSPRING].xSpeed = 5;
  6.   jjObjectPresets[OBJECT::REDSPRING].scriptedCollisions = true;
  7.   jjObjectPresets[OBJECT::REDSPRING].behavior = MovingSpring();
  8. }
  9.  
  10. class MovingSpring : jjBEHAVIORINTERFACE {
  11.  
  12.   void onBehave(jjOBJ@ obj) {
  13.     obj.behave(BEHAVIOR::WALKINGENEMY);
  14.     obj.putOnGround();
  15.   }
  16.   bool onObjectHit(jjOBJ@ obj, jjOBJ@, jjPLAYER@ player, int) {
  17.     player.direction = player.ySpeed = -32;
  18.     obj.scriptedCollisions = true;
  19.     jjSample(obj.xPos, obj.yPos, SOUND::COMMON_SPRING1);
  20.     return true;
  21.     }
  22. }
  23.  
  24. //flying spring
  25.  
  26. void onLevelLoad() {
  27.  
  28.   jjObjectPresets[OBJECT::BLUESPRING].xSpeed = 5;
  29.   jjObjectPresets[OBJECT::BLUESPRING].scriptedCollisions = true;
  30.   jjObjectPresets[OBJECT::BLUESPRING].behavior =FlyingSpring();  
  31.   jjObjectPresets[OBJECT::BLUESPRING].determineCurAnim(ANIM::SPRING,6);
  32. }
  33.  
  34. class FlyingSpring : jjBEHAVIORINTERFACE {
  35.  
  36.   void onBehave(jjOBJ@ obj) {
  37.     float YSpeed = 22;
  38.     obj.behave(BEHAVIOR::BUTTERFLY);
  39.  
  40.   }
  41.   bool onObjectHit(jjOBJ@ obj, jjOBJ@, jjPLAYER@ player, int) {
  42.     player.direction = player.ySpeed = -42;
  43.     obj.scriptedCollisions = true;
  44.     jjSample(obj.xPos, obj.yPos, SOUND::COMMON_SPRING1);
  45.     return true;
  46.     }
  47. }