var Ship:MovieClip = new ship();
addChild(Ship);
//This drags our ship file onto the stage and names it Ship
Ship.startDrag(true);
Mouse.hide();
//drags Ship and hides mouse
Now our ship appears onto our stage and is clipped to our mouse. Part of the old code made the blocks go transparent with a hit test for our mouse so now when we roll over a block with our ship attached it goes transparent. This can be changed easily though to something like ship goes transparent or any other event so it's a very useful code that I will use in my game.
We also wanted to make the blocks scroll from the top to the bottom and loop back up to the top. With the code now 15 blocks show up randomly on the screen.
var speed=3
//Here we set the speed for the blocks, we could just set a fixed movement instead of using a speed variable but with a speed variable it can be changed so that the blocks get progressively faster. This piece of code is put at the top with the other variables
blockArray[i].y+=speed
//This talks to the whole Array and tells them to move along the y axis at the speed we set up in the variable.
if (blockArray[i].y>450){
//if any of the blocks in the Array get to 50 pixels below the bottom of the screen
blockArray[i].y=-50
//move it to 50 pixels above the top of the screen
blockArray[i].x=Math.random()*550;
//then reposition it randomly along the X axis
speed+=0.1;
//And increase the speed by 0.1
}
}
This now means that every time the blocks go back up the the top of the screen they get as little faster.
Next we wanted to make the ship explode when it hits one of the blocks so we went into the movie clip from the library and on the next frame we drew a quick explosion with the pen tool, then on the frame after we delete the ship, we then leave a break of around 10 frames and then add she ship back in. Before we leave the movie clip we added a small bit of code (stop();) so that the clip doesn't play continuously.
We then simply added Ship.play(); to the end of the hit test code.
Finally we added lives to the game, first we made a square and converted it to a movie clip making sure that in advanced settings we clicked 'export for ActionScript' and called it 'lives' and set the class to 'lives'. We then went into the lives movie clip and made three squares in a line, then we made a new frame and deleted one of the squares and so on, then we added a stop to frame 1.
Finally we added this code (MovieClip(root).lives.nextFrame();) onto the last frame of the ship so when the ship is triggered to play it goes to the root (the stage), finds lives and moves it to the next frame.
No comments:
Post a Comment