Downloads containing STVutilminus.asc

Downloads
Name Author Game Mode Rating
TSF with JJ2+ Only: Custom HUD Spaz Electro Mutator N/A Download file

File preview

  1. funcdef void TimerVDictionaryFunction(dictionary @);
  2. class TimerV : jjBEHAVIORINTERFACE
  3. {
  4.         TimerV(int time, jjVOIDFUNC @callback)
  5.         {
  6.                 @_callback = @callback;
  7.                 _start(time);
  8.         }
  9.         TimerV(int time, TimerVDictionaryFunction @callback, dictionary @arguments)
  10.         {
  11.                 @_callbackWithArguments = @callback;
  12.                 @_arguments = @arguments;
  13.                 _start(time);
  14.         }
  15.         bool get_Active() const
  16.         {
  17.                 return cast<jjBEHAVIORINTERFACE @>(_object.behavior) is this;
  18.         }
  19.         int get_Elapsed() const
  20.         {
  21.                 if (Active)
  22.                         return _object.age;
  23.                 return -1;
  24.         }
  25.         int get_Total() const
  26.         {
  27.                 if (Active)
  28.                         return _object.counter;
  29.                 return -1;
  30.         }
  31.         int get_Remaining() const
  32.         {
  33.                 if (Active)
  34.                         return _object.counter - _object.age;
  35.                 return -1;
  36.         }
  37.         bool Stop()
  38.         {
  39.                 if (Active && _object.age < _object.counter)
  40.                 {
  41.                         _object.delete();
  42.                         return true;
  43.                 }
  44.                 return false;
  45.         }
  46.         bool Paused = false;
  47.  
  48. private
  49.         jjVOIDFUNC @_callback = null;
  50. private
  51.         TimerVDictionaryFunction @_callbackWithArguments;
  52. private
  53.         dictionary @_arguments;
  54. private
  55.         jjOBJ @_object;
  56. private
  57.         int _startTime;
  58. private
  59.         void _start(int time)
  60.         {
  61.                 if (time > 0)
  62.                 {
  63.                         @_object = jjObjects[jjAddObject(OBJECT::BEES, -1000, -1000, 0, CREATOR::OBJECT, BEHAVIOR::BEES)];
  64.                         _object.behavior = this;
  65.                         _object.counter = time;
  66.                         _object.age = 0;
  67.                         _object.playerHandling = HANDLING::PARTICLE;
  68.                         _object.deactivates = false;
  69.                         _startTime = jjGameTicks;
  70.                 }
  71.                 else
  72.                 {
  73.                         @_object = jjObjects[0]; // avoid null pointer access
  74.                         _pickCallback();
  75.                 }
  76.         }
  77. private
  78.         void onBehave(jjOBJ @obj)
  79.         {
  80.                 if (!Paused && jjGameTicks > _startTime && obj is _object && ++_object.age >= _object.counter)
  81.                 {
  82.                         _pickCallback();
  83.                         _object.delete();
  84.                 }
  85.         }
  86. private
  87.         void _pickCallback()
  88.         {
  89.                 if (_callback !is null)
  90.                         _callback();
  91.                 else
  92.                         _callbackWithArguments(_arguments);
  93.         }
  94. }
  95.  
  96. class Key
  97. {
  98.         string id;
  99.         uint code;
  100.  
  101.         Key(string id, uint code)
  102.         {
  103.                 this.id = id;
  104.                 this.code = code;
  105.         }
  106. }
  107.  
  108. jjRNG stvutilRNG = jjRNG();
  109. jjTEXTAPPEARANCE normalTextAppearance = jjTEXTAPPEARANCE(STRING::NORMAL);
  110.  
  111. array<Key @>
  112.         KEYS = {
  113.                 Key("F2", 0x71),                         // 0
  114.                 Key("F5", 0x74),                         // 1
  115.                 Key("F6", 0x75),                         // 2
  116.                 Key("F7", 0x76),                         // 3
  117.                 Key("F10", 0x79),                        // 4
  118.                 Key("F11", 0x7A),                        // 5
  119.                 Key("Insert", 0x2D),             // 6
  120.                 Key("Home", 0x24),                       // 7
  121.                 Key("PageUp", 0x21),             // 8
  122.                 Key("Delete", 0x2E),             // 9
  123.                 Key("End", 0x23),                        // 10
  124.                 Key("PageDown", 0x22),           // 11
  125.                 Key("Colon", 0xBA),                      // 12
  126.                 Key("QuotationMark", 0xDE),      // 13
  127.                 Key("Backspace", 0x08),          // 14
  128.                 Key("Backslash", 0xDC),          // 15
  129.                 Key("Backquote", 0xC0),          // 16
  130.                 Key("BracketLeft", 0xDB),        // 17
  131.                 Key("BracketRight", 0xDD),       // 18
  132.                 Key("Comma", 0xBC),                      // 19
  133.                 Key("Minus", 0xBD),                      // 20
  134.                 Key("Period", 0xBE),             // 21
  135.                 Key("Slash", 0xBF),                      // 22
  136.                 Key("Plus", 0xBB),                       // 23
  137.                 Key("Shift", 0x10),                      // 24
  138.                 Key("Alt", 0x12),                        // 25
  139.                 Key("Control", 0x11),            // 26
  140.                 Key("Tab", 0x09),                        // 27
  141.                 Key("Caps Lock", 0x14),          // 28
  142.                 Key("Space", 0x20),                      // 29
  143.                 Key("Up", 0x26),                         // 30
  144.                 Key("Down", 0x28),                       // 31
  145.                 Key("Left", 0x25),                       // 32
  146.                 Key("Right", 0x27),                      // 33
  147.                 Key("NumpadSlash", 0x6F),        // 34
  148.                 Key("NumpadAsterisk", 0x6A), // 35
  149.                 Key("NumpadMinus", 0x6D),        // 36
  150.                 Key("NumpadPlus", 0x6B),         // 37
  151.                 Key("Numpad1", 0x61),            // 38
  152.                 Key("Numpad2", 0x62),            // 39
  153.                 Key("Numpad3", 0x63),            // 40
  154.                 Key("Numpad4", 0x64),            // 41
  155.                 Key("Numpad5", 0x65),            // 42
  156.                 Key("Numpad6", 0x66),            // 43
  157.                 Key("Numpad7", 0x67),            // 44
  158.                 Key("Numpad8", 0x68),            // 45
  159.                 Key("Numpad9", 0x69),            // 46
  160.                 Key("Numpad0", 0x60),            // 47
  161.                 Key("NumpadPeriod", 0x6E),       // 48
  162.                 Key("0", 0x30),                          // 49
  163.                 Key("1", 0x31),                          // 50
  164.                 Key("2", 0x32),                          // 51
  165.                 Key("3", 0x33),                          // 52
  166.                 Key("4", 0x34),                          // 53
  167.                 Key("5", 0x35),                          // 54
  168.                 Key("6", 0x36),                          // 55
  169.                 Key("7", 0x37),                          // 56
  170.                 Key("8", 0x38),                          // 57
  171.                 Key("9", 0x39),                          // 58
  172.                 Key("A", 0x41),                          // 59
  173.                 Key("B", 0x42),                          // 60
  174.                 Key("C", 0x43),                          // 61
  175.                 Key("D", 0x44),                          // 62
  176.                 Key("E", 0x45),                          // 63
  177.                 Key("F", 0x46),                          // 64
  178.                 Key("G", 0x47),                          // 65
  179.                 Key("H", 0x48),                          // 66
  180.                 Key("I", 0x49),                          // 67
  181.                 Key("J", 0x4A),                          // 68
  182.                 Key("K", 0x4B),                          // 69
  183.                 Key("L", 0x4C),                          // 70
  184.                 Key("M", 0x4D),                          // 71
  185.                 Key("N", 0x4E),                          // 72
  186.                 Key("O", 0x4F),                          // 73
  187.                 Key("P", 0x50),                          // 74
  188.                 Key("Q", 0x51),                          // 75
  189.                 Key("R", 0x52),                          // 76
  190.                 Key("S", 0x53),                          // 77
  191.                 Key("T", 0x54),                          // 78
  192.                 Key("U", 0x55),                          // 79
  193.                 Key("V", 0x56),                          // 80
  194.                 Key("W", 0x57),                          // 81
  195.                 Key("X", 0x58),                          // 82
  196.                 Key("Y", 0x59),                          // 83
  197.                 Key("Z", 0x5A),                          // 84
  198.                 Key("Enter", 0x0D),                      // 85
  199. };
  200.  
  201. class AnimatedSprite
  202. {
  203.         int id;
  204.         float frame;
  205.         int frame_count;
  206.         int x;
  207.         int y;
  208.         double anim_speed;
  209.         bool can_reverse;
  210.         bool reverse = false;
  211.         bool visible = true;
  212.         ANIM::Set animSet = ANIM::AMMO;
  213.         SPRITE::Mode spriteMode = SPRITE::NORMAL;
  214.         int spriteModeParam = 123;
  215.         SPRITE::Direction direction = SPRITE::FLIPNONE;
  216.  
  217.         AnimatedSprite(int id, int frame, int x, int y, double anim_speed, bool can_reverse)
  218.         {
  219.                 this.id = id;
  220.                 this.frame = frame;
  221.                 this.x = x;
  222.                 this.y = y;
  223.                 this.anim_speed = anim_speed;
  224.                 this.can_reverse = can_reverse;
  225.                 this.frame_count = jjAnimations[jjAnimSets[animSet].firstAnim + id].frameCount;
  226.         }
  227.  
  228.         void setVisible(bool visible)
  229.         {
  230.                 this.visible = visible;
  231.         }
  232.  
  233.         void setAnimSet(ANIM::Set animSet)
  234.         {
  235.                 this.animSet = animSet;
  236.                 this.frame_count = jjAnimations[jjAnimSets[animSet].firstAnim + id].frameCount;
  237.         }
  238.  
  239.         void setId(uint id)
  240.         {
  241.                 this.id = id;
  242.                 this.frame_count = jjAnimations[jjAnimSets[this.animSet].firstAnim + id].frameCount;
  243.         }
  244.  
  245.         void update()
  246.         {
  247.                 if (this.reverse == false)
  248.                 {
  249.                         this.frame += this.anim_speed;
  250.                 }
  251.                 else
  252.                 {
  253.                         this.frame -= this.anim_speed;
  254.                 }
  255.  
  256.                 if (this.frame > this.frame_count)
  257.                 {
  258.                         if (this.can_reverse == true)
  259.                         {
  260.                                 this.reverse = not this.reverse;
  261.                         }
  262.                         else
  263.                         {
  264.                                 this.frame = 0;
  265.                         }
  266.                 }
  267.  
  268.                 if (this.frame <= 0)
  269.                 {
  270.                         if (this.can_reverse == true)
  271.                         {
  272.                                 this.reverse = not this.reverse;
  273.                         }
  274.                         else
  275.                         {
  276.                                 this.frame = 0;
  277.                         }
  278.                 }
  279.         }
  280.  
  281.         void draw(jjCANVAS @canvas)
  282.         {
  283.                 if (this.visible)
  284.                 {
  285.                         canvas.drawSprite(this.x, this.y, this.animSet, this.id, int(this.frame), this.direction, this.spriteMode, this.spriteModeParam);
  286.                 }
  287.         }
  288. }
  289.  
  290. class Vector2
  291. {
  292.         uint x;
  293.         uint y;
  294.  
  295.         Vector2(int x, int y)
  296.         {
  297.                 this.x = x;
  298.                 this.y = y;
  299.         }
  300.  
  301.         float magnitude(Vector2 @otherVector)
  302.         {
  303.                 return sqrt((this.x + this.y) - (otherVector.x + otherVector.y));
  304.         }
  305. };
  306.  
  307. class Box
  308. {
  309.         uint x;
  310.         uint y;
  311.         uint width;
  312.         uint height;
  313.  
  314.         Box(uint x, uint y, uint width, uint height)
  315.         {
  316.                 this.x = x;
  317.                 this.y = y;
  318.                 this.width = width;
  319.                 this.height = height;
  320.         }
  321.  
  322.         void draw(jjCANVAS @canvas)
  323.         {
  324.                 canvas.drawRectangle(this.x, this.y, this.width, this.height, 0, SPRITE::NORMAL, 0);
  325.         }
  326. }
  327.  
  328. // incomplete
  329. enum RabbitState {
  330.         IDLE,
  331.         WALKING,
  332.         RUNNING,
  333.         JUMPING,
  334.         FALLING,
  335.         DYING,
  336.         DEAD,
  337.         SHOOTING,
  338.         PUSHING,
  339.         HURT
  340. };
  341.  
  342. class RabbitFur {
  343.         // this isn't RGBA but its instead of using "abcd"
  344.         int r, g, b, a;
  345.  
  346.         RabbitFur(int r, int g, int b, int a) {
  347.                 this.r = r;
  348.                 this.g = g;
  349.                 this.b = b;
  350.                 this.a = a;
  351.         }
  352.  
  353.         // use SPRITE::PLAYER and spriteParam as the result
  354.         int emulateFur() {
  355.                 getFreePlayer().furSet(this.r, this.g, this.b, this.a);
  356.  
  357.                 return getFreePlayer().clientID;
  358.         }
  359. }
  360.  
  361. class RabbitNPC {
  362.         RabbitState state;
  363.         string name;
  364.         RabbitFur@ fur;
  365.  
  366.         RabbitNPC(string name, RabbitFur fur) {
  367.                 this.name = name;
  368.                 @this.fur  = fur;
  369.                 this.state = RabbitState::IDLE;
  370.         }
  371. }
  372.  
  373. jjPLAYER@ getFreePlayer() {
  374.         for (int i = 0; i < 32; i++)
  375.         {
  376.                 if (!jjPlayers[i].isActive)
  377.                         return jjPlayers[i];
  378.         }
  379.  
  380.         return jjPlayers[1];
  381. }
  382.  
  383. uint getStringLength(string str)
  384. {
  385.         string str2 = str;
  386.         uint i = 0;
  387.  
  388.         while (i < str2.length())
  389.         {
  390.                 if (str2[i] == "|"[0])
  391.                 {
  392.                         str2 = str2.substr(0, i) + str2.substr(i + 1);
  393.                 }
  394.  
  395.                 i++;
  396.         }
  397.  
  398.         return str2.length();
  399. }
  400.  
  401. uint getStringHeight(string str)
  402. {
  403.         uint height = 0;
  404.  
  405.         for (uint i = 0; i < str.length(); i++)
  406.         {
  407.                 if (str[i] == "@"[0])
  408.                 {
  409.                         height += 1;
  410.                 }
  411.         }
  412.  
  413.         return height * 20;
  414. }
  415.  
  416. bool parseBool(string str)
  417. {
  418.         if (str == "true" || str == "1" || str == "yes")
  419.                 return true;
  420.         return false;
  421. }
  422.  
  423. string formatBool(bool b)
  424. {
  425.         if (b)
  426.                 return "1";
  427.         return "0";
  428. }
  429.  
  430. string formatSize(STRING::Size size)
  431. {
  432.         if(size == STRING::SMALL) return "small";
  433.         if(size == STRING::MEDIUM) return "medium";
  434.         return "large";
  435. }
  436.  
  437. STRING::Size parseSize(string size)
  438. {
  439.         if(size == "small") return STRING::SMALL;
  440.         if(size == "medium") return STRING::MEDIUM;
  441.         return STRING::LARGE;
  442. }
  443.  
  444. string formatBoolToStringInteger(bool b)
  445. {
  446.         if (b)
  447.                 return "1";
  448.         return "0";
  449. }
  450.  
  451. CHAR::Char parseCharacter(string str)
  452. {
  453.         if (str == "SPAZ")
  454.                 return CHAR::SPAZ;
  455.         if (str == "LORI")
  456.                 return CHAR::LORI;
  457.         if (str == "BIRD")
  458.                 return CHAR::BIRD;
  459.         if (str == "FROG")
  460.                 return CHAR::FROG;
  461.         if (str == "BIRD2")
  462.                 return CHAR::BIRD2;
  463.  
  464.         return CHAR::JAZZ;
  465. }
  466.  
  467. string formatCharacter(CHAR::Char charc)
  468. {
  469.         if (charc == CHAR::SPAZ)
  470.                 return "SPAZ";
  471.         if (charc == CHAR::LORI)
  472.                 return "LORI";
  473.         if (charc == CHAR::BIRD)
  474.                 return "BIRD";
  475.         if (charc == CHAR::FROG)
  476.                 return "FROG";
  477.         if (charc == CHAR::BIRD2)
  478.                 return "BIRD2";
  479.  
  480.         return "JAZZ";
  481. }
  482.  
  483. GEM::Color parseGem(string str)
  484. {
  485.         if (str == "GREEN")
  486.                 return GEM::GREEN;
  487.         if (str == "BLUE")
  488.                 return GEM::BLUE;
  489.         if (str == "PURPLE")
  490.                 return GEM::PURPLE;
  491.  
  492.         return GEM::RED;
  493. }
  494.  
  495. string formatGem(GEM::Color g)
  496. {
  497.         if (g == GEM::GREEN)
  498.                 return "GREEN";
  499.         if (g == GEM::BLUE)
  500.                 return "BLUE";
  501.         if (g == GEM::PURPLE)
  502.                 return "PURPLE";
  503.  
  504.         return "RED";
  505. }
  506.  
  507. array<string> cloneStringArray(array<string> arr)
  508. {
  509.         array<string> newArray;
  510.  
  511.         for (uint itemIndex = 0; itemIndex < arr.length; itemIndex++)
  512.         {
  513.                 newArray.insertLast(arr[itemIndex]);
  514.         }
  515.  
  516.         return newArray;
  517. }
  518.  
  519. int boolToInt(bool b)
  520. {
  521.         if (b)
  522.                 return 1;
  523.         else
  524.                 return 0;
  525. }
  526.  
  527. string getPipeColor(int pipeCount)
  528. {
  529.         string color = "white";
  530.  
  531.         switch (pipeCount)
  532.         {
  533.         case 1:
  534.                 color = "green";
  535.                 break;
  536.         case 2:
  537.                 color = "red";
  538.                 break;
  539.         case 3:
  540.                 color = "blue";
  541.                 break;
  542.         case 4:
  543.                 color = "yellow";
  544.                 break;
  545.         case 5:
  546.                 color = "pink";
  547.                 break;
  548.         case 6:
  549.                 color = "white";
  550.                 break;
  551.         case 7:
  552.                 color = "green";
  553.                 break;
  554.         case 8:
  555.                 color = "cyan";
  556.                 break;
  557.         }
  558.  
  559.         return color;
  560. }
  561.  
  562. string restartPipePattern(string str)
  563. {
  564.         // fix this
  565.         // w|g|r|b|y|p|w|g|c|(restart from g)
  566.         // white-green-red-blue-yellow-pink-white(ish)-green-cyan(i think)
  567.  
  568.         int pipeCount = 0;
  569.         string color = "white";
  570.  
  571.         for (uint i = 0; i < str.length(); i++)
  572.         {
  573.                 if (str[i] == "|"[0])
  574.                 {
  575.                         pipeCount += 1;
  576.  
  577.                         if (pipeCount > 8)
  578.                         {
  579.                                 pipeCount = 1;
  580.                         }
  581.                 }
  582.         }
  583.  
  584.         color = getPipeColor(pipeCount);
  585.  
  586.         while (color != "white")
  587.         {
  588.                 str = str + "|";
  589.  
  590.                 pipeCount += 1;
  591.  
  592.                 if (pipeCount > 8)
  593.                 {
  594.                         pipeCount = 1;
  595.                 }
  596.         }
  597.  
  598.         return str;
  599. }
  600.  
  601. Key @isAnyKeyDown()
  602. {
  603.         Key @keyThatIsDown;
  604.  
  605.         for (uint i = 0; i < KEYS.length() - 1; i++)
  606.         {
  607.                 Key @key = KEYS[i];
  608.  
  609.                 if (jjKey[key.code])
  610.                 {
  611.                         @keyThatIsDown = key;
  612.                 }
  613.         }
  614.  
  615.         return keyThatIsDown;
  616. }
  617.  
  618. bool isKeyDown(Key @key)
  619. {
  620.         return jjKey[key.code];
  621. }
  622.  
  623. Key @getKeyById(string id)
  624. {
  625.         Key @foundKey;
  626.  
  627.         for (uint i = 0; i < KEYS.length() - 1; i++)
  628.         {
  629.                 Key @key = KEYS[i];
  630.  
  631.                 if (key.id == id)
  632.                 {
  633.                         @foundKey = key;
  634.                         break;
  635.                 }
  636.         }
  637.  
  638.         return foundKey;
  639. }
  640.  
  641. int getRandomNumber(int min, int max)
  642. {
  643.         int num = stvutilRNG();
  644.  
  645.         if (num < 0)
  646.                 num *= -1;
  647.  
  648.         num = (num % (max - min + 1)) + min;
  649.  
  650.         return num;
  651. }
  652.  
  653. int getPlayerCount()
  654. {
  655.         int count = 0;
  656.  
  657.         for (int i = 0; i < 32; i++)
  658.         {
  659.                 if (jjPlayers[i].isActive)
  660.                         count++;
  661.         }
  662.  
  663.         return count;
  664. }
  665.  
  666. jjPLAYER @getRandomPlayer()
  667. {
  668.         jjPLAYER @user = jjPlayers[getRandomNumber(0, getPlayerCount())];
  669.  
  670.         if (user.isActive and !user.isOut)
  671.                 return user;
  672.         else
  673.                 return getRandomPlayer();
  674. }
  675.  
  676. funcdef void KeyPressCallback(uint);
  677.  
  678. array<bool> prevKeys(256, false);
  679. array<KeyPressCallback@> keyPressCallbacks;
  680.  
  681. void updateKeys()
  682. {
  683.     for (uint keyCode = 0; keyCode < 256; keyCode++)
  684.     {
  685.         if (jjKey[keyCode] && !prevKeys[keyCode])
  686.         {
  687.             for (uint i = 0; i < keyPressCallbacks.length; i++)
  688.             {
  689.                 keyPressCallbacks[i](keyCode);
  690.             }
  691.         }
  692.  
  693.         prevKeys[keyCode] = jjKey[keyCode];
  694.     }
  695. }