Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- init();
- function init() {
- angle = 0;
- r = w._width/2;
- rspeed = 0;
- maxspeed = Math.PI/30;
- a._x = (a._width/2)*-1;
- a._y = (a._height/2)*-1;
- a.speed = 2;
- b.speed = 1;
- i = 0;
- u = 0;
- maxi = 0;
- a.sec = 0;
- b._x = g._x;
- b._y = g._y;
- firedelay = 10;
- firewait = false;
- }
- _root.onEnterFrame = function() {
- gunmove();
- gunfire();
- enemy();
- moveEnemy();
- moveBullets();
- };
- function gunmove() {
- if (Key.isDown(Key.LEFT)) {
- rspeed = rspeed-Math.PI/200;
- } else if (Key.isDown(Key.RIGHT)) {
- rspeed = rspeed+Math.PI/200;
- } else {
- if (rspeed<0) {
- rspeed = rspeed+Math.PI/200;
- }
- if (rspeed>0) {
- rspeed = rspeed-Math.PI/200;
- }
- }
- if ((rspeed<Math.PI/200) && (rspeed>-Math.PI/200)) {
- rspeed = 0;
- }
- if (rspeed>maxspeed) {
- rspeed = maxspeed;
- } else if (rspeed<(maxspeed*-1)) {
- rspeed = maxspeed*-1;
- }
- angle = angle+rspeed;
- if(angle > Math.PI*2) {
- angle = angle - (Math.PI*2);
- } else if(angle< (Math.PI*2*-1)) {
- angle = angle + (Math.PI*2);
- }
- g._rotation = (angle*180)/Math.PI;
- g._x = w._x+(r*Math.sin(angle));
- g._y = w._y-(r*Math.cos(angle));
- }
- function gunfire() {
- b._x = g._x;
- b._y = g._y;
- if (firetimer>0) {
- firetimer -= 1;
- if (firetimer == 0) {
- firewait = false;
- }
- }
- if (Key.isDown(Key.SPACE)) {
- if (firewait == false) {
- u = u+1;
- duplicateMovieClip(b, "b"+u, u);
- currentb = eval("b"+u);
- currentb.dx = b.speed*Math.cos(angle-Math.PI/2);
- currentb.dy = b.speed*Math.sin(angle-Math.PI/2);
- firewait = true;
- firetimer = firedelay;
- }
- }
- }
- function enemy() {
- timer = random(20);
- if (timer == 1) {
- i = i+1;
- duplicateMovieClip(_root.a, "a"+i, i);
- currenta = eval("a"+i);
- rand = random(4)+1;
- if (rand == 1) {
- currenta.sec = 1;
- currenta._x = random(Stage.width);
- currenta._y = (a._height/2)*-1;
- currenta.dx = random(a.speed)+1;
- currenta.dy = random(a.speed)+1;
- } else if (rand == 2) {
- currenta.sec = 2;
- currenta._x = random(Stage.width);
- currenta._y = Stage.height+(a._height/2);
- currenta.dx = random(a.speed)+1;
- currenta.dy = (random(a.speed)+1)*-1;
- } else if (rand == 3) {
- currenta.sec = 3;
- currenta._x = (a._width/2)*-1;
- currenta._y = random(Stage.height);
- currenta.dx = random(a.speed)+1;
- currenta.dy = random(a.speed*2)-a.speed;
- } else if (rand == 4) {
- currenta.sec = 4;
- currenta._x = Stage.width+a._width/2;
- currenta._y = random(Stage.height);
- currenta.dx = (random(a.speed)+1)*-1;
- currenta.dy = random(a.speed*2)-a.speed;
- }
- }
- }
- function moveEnemy() {
- if (i>0) {
- for (h=i; h>0; h--) {
- currenta = eval("a"+h);
- currenta._x += currenta.dx;
- currenta._y += currenta.dy;
- if ((currenta._x>Stage.width+currenta._width/2) && currenta.dx>0) {
- removeMovieClip(currenta);
- } else if ((currenta._x<-currenta._width/2) && (currenta.dx<0)) {
- removeMovieClip(currenta);
- } else if ((currenta._y>Stage.height+currenta._height/2) && (currenta.dy>0)) {
- removeMovieClip(currenta);
- } else if ((currenta._y<-currenta._height/2) && (currenta.dy<0)) {
- removeMovieClip(currenta);
- }
- }
- }
- }
- function moveBullets() {
- if (u>0) {
- for (j=u; j>0; j--) {
- currentb = eval("b"+j);
- currentb._x += currentb.dx;
- currentb._y += currentb.dy;
- if ((currentb._x>Stage.width+currentb._width/2) && currentb.dx>0) {
- removeMovieClip(currentb);
- u--;
- } else if ((currentb._x<-currentb._width/2) && (currentb.dx<0)) {
- removeMovieClip(currentb);
- u--;
- } else if ((currentb._y>Stage.height+currentb._height/2) && (currentb.dy>0)) {
- removeMovieClip(currentb);
- u--;
- } else if ((currentb._y<-currentb._height/2) && (currentb.dy<0)) {
- removeMovieClip(currentb);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment