Step by Step
Instructions and Codes
Step 1 -
Getting Started
Pastikan
bahwa dokumen Anda disetel pada ukuran default yaitu 550 px kali 400 px.
Pastikan bahwa frekuensi gambar Anda (fps) adalah antara 15 dan 24. Bukalah
pustaka Anda (di bawah "Jendela" di bagian atas). Klik kanan di dalam
perpustakaan Anda dan pilih "simbol baru". Pastikan bahwa simbol baru
Anda adalah "klip film". Beri nama simbol baru "SpaceShip".
Pastikan untuk menyebutkan dengan cara yang persis sama dengan yang saya miliki
di sini. Jika tidak, kode Anda tidak akan berfungsi dengan benar. Gambarkan
pahlawan Anda di layar. Ini bisa menjadi kapal angkasa, atau apa pun yang Anda
inginkan. Kreatiflah di sini. Anda selalu dapat kembali dan mengubahnya nanti.
Sejajarkan pendaftaran Anda, "+" di tengah, dengan apakah Anda akan
ingin peluru Anda keluar. Jika pahlawan Anda memiliki pistol, pastikan untuk
meletakkan ujung pistol di garis bidik dari pendaftaran.
Step 2 - Add Your Hero/Karakter
Kembali ke
garis waktu utama. Klik dan seret kapal angkasa Anda (pahlawan) ke panggung. Di
mana Anda menempatkan pahlawan Anda akan menentukan di mana dia akan mulai
dalam permainan. Beri nama contoh "Kapal". Sekali lagi, kita harus
sangat spesifik dengan ini. Perlu dieja persis sama dengan yang saya miliki di
sini dengan modal "S".
Step 3 . Add Some Code
Salin dan
sisipkan kode berikut ke panel tindakan dari bingkai pertama utama Anda timeline...
var timer =
8;
var nrEnemies = 3;
var lives = 3;
var score = 0;
var nrEnemies = 3;
var lives = 3;
var score = 0;
for (i = 1;
i < nrEnemies; i++)
{
_root.Enemy.duplicateMovieClip("Enemy" + i, _root.getNextHighestDepth());
}
{
_root.Enemy.duplicateMovieClip("Enemy" + i, _root.getNextHighestDepth());
}
var i =
0;
this.onEnterFrame = function()
{
timer++;
if (Key.isDown(Key.RIGHT))
{
if (Ship.hitTest(550, Ship._y, true))
{
Ship._x -= 10;
}
this.onEnterFrame = function()
{
timer++;
if (Key.isDown(Key.RIGHT))
{
if (Ship.hitTest(550, Ship._y, true))
{
Ship._x -= 10;
}
Ship._x += 10;
} else if (Key.isDown(Key.LEFT))
{
if (Ship.hitTest(0, Ship._y, true))
{
Ship._x += 10;
}
Ship._x -= 10;
} else if (Key.isDown(Key.UP))
{
if (Ship.hitTest(Ship._x - 40, 0, true))
{
Ship._y += 10;
}
Ship._y -= 10;
} else if (Key.isDown(Key.DOWN))
{
if (Ship.hitTest(Ship._x - 40, 400, true))
{
Ship._y -= 10;
}
Ship._y += 10;
}
if (Key.isDown(Key.SPACE))
{
i++;
if(timer >= 8)
{
} else if (Key.isDown(Key.LEFT))
{
if (Ship.hitTest(0, Ship._y, true))
{
Ship._x += 10;
}
Ship._x -= 10;
} else if (Key.isDown(Key.UP))
{
if (Ship.hitTest(Ship._x - 40, 0, true))
{
Ship._y += 10;
}
Ship._y -= 10;
} else if (Key.isDown(Key.DOWN))
{
if (Ship.hitTest(Ship._x - 40, 400, true))
{
Ship._y -= 10;
}
Ship._y += 10;
}
if (Key.isDown(Key.SPACE))
{
i++;
if(timer >= 8)
{
_root.attachMovie("Bullet", "Bullet" + i,
_root.getNextHighestDepth());
_root["Bullet" + i]._x = Ship._x + 3;
_root["Bullet" + i]._y = Ship._y;
var shoot_sound = new Sound();
shoot_sound.attachSound("shoot");
shoot_sound.start();
timer = 0;
}
_root["Bullet" + i]._x = Ship._x + 3;
_root["Bullet" + i]._y = Ship._y;
var shoot_sound = new Sound();
shoot_sound.attachSound("shoot");
shoot_sound.start();
timer = 0;
}
}
}
}
Sekarang uji
game Anda dengan menekan "control + enter". Kapal Anda (pahlawan)
harus bergerak di sekitar panggung dengan menekan tombol panah. Itu harus tetap
di atas panggung dan tidak menghilang dari tepi.
Step 4. Crete Some Bullets
Klik kanan
lagi di perpustakaan Anda. Buat "simbol baru" lagi dan pastikan itu
adalah klip film. Beri nama "Peluru". Pastikan untuk mengklik tombol
radio "ekspor untuk naskah tindakan". Jika Anda tidak melihatnya,
klik tombol lanjutan untuk melihat opsi. Dalam simbol peluru, gambar peluru
Anda. Jadilah kreatif, itu bisa apa saja. Pastikan untuk meluruskan peluru Anda
dengan sisi kanan tanda pendaftaran.
Tambahkan
kode berikut ke panel tindakan bingkai pertama dari simbol "Peluru" timeline...
this.onEnterFrame
= function()
{
for (i = 0; i < _root.nrEnemies; i++)
{
if (this.hitTest(_root["Enemy" + i]))
{
_root["Enemy" + i].reset();
_root.score += 10;
this.removeMovieClip();
}
}
{
for (i = 0; i < _root.nrEnemies; i++)
{
if (this.hitTest(_root["Enemy" + i]))
{
_root["Enemy" + i].reset();
_root.score += 10;
this.removeMovieClip();
}
}
this._x += 12;
if (this._x > 550)
{
this.removeMovieClip();
}
if (this._x > 550)
{
this.removeMovieClip();
}
}
Sekarang jalankan
animasi Anda. Pahlawan Anda (Kapal) harus bergerak dan menembak peluru Anda
ketika Anda menekan bilah spasi. Sangat keren, ya? Sekarang mari tambahkan
beberapa orang jahat.
Step 5. Add Some Bad Guys
Klik kanan
di perpustakaan Anda dan buat simbol baru. Sekali lagi, ini harus menjadi klip
film. Namai simbol baru Anda "Enemy". Sekarang, gambar apa yang Anda
inginkan dari musuh Anda. Setelah musuh Anda ditarik, kembalilah ke timeline
utama Anda dan seret musuh Anda ke atas panggung. Memberi Anda musuh pertama
nama instance (di bawah properti) dari "Enemy0", musuh kedua Anda
harus memiliki nama instance "Enemy1" dan yang ketiga harus memiliki
nama instance pada "Enemy2". Tambahkan kode berikut ke setiap
instance di atas panggung. Untuk melakukan ini, klik kanan pada setiap musuh,
pilih "tindakan" dan salin dan tempel kode berikut ...
onClipEvent(load)
{
function reset()
{
var timer = 12;
this._y = Math.random() * 300
this._x = 550
mySpeed = Math.ceil(Math.random() * 6) + 1;
}
reset();
}
onClipEvent(enterFrame)
{
//in every frame the enemy move left in the speed defined in the reset function.
this._x -= mySpeed;
if (this._x < -10)
{
//if the enemy is not on the screen, we reset it.
reset();
}
//if our timer is bigger than 12 we get a new
if (timer >= 12)
{
//direction to the Ship.
var dir = Math.ceil(Math.random() * 2)
//We get a random number, 1 or 2. 1 is up, 2 is down.
//Then we set timer to 0, so we only get a new dir when timer is bigger than 12
timer = 0;
}
if (dir == 1)
{
//if dir = 1, we move the ship up.
this._y -= 3;
} else if(dir == 2)
{
//if dir = 2, we move the ship down.
this._y += 3;
}
//increase timer by 1, so the timer gets equal to 12 and we get a new direction.
timer++
}
{
function reset()
{
var timer = 12;
this._y = Math.random() * 300
this._x = 550
mySpeed = Math.ceil(Math.random() * 6) + 1;
}
reset();
}
onClipEvent(enterFrame)
{
//in every frame the enemy move left in the speed defined in the reset function.
this._x -= mySpeed;
if (this._x < -10)
{
//if the enemy is not on the screen, we reset it.
reset();
}
//if our timer is bigger than 12 we get a new
if (timer >= 12)
{
//direction to the Ship.
var dir = Math.ceil(Math.random() * 2)
//We get a random number, 1 or 2. 1 is up, 2 is down.
//Then we set timer to 0, so we only get a new dir when timer is bigger than 12
timer = 0;
}
if (dir == 1)
{
//if dir = 1, we move the ship up.
this._y -= 3;
} else if(dir == 2)
{
//if dir = 2, we move the ship down.
this._y += 3;
}
//increase timer by 1, so the timer gets equal to 12 and we get a new direction.
timer++
}
Sekarang jalankan
animasinya lagi. Anda dapat terbang dan membunuh musuh, tetapi pahlawan Anda
tidak mati ketika terkena.
Step 6. Code Your Hero (Ship)
Sekarang
Anda siap untuk menambahkan kode ke instance kapal pada tahap garis waktu
utama.
Klik kanan
pada contoh kapal di timeline utama, pilih tindakan, dan tambahkan kode berikut
...
onClipEvent(load)
{
function reset()
{
this._x = 100;
this._y = 150;
}
reset()
}
onClipEvent(enterFrame)
{
for (i = 0; i < _root.nrEnemies; i++)
{
if (this.hitTest(_root["Enemy" + i]))
{
_root.lives -= 1;
if (_root.lives <= 0)
{
_root.attachMovie("GameOver", "GameOver", 100)
_root.GameOver._x = 275
_root.GameOver._y = 150
this.swapDepths(10);
this.removeMovieClip();
}
{
function reset()
{
this._x = 100;
this._y = 150;
}
reset()
}
onClipEvent(enterFrame)
{
for (i = 0; i < _root.nrEnemies; i++)
{
if (this.hitTest(_root["Enemy" + i]))
{
_root.lives -= 1;
if (_root.lives <= 0)
{
_root.attachMovie("GameOver", "GameOver", 100)
_root.GameOver._x = 275
_root.GameOver._y = 150
this.swapDepths(10);
this.removeMovieClip();
}
reset()
for(k = 0; k < _root.nrEnemies; k++)
{
_root["Enemy" + k].reset();
}
}
}
}
for(k = 0; k < _root.nrEnemies; k++)
{
_root["Enemy" + k].reset();
}
}
}
}
Sekarang jalankan
animasi Anda. Musuh Anda akan mati ketika Anda menembak mereka, dan mereka akan
membunuh Anda ketika mereka memukul Anda. Di bagian dua, kita akan menghidupkan
karakter kita.


0 comments:
Posting Komentar