Skip to main content

beberapa contoh animasi

// ulara II

#include
#include
#include
#include
#include
#include
#include
#include
int main()
{
// source code anda
int ULANGTERUS=1;
// konstanta arah
int KANAN = 0;
int KIRI = 1;
int ATAS = 2;
int BAWAH = 3;
//pada saat awal ular akan bergerak ke kanan
int ARAH=KANAN;

//konstanta batas
int BATASATAS = 6;
int BATASBAWAH = 10;
int BATASKIRI = 2;
int BATASKANAN = 45;
//mengatur badan ular
//sim1 = simbol untuk kepala
//sim2 = simbol untuk badan
//sim3 = simbol untuk ekor
char sim1='X';
char sim2='o';
char sim3='o';
//mengatur posisi ular
//posX1, posY1 = menentukan posisi kepala
//posX2, posY2 = menentukan posisi badan
//posX3, posY3 = menentukan posisi ekor
int posX1=BATASKIRI+2, posY1=BATASATAS+2;
int posX2=1, posY2=1;
int posX3=1, posY3=1;
printf("==============================================\n");
printf("== RATTLE SNAKE : ULAR BERJALAN TDK TERATUR ==\n");
printf("== Author : VnP ==\n");
printf("== http://cplusplusindonesia.blogspot.com ==\n");
printf("=============================================\n\n");
gotoxy(1,12); printf("KELUAR Tekan sembarang tombol\n");
//inisialisasi proses random
srand(time(NULL));
while(ULANGTERUS)
{

}

//gambar ular
gotoxy(posX1,posY1); printf("%c",sim1);
gotoxy(posX2,posY2); printf("%c",sim2);
gotoxy(posX3,posY3); printf("%c",sim3);
delay(150);
//hapus ular pada posisi lama
gotoxy(posX1,posY1); printf(" ");
gotoxy(posX2,posY2); printf(" ");
gotoxy(posX3,posY3); printf(" ");
//ubah posisi
posX3=posX2;
posY3=posY2;
posX2=posX1;
posY2=posY1;
//kita hanya perlu mengontrol posisi kepala
//dalam hal ini, posisi dari sim1
//arah dari ular diganti
if(ARAH==KANAN)
{
if(posX1>=BATASKANAN) ARAH= (rand()%100)%4;
else
posX1+=1;
} else
if(ARAH==BAWAH)
{
if(posY1>=BATASBAWAH) ARAH=(rand()%100)%4;
else
posY1+=1;
} else
if(ARAH==KIRI)
{
if(posX1<=BATASKIRI) ARAH=(rand()%100)%4; else posX1= 1; } else if(ARAH==ATAS) { if(posY1<=BATASATAS) ARAH=(rand()%100)%4; else posY1= 1; } //cek penekanan sembarang tombol if(kbhit()) break; } return 0;

Comments