jellyfishswim.lslp 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /*
  2. * Part of the Sloodle project (www.sloodle.org)
  3. *
  4. * Copyright (c) 2011-06 contributors (see below)
  5. * Released under the GNU GPL v3
  6. * -------------------------------------------
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. * All scripts must maintain this copyrite information, including the contributer information listed
  22. *
  23. * Contributors:
  24. * Paul Preibisch
  25. *
  26. * DESCRIPTION
  27. * Contributors:
  28. * Edmund Edgar
  29. * Paul Preibisch
  30. *
  31. * SND_JELLY_APPROACH - was mashed up from: http://www.freesound.org/people/suonho/ under the sampling license: http://creativecommons.org/licenses/sampling+/1.0/
  32. */
  33. // bending fish
  34. // 2007 Copyright by Shine Renoir (fb@frank-buss.de)
  35. //
  36. // The center position is stored on rez.
  37. // maximum swim radius from last center
  38. float radius = 6.0;
  39. // maximum swim distance for swimming up or down from last center
  40. float height = 1.0;
  41. // delay in seconds for next movement
  42. float delay = 3.0;
  43. list colors;
  44. // internal channel for communication
  45. integer CHANNEL = -87;
  46. integer MAX=30;
  47. // last center position
  48. vector center;
  49. integer target_id;
  50. list screams;
  51. float randBetween(float min, float max)
  52. {
  53. return llFrand(max - min) + min;
  54. }
  55. blood(key av){
  56. llMessageLinked(LINK_SET, BLOOD, "", av);
  57. }
  58. noblood(){
  59. llMessageLinked(LINK_SET, NOBLOOD, "", NULL_KEY);
  60. }
  61. integer BLOOD=-999922110;
  62. integer NOBLOOD=-999922111;
  63. init()
  64. {
  65. llSetPrimitiveParams([ PRIM_PHYSICS, TRUE]);
  66. llSetStatus(STATUS_ROTATE_X, FALSE);
  67. llSetStatus(STATUS_ROTATE_Y, FALSE);
  68. float t = llSqrt(2.0) / 2.0;
  69. llSetRot(<0, 0, 0, 0>);
  70. llSetBuoyancy(0.9);
  71. llSetTimerEvent(delay);
  72. }
  73. integer counter =0;
  74. vector deathTarget;
  75. key deathKey;
  76. integer attackTimes=0;
  77. integer screamCounter=0;
  78. vector RED =<1.00000, 0.00000, 0.00000>;
  79. vector ORANGE=<1.00000, 0.43763, 0.02414>;
  80. vector YELLOW=<1.00000, 1.00000, 0.00000>;
  81. vector GREEN=<0.00000, 1.00000, 0.00000>;
  82. vector BLUE=<0.00000, 0.00000, 1.00000>;
  83. vector BABYBLUE=<0.00000, 1.00000, 1.00000>;
  84. vector PINK=<1.00000, 0.00000, 1.00000>;
  85. vector PURPLE=<0.57338, 0.25486, 1.00000>;
  86. vector BLACK= <0.00000, 0.00000, 0.00000>;
  87. vector WHITE= <1.00000, 1.00000, 1.00000>;
  88. vector AVCLASSBLUE= <0.06274,0.247058,0.35294>;
  89. vector AVCLASSLIGHTBLUG=<0.8549,0.9372,0.9686>;//#daeff7
  90. vector getColor(){
  91. list colors=[RED,ORANGE,YELLOW,BLUE,BABYBLUE,PINK,PURPLE];
  92. colors = llListRandomize(colors, 1);
  93. return llList2Vector(colors,0);
  94. }
  95. //returns a random scream sound
  96. string getScream(){
  97. screams = ["scream1","scream2","scream3","scream4"];
  98. integer screamLen = llGetListLength(screams);
  99. screamCounter++;
  100. if (screamCounter>screamLen-1){
  101. screamCounter=0;
  102. }
  103. return llList2String(screams,screamCounter);
  104. }
  105. changeColor(vector color, float alpha, float glow){
  106. integer num = llGetNumberOfPrims();
  107. integer j;
  108. for (j=0;j<num;j++){
  109. llSetLinkPrimitiveParamsFast(j,[PRIM_COLOR,ALL_SIDES,color,alpha,
  110. PRIM_GLOW, ALL_SIDES, glow]);
  111. }
  112. llMessageLinked(LINK_SET, -99, "SET ALPHA|"+(string)alpha, NULL_KEY);
  113. }
  114. default{
  115. state_entry(){
  116. llSetPrimitiveParams([ PRIM_PHYSICS, FALSE]);
  117. noblood();
  118. counter=0;
  119. llSetTimerEvent(3);
  120. }
  121. on_rez(integer start_param) {
  122. llResetScript();
  123. }
  124. timer() {
  125. state myPos;
  126. }
  127. }
  128. state myPos{
  129. state_entry() {
  130. center = llGetPos();
  131. state ready;
  132. }
  133. on_rez(integer start_param) {
  134. llResetScript();
  135. }
  136. }
  137. state before_ready{
  138. state_entry() {
  139. state ready;
  140. }
  141. }
  142. state ready{
  143. on_rez(integer start_param) {
  144. llResetScript();
  145. }
  146. state_entry() {
  147. llParticleSystem([]);
  148. changeColor(getColor(),1,0);
  149. noblood();
  150. deathKey=NULL_KEY;
  151. deathTarget = ZERO_VECTOR;
  152. llSetText("", <0,0,1>, 1);
  153. llSensorRepeat("", "", AGENT, 5, PI,5);
  154. init();
  155. llMoveToTarget(center, 1);
  156. }
  157. sensor(integer num_detected) {
  158. deathTarget = llDetectedPos(0);
  159. deathKey = llDetectedKey(0);
  160. vector pos = llGetPos();
  161. vector delta = pos - deathTarget;
  162. float angle = llAtan2(delta.y, delta.x) + PI / 2.0;
  163. rotation rot = llEuler2Rot(<0, 0, angle>);
  164. llRotLookAt(rot, 1.0, 1.0);
  165. state attack;
  166. }
  167. link_message(integer sender_num, integer num, string str, key id) {
  168. if (num==-99){
  169. if (str=="DEAD"){
  170. llSleep(10);
  171. llSetTimerEvent(0);
  172. state before_ready;
  173. }
  174. }
  175. }
  176. timer()
  177. {
  178. // get current position
  179. vector pos = llGetPos();
  180. // calculate random next position
  181. vector dest = pos;
  182. dest.x += randBetween(-radius, radius);
  183. dest.y += randBetween(-radius, radius);
  184. // dest.z += randBetween(-radius, height);
  185. // move to center, if outside radius
  186. integer i;
  187. for (i = 0; i < 3; i++) {
  188. if (llVecMag(dest - center) > radius) {
  189. dest = (dest - pos) / 2.0 + pos;
  190. }
  191. }
  192. // fallback: if other objects pushes the fish, move back to center
  193. if (llVecMag(dest - center) > radius) {
  194. dest = center;
  195. }
  196. // calculate new rotation and move to target
  197. vector delta = pos - dest;
  198. float angle = llAtan2(delta.y, delta.x) + PI / 2.0;
  199. rotation rot = llEuler2Rot(<0, 0, angle>);
  200. llRotLookAt(rot, 1.0, 1.0);
  201. llMoveToTarget(dest, 2);
  202. }
  203. }
  204. state attack{
  205. on_rez(integer start_param) {
  206. llResetScript();
  207. }
  208. state_entry() {
  209. attackTimes = 0;
  210. target_id = llTarget(deathTarget, 0.5);
  211. llTriggerSound("SND_JELLY_APPROACH", 1);
  212. llMoveToTarget(deathTarget, 0.1);
  213. llSensorRepeat("", "", AGENT, 10, PI,1);
  214. llSetTimerEvent(10);
  215. }
  216. sensor(integer num_detected) {
  217. deathTarget =llDetectedPos(0);
  218. deathKey = llDetectedKey(0);
  219. target_id = llTarget(deathTarget, 0.5);
  220. vector pos = llGetPos();
  221. vector delta = pos - deathTarget;
  222. float angle = llAtan2(delta.y, delta.x) + PI / 2.0;
  223. rotation rot = llEuler2Rot(<0, 0, angle>);
  224. llRotLookAt(rot, 1.0, 1.0);
  225. llLookAt( deathTarget + <0.0, 0.0, 1.0>, 3.0, 1.0 );
  226. llMoveToTarget(deathTarget, 0.5);
  227. }
  228. link_message(integer sender_num, integer num, string str, key id) {
  229. if (num==-99){
  230. if (str=="DEAD"){
  231. llSleep(10);
  232. llSetTimerEvent(0);
  233. state ready;
  234. }
  235. }
  236. }
  237. timer() {
  238. llSetTimerEvent(0);
  239. integer i;
  240. // get current position
  241. vector pos = llGetPos();
  242. // calculate random next position
  243. vector dest = pos;
  244. for (i = 0; i < 3; i++) {
  245. if (llVecMag(dest - center) > radius) {
  246. dest = (dest - pos) / 2.0 + pos;
  247. }
  248. }
  249. // fallback: if other objects pushes the fish, move back to center
  250. if (llVecMag(dest - center) > radius) {
  251. dest = center;
  252. }
  253. // calculate new rotation and move to target
  254. vector delta = pos - dest;
  255. float angle = llAtan2(delta.y, delta.x) + PI / 2.0;
  256. rotation rot = llEuler2Rot(<0, 0, angle>);
  257. llRotLookAt(rot, 1.0, 1.0);
  258. llMoveToTarget(dest, 2);
  259. state ready;
  260. }
  261. at_target(integer tnum, vector targetpos, vector ourpos)
  262. {
  263. if (tnum == target_id)
  264. {
  265. llTriggerSound(getScream(), 0.3);
  266. llTriggerSound("SND_JELLY_ATTACK", 0.5);
  267. attackTimes++;
  268. changeColor(WHITE,1,0.2);
  269. blood(deathKey);
  270. llPushObject(deathKey,<5,5,5>, <5,5,5>, TRUE);
  271. llTargetRemove(target_id);
  272. if (attackTimes>5) {
  273. attackTimes= 0;
  274. state ready;
  275. }
  276. }
  277. }
  278. }
  279. // Please leave the following line intact to show where the script lives in Git:
  280. // SLOODLE LSL Script Git Location: mod/interaction-1.0/objects/jellyfish/assets/jellyfishswim.lslp