Guest User

Untitled

a guest
Feb 4th, 2013
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.74 KB | None | 0 0
  1. #TouhouDanmakufu
  2. #Title[Profielwerkstuk 1]
  3. #Text[(easy)]
  4. #Player[FREE]
  5. #ScriptVersion[2]
  6.  
  7. script_enemy_main{
  8.  
  9. let CSD = GetCurrentScriptDirectory;
  10.  
  11. let imgBoss = CSD ~ "img/Death Ball.png";
  12. let bg = CSD ~ "img/Stars.png";
  13.  
  14. let slide = 0;
  15.  
  16. @Initialize{
  17. SetLife(1000);
  18. SetTimer(60);
  19. SetScore(100000);
  20. SetMovePosition01(GetCenterX,GetCenterY,5);
  21.  
  22. LoadGraphic(imgBoss);
  23. LoadGraphic(bg);
  24.  
  25. CutIn(YOUMU,"Wind Bullets - easy -",imgBoss,0,0,100,100);
  26.  
  27. LoadMusic(CSD ~ "bgm\Bad Situation.mp3");
  28. PlayMusic(CSD ~ "bgm\Bad Situation.mp3");
  29.  
  30. mainTask;
  31.  
  32. }
  33.  
  34. @MainLoop{
  35. SetCollisionA(GetX,GetY,50);
  36. SetCollisionB(GetX,GetY,40);
  37.  
  38. yield;
  39. }
  40.  
  41. @DrawLoop{
  42.  
  43. SetTexture(imgBoss);
  44. SetRenderState(ALPHA);
  45. SetAlpha(255);
  46. SetGraphicRect(0,0,100,100);
  47. SetGraphicScale(1,1);
  48. SetGraphicAngle(0,0,0);
  49. DrawGraphic(GetX,GetY);
  50.  
  51. }
  52.  
  53. @BackGround{
  54.  
  55. SetTexture(bg);
  56. SetRenderState(ALPHA);
  57. SetAlpha(255);
  58. SetGraphicRect(0,0-slide,512,512-slide);
  59. SetGraphicScale(1,1);
  60. SetGraphicAngle(0,0,0);
  61. DrawGraphic(GetCenterX,GetCenterY);
  62.  
  63. slide +=2;
  64. }
  65.  
  66. @Finalize{
  67.  
  68. DeleteGraphic(imgBoss);
  69. DeleteGraphic(bg);
  70.  
  71.  
  72. }
  73.  
  74. task mainTask{
  75. yield;
  76. hypocycloid2(GetEnemyX,GetEnemyY,100,0.7,0.8); //Hypocycloid with radius 100, the final
  77. //two numbers are shape modifiers
  78. movement;
  79. }
  80.  
  81. task movement{ //moves the boss around
  82. loop{
  83. SetMovePosition01(GetCenterX-100,120,5);
  84. wait(120);
  85. SetMovePosition01(GetCenterX+100,120,5);
  86. wait(120);
  87. yield;
  88. }
  89. }
  90.  
  91. task hypocycloid2(a,b,r,k,l){
  92. loop{
  93. //First make sure k has only one decimal space and is between 0 and 1
  94.  
  95. k = absolute(trunc(10*k)/10 - trunc(k));
  96.  
  97. //Calculate the limit for the amount of points to spawn. The arc length of the
  98. //shape is dependant on the value f the smallest nominator of the fraction of k
  99. //ToFractionNom and ToFractionDeNom return the nominator and the denominator of
  100. //that fraction, respectively, while the division by their GCD or Greatest
  101. //Common Divisor makes sure it's in its most simplified form. Then multiply by
  102. //a full circle since this value is the amount of turns it has to make.
  103. //For example, k = 3/7 would simply return 3 while k = 0.4 would return 2 since
  104. //k = 0.4 = 4/10 = 2/5.
  105.  
  106. let limit = 360 * (ToFractionNom(k) / GCD(ToFractionNom(k), ToFractionDeNom(k)));
  107. let t = 0;
  108.  
  109. //Makes sure 100 bullets are distributed along the shape. This, along with the
  110. //former ensures that no matter what values you take the generation speed won't
  111. //differ significantly.
  112.  
  113. loop(100){
  114. t += limit/100;
  115.  
  116. //The formulas themselves. These aren't like the normal Hypocycloid ones,
  117. //which I'm aware of, but when testing with an immobile shape this did
  118. //exactly what I expected it to do.
  119.  
  120. let x = a + r * ( (1 - k) * cos(t) + l * k * cos((1 - k) / k * t));
  121. let y = b + r * ( (1 - k) * sin(t) - l * k * sin((1 - k) / k * t));
  122. RotatingBullet(x, y, 3, GetAngleToPlayer, RED01);
  123.  
  124. //This is embedded within the Hypocycloid task and the loop to enable
  125. //me to pass several values to it, most notably the center coordinates of
  126. //the spirograph.
  127.  
  128. task RotatingBullet(x, y, v, angle, graphic) {
  129. let obj=Obj_Create(OBJ_SHOT);
  130.  
  131. Obj_SetPosition(obj, x, y);
  132. Obj_SetAngle(obj, angle);
  133. Obj_SetSpeed(obj, v);
  134. ObjShot_SetGraphic(obj, graphic);
  135. ObjShot_SetDelay (obj, 0);
  136. ObjShot_SetBombResist (obj, true);
  137.  
  138. //atan3 does the same as atan, with the difference that it
  139. //requires x and y like atan2 but handles degenerate cases like
  140. //x = 0 and y = 0 properly. This angle is required to make sure
  141. //that not all bullets will start at an angle of 0, which would
  142. //make it a dense rotating line instead of a shape.
  143.  
  144. let angle = atan3(x-a,y-b);
  145. let t2 = 0;
  146.  
  147. //This is just the distance from the center of the spirograph
  148. //(a,b) to the bullet (x,y) which will become the radius of its
  149. //rotation around (a,b)
  150.  
  151. let r = ((x-a)^2 + (y-b)^2)^0.5;
  152. while(Obj_BeDeleted(obj)==false) {
  153. t2 += 1;
  154.  
  155. //Makes the shape move downwards. No idea why this value
  156. //has to be this low, but b += 1 was enough to make the
  157. //shape zip past in a single frame.
  158. //Perhaps this is part of the problem?
  159.  
  160. b += 0.01;
  161.  
  162. //Describes the circular motion of the bullet. Pretty
  163. //straightforward.
  164.  
  165. x = a + r * cos(t2 + angle);
  166. y = b + r * sin(t2 + angle);
  167. Obj_SetPosition(obj, x, y);
  168. yield;
  169. }
  170. }
  171. }
  172. wait(300);
  173. }
  174. }
  175.  
  176. //Speaks for itself, I think. What it does exactly has been described above already.
  177.  
  178. function atan3(x,y){
  179. if ( x == 0 && y == 0 ){
  180. break;
  181. }
  182. if ( x == 0 ){
  183. if ( y > 0 ){
  184. return 90;
  185. }else{
  186. return 270;
  187. }
  188. }
  189. if ( y == 0 ){
  190. if ( x > 0 ){
  191. return 0;
  192. }else{
  193. return 180;
  194. }
  195. }
  196. let a = atan(y/x);
  197. if ( x < 0 ){a = -a;}
  198. return a;
  199. }
  200.  
  201. //Using Eulers formula. Tried doing some simple GCD's by hand and it worked perfectly.
  202.  
  203. function GCD(a,b){
  204. let c;
  205. loop{
  206. if ( b == 0 ){return a;}
  207. c = b;
  208. b = a % b;
  209. a = c;
  210. }
  211. }
  212.  
  213. //Returns the nominator of the value a. Keeps shifting the decimal point until the value equals
  214. //itself truncated, which means it doesn't have any decimal part anymore.
  215.  
  216. function ToFractionNom(a){
  217. loop{
  218. a *= 10;
  219. if( a == trunc(a) ){return a;}
  220. }
  221. }
  222.  
  223. //Same as the above, just returns the denominator instead of the nominator.
  224.  
  225. function ToFractionDeNom(a){
  226. let b = 1;
  227. loop{
  228. a *= 10;
  229. b *= 10;
  230. if( a == trunc(a) ){return b;}
  231. }
  232. }
  233.  
  234. //wait function
  235. function wait (w){
  236. loop(w){yield;}
  237. }
  238. }
Advertisement
Add Comment
Please, Sign In to add comment