Melanjutkan game Virus sebelumnya (sudah ada mekanisme klik, skor, dan Game Over), kini kita akan menambahkan fitur countdown (hitung mundur “3, 2, 1, Go!”) yang muncul setiap kali permainan dimulai, sekaligus memastikan virus tidak mulai bergerak sebelum countdown selesai.
3, ubah warnanya (misalnya merah), perbesar ukurannya, dan posisikan di tengah.2, 1, dan Go secara berurutan — pastikan setiap teks tetap diposisikan tepat di tengah.Tips: sementara mengatur posisi teks, sembunyikan sprite Game Over (klik lalu pilih hide/nonaktifkan sementara) agar area kerja terlihat jelas tanpa tertutup.
when [green flag] clicked
show
switch costume to [three]
wait 0.5 seconds
switch costume to [two]
wait 0.5 seconds
switch costume to [one]
wait 0.5 seconds
switch costume to [go]
wait 0.2 seconds
hide
Skrip ini menampilkan sprite Counter (show), lalu menampilkan angka 3, 2, 1, dan “Go” secara berurutan dengan jeda 0.5 detik di antaranya. Setelah “Go” tampil sebentar (0.2 detik), sprite Counter disembunyikan kembali (hide).
Jika dicoba, akan terlihat masalah: virus-virus tetap bergerak naik-turun dan berganti costume bersamaan dengan countdown yang sedang berjalan — padahal seharusnya virus baru mulai bergerak setelah countdown selesai (“Go” muncul).
Solusinya: hapus event when green flag clicked dari setiap sprite virus (agar tidak langsung berjalan saat green flag diklik), lalu gunakan sistem broadcast agar virus baru mulai bergerak setelah menerima sinyal dari Counter.
Pada sprite Counter, tambahkan blok broadcast di akhir skrip:
when [green flag] clicked
show
switch costume to [three]
wait 0.5 seconds
switch costume to [two]
wait 0.5 seconds
switch costume to [one]
wait 0.5 seconds
switch costume to [go]
wait 0.2 seconds
hide
broadcast [play]
Pada setiap sprite virus (virus_1 sampai virus_6), ganti event awal dari when green flag clicked menjadi when I receive [play]:
when I receive [play]
forever
next costume
wait (pick random 0.5 to 1) seconds
Dengan perubahan ini, seluruh virus baru akan mulai bergerak dan berganti costume setelah menerima pesan “play” yang dikirim Counter di akhir countdown — bukan langsung berjalan bersamaan dengan klik green flag.
Karena setiap virus sebelumnya memiliki set Score to 0 masing-masing (berpotensi duplikat/tidak perlu), cukup letakkan sekali saja di titik masuk utama program — misalnya pada skrip sprite Game Over, karena skrip itulah yang benar-benar berjalan sejak awal lewat when green flag clicked:
when [green flag] clicked
set [Score] to 0
show variable [Score]
hide
forever
if <(Score) < 0> then
show
hide variable [Score]
stop [all]
Hapus blok set Score to 0 yang ada di masing-masing sprite virus, karena sudah tidak diperlukan lagi.
Terakhir, tambahkan backdrop yang sesuai, misalnya Blue Sky, agar tampilan game lebih menarik secara visual.
Sprite Counter:
when [green flag] clicked
show
switch costume to [three]
wait 0.5 seconds
switch costume to [two]
wait 0.5 seconds
switch costume to [one]
wait 0.5 seconds
switch costume to [go]
wait 0.2 seconds
hide
broadcast [play]
Setiap Sprite Virus (virus_1 s/d virus_6):
when I receive [play]
forever
next costume
wait (pick random 0.5 to 1) seconds
when this sprite clicked
if <(costume [name]) = "virus_show"> then
change [Score] by 1
if <(costume [name]) = "virus_hide"> then
change [Score] by -1
Sprite Game Over:
when [green flag] clicked
set [Score] to 0
show variable [Score]
hide
forever
if <(Score) < 0> then
show
hide variable [Score]
stop [all]
Dengan fitur countdown ini, Virus Clicker Game kini sudah benar-benar lengkap:
broadcast dan when I receive.set Score to 0) yang lebih rapi hanya di satu tempat.