Donatur utama

Kamis, 20 November 2008

Animasi Bola Pantul2

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();

}

4 komentar:

Anonim mengatakan...

wah lumayan ne,,,
thanks mgkn nnti akn menambah minat untuk bljar Cpp,,,mklum br pmula,,,
kbalik cr bljarnya

WW on 6 Mei 2009 pukul 23.49 mengatakan...

asyik juga nih belajar cpp.
tapi nge-run-nya pake program apa?
soalnya aq pake visual c++ koq g bisa. Trims

nyaxti on 4 Agustus 2009 pukul 05.31 mengatakan...

cpp itu apa si?
aq br belajar pemrograman, n' gmn cara jalaninya? trus hasil tampilannya gmn?

Shikamaru Nara on 29 Juni 2020 pukul 23.37 mengatakan...

infonya sangat bermanfaat bagi ane
Peniup debu panjang

 

Berlangganan

Enter your email address:

Delivered by FeedBurner

Belajar Tik


Pengikut

Komentar Terbaru

Belajar Tik
Tempatnya Belajar Teknologi Informasi dan Komunikasi

Administrator By : 3eta