Akhirnya kita dapat sprite yang bisa kita pakai dan kita gunakan dalam program kita. Dengan cara yang sama, kita dapat mengambil object2 untuk sprite kita dari bermacam2 source. Sebagai percobaan saya mengambil beberapa sprite Marle… temennya si Chrono dalam game Chrono
Trigger. Berikut programnya:

‘Load Gambar Marle
‘Taken from CHRONO TRIGGER

CLEAR
DEFINT A-Z

CONST Path$ = “”

‘11 x 32
OPEN Path$ + “Marle1.shp” FOR INPUT AS #1
DIM SHARED Marle1(200): FOR i = 0 TO 200: INPUT #1, Marle1(i): NEXT: CLOSE #1
‘40 x 11
OPEN Path$ + “Marle2.shp” FOR INPUT AS #1
DIM SHARED Marle2(248): FOR i = 0 TO 248: INPUT #1, Marle2(i): NEXT: CLOSE #1
‘14 x 24
OPEN Path$ + “Marle3.shp” FOR INPUT AS #1
DIM SHARED Marle3(189): FOR i = 0 TO 189: INPUT #1, Marle3(i): NEXT: CLOSE #1
‘20 x 24
OPEN Path$ + “Marle4.shp” FOR INPUT AS #1
DIM SHARED Marle4(264): FOR i = 0 TO 264: INPUT #1, Marle4(i): NEXT: CLOSE #1
‘10 x 31
OPEN Path$ + “Marle5.shp” FOR INPUT AS #1
DIM SHARED Marle5(178): FOR i = 0 TO 178: INPUT #1, Marle5(i): NEXT: CLOSE #1
‘15 x 28
OPEN Path$ + “Marle6.shp” FOR INPUT AS #1
DIM SHARED Marle6(234): FOR i = 0 TO 234: INPUT #1, Marle6(i): NEXT: CLOSE #1
‘14 x 31
OPEN Path$ + “Marle7.shp” FOR INPUT AS #1
DIM SHARED Marle7(242): FOR i = 0 TO 242: INPUT #1, Marle7(i): NEXT: CLOSE #1
‘14 x 31
OPEN Path$ + “Marle8.shp” FOR INPUT AS #1
DIM SHARED Marle8(242): FOR i = 0 TO 242: INPUT #1, Marle8(i): NEXT: CLOSE #1
‘18 x 22
OPEN Path$ + “Marle9.shp” FOR INPUT AS #1
DIM SHARED Marle9(220): FOR i = 0 TO 220: INPUT #1, Marle9(i): NEXT: CLOSE #1
‘17 x 27
OPEN Path$ + “Marle10.shp” FOR INPUT AS #1
DIM SHARED Marle10(254): FOR i = 0 TO 254: INPUT #1, Marle10(i): NEXT: CLOSE #1

‘15 x 32
OPEN Path$ + “Marler.shp” FOR INPUT AS #1
DIM SHARED marler(266): FOR i = 0 TO 266: INPUT #1, marler(i): NEXT: CLOSE #1
‘17 x 32
OPEN Path$ + “Marler1.shp” FOR INPUT AS #1
DIM SHARED marler1(299): FOR i = 0 TO 299: INPUT #1, marler1(i): NEXT: CLOSE #1
‘18 x 30
OPEN Path$ + “Marler2.shp” FOR INPUT AS #1
DIM SHARED marler2(296): FOR i = 0 TO 296: INPUT #1, marler2(i): NEXT: CLOSE #1
‘18 x 32
OPEN Path$ + “Marler3.shp” FOR INPUT AS #1
DIM SHARED marler3(315): FOR i = 0 TO 315: INPUT #1, marler3(i): NEXT: CLOSE #1
‘17 x 32
OPEN Path$ + “Marler4.shp” FOR INPUT AS #1
DIM SHARED marler4(299): FOR i = 0 TO 299: INPUT #1, marler4(i): NEXT: CLOSE #1
‘18 x 31
OPEN Path$ + “Marler5.shp” FOR INPUT AS #1
DIM SHARED marler5(306): FOR i = 0 TO 306: INPUT #1, marler5(i): NEXT: CLOSE #1
‘19 x 32
OPEN Path$ + “Marler6.shp” FOR INPUT AS #1
DIM SHARED marler6(332): FOR i = 0 TO 332: INPUT #1, marler6(i): NEXT: CLOSE #1

SCREEN 13
CLS
PUT (10, 30), Marle2
PUT (55, 17), Marle3
PUT (75, 17), Marle4
PUT (100, 13), Marle6
PUT (120, 9), Marle1
PUT (140, 10), Marle5
PUT (160, 10), Marle7
PUT (180, 10), Marle8
PUT (200, 19), Marle9
PUT (220, 10), Marle10

PUT (10, 50), marler
PUT (30, 50), marler1
PUT (50, 50), marler2
PUT (70, 50), marler3
PUT (90, 50), marler4
PUT (110, 50), marler5
PUT (130, 50), marler6

a$ = INPUT$(1)
‘ Buat Animasi Marle meloncat-loncat
CLS
DO
PUT (150, 29), Marle9
FOR j = 1 TO 1000: FOR k = 1 TO 6000: NEXT: NEXT
PUT (150, 29), Marle9
PUT (160, 10), Marle10
FOR j = 1 TO 1000: FOR k = 1 TO 6000: NEXT: NEXT
PUT (160, 10), Marle10
LOOP UNTIL INKEY$ = CHR$(13)

‘Animasi berjalan

x.pos = 10: y.pos = 50
x.old = x.pos: y.old = y.pos
x.ofset = 4: y.ofset = 4
delay = 1800

PUT (x.pos, y.pos), marler

main:
a$ = INKEY$
IF a$ = “” THEN GOTO main
IF LEN(a$) <> 2 THEN GOSUB not.arrow
keyb = ASC(RIGHT$(a$, 1))
‘IF keyb = 72 THEN GOSUB atas
‘IF keyb = 75 THEN GOSUB kiri
IF keyb = 77 THEN GOSUB kanan
‘IF keyb = 80 THEN GOSUB bawah

‘clean the keyboard buffer before go back to main loop
DEF SEG = &H40
POKE &H1A, PEEK(&H1C)

GOTO main

kanan:
‘hapus spritenya
oldx.pos = x.pos: oldy.pos = y.pos
PUT (oldx.pos, oldy.pos), marler
x.pos = x.pos + x.ofset
‘letakkan di posisi baru
PUT (x.pos, y.pos), marler1
FOR z = 1 TO delay: FOR y = 1 TO delay: NEXT: NEXT
‘hapus spritenya
oldx.pos = x.pos: oldy.pos = y.pos
PUT (oldx.pos, oldy.pos), marler1
x.pos = x.pos + x.ofset
‘letakkan di posisi baru
PUT (x.pos, y.pos), marler2
FOR z = 1 TO delay: FOR y = 1 TO delay: NEXT: NEXT
‘hapus spritenya
oldx.pos = x.pos: oldy.pos = y.pos
PUT (oldx.pos, oldy.pos), marler2
x.pos = x.pos + x.ofset
‘letakkan di posisi baru
PUT (x.pos, y.pos), marler3
FOR z = 1 TO delay: FOR y = 1 TO delay: NEXT: NEXT
‘hapus spritenya
oldx.pos = x.pos: oldy.pos = y.pos
PUT (oldx.pos, oldy.pos), marler3
x.pos = x.pos + x.ofset
‘letakkan di posisi baru
PUT (x.pos, y.pos), marler4
FOR z = 1 TO delay: FOR y = 1 TO delay: NEXT: NEXT
‘hapus spritenya
oldx.pos = x.pos: oldy.pos = y.pos
PUT (oldx.pos, oldy.pos), marler4
x.pos = x.pos + x.ofset
‘letakkan di posisi baru
PUT (x.pos, y.pos), marler5
FOR z = 1 TO delay: FOR y = 1 TO delay: NEXT: NEXT
‘hapus spritenya
oldx.pos = x.pos: oldy.pos = y.pos
PUT (oldx.pos, oldy.pos), marler5
x.pos = x.pos + x.ofset
‘letakkan di posisi baru
PUT (x.pos, y.pos), marler6
FOR z = 1 TO delay: FOR y = 1 TO delay: NEXT: NEXT
‘hapus spritenya
oldx.pos = x.pos: oldy.pos = y.pos
PUT (oldx.pos, oldy.pos), marler6
x.pos = x.pos + x.ofset
‘letakkan di posisi baru
PUT (x.pos, y.pos), marler
‘RETURN

not.arrow:
‘Jika ditekan tombol q maka program akan berhenti
IF a$ = “q” THEN
WIDTH 80
SCREEN 0
COLOR 7, 0
CLS
END
END IF
RETURN

Pada scene pertama, saya hanya meletakkan semua sprite secara statis, istilahnya diPUT aja, tanpa animasi. Lalu scene berikutnya, saya gambarkan animasi Marle meloncat2, sprite ini saya dapatkan sewaktu Marle menang melawan musuh2nya.
Sekarang bagian animasi berjalannya… kalo diperhatikan satu kali dia berjalan, terdiri dari 6 buah sprite.semakin banyak sprite
untuk sebuah gerakan, maka gerakannya akan keliatan bagus dan asli, kalo di game rosetta, saya hanya menggunakan 2 buah sprite, itupun sprite yang sama, hanya kakinya aja yang letaknya berbeda. jadi kurang bagus …
Penggunaan INKEY$ sebagai fungsi pembacaan keyboard tidak direkomendasikan oleh pakar2nya game, tapi saya rasa saya akan coba memakai INKEY$. Nah, sekarang yang jadi masalah neh… pada saat kita menekan tombol kanan, program akan lari ke subrutin memPUT sprite sebanyak 6 buah. Jika user menekan tombol kanan terus menerus, hal ini akan mengakibatkan keyboard buffer penuh, sehingga hasil animasi tidak akan sesuai dengan yang diharapkan user, yaitu pada saat user sudah
melepas tombol, sprite akan tetap berjalan. kenapa bisa gitu? karena pada saat itu, masih ada sisa instruksi yang disimpan di buffer keyboard. trus caranya gimana? pemikiran saya gini… kita harus memberikan perintah untuk mengosongkan buffer keyboard pada saat kembali ke looping utama. Dan ternyata bisa dilakukan dengan memberikan perintah ini;
DEF SEG = &H40
POKE &H1A, PEEK(&H1C)
Lega deh… akhirnya ketemu solusinya, walaupun ngga bagus2 amat, tapi lumayanlah. untuk mengaplikasikan animasi ini untuk deteksi tubrukan, mungkin akan timbul masalah baru dengan pembersihan keyboard buffernya…