Cool Neon Green Outer Glow Pointer

Senin, 09 April 2012

Membuat game dengan Delphi Advanced

DRAGON BALL 13090434 EDITION HEHE....
Halo temen” terima kasih dah mampir di mari,,,

senengnya bisa mencuri dan berbagi ilmu melalui internet hhehe...
kali ini saya mau berbagi sdikit cara pmbuatan game sederhana menggunakan delphi 7,lumayan deh buat melatih n blajar .
Game yg saya buat ini menggunakan tokoh kartun dragon ball(songoku,cell,frezzer n bhu)berhubung ilmu saya masih blum nyampe,untuk dragon ball yg saya buat ini tidak bertarung n mngeluarkan jurus” ampuh heheh...
Disini Songoku harus bersaing menyentuh bola naga dengan cell
Jika songoku menyentuh bola naga maka akan mendapatkan poin=10 begitu juga cell.
Tp jika songoku menyentuh cell maka poinnya akan berkurang=5,menyentuh frezzer n bhu berkurang=1
Sebelum mulai membuat siapkan dulu image atau gambar format ico.wmf.jpg. dll yg akan dipakai
Kemudian desain kurang lebih sperti ini:


Klo ni hasilnya,,,

 ni listing nya.....
LISTING PROGRAM

 private
    { Private declarations }
  public
    { Public declarations }
    procedure aktif;
    procedure nonaktif;
  end;

var
  Form3: TForm3;
    lima : Integer;
   lemah : Integer;
   vskorgoku,vskorcell : Integer;
   menit , detik : Integer ;
   jamawal , jamakhir , ketpemenang : String ;

implementation

{$R *.dfm}
procedure TForm3.aktif;
begin
panel1.Enabled:=true;
image1.Enabled:=true;
image2.Enabled:=true;
image3.Enabled:=true;
poin.Enabled:=true;
tanah.Enabled:=true;
sbatas.Enabled:=true;
sbbawah.Enabled:=true;
sbkanan.Enabled:=true;
sbkiri.Enabled:=true;
timer1.Enabled:=true;
timer2.Enabled:=true;
button1.Enabled:=false;
button2.Enabled:=true;
button3.Enabled:=false;
button4.Enabled:=false;
end;

procedure TForm3.nonaktif;
begin
panel1.Enabled:=false;
image1.Enabled:=false;
image2.Enabled:=false;
image3.Enabled:=false;
poin.Enabled:=false;
tanah.Enabled:=false;
sbatas.Enabled:=false;
sbbawah.Enabled:=false;
sbkanan.Enabled:=false;
sbkiri.Enabled:=false;
timer1.Enabled:=false;
timer2.Enabled:=false;
button1.Enabled:=true;
button2.Enabled:=false;
button3.Enabled:=true;
button4.Enabled:=true;
end;

procedure TForm3.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if Key=VK_left then
        begin
                sbkiriClick(Owner);
        end;

        if Key=VK_right then
        begin
                sbkananClick(Owner);
        end;
        if Key=VK_up then
        begin
                sbatasClick(Owner);
        end;
        if Key=VK_down then
        begin
                sbbawahClick(Owner);
        end;
end;


procedure TForm3.sbkananClick(Sender: TObject);
begin
if image1.Left+image1.Width < Panel1.Width   then
 begin
    image1.Left:=image1.Left+10 ;
 end
end;


procedure TForm3.sbkiriClick(Sender: TObject);
begin
  if image1.Left >= Panel1.Left  then
  begin
       image1.Left:=image1.Left-10 ;
  end

end;

procedure TForm3.sbbawahClick(Sender: TObject);
begin
if image1.Top+image1.Height<=Panel1.Height then
begin
      image1.Top:=image1.Top+10 ;
end

end;

procedure TForm3.sbatasClick(Sender: TObject);
begin
if image1.Top>=35 then
begin
       image1.Top:=image1.Top-10 ;
end

end;

procedure TForm3.FormCreate(Sender: TObject);
begin
lima:= 10;
lemah:= 5;
vskorgoku.text:= '0';
vskorcell.Text:='0';
menit:= 5;
detik:= 0;
ketpemenang:=TimeToStr(Now);
nonaktif;
end;


procedure TForm3.Timer1Timer(Sender: TObject);
begin
image2.Left:=image2.Left+3;
image2.top:=image2.Top+lima;


 if image2.Left> Panel1.Width then
 begin
      image2.Left:=-100;
 end;

  if image2.Top+image2.Height>Panel1.Height then
    begin
       lima:=-lima;
    end;


 if image2.Top<0 then
     begin
       lima:=-lima;
     end;

   if (image1.Left+image1.Width>poin.Left) and
      (image1.Left<poin.Left+poin.Width)     and
      (image1.Top+image1.Height>poin.Top) and
      (image1.Top<poin.Top+poin.Height) then
   begin

    Randomize;
    poin.Left:=random(Panel1.Width-poin.Height);
    poin.Top:=tanah.top+random(tanah.Height-poin.Height);
    vskorgoku.text:=inttostr(strtoint(vskorgoku.Text)+10);
   end
   else

    if (image2.Left+image2.Width>image1.Left) and
      (image2.Left<image1.Left+image1.Width)     and
      (image2.Top+image2.Height>image1.Top) and
      (image2.Top<image1.Top+image1.Height) then
   begin


   vskorgoku.text:=inttostr(strtoint(vskorgoku.Text)-1);
   end ;

end;

procedure TForm3.Timer2Timer(Sender: TObject);
begin
if image3.Left+5>image1.Left then
      begin
        image3.Left := image3.Left-3;
      end
      else
      begin
        image3.Left := image3.Left+3;
      end;

    if image3.Top+image3.Height-5>=image1.Top then
    begin
      image3.Top:=image3.Top-2;
    end
    else
    begin
    image3.Top:=image3.Top+2;
    end;

    if (image3.Left+image3.Width>image1.Left) and
      (image3.Left<image1.Left+image1.Width)     and
      (image3.Top+image3.Height>image1.Top) and
      (image3.Top<image1.Top+image1.Height) then
   begin


   vskorgoku.text:=inttostr(strtoint(vskorgoku.Text)-1);
   end ;
   if image5.Left+5>poin.Left then
      begin
        image5.Left := image5.Left-4;
      end
      else
      begin
        image5.Left := image5.Left+4;
      end;

    if image5.Top+image5.Height-5>=poin.Top then
    begin
      image5.Top:=image5.Top-3;
    end
    else
    begin
    image5.Top:=image5.Top+3;
    end;

    if (image5.Left+image5.Width>poin.Left) and
      (image5.Left<poin.Left+poin.Width)     and
      (image5.Top+image5.Height>poin.Top) and
      (image5.Top<poin.Top+poin.Height) then
   begin

    Randomize;
    poin.Left:=random(Panel1.Width-poin.Height);
    poin.Top:=tanah.top+random(tanah.Height-poin.Height);
    vskorcell.text:=inttostr(strtoint(vskorcell.Text)+10);
    end
     else

    if (image5.Left+image5.Width>image1.Left) and
      (image5.Left<image1.Left+image1.Width)     and
      (image5.Top+image5.Height>image1.Top) and
      (image5.Top<image1.Top+image1.Height) then
   begin


   vskorgoku.text:=inttostr(strtoint(vskorgoku.Text)-5);
   end;
   jamakhir:=TimeToStr(now);
if jamawal<>jamakhir then
begin
detik:=detik-1;
if detik<0 then
begin
detik:=59;
menit:=menit-1;
end;

if menit<0 then
  begin

    if vskorgoku.text>vskorcell.text then
      begin
        ketpemenang:='Selamat Anda Menang';
      end
      else
      if vskorgoku.text<vskorcell.text then
      begin
        ketpemenang:='Maaf anda kalah';
      end
      else
      begin
        ketPemenang:='Permainan Seri';
      end;
        Timer1.Enabled:=false;
        Timer2.Enabled:=false;
        MessageDlg(ketpemenang,mtInformation,mbOKCancel,0);
        Application.Terminate;
      end;
              jamawal:=jamakhir;
        Jam.Caption:='0'+IntToStr(menit)+':'+
        IntToStr(detik);
    if detik<10 then
      begin
        Jam.Caption:='0'+IntToStr(menit)+':'+
        '0'+IntToStr(detik);
      end;
  end;

end;

procedure TForm3.Button1Click(Sender: TObject);
begin
aktif;
end;

procedure TForm3.Button2Click(Sender: TObject);
begin
nonaktif;
end;

procedure TForm3.Button3Click(Sender: TObject);
begin
if colordialog1.Execute=true then
form3.Color:=colordialog1.Color;
end;

procedure TForm3.Button4Click(Sender: TObject);
begin
if application.MessageBox('Are you sure,to close?','confirmation',36)=idyes then
close;
end;

end.

Tidak ada komentar:

Posting Komentar