Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
ПРАКТИЧЕСКИЕ ЗАДАНИЯ по учебной практики.docx
Скачиваний:
2
Добавлен:
26.09.2019
Размер:
3.81 Mб
Скачать

Практическая работа №11

Hit Object

1. Open “T2-touch.swf” for a preview of what can be accomplished from this tutorial.

2. Open “T2-touch.fla”, then Ctrl + L to open Library of the file.

3. Point to UFO1, press F9, type the following scripts:

4. Create a new layer.

5. Drag UFO2 to the stage. Make sure this UFO2 is in the new layer.

6. Point to UFO2, point to the “Properties” bar, type “movie1” in the “Instance Name” box.

7. Create one more new layer.

8. Point to the first frame of the new layer, press F9 and type the following:

9. Point to the “0” located on the left bottom of the stage.

10. Point to the “Properties” bar, type “dd” in the “Var” box.

That's all, run your movie (Ctrl + Enter) and check it all works. If not, go back though this tutorial and check you have not missed anything,

Практическое задание №12

Let’s play game!

1. Download "T3-spacerock.fla" file

2. Click on the “play” button and press F9, copy the following to the action scripts space:

3. For this round, we make it easy, just copy the following scripts in 2nd frame of "Layer1":

stop();

function startLevel() {

// ship stationary

ship.dx = 0.0;

ship.dy = 0.0;

// new arrays

bullets = new Array();

rocks = new Array();

// start using movie clip level 0

level = 0;

// add new rocks = number of level + 1

for(i=0;i<gameLevel+1;i++) {

newRock(100,0,0);

}

// all to fire right away

timeOfLastFire = 0;

}

function shipTurn(amt) {

// rotate the ship

ship._rotation += amt;

}

function shipThrust() {

// thrust ship in direction it faces

ship.dx += Math.cos(2.0*Math.PI*(ship._rotation-90)/360.0);

ship.dy += Math.sin(2.0*Math.PI*(ship._rotation-90)/360.0);

// show engines firing

ship.gotoAndPlay("thrust");

}

function shipBreak() {

// stop ship

ship.dx = 0;

ship.dy = 0;

}

function shipFire() {

// make sure enough time has passed since last fire

if (timeOfLastFire+200 < getTimer()) {

// remember time of this fire

timeOfLastFire = getTimer();

// create bullet

level++;

attachMovie("bullet","bullet"+level,level);

// set bullet location and direction

clip = _root["bullet"+level];

clip._x = ship._x;

clip._y = ship._y;

clip.dx = 10.0*Math.cos(2.0*Math.PI*(ship._rotation-90)/360.0);

clip.dy = 10.0*Math.sin(2.0*Math.PI*(ship._rotation-90)/360.0);

// add to bullets array

bullets.push(clip);

}

}

function shipMove() {

// move ship horizontally and wrap

ship._x += ship.dx;

if (ship._x > 550) ship._x -= 550;

if (ship._x < 0) ship._x += 550;

// move ship vertically and wrap

ship._y += ship.dy;

if (ship._y > 400) ship._y -= 400;

if (ship._y < 0) ship._y += 400;

}

function bulletsMove() {

// loop through all bullets

for(i=bullets.length-1;i>=0;i--) {

// move ship horizontally and vertically

bullets[i]._x += bullets[i].dx;

bullets[i]._y += bullets[i].dy;

// see whether the bullet is off the edge of the screen

if ((bullets[i]._x > 550) or (bullets[i]._x < 0) or (bullets[i]._y > 400) or (bullets[i]._y < 0)) {

// remove clip and array item

bullets[i].removeMovieClip();

bullets.splice(i,1);

}

}

}

function newRock(size,x,y) {

// create rock clip

level++;

rockNum = int(Math.random()*3+1);

attachMovie("rock"+rockNum,"rock"+level,level);

// set rock location and size

clip = _root["rock"+level];

clip._x = x;

clip._y = y;

clip._xscale = size;

clip._yscale = size;

// set rock speed and direction

clip.dx = Math.Random()*gameLevel+.5;

if (Math.random() < .5) clip.dx *= -1;

clip.dy = Math.Random()*gameLevel+.5;

if (Math.random() < .5) clip.dy *= -1;

// set rock spin

clip.spin = Math.random()*6-3;

// add rock to rocks array

rocks.push(clip);

}

function rocksMove() {

// loop through all rocks

for(i=rocks.length-1;i>=0;i--) {

clip = rocks[i].clip;

// move rock horizontally and wrap

rocks[i]._x += rocks[i].dx;

if (rocks[i]._x > 550) rocks[i]._x -= 550;

if (rocks[i]._x < 0) rocks[i]._x += 550;

// move rock vertically and wrap

rocks[i]._y += rocks[i].dy;

if (rocks[i]._y > 400) rocks[i]._y -= 400;

if (rocks[i]._y < 0) rocks[i]._y += 400;

// spin rock

rocks[i]._rotation += rocks[i].spin;

}

}

function checkHits() {

// loop through all rocks

for(i=rocks.length-1;i>=0;i--) {

// loop through all bullets

for(j=bullets.length-1;j>=0;j--) {

// see whether bullet hit rock

if (rocks[i].hitTest(bullets[j]._x,bullets[j]._y,true)) {

// remove bullet

bullets[j].removeMovieClip();

bullets.splice(j,1);

// get size and location of new rocks

newsize = rocks[i]._xscale / 2;

x = rocks[i]._x;

y = rocks[i]._y;

// remove rock

rocks[i].removeMovieClip();

rocks.splice(i,1);

// create two new rocks in its place

if (newsize >= 25) {

newRock(newsize,x,y);

newRock(newsize,x,y);

}

// increase score

score++;

// no need to keep checking bullets against this rock

break;

}

}

// see whether rock hits ship

if (rocks[i].hitTest(ship._x,ship._y,true)) {

// see whether there are not more lives

if (lives < 1) {

removeAll();

gotoAndPlay("game over");

// life left, deduct life

} else {

removeAll();

lives--;

gotoAndPlay("ship hit");

}

}

}

// see whether there are no more rocks

if (rocks.length == 0) {

removeAll();

gotoAndPlay("level over");

gameLevel++;

}

}

function removeAll() {

// remove all bullets

for(i=0;i<bullets.length;i++) {

bullets[i].removeMovieClip();

}

// remove all rocks

for(i=0;i<rocks.length;i++) {

rocks[i].removeMovieClip();

}

}

4. That's all, run your movie (Ctrl + Enter) and check it all works. If not, go back though this tutorial and check you have not missed anything,

5. Here is an exercise for you. You are given graphics of stones and space ship below. Use PhotoShop to do the necessary adjustment and then replace them with those in the game.