Advertisement
Xplosive_

Ghost v3

Apr 15th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var rate = Math.pow(Math.round(World.frameRate * 0.01) + 60,1)
  2. Enem = ["AlienP","AlienY","AlienT","AlienG","AlienB"]
  3. EnemSize = ["0.5","0.6","0.7","0.8","0.9","1"]
  4. spawnarea = ["-30","30"]
  5. var Background = createSprite(200,200)
  6. var Ghost = createSprite(200,200);
  7. var Score = createSprite(65,65)
  8. Score.scale = 0.8
  9. Score.setAnimation("Lives3")
  10. z = 0
  11. y = 0
  12. Ghost.setAnimation("ghostNeutral")
  13. Fdir = "N"
  14. var Invis = "false"
  15. var Shot = "false"
  16. var ShotT = "False"
  17. Run()
  18. draw()
  19. function draw(){
  20. World.frameRate = rate
  21. if (e > 4)
  22. {var vel12 = "8"}
  23. else if (e > 6)  
  24. {var vel12 = "10"}
  25. else if (e > 8)
  26. {var vel12 = "12"}
  27. else
  28. {var vel12 = "5"}
  29. if (e > 15)
  30. {var vel12N = "-3"}
  31. else if (e > 23)  
  32. {var vel12N = "-4"}
  33. else if (e > 26)
  34. {var vel12N = "-5"}
  35. else
  36. {var vel12N = "-4"
  37. var vel12 = "6"}
  38. GX = Ghost.x;
  39. GY = Ghost.y;
  40. EnemPick =  randomNumber(0,4)
  41. SizePick =  randomNumber(0,5)
  42. VelPicked = randomNumber(2,vel12)
  43. SizePicked = EnemSize[SizePick]
  44. EnemPicked = Enem[EnemPick]
  45. EnemLoc =  randomNumber(0,400)
  46. EnemPick1 =  randomNumber(0,4)
  47. SizePick1 =  randomNumber(0,5)
  48. SizePicked1 = EnemSize[SizePick1]
  49. EnemPicked1 = Enem[EnemPick1]
  50. EnemLoc1 =  randomNumber(0,400)
  51. VelPicked1 = randomNumber(2,vel12)
  52. EnemPick2 =  randomNumber(0,4)
  53. SizePick2 =  randomNumber(0,5)
  54. SizePicked2 = EnemSize[SizePick2]
  55. EnemPicked2 = Enem[EnemPick2]
  56. EnemLoc2 =  randomNumber(0,400)
  57. VelPicked2 = randomNumber(2,vel12)
  58. EnemPick3 =  randomNumber(0,4)
  59. SizePick3 =  randomNumber(0,5)
  60. SizePicked3 = EnemSize[SizePick3]
  61. EnemPicked3 = Enem[EnemPick3]
  62. EnemLoc3 =  randomNumber(0,400)
  63. VelPicked3 = randomNumber(-3,vel12N)
  64. EnemPick4 =  randomNumber(0,4)
  65. SizePick4 =  randomNumber(0,5)
  66. SizePicked4 = EnemSize[SizePick4]
  67. EnemPicked4 = Enem[EnemPick4]
  68. EnemLoc4 =  randomNumber(0,400)
  69. VelPicked4 = randomNumber(-3,vel12N)
  70. EnemPick5 =  randomNumber(0,4)
  71. SizePick5 =  randomNumber(0,5)
  72. SizePicked5 = EnemSize[SizePick5]
  73. EnemPicked5 = Enem[EnemPick5]
  74. EnemLoc5 =  randomNumber(0,400)
  75. VelPicked5 = randomNumber(-3,vel12N)
  76. if (GX > 375) { Ghost.velocityX = 0; Ghost.x = GX - 1.5}
  77. if (GY > 370) { Ghost.velocityY = 0; Ghost.y = GY - 1.5}
  78. if (GX < 25 ) { Ghost.velocityX = 0; Ghost.x = GX + 1.5}
  79. if (GY < 30 ) { Ghost.velocityY = 0; Ghost.y = GY + 1.5}
  80. drawSprites()
  81. Background.setAnimation("Background")
  82. Background.scale = 0.53
  83. if (keyWentDown("W")){var Direction = "Wdown"} else if (keyWentUp("W")){var Direction = "Wup"}
  84. if (keyWentDown("S")){var Direction = "Sdown"} else if (keyWentUp("S")){var Direction = "Sup"}
  85. if (keyWentDown("A")){var Direction = "Adown"} else if (keyWentUp("A")){var Direction = "Aup"}
  86. if (keyWentDown("D")){var Direction = "Ddown"} else if (keyWentUp("D")){var Direction = "Dup"}
  87. if (keyWentDown("space")){var ShotN = "true"} else {ShotN = "false"}
  88. if (keyWentDown("up")){ ShotD = "up"; ShotT = "True"}
  89. if (keyWentDown("down")){ ShotD = "down"; ShotT = "True"}
  90. if (keyWentDown("left")){ ShotD = "left"; ShotT = "True"}
  91. if (keyWentDown("right")){ ShotD = "right"; ShotT = "True"}
  92. if (keyWentDown("q")){var Invis = "true"} else {Invis = "false"}
  93. switch(Direction){ case "undefined":  Fdir = "N"}
  94. switch(Direction){ case "Wdown": Ghost.velocityY = -4.5; Fdir = "U"}
  95. switch(Direction){ case "Wup": Ghost.velocityY = 0; Fdir = "N"}
  96. switch(Direction){ case "Sdown": Ghost.velocityY = 4.5; Fdir = "D" }
  97. switch(Direction){ case "Sup": Ghost.velocityY = 0; Fdir = "N"}
  98. switch(Direction){ case "Adown": Ghost.velocityX = -4.5; Fdir = "L"}
  99. switch(Direction){ case "Aup":  Ghost.velocityX = 0; Fdir = "N"}
  100. switch(Direction){ case "Ddown": Ghost.velocityX = 4.5; Fdir = "R"}
  101. switch(Direction){ case "Dup": Ghost.velocityX = 0; Fdir = "N"}
  102. switch(Fdir){case "L": Ghost.setAnimation("ghostLeft") }
  103. switch(Fdir){case "R": Ghost.setAnimation("ghostRight") }
  104. switch(Fdir){case "U": Ghost.setAnimation("ghostUp") }
  105. switch(Fdir){case "D": Ghost.setAnimation("ghostDown") }
  106. switch(Fdir){case "N": Ghost.setAnimation("ghostNeutral") }
  107. switch(ShotT) {
  108. case "True":
  109. if (ShotN == "true"){
  110. if (ShotD == "up"){ShootUp(); }
  111. if (ShotD == "down"){ShootDown();}  
  112. if (ShotD == "left"){ShootLeft();}
  113. if (ShotD == "right"){ShootRight();}
  114. }
  115. break;
  116. case "False":
  117. }
  118. switch(Invis){
  119. case "false":
  120. break;
  121. case "true":
  122. Ghost.tint = "Cyan"
  123. setTimeout(function(){Ghost.tint = "none"},2000)
  124. }
  125. }
  126. spawner();
  127. ShootUp();
  128. Shot1.destroy()
  129. ShootDown();
  130. Shot2.destroy()
  131. ShootLeft();
  132. Shot3.destroy()
  133. ShootRight();
  134. Shot4.destroy()
  135. function ShootUp(){
  136. Shot1 = createSprite(GX,GY)
  137. Shot1.setAnimation("Shot")
  138. Shot1.velocityY = -6
  139. Shot1.scale =  0.4
  140. drawSprites()
  141. }
  142. function ShootDown(){
  143. Shot2 = createSprite(GX,GY)
  144. Shot2.setAnimation("Shot")
  145. Shot2.velocityY = 5
  146. Shot2.scale =  0.4
  147. drawSprites()
  148. }
  149. function ShootLeft(){
  150. Shot3 = createSprite(GX,GY)
  151. Shot3.setAnimation("Shot")
  152. Shot3.velocityX = -5
  153. Shot3.scale =  0.4
  154. drawSprites()
  155. }
  156. function ShootRight(){
  157. Shot4 = createSprite(GX,GY)
  158. Shot4.setAnimation("Shot")
  159. Shot4.velocityX = 5
  160. Shot4.scale =  0.4
  161. drawSprites()
  162. }
  163. spawner();
  164. setInterval(spawner,1000)
  165. setInterval(spawn,TimeSpawn)
  166. spawn()
  167. function spawner(){
  168. TimeSpawn =  5000 - World.seconds * 35.5
  169. if ( 5000 - World.seconds * 95.5 < 1000)
  170. {TimeSpawn = 1500;}
  171. else
  172. {TimeSpawn =  5000 - World.seconds * 35.5
  173. }
  174. }
  175. Run()
  176. function spawn(){
  177.   if (e > 1){
  178. var life = 300
  179. } else {
  180.   var life = 0}
  181. if (e > 3) {
  182. var life1 = 300
  183. } else {
  184. var life1 = 0
  185. }
  186. if (e > 13) {
  187. var life2 = 300  
  188. } else {
  189.   life2 = 0
  190. }
  191. if (e > 16) {
  192. var life3 = 300  
  193. } else {
  194. var life3 = 0
  195. }
  196. if (e > 20){
  197.   var life4 = 300
  198. }else {
  199.   var life4 = 0
  200. }
  201. Enemy1 = createSprite(-30,EnemLoc)
  202. Enemy1.setAnimation(EnemPicked);
  203. Enemy1.velocityX = VelPicked;
  204. Enemy1.scale = SizePicked;
  205. Enemy1.lifetime = 300;
  206. Enemy2 = createSprite(-30,EnemLoc1);
  207. Enemy2.setAnimation(EnemPicked1);
  208. Enemy2.velocityX = VelPicked1;
  209. Enemy2.scale = SizePicked1;
  210. Enemy2.lifetime = life;
  211. Enemy3 = createSprite(-30,EnemLoc1);
  212. Enemy3.setAnimation(EnemPicked1);
  213. Enemy3.velocityX = VelPicked1;
  214. Enemy3.scale = SizePicked1;
  215. Enemy3.lifetime = life1;
  216. Enemy4 = createSprite(430,EnemLoc3);
  217. Enemy4.setAnimation(EnemPicked3);
  218. Enemy4.velocityX = VelPicked3;
  219. Enemy4.scale = SizePicked3;
  220. Enemy4.lifetime = life2;
  221. Enemy5 = createSprite(430,EnemLoc4);
  222. Enemy5.setAnimation(EnemPicked4);
  223. Enemy5.velocityX = VelPicked4;
  224. Enemy5.scale = SizePicked4;
  225. Enemy5.lifetime = life3;
  226. Enemy6 = createSprite(430,EnemLoc5);
  227. Enemy6.setAnimation(EnemPicked5);
  228. Enemy6.velocityX = VelPicked5;
  229. Enemy6.scale = SizePicked5;
  230. Enemy6.lifetime = life4;
  231. }
  232. setInterval(function(){
  233. if (Enemy1.isTouching(Ghost) || Enemy2.isTouching(Ghost)  || Enemy3.isTouching(Ghost) || Enemy4.isTouching(Ghost) || Enemy5.isTouching(Ghost) || Enemy6.isTouching(Ghost)){
  234. l = z++
  235. if (Enemy1.isTouching(Ghost)){Enemy1.destroy()}
  236. if (Enemy2.isTouching(Ghost)){Enemy2.destroy()}
  237. if (Enemy3.isTouching(Ghost)){Enemy3.destroy()}
  238. if (Enemy4.isTouching(Ghost)){Enemy4.destroy()}
  239. if (Enemy5.isTouching(Ghost)){Enemy5.destroy()}
  240. if (Enemy6.isTouching(Ghost)){Enemy6.destroy()}
  241. if (l == 0) {
  242. Score.setAnimation("Lives2");
  243. }
  244. if (l == 1){
  245. Score.setAnimation("Lives1");
  246. }
  247. if (l == 2){
  248. Score.setAnimation("Lives0");
  249. gameover()
  250. }
  251. function gameover(){
  252. var gameover = createSprite(200,200);
  253. gameover.scale = 1.5;
  254. gameover.setAnimation("Gameover")
  255. Ghost.destroy();
  256. setInterval(function(){Enemy1.destroy(); Enemy1.destroy(); Enemy1.destroy(); Enemy1.velocityX = 0; Enemy1.lifetime = 0; Enemy1.scale = 0.01; Ghost.velocityX = 0; Ghost.velocityY = 0;},0)
  257. setInterval(function(){Enemy2.destroy(); Enemy2.destroy(); Enemy2.destroy(); Enemy2.velocityX = 0; Enemy2.lifetime = 0; Enemy2.scale = 0.01; Ghost.velocityX = 0; Ghost.velocityY = 0;},0)
  258. setInterval(function(){Enemy3.destroy(); Enemy3.destroy(); Enemy3.destroy(); Enemy3.velocityX = 0; Enemy3.lifetime = 0; Enemy3.scale = 0.01; Ghost.velocityX = 0; Ghost.velocityY = 0;},0)
  259. setInterval(function(){Enemy4.destroy(); Enemy4.destroy(); Enemy4.destroy(); Enemy4.velocityX = 0; Enemy4.lifetime = 0; Enemy4.scale = 0.01; Ghost.velocityX = 0; Ghost.velocityY = 0;},0)
  260. setInterval(function(){Enemy5.destroy(); Enemy5.destroy(); Enemy5.destroy(); Enemy5.velocityX = 0; Enemy5.lifetime = 0; Enemy5.scale = 0.01; Ghost.velocityX = 0; Ghost.velocityY = 0;},0)
  261. setInterval(function(){Enemy6.destroy(); Enemy6.destroy(); Enemy6.destroy(); Enemy6.velocityX = 0; Enemy6.lifetime = 0; Enemy6.scale = 0.01; Ghost.velocityX = 0; Ghost.velocityY = 0;},0)  
  262. }}},0)
  263. setInterval(function(){
  264. if(Shot3.x < 5|| Shot4.x > 395){
  265. Shot3.destroy()  
  266. Shot4.destroy()
  267. }
  268. if(Enemy1.isTouching(Shot1) || Enemy1.isTouching(Shot2) || Enemy1.isTouching(Shot3) || Enemy3.isTouching(Shot4) ){Shot1.destroy(); Shot2.destroy(); Shot3.destroy(); Shot4.destroy(); Enemy1.velocityX = "0"; Enemy1.tint = "red"; setTimeout(function() {Enemy1.destroy(); PointAdd() },320); }
  269. if(Enemy2.isTouching(Shot1) || Enemy2.isTouching(Shot2) || Enemy2.isTouching(Shot3) || Enemy2.isTouching(Shot4) ){Shot1.destroy(); Shot2.destroy(); Shot3.destroy(); Shot4.destroy(); Enemy2.velocityX = "0"; Enemy2.tint = "red"; setTimeout(function() {Enemy2.destroy(); PointAdd() },320);  }
  270. if(Enemy3.isTouching(Shot1) || Enemy3.isTouching(Shot2) || Enemy3.isTouching(Shot3) || Enemy3.isTouching(Shot4) ){Shot1.destroy(); Shot2.destroy(); Shot3.destroy(); Shot4.destroy(); Enemy3.velocityX = "0"; Enemy3.tint = "red"; setTimeout(function() {Enemy3.destroy(); PointAdd() },320);  }
  271. if(Enemy4.isTouching(Shot1) || Enemy4.isTouching(Shot2) || Enemy4.isTouching(Shot3) || Enemy4.isTouching(Shot4) ){Shot1.destroy(); Shot2.destroy(); Shot3.destroy(); Shot4.destroy(); Enemy4.velocityX = "0"; Enemy4.tint = "red"; setTimeout(function() {Enemy4.destroy(); PointAdd() },320); }
  272. if(Enemy5.isTouching(Shot1) || Enemy5.isTouching(Shot2) || Enemy5.isTouching(Shot3) || Enemy5.isTouching(Shot4) ){Shot1.destroy(); Shot2.destroy(); Shot3.destroy(); Shot4.destroy(); Enemy5.velocityX = "0"; Enemy5.tint = "red"; setTimeout(function() {Enemy5.destroy(); PointAdd() },320); }
  273. if(Enemy6.isTouching(Shot1) || Enemy6.isTouching(Shot2) || Enemy6.isTouching(Shot3) || Enemy6.isTouching(Shot4) ){Shot1.destroy(); Shot2.destroy(); Shot3.destroy(); Shot4.destroy(); Enemy6.velocityX = "0"; Enemy6.tint = "red"; setTimeout(function() {Enemy6.destroy(); PointAdd() },320); }  
  274. },0)
  275. var Score1 = ["","Points1","Points2","Points3","Points4","Points5","Points6","Points7","Points8","Points9"];
  276. var score = createSprite(250,45);
  277. var score1 = createSprite(300,40);
  278. var score2 = createSprite(280,40);
  279. score.setAnimation("Score")
  280. score.scale = 0.4
  281. score1.scale = 0.5
  282. score2.scale = 0.5
  283. PointAdd()
  284. function PointAdd(){
  285. var h = y++;
  286. if (h == 0) {score1.setAnimation("Points0"); score2.setAnimation("Points0")}
  287. if (h == 1) {score1.setAnimation("Points1"); score2.setAnimation("Points0")}
  288. if (h == 2) {score1.setAnimation("Points2"); score2.setAnimation("Points0")}
  289. if (h == 3) {score1.setAnimation("Points3"); score2.setAnimation("Points0")}
  290. if (h == 4) {score1.setAnimation("Points4"); score2.setAnimation("Points0")}
  291. if (h == 5) {score1.setAnimation("Points5"); score2.setAnimation("Points0")}
  292. if (h == 6) {score1.setAnimation("Points6"); score2.setAnimation("Points0")}
  293. if (h == 7) {score1.setAnimation("Points7"); score2.setAnimation("Points0")}
  294. if (h == 8) {score1.setAnimation("Points8"); score2.setAnimation("Points0")}
  295. if (h == 9) {score1.setAnimation("Points9"); score2.setAnimation("Points0")}
  296. if (h == 10) {score1.setAnimation("Points0"); score2.setAnimation("Points1")}
  297. if (h == 11) {score1.setAnimation("Points1"); score2.setAnimation("Points1")}
  298. if (h == 12) {score1.setAnimation("Points2"); score2.setAnimation("Points1")}
  299. if (h == 13) {score1.setAnimation("Points3"); score2.setAnimation("Points1")}
  300. if (h == 14) {score1.setAnimation("Points4"); score2.setAnimation("Points1")}
  301. if (h == 15) {score1.setAnimation("Points5"); score2.setAnimation("Points1")}
  302. if (h == 16) {score1.setAnimation("Points6"); score2.setAnimation("Points1")}
  303. if (h == 17) {score1.setAnimation("Points7"); score2.setAnimation("Points1")}
  304. if (h == 18) {score1.setAnimation("Points8"); score2.setAnimation("Points1")}
  305. if (h == 19) {score1.setAnimation("Points9"); score2.setAnimation("Points1")}
  306. if (h == 20) {score1.setAnimation("Points0"); score2.setAnimation("Points2")}
  307. if (h == 21) {score1.setAnimation("Points1"); score2.setAnimation("Points2")}
  308. if (h == 22) {score1.setAnimation("Points2"); score2.setAnimation("Points2")}
  309. if (h == 23) {score1.setAnimation("Points3"); score2.setAnimation("Points2")}
  310. if (h == 24) {score1.setAnimation("Points4"); score2.setAnimation("Points2")}
  311. if (h == 25) {score1.setAnimation("Points5"); score2.setAnimation("Points2")}
  312. if (h == 26) {score1.setAnimation("Points6"); score2.setAnimation("Points2")}
  313. if (h == 27) {score1.setAnimation("Points7"); score2.setAnimation("Points2")}
  314. if (h == 28) {score1.setAnimation("Points8"); score2.setAnimation("Points2")}
  315. if (h == 29) {score1.setAnimation("Points9"); score2.setAnimation("Points2")}
  316. if (h == 30) {score1.setAnimation("Points0"); score2.setAnimation("Points3")}
  317. if (h == 31) {score1.setAnimation("Points1"); score2.setAnimation("Points3")}
  318. if (h == 32) {score1.setAnimation("Points2"); score2.setAnimation("Points3")}
  319. if(h++){
  320. Run()
  321. }
  322. }
  323. var r = 0
  324. function Run(){
  325. e = r++
  326. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement