Contoh program animasi bergerak c++

Kali ini kami akan share contoh program yang sangat sederhana tapi tidak kalah penting untuk dipelajari, yaitu program animasi bergerak c++.

 #include <iostream>

#include <conio.h>

#include <windows.h>

using namespace std;



void gotoxy (int x, int y)

{

    COORD coord = {30, 31};

    coord.X = x; coord.Y = y;

    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);

}



void setcolor(unsigned short color)

{

  HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);

  SetConsoleTextAttribute(hCon,color);

}



char name[15];

int y=30;



delay (int x)

{

    for (int y=0; y<x*100; y++)

    {

        for (int z=0; z<x*100; z++)

        {



        }

    }

}

right()

{

    for (int x=32; x<=90-sizeof(name); x++)

    {

     

        delay (40);

        setcolor(13);

        gotoxy (x,32);

        cout<<name;



        gotoxy (x-1,32);

        cout<<" ";

    }

}



left()

{

 for (int x=31-sizeof(name); x>=1; x--)

 {

  delay(45);

  gotoxy (x,31);

  cout<<name;

  setcolor(12);

  gotoxy(x-31,31);

  cout<<" ";

 }

}



up()

{

 for(int k=35; k>=1; k--)

 {

  delay(45);

  setcolor(12);

  gotoxy (35, k);

  cout<<name;

  

  gotoxy(35,k+1);

  for(int z=1; z<=sizeof(name); z++)

  {

   cout<<" ";

  }

  

 }

}



down()

{

 

 for(int k=31; k<=55; k++)

 {

  delay(40);

  setcolor(2);

  gotoxy (55-sizeof(name),k);

  cout<<name;

  

  gotoxy(55-sizeof(name),k-1);

  for(int s=1; s<sizeof(name); s++)

  {

   cout<<" ";

  }

  

 }

}

sampingkananatas()

{

   for(int x=30; x<=70-sizeof(name); x++)

  {

   delay(50);

   setcolor(8);

 

   gotoxy(x, y-1);

   cout<<name;

   

   gotoxy(x-1, y);

   cout<<"                                             ";y--;

   

  }

}



sampingkananbawah()//masih errorrrrrrrrrrrrrrrr

{

    for (int i=32; i<=70-sizeof(name); i++)

      {

       

          delay (40);

          setcolor(13);

          gotoxy (i,i-1);

          cout<<name;

  

          gotoxy (i-1,i);

          cout<<" ";

   }

  system("cls");



}



main()

{



  gotoxy (30,30);

     cout<<"Enter Your Text= "<<endl;

     gotoxy (30,31);

  cin>>name;

  

 



 system ("cls");

 up();

  gotoxy (30,30);

     cout<<"Enter Your Text= "<<endl;

     gotoxy (30,31);

  cin>>name;

  system ("cls");

 down();

  gotoxy (30,30);

     cout<<"Enter Your Text= "<<endl;

     gotoxy (30,31);

  cin>>name;

  system ("cls");

  left();

  gotoxy (30,30);

     cout<<"Enter Your Text= "<<endl;

     gotoxy (30,31);

  cin>>name;

  system ("cls");

 

 right();

  gotoxy (30,30);

     cout<<"Enter Your Text= "<<endl;

     gotoxy (30,31);

  cin>>name;

  system ("cls");

 

 sampingkananatas();

  gotoxy (30,30);

     cout<<"Enter Your Text= "<<endl;

     gotoxy (30,31);

  cin>>name;

  system ("cls");

  

 sampingkananbawah();

} 
Default image
Arman Basir
A New Journey. Menyukai hal-hal baru yang menantang dan kompleks untuk di pecahkan

Leave a Reply