2016-06-14 11 views
-1

私のシューティングゲームの次のフレームに新しいムービークリップを追加しようとしています。私は私が私の評価をして助けを必要とするものの基礎を与えるために別のムービークリップを別のフレームに追加する

のActionScript 3.0を使用しています

。スコア= 50の場合、次のフレームに切り替えます。ここで私はユーザーが撮影するための新しいタイプのムービークリップを追加したいと思っています!

これまでのコードは次のとおりです。

FRAME 1

//Tate's open screen 
stop(); //makes the screen wait for events 

paraBtn.addEventListener(MouseEvent.CLICK, playClicked); //this line is making your button an mouse click event 

function playClicked(evt: MouseEvent): void { // now we are calling the event from this function and telling it to go to the next frame we labelled play 
    gotoAndStop("frame2"); 
    // All rights of this music goes towards the makers of the game "Risk of Rain" which was made by Hapoo Games 
} 

(ゲームが実際に開始)FRAME 2

stop(); 
// This plays the sound when left click is used 
var spitSound: Sound = new Sound(); 
spitSound.load(new URLRequest("gunSound.mp3")); 
//This plays the gameover sound when your lives reach 0 
var overSound: Sound = new Sound(); 
overSound.load(new URLRequest("Gameover.mp3")); 
//This plays the sound when you are hit 
var etSound: Sound = new Sound(); 
etSound.load(new URLRequest("Urgh.mp3")); 


//This sets the lives and points. 
stage.addEventListener(MouseEvent.MOUSE_MOVE, aimTurret); 
var points: Number = 0; 
var lives: Number = 3; 
var target: MovieClip; 
var _health: uint = 100; 
initialiseCursor(); 

//This variable stops the multiple errors with the move objects and bullets and range to stop compiling. 
var Gameover: Boolean = false; 

//This aims the turrent to where you mouse is on the screen 
function aimTurret(evt: Event): void { 
    if (Gameover == false) { 
     gun.rotation = getAngle(gun.x, gun.y, mouseX, mouseY); 
     var distance: Number = getDistance(gun.x, gun.y, mouseX, mouseY); 

     var adjDistance: Number = distance/12 - 7; 
    } 

} 

function getAngle(x1: Number, y1: Number, x2: Number, y2: Number): Number { 
    var radians: Number = Math.atan2(y2 - y1, x2 - x1); 
    return rad2deg(radians); 
} 

function getDistance(x1: Number, y1: Number, x2: Number, y2: Number): Number { 
    var dx: Number = x2 - x1; 
    var dy: Number = y2 - y1; 
    return Math.sqrt(dx * dx + dy * dy); 
} 

function rad2deg(rad: Number): Number { 
    return rad * (180/Math.PI); 
} 
//Starts lives and shows text next to the numbers 
function initialiseCursor(): void { 
    Mouse.hide(); 
    target = new Target(); 
    target.x = mouseX; 
    target.y = mouseY; 
    target.mouseEnabled = false; 
    addChild(target); 
    stage.addEventListener(MouseEvent.MOUSE_MOVE, targetMove); 
    stage.addEventListener(MouseEvent.MOUSE_DOWN, targetDown); 
    stage.addEventListener(MouseEvent.MOUSE_UP, targetUp); 
    livesdisplay.text = String(lives) + " Lives Left"; 
    pointsdisplay.text = String(points) + " Points"; 
} 

function targetMove(evt: MouseEvent): void { 
    target.x = this.mouseX; 
    target.y = this.mouseY; 
} 

function targetDown(evt: MouseEvent): void { 
    target.gotoAndStop(2); 
} 

function targetUp(evt: MouseEvent): void { 
    target.gotoAndStop(1); 
} 
//Starts bullets and speed of bullets, also addding new arrays for baddies 
var gunLength: uint = 90; 
var bullets: Array = new Array(); 
var bulletSpeed: uint = 20; 
var baddies: Array = new Array(); 
stage.addEventListener(MouseEvent.MOUSE_DOWN, fireGun); 
function fireGun(evt: MouseEvent) { 
    if (Gameover == false) { 
     var bullet: Bullet = new Bullet(); 
     bullet.rotation = gun.rotation; 
     bullet.x = gun.x + Math.cos(deg2rad(gun.rotation)) * gunLength; 
     bullet.y = gun.y + Math.sin(deg2rad(gun.rotation)) * gunLength; 
     addChild(bullet); 
     bullets.push(bullet); 
     spitSound.play(); 
    } 
} 
function deg2rad(deg: Number): Number { 
    return deg * (Math.PI/180); 
} 

stage.addEventListener(Event.ENTER_FRAME, moveObjects); 

function moveObjects(evt: Event): void { 
    if (Gameover == false) { 
     moveBullets(); 
     moveBaddies(); 
    } 
} 

function moveBullets(): void { 
    for (var i: int = 0; i < bullets.length; i++) { 
     var dx = Math.cos(deg2rad(bullets[i].rotation)) * bulletSpeed; 
     var dy = Math.sin(deg2rad(bullets[i].rotation)) * bulletSpeed; 
     bullets[i].x += dx; 
     bullets[i].y += dy; 
     if (bullets[i].x < -bullets[i].width || bullets[i].x > stage.stageWidth + bullets[i].width || bullets[i].y < -bullets[i].width || bullets[i].y > stage.stageHeight + bullets[i].width) { 
      removeChild(bullets[i]); 
      bullets.splice(i, 1); 
     } 
    } 
} 
// This is the start of the timer 
var timer: Timer = new Timer(1000); 
timer.addEventListener(TimerEvent.TIMER, addBaddie); 
timer.start(); 

// Adding army men on a timer and only from the top side 
function addBaddie(evt: TimerEvent): void { 
    var baddie: Baddie = new Baddie(); 
    var side: Number = Math.ceil(Math.random() * 1); 
    if (side == 1) { 
     baddie.x = Math.random() * stage.stageWidth; 
     baddie.y = -baddie.height; 
    } 
    baddie.angle = getAngle(baddie.x, baddie.y, gun.x, gun.y); 
    baddie.speed = 7; 
    addChild(baddie); 
    baddies.push(baddie); 
} 

function moveBaddies(): void { 
    for (var i: int = 0; i < baddies.length; i++) { 
     var dx = Math.cos(deg2rad(baddies[i].angle)) * baddies[i].speed; 
     var dy = Math.sin(deg2rad(baddies[i].angle)) * baddies[i].speed; 
     baddies[i].x += dx; 
     baddies[i].y += dy; 
     if (baddies[i].hitTestPoint(gun.x, gun.y, true)) { 
      removeChild(baddies[i]); 
      baddies.splice(i, 1); 
      loseLife(); 
      //If baddie was removed then we don’t check for bullet hits 
     } else { 
      checkForHit(baddies[i]); 
     } 
    } 
} 

function checkForHit(baddie: Baddie): void { 
    for (var i: int = 0; i < bullets.length; i++) { 
     if (baddie.hitTestPoint(bullets[i].x, bullets[i].y, true)) { 
      removeChild(baddie); 
      points++; 
      if (points == 50) { 
       gotoAndStop("frame3") 
      } 
      pointsdisplay.text = String(points) + " Points"; 
      baddies.splice(baddies.indexOf(baddie), 1); 
     } 
    } 
} 


// Keeping track of lost lives and when hitting 0 doing to frame four, also displaying "Lose life!" 
function loseLife(): void { 
    etSound.play(); 
    lives--; 
    if (lives == 0) { 
     Gameover = true; 
     overSound.play(); 
     gotoAndStop("frame4") 
    } 
    livesdisplay.text = String(lives) + " Lives Left"; 
    trace("Lose Life!"); 
} 

は、FRAME 3(私は別のムービークリップを追加するには、助けを必要とする場所です)(私は1つを作りましたリンケージは「Baddiered」された状態で、「BaddieRed」という名前のフレームのための

stop(); 
// The code from frame2 carries over and works the same in this frame 

FRAME 4(これは、それはだ画面ですゲームオーバー)

stop(); 
timer.stop(); 

// User need to close by pressing the close button 
//And restart the game manually 

答えて

0

これは達成しようとしていることですか?何かのように...

function addBaddie(evt: TimerEvent): void 
{ 
    var baddie : MovieClip; 
    if (points < 50) { var bad1: Baddie = new Baddie(); baddie = bad1; } 
    if (points >= 50) { var bad2 : Baddiered = new Baddiered(); baddie = bad2; } 

    var side: Number = Math.ceil(Math.random() * 1); 
    if (side == 1) 
    { 
     baddie.x = Math.random() * stage.stageWidth; 
     baddie.y -= baddie.height; 
    } 
    baddie.angle = getAngle(baddie.x, baddie.y, gun.x, gun.y); 
    baddie.speed = 7; 
    addChild(baddie); 
    baddies.push(baddie); 
} 
関連する問題