Lewati ke konten

Bab 2: Game Whack-a-Mole (Pukul Tikus Lengkap)

Demo Interaktif: Whack-a-Mole
Buka di Scratch
Klik bendera hijau untuk memulai, lalu klik tikus yang muncul dengan palu.
Tampilan permainan Whack-a-Mole dengan indikator Score, Lives, dan Level

Tampilan permainan Whack-a-Mole dengan indikator Score, Lives, dan Level.

Progres Praktik: Whack-a-Mole
0 / 4 selesai
Lompat
Lompat
Lompat
Lompat
Koordinat

Koordinat Mouse & Titik Pusat

Palu terus mengikuti koordinat X dan Y mouse dengan blok go to mouse-pointer. Titik pusat kostum (costume center) diletakkan tepat di kepala palu agar pukulan akurat.

Kontrol Klik

Anti-Hold Klik (Debounce)

Blok wait until not mouse down? menahan skrip sampai klik mouse dilepas sehingga pemain tidak bisa curang dengan menahan tombol klik.

Prosedur

Fungsi / Prosedur (My Blocks)

Animasi 4 kostum tikus dibungkus ke dalam Mole Up dan Mole Down agar kode utama tetap ringkas dan tidak berulang-ulang.

Sinkronisasi

Menghentikan Skrip Paralel

Saat tikus terpukul, blok stop other scripts in sprite langsung mematikan hitung mundur di Mole Up supaya nyawa pemain tidak ikut berkurang.

Tabel Komponen Sprite, Variabel, & Sinyal Broadcast

Section titled “Tabel Komponen Sprite, Variabel, & Sinyal Broadcast”
Komponen Nama di Scratch Peran & Fungsi Teknis
Variable (Global) Score, Lives, Level Score menghitung tikus terpukul; Lives nyawa pemain (awal 3); Level mempercepat waktu tikus bersembunyi.
Broadcast whack, game over, debug whack dikirim saat palu memukul; game over saat nyawa habis; debug untuk menampilkan semua tikus.
Sprite Palu hammer Berada di lapisan paling depan (front layer) dengan 2 kostum: hammer up dan hammer down.
Sprite Tikus Mole s.d. Mole8 8 sprite tikus dengan 4 kostum bertahap (costume1 s.d. costume4). Tikus belakang berukuran 70–80% untuk efek perspektif.
Stage Backdrop game screen, game over 2 latar belakang: padang rumput dengan 8 lubang tanah dan layar penutup saat kalah.

Langkah 1: Membuat Sprite Palu (hammer) & Variabel

Section titled “Langkah 1: Membuat Sprite Palu (hammer) & Variabel”
  1. Hapus sprite kucing bawaan, klik Choose a Sprite → Paint, dan beri nama sprite hammer.
  2. Gambar palu pada kostum pertama, geser bagian kepala palu tepat ke titik tengah kanvas (crosshair), lalu beri nama kostum hammer down.
  3. Klik kanan kostum tersebut → Duplicate, beri nama hammer up, lalu putar sedikit gambar palu ke arah atas.
  4. Buka kategori Variables → Make a Variable, buat 3 variabel (pilih For all sprites): Score, Lives, dan Level.
  5. Susun 3 skrip blok berikut pada sprite hammer:
Skrip Sprite Paluhammer
Geser ke samping jika terpotong
Skrip 1 — Inisialisasi Layer & Variabel

when

clicked

show
go to front layer
set Score to 0
set Lives to 3
set Level to 1
Skrip 2 — Ikuti Mouse & Aksi Memukul

when

clicked

switch costume to hammer up
forever
go to mouse-pointer

if mouse down? then

start sound pop
switch costume to hammer down
broadcast whack

wait until not mouse down?

switch costume to hammer up
Skrip 3 — Sembunyi Saat Game Over
when I receive game over
hide

Langkah 2: Menggambar 4 Kostum Tikus & Membuat My Blocks

Section titled “Langkah 2: Menggambar 4 Kostum Tikus & Membuat My Blocks”

A. Menggambar & Memotong 4 Kostum di Paint Editor

Section titled “A. Menggambar & Memotong 4 Kostum di Paint Editor”

Gunakan simulator interaktif di bawah ini untuk melihat posisi potongan tiap kostum terhadap titik tengah kanvas (crosshair) serta cara kerja animasi naik-turun tikus:

Panduan Visual Paint Editor

4 Kostum Animasi Tikus & Simulator Kemunculan

Gambar utuh dulu, duplikasi 4 kali, lalu potong dari bawah
1Gambar Badan & Kepala Utuh

Buat sprite baru (Paint) bernama Mole. Pakai Circle Tool & Rectangle Tool warna cokelat (#752f2f) untuk kepala melengkung, 2 lingkaran mata putih + hitam, serta mulut tersenyum.

2Duplikasi Menjadi 4 Kostum

Klik kanan kostum pertama lalu pilih Duplicate sebanyak 3 kali menjadi costume1 sampai costume4. Biarkan costume4 tetap utuh sebagai posisi muncul penuh.

3Potong Bawah & Sejajarkan Crosshair

Klik Convert to Bitmap, seleksi bagian bawah badan dengan Select Tool lalu tekan Delete. Geser sisa gambar hingga garis potong tepat menempel di titik tengah kanvas (crosshair).

costume145 x 16 px
Dihapus

Ujung Kepala: Potong di atas mata, sisakan puncak kepala.

costume245 x 40 px
Dihapus

Setengah Kepala: Potong di bawah mata, mulut belum tampak.

costume345 x 63 px
Dihapus

Hampir Penuh: Mata & mulut tampak, potong sedikit perut bawah.

costume445 x 84 px

Badan Utuh: Tidak dipotong sama sekali (muncul penuh).

Simulator Animasicostume4 (show)

B. Membungkus 4 Kostum ke dalam My Blocks (Mole Up & Mole Down)

Section titled “B. Membungkus 4 Kostum ke dalam My Blocks (Mole Up & Mole Down)”

Buka kategori My Blocks → Make a Block, lalu buat blok Mole Up (animasi naik costume1 → costume4 ditambah hitung mundur repeat (10 - Level) sebelum mengurangi Lives) dan Mole Down (animasi turun costume3 → costume1 lalu hide):

Definisi My BlocksMole
Geser ke samping jika terpotong
My Block 1 — Animasi Muncul & Hitung Mundur Nyawa

define Mole Up

switch costume to costume1
show
wait 0.1 seconds
switch costume to costume2
wait 0.1 seconds
switch costume to costume3
wait 0.1 seconds
switch costume to costume4
wait 0.1 seconds

repeat 10 - Level

wait 1 seconds
change Lives by -1
say Haha! for 0.5 seconds
Mole Down

wait pick random 1 to 15 seconds

Mole Up
My Block 2 — Animasi Masuk ke Lubang

define Mole Down

switch costume to costume3
wait 0.1 seconds
switch costume to costume2
wait 0.1 seconds
switch costume to costume1
wait 0.1 seconds
hide

Langkah 3: Memprogram Kemunculan Acak, Deteksi Pukulan, & Mode Debug

Section titled “Langkah 3: Memprogram Kemunculan Acak, Deteksi Pukulan, & Mode Debug”

Masih di sprite Mole, tambahkan 4 skrip event di bawah ini.

Skrip Event Kemunculan & PukulanMole
Geser ke samping jika terpotong
Skrip 3 — Kemunculan Awal

when

clicked

hide

wait pick random 1 to 15 seconds

Mole Up
Skrip 4 — Saat Dipukul Palu (whack)
when I receive whack

if touching hammer ? then

stop other scripts in sprite
change Score by 1
Mole Down

wait pick random 1 to 15 seconds

Mole Up
Skrip 5 — Saat Game Over
when I receive game over
hide
Skrip 6 — Mode Debug (Atur Posisi)
when I receive debug
show
switch costume to costume4

Langkah 4: Duplikasi 8 Tikus & Program Kenaikan Level di Stage

Section titled “Langkah 4: Duplikasi 8 Tikus & Program Kenaikan Level di Stage”
  1. Gambar 2 backdrop pada Stage: game screen (rumput hijau dengan 8 lubang cokelat) dan game over (layar bertuliskan GAME OVER).
  2. Klik kanan sprite Mole → Duplicate sebanyak 7 kali hingga terdapat 8 tikus (Mole s.d. Mole8). Posisikan masing-masing tikus di atas lubangnya, dan kecilkan ukuran (Size) tikus bagian belakang ke 70–80%.
  3. Pilih Stage, lalu susun blok berikut untuk menaikkan Level setiap kelipatan skor dan memicu game over saat Lives < 1:
Skrip Pengendali StageStage
Geser ke samping jika terpotong
Stage Skrip 1 — Cek Naik Level & Deteksi Nyawa Habis

when

clicked

switch backdrop to game screen
forever

if Score = 10 then

set Level to 2

if Score = 20 then

set Level to 3

if Score = 30 then

set Level to 4

if Lives < 1 then

broadcast game over
stop all
Stage Skrip 2 — Ganti Layar Game Over
when I receive game over
switch backdrop to game over