Monday, 18 April 2011

Animasi Bola Pantul2 di C++

Ternyata banyak Game yang dapat dibuat menggunakan tampilan console, kini saya menyertakan sebuah game yang dapat dibuat menggunakan CPP dan VbNet console, Game tersebut adalah Game Bola Pantul dimana, Bola akan dipantul jika kena papan pantul yang posisinya dapat digeser kekiri dan ke kanan. Skor akan bertambah jika bola mengenai bidang pantulan di sisi berlawanan.

Ini nih kodenya, dan jika Mau langsung programnya silahkan aja di Belajar Tik dan Ziddu.

Kode Pada CPP:

#include<constream.h>

#include<dos.h>

#include<stdlib.h>

void main()

{

        textbackground(0);

        clrscr();

        int xb,yb,axb,ayb;

        int w[41];

        int v[15];

        int speed;

        int csk,t;

        t=4;       

        speed=100;

         axb=1;

        ayb=1;

        xb=20;

        yb=5;

        int xp,yp;

        xp=25;

        yp=23;

        int skor=0;

        int tombol;

        int p;

        for(p=1;p<=42;p++)

        {

                textbackground(3);

                gotoxy(p,1);

                cprintf(" ");

                gotoxy(p,24);

                cprintf(" ");

        }

        for(p=1;p<=24;p++)

        {

                textbackground(3);

                gotoxy(1,p);

                cprintf(" ");

                gotoxy(42,p);

                cprintf(" ");

        }

        textbackground(0);

        int pj;

        for(p=5;p<=36;p++)

                w[p]=1;

                for(p=2;p<=t;p++)

                v[p]=p;

                int br;

        for(br=2;br<=t;br++)

        {

                for(p=5;p<=36;p++)

                { gotoxy(p,br);

                   cprintf("ß");}

        }

        _setcursortype(_NOCURSOR);

        do

        {

                // textbackground(CYAN);

                gotoxy(10,1);

                cout<<"skor = "<<skor;

                gotoxy(30,1);

                cout<<"speed = "<<speed;

                pj=xp+8;

                for(p=xp;p<=pj;p++)

                {

                        gotoxy(p,yp);

                        cprintf("ß");

                }

                 gotoxy(xb,yb);

               cprintf("O");

                delay(speed);

                gotoxy(xb,yb);

                cprintf(" ");

                for(p=xp;p<=pj;p++)

                {

                        gotoxy(p,yp);

                        cprintf(" ");

                }

                if(kbhit())

                {

                        tombol=getch();

                        if(tombol==75)

                        {

                                if(xp>10)

                                        xp=xp-6;

                                else

                                        xp=2;

                        }

                        else if(tombol==77)

                        {

                                if(xp<30)

                                        xp=xp+6;

                                else

                                        xp=33;

                        }

               }

                        xb=xb+axb;

                        yb=yb+ayb;

                if(xb==2)

                        axb=1;

                else if(xb==41)

                        axb=-1;

                if(yb==2)

                        ayb=1;

                if(yb==22 && (xb>=xp-1 && xb<=pj+1))

                {

                        ayb=-1;

                }

                else if(yb==23)

                {

                        gotoxy(30,12);

                        cout<<"Game Over";

                        tombol=27;

                }

                for(csk=t;csk>=3;csk--)

                {

                        if(yb==csk && w[xb]==1)

                        {

                                w[xb]=0;

                                ayb=-ayb;

                                skor=skor+10;

                                if(skor%50==0)

                                {

                                        if(speed>30)

                                        speed=speed-5;

                                }

                        }

                }

        }while(tombol!=27);

        getch();

}

0 komentar:

Post a Comment

 
Design by Andhika Yuswanto | Bloggerized by Kunir - JAWA TIMUR | UNIVERSITAS JEMBER