Pada tahap ini kita akan membuat musuh dari spaceship.
Langkah 1. Membuat musuh
Buatlah sebuah gambar seperti berikut:
Tekan ctrl + L untuk membuka library, pastikan enemy ada pada library tersebut.
Langkah 2. Me-linkan enemy
Di library klik kanan pada enemy. lalu pilih “Linkage…” (or “Properties…” jika kamu menggunakan Adobe Flash CS4 atau diatasnya).
Lakukan seperti pada gambar:
Langkah 3. Coding part 1
Ini mungkin kode tersulit pada pembelajaran ini, jadi perhatikanlah baik-baik.
Kita akan membuat kode di stage, jadi klik stage kosong lalu tekan F9, dan masukkan kode berikut:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | i = 0; enemies = []; spawnEnemy = function(){ _root.attachMovie("enemy", "enemy"+i, _root.getNextHighestDepth()); _root["enemy"+i]._x = random(Stage.width); _root["enemy"+i]._y = 0; enemies.push("enemy"+i); _root["enemy"+i].onEnterFrame = function(){ this._y += 3; if(this._y > Stage.height){ for(e = 0; e < _root.enemies.length; e++){ if(_root.enemies[e] == this._name){ _root.enemies.splice(e, 1); } } this.removeMovieClip(); } } i++; } enemy_interval = setInterval(spawnEnemy, 2000); |
Langkah 4. Coding part 2
Klik spaceship lalu tekan F9 dan masukkan kode berikut:
1 2 3 4 5 6 | _root["bullet"+i].onEnterFrame = function(){ this._y -= 10; if(this._y < -30){ this.removeMovieClip(); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | _root["bullet"+i].onEnterFrame = function(){ this._y -= 10; if(this._y < -30){ this.removeMovieClip(); } for(k = 0; k < _root.enemies.length; k++){ if(this.hitTest(_root[_root.enemies[k]])){ this.removeMovieClip(); _root[_root.enemies[k]].removeMovieClip(); _root.enemies.splice(k, 1); } } } |
Part 3 telah selesai.
Jika belum mengerti download saja file yang sudah jadi:
SPACESHIP PART 3
source: www.tutorialized.com
0 comments:
Post a Comment