Advertisement
Xplosive_

Ghost v5

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