游戏加快了下一次启动的速度

时间:2019-05-31 14:23:20

标签: actionscript-3

重启游戏后输掉或赢了游戏后加速。

游戏简介。

游戏的标题是打字的太空大师。应用程序允许您学习如何快速在键盘上打字,而无需查看为什么要在PC上使用。 游戏位于科幻世界。 主角是一艘太空飞船。敌人是飞船,上面有字母乱码。
游戏的目的是由玩家射击所有敌人。如果玩家想射击标有“ c”垃圾的敌人,则必须按下“ c”键。

下面是带有游戏注释的代码。

游戏结束,场景:

stop(); /*The application is stop and it does not move to next scene*/
btnOver.addEventListener(MouseEvent.CLICK, funPagePlay); //After clicking the home button the Play screen will be open

function funPagePlay(event:MouseEvent):void{ 
//Declaration function funPageHome
Object(root).gotoAndStop(1, 'Scene 2'); //Calling function gotoAndStop and maoving to Scene 2   
}

播放场景:

stop(); /*The application is stop and it does not move to next scene*/

import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.KeyboardEvent;
import flash.display.Sprite;


var speedEnemy = -20; //Speed for nemies
var speedPlayer = 30; //Speed for the player 
var speedMissile = 7; //Speed for the missile
var speedTimer= 100;


var missileKey; //In the variable we store which key we pressed the range a, b, c, d, e, f
var score = 0; //The variable stores the result
score_txt.text = String(score); //Displaying the result

var missile:bullet = new bullet(); //Missile, object
var aliens:Array = new Array(alienA, alienB, alienC, alienD, alienE, alienF); //Aliens, array
var myTimer:Timer = new Timer(100); //We create Timer so that the enemies move

敌人的运动:

myTimer.addEventListener("timer",timerHandler);
myTimer.start(); //Starting myTimer
function timerHandler(event:TimerEvent){ //This decleares a function call alient timer which is going to run a timer 
for each(var i in aliens){ //Go throught aliens array each one will be stored in a variable called i
    //Move enemies vertically
    i.y -= speedEnemy; //increase the aliens x value by the speed var. Move enemies horizontally
}   

for each (var j in aliens){ //Go throught aliens array each one will be stored in a variable called i
    if(j.y <= 7 || j.y >= 270){  //
        speedEnemy *= -1; //Change direction 
        for each ( var k in aliens){    
            k.x -= 10; //Move enemies forward
        }
    }

    //Hit the enemy
    if(j.y >= player.y && j.x <= player.x + 60 ){ //When the player hits the enemy
        gotoAndPlay(1,"Scene 4"); //Go to the lost you page
    }
}
}

向上移动玩家并获得胜利:

var playerTimer:Timer = new Timer(speedTimer);
playerTimer.addEventListener("timer", timerHandlerPlayer);
playerTimer.start(); //Start timer for player
function timerHandlerPlayer(event:TimerEvent){
player.y += speedPlayer; //Moveing vertical and speed for player
if(player.y >= 280 || player.y <= 17){
    speedPlayer *= -1; //Vertical change direction for player
}
}

function displayMissile(){
missileTimer.start(); //Start timer for missile
stage.addChild(missile); //display missile
missile.y = player.y + 30; //position missle y
missile.x = player.x + 80; //position missile x
}

stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressedDown); //After pressing key
//Display missile after pressing
function keyPressedDown(event:KeyboardEvent):void{
var key:uint = event.keyCode; //Download the keyboard button
trace("you pressed" + key);
var step:uint = 5;  

射击:

if(key == Keyboard.A || key == Keyboard.B || key == Keyboard.C || key == Keyboard.D || key == Keyboard.E || key == Keyboard.F){ //Press key space
    if(key == Keyboard.A){
        missileKey = "a"; //After pressing the key a set the variable
        displayMissile(); //displaying missile
    }
    else if(key == Keyboard.B){
        missileKey = "b"; //After pressing the key b set the variable
        displayMissile(); //displaying missile
    }
    else if(key == Keyboard.C){
        missileKey = "c"; //After pressing the key c set the variable
        displayMissile(); //displaying missile
    }
    else if(key == Keyboard.D){
        missileKey = "d"; //After pressing the key d set the variable
        displayMissile(); //displaying missile
    }
    else if(key == Keyboard.E){
        missileKey = "e"; //After pressing the key c set the variable
        displayMissile();
    }
    else if(key == Keyboard.F){
        missileKey = "f"; //After pressing the key f set the variable
        displayMissile(); //displaying missile
    }
}
}

为导弹创建计时器:

var missileTimer:Timer = new Timer(30); 
missileTimer.addEventListener("timer", timerHandlerMissile)
missileTimer.start() //start timer
function timerHandlerMissile(event:TimerEvent){ //moving missile
missile.x += speedMissile; //otherwise move up. Move the missile forward, speed

//We check for any aliens or have not been shot
for(var i:int = 0; i < aliens.length; i++){
    if( missile.hitTestObject(aliens[i]) ) //if the missile hits an alien
    {

        if(missileKey == "a" && missile.hitTestObject(alienA)){ //Two conditions were you pressed the a key and if you killed enemy a  
            score++;    
            score_txt.text = String(score); //We are changing the result of the game
        }else if(missileKey == "b" && missile.hitTestObject(alienB)){ //Two conditions were you pressed the b key and if you killed enemy b 
            score++;    
            score_txt.text = String(score); //We are changing the result of the game
        }else if(missileKey == "c" && missile.hitTestObject(alienC)){ //Two conditions were you pressed the c key and if you killed enemy c 
            score++;    
            score_txt.text = String(score); //We are changing the result of the game
        }else if(missileKey == "d" && missile.hitTestObject(alienD)){ //Two conditions were you pressed the d key and if you killed enemy d 
            score++;    
            score_txt.text = String(score); //We are changing the result of the game
        }else if(missileKey == "e" && missile.hitTestObject(alienE)){ //Two conditions were you pressed the e key and if you killed enemy e 
            score++;    
            score_txt.text = String(score); //We are changing the result of the game
        }else if(missileKey == "f" && missile.hitTestObject(alienF)){ //Two conditions were you pressed the f key and if you killed enemy f 
            score++;    
            score_txt.text = String(score); //We are changing the result of the game
        }
        else{
            score--;
            score_txt.text = String(score); //Changing the result of the game
            gotoAndPlay(1,"Scene 4"); //Go to the lost you page
        }

        aliens[i].visible = false; //Set the hit alien to visible
        aliens.splice(i, 1); //Remove the alien from the array
        missileTimer.stop(); //Stop timer
        stage.removeChild(missile); //Remove the missile

        if(aliens.length == 0) //We check if we killed all enemies
        {
                gotoAndPlay(1,"Scene 3"); //Go to the You win page
        }

    }
}
}

我不知道为什么,但是游戏正在加速

0 个答案:

没有答案