Guest User

Untitled

a guest
Apr 26th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.07 KB | None | 0 0
  1. import com.gskinner.sprites.CollisionDetection;
  2. import flash.geom.Rectangle;
  3.  
  4.  
  5. //bgScroller
  6. //player
  7.  
  8. bgWidth = 1161.95;
  9.  
  10. button1.onRelease = function(){
  11. trace("level 1");
  12. lvl = 1;
  13. setUp(lvl);
  14.  
  15. }
  16.  
  17. button2.onRelease = function(){
  18. trace("level 2");
  19. lvl = 2;
  20. setUp(lvl);
  21.  
  22. }
  23.  
  24. setUp = function (lvl){
  25. trace("running");
  26.  
  27. speed = 5;
  28. for2GroundSpeed = 8;
  29.  
  30. _root.createEmptyMovieClip("projectileLayer", this.getNextHighestDepth());
  31. projectileCount = 0;
  32.  
  33. jump = 0;
  34. jumping = false;
  35.  
  36.  
  37. touchingGround = true;
  38. ammo = 10;
  39.  
  40. firing = false; // Is player firing?
  41. fireRate = 10; // Frame delay between shots
  42.  
  43. score = 0;
  44. score_txt.text = score;
  45. counter = 5; // Game time
  46. counter_txt.text = counter;
  47. bulletSpeed = 15;
  48.  
  49. currentLevel = "level"+lvl;
  50. trace(currentLevel);
  51. _root.attachMovie( lvl, currentLevel, 1);
  52.  
  53.  
  54. player.swapDepths(20200);
  55. mouse.swapDepths(20002);
  56.  
  57. //Firing
  58. // When mouse is down fire the weapon off of ship
  59. mouse.onMouseDown = function()
  60. {
  61.  
  62. firing = true;
  63. //trace(firing);
  64. //For frame
  65. repeatTime = 0;
  66. }//end of mouseDown
  67.  
  68.  
  69. // When mouse up do not fire
  70. mouse.onMouseUp = function()
  71. {
  72. //trace("firing the lazer");
  73. firing = false;
  74. }//end of shipMouseU
  75.  
  76.  
  77. //MOUSE
  78. mouse.onEnterFrame = function() {
  79. //desx =desire postion of the ship on the X_mouse
  80. //This where you will mess with to add Y ties
  81. this._x = _xmouse;
  82. this._y = _ymouse;
  83.  
  84.  
  85. if(this._x < player._x){
  86. if(this._xscale < 0){
  87. this._xscale *= -1;
  88. }//end of if why
  89.  
  90. left = false;
  91.  
  92. }
  93. else{
  94.  
  95. if(this._xscale >0){
  96. this._xscale *= -1;
  97. }//end of if why
  98.  
  99. left = true;
  100. }
  101.  
  102.  
  103. //FIRING
  104. // How you fire your gun
  105. //If firing true, repeat time 0 and you have more than 0 ammo
  106. if (firing && repeatTime == 0 && ammo >=1)
  107. {
  108. ammo--;
  109. trace(ammo);
  110.  
  111. //This is for the function for the bullet
  112. // Tells the bullet to be a little bt above it
  113. //you can change the angel of where its at
  114. //Tells the speed and angle of the bullet
  115. //trace("FUCK");
  116. if (left){
  117. createProjectile("bullet", mouse._x, mouse._y, -bulletSpeed, 0);
  118. }//end of leftfiring
  119.  
  120. else{
  121. createProjectile("bullet", mouse._x, mouse._y, bulletSpeed, 0);
  122. }//end of riight firing
  123.  
  124. }//end of firing && repeatTime == 0
  125.  
  126. //its a Loop this ia for a fire rate
  127. repeatTime ++;
  128.  
  129. // in its heart is a loop
  130. // When it hits a Fire rate of 10 then of back to 0
  131. repeatTime %= fireRate;
  132.  
  133. }//end of the mouse
  134.  
  135. ghostEnemyArray = new Array ();
  136. ghostEnemyArray.push(_root[currentLevel].ghost1);
  137.  
  138.  
  139. //trace(ghostEnemyArray[0]);
  140.  
  141.  
  142. //Will Change for the else
  143. _root[currentLevel].onEnterFrame = function(){
  144.  
  145. if(Key.isDown(Key.RIGHT) || Key.isDown(68)){
  146. this._x -=speed;
  147. foreGround1._x -=for2GroundSpeed;
  148. }//end up up
  149.  
  150. //IS UP or w key
  151. if(Key.isDown(Key.LEFT) || Key.isDown(65)){
  152. this._x +=speed;
  153. foreGround1._x +=for2GroundSpeed;
  154. }//end up up
  155.  
  156. //DEBUGGER here!!!
  157. if(Key.isDown(Key.ENTER)){
  158. //trace(this._x);
  159. trace("x: " +this._x + " y: " + this._y);
  160. trace(this._width/2+1);
  161. }//end up up
  162.  
  163.  
  164.  
  165. //the 'walls'
  166. if(this._x >= 0){
  167. this._x = 0;
  168. }
  169.  
  170. if(this._x <= -(this._width/2-130 )){
  171. //trace(this._width/2);
  172. this._x = -455;
  173. }
  174. }//end of onEnterFrame
  175.  
  176.  
  177.  
  178.  
  179. //Jumping
  180. player.onEnterFrame = function(){
  181.  
  182.  
  183.  
  184. //JUMPING
  185. if (Key.isDown(Key.SPACE) && !jumping) {
  186. // if up is pressed and NOT jumping
  187. jumping = true;
  188. // jumping is set true
  189. }
  190. if (jumping) {
  191. // if jumping is true
  192. //this.gotoAndStop("jump");
  193. this._y -= jump;
  194. // Y position is set down jump
  195. jump -= .5;
  196. // jump is set down .5
  197. if (jump<0) {
  198. // if jump is smaller than 0
  199. falling = true;
  200. // falling is true
  201. }
  202. if (jump<-15) {
  203. // if jump is smaller than neg. 5
  204. jump = -15;
  205. // jump is set to neg 5
  206. // capping fall speeds prevents falling through grounds
  207. }
  208. }
  209.  
  210. if (_root[currentLevel].ground.hitTest(this._x, this._y + this._height/2, true) && falling) {
  211. // if hitting X an Y postions with the ground and falling
  212. jump = 12;
  213. // jump is set to 9
  214. jumping = false;
  215. // jumping is false
  216. falling = false;
  217. // falling is false
  218. }
  219.  
  220.  
  221.  
  222. for(i in ghostEnemyArray){
  223.  
  224.  
  225. //trace(ghostEnemyArray[i]._x);
  226. //trace(i);
  227. //trace(_root[currentLevel].ghostEnemyArray[marker]._x);
  228. var collisionPlayer:Rectangle = CollisionDetection.checkForCollision(player,ghostEnemyArray[i],120);
  229.  
  230. //trace(_root[currentLevel].boundary);
  231. // What!? you hit the grass!
  232. if(collisionPlayer && jumping) {
  233.  
  234.  
  235.  
  236.  
  237. ghostEnemyArray[i].play();
  238. //trace(ghostEnemyArray.splice(i));
  239. ghostEnemyArray[i].swapDepths(1979);
  240. ghostEnemyArray[i].removeMovieClip();
  241. ghostEnemyArray.splice(i);
  242. //ghostEnemyArray[i].removeMovieClip();
  243.  
  244. //delete ghostEnemyArray[i];
  245. }
  246.  
  247.  
  248. if( collisionPlayer && !jumping){
  249. trace("u died");
  250.  
  251. _root[currentLevel]._x += ghostEnemyArray[i]._width/2;
  252. //ghostEnemyArray[i].removeMovieClip();
  253. //this._x += 10;
  254. }
  255.  
  256.  
  257.  
  258. }
  259.  
  260. return jumping;
  261. }//end of paplayer
  262. ghostSpeed = 10;
  263. ////////////////////
  264. //GHOST ENEMU
  265. _root[currentLevel].ghost1.onEnterFrame = function(){
  266.  
  267. //trace("rawr");
  268.  
  269. //MOVING THE ENEMY
  270.  
  271. //checking if touching any invisible markers
  272. for(var i:String in ghostEnemyArray){
  273. //the process is very similar to the main guy's testing with other elements
  274. //trace(ghostEnemyArray[i]);
  275. var collisionGhost:Rectangle = CollisionDetection.checkForCollision(_root[currentLevel].boundary,ghostEnemyArray[i],120);
  276.  
  277. //trace(_root[currentLevel].boundary);
  278. // What!? you hit the grass!
  279. if(collisionGhost) {
  280. //trace("collision between " + _root[currentLevel].boundary + " and " + ghostEnemyArray[i]);
  281. ghostSpeed =ghostSpeed *-1;
  282. this._x += ghostSpeed;
  283. this._xscale *= -1;
  284.  
  285. }
  286.  
  287.  
  288.  
  289.  
  290.  
  291. else{this._x += ghostSpeed;
  292.  
  293. }
  294. }
  295.  
  296.  
  297.  
  298. }//end of GHOST
  299.  
  300. }//end of on init
  301.  
  302.  
  303. //Bullets
  304. //This creates the objects
  305. // So it can go with Angle and such
  306. createProjectile = function(type, x, y, dx, dy)
  307. {
  308. //nm (everything) is the proj and the count for it
  309. var nm = "proj" + projectileCount;
  310. //the count is the depth lvl of the bullet
  311. //This is attaching the BULLET to the layer
  312. projectileLayer.attachMovie(type, nm, projectileCount);
  313. //trace(nm);
  314. //This defines where it is at
  315. projectileLayer[nm]._x = x;
  316. projectileLayer[nm]._y = y;
  317. // Speed from previously is the same now
  318. // These are just saftey checks
  319. projectileLayer[nm].dx = dx;
  320. projectileLayer[nm].dy = dy;
  321.  
  322.  
  323. //NM is now tied into the the projectile layer now
  324. // THis is what defines the layer from above
  325. projectileLayer[nm].onEnterFrame = function()
  326. {
  327. //This adds the dx and dy to its x and y
  328. //This line is what makes it work
  329. // This defines the speed limits
  330. this._x += this.dx;
  331. this._y += this.dy;
  332.  
  333.  
  334. //if it has a thing less than ZERO then REMOVE IT NOW
  335. if (this._y < 0){
  336. this.removeMovieClip();
  337. }//end of y<0
  338.  
  339.  
  340. // LOOP TIME
  341. //This is the HIT TEST
  342. //You can adjust this this is so theres 9 bullets and 9 bullets
  343.  
  344.  
  345. for(i in ghostEnemyArray){
  346.  
  347. if( ghostEnemyArray[i].hitTest(this._x, this._y, true)){
  348. ghostEnemyArray[i].play();
  349. //trace(ghostEnemyArray[i]);
  350. ghostEnemyArray[i].swapDepths(1979);
  351. ghostEnemyArray[i].removeMovieClip();
  352. //trace(ghostEnemyArray.splice(i));
  353. ghostEnemyArray.splice(i);
  354.  
  355. }
  356.  
  357. }
  358.  
  359.  
  360.  
  361.  
  362. }//end of projectileLayer[nm]
  363.  
  364. //max of 10
  365. projectileCount ++;
  366. projectileCount %= 10;
  367.  
  368. }//end createProjectile
Add Comment
Please, Sign In to add comment