Tekil Mesaj gösterimi
Alt 11 Temmuz 2014, 10:21   #1
Çevrimdışı
Swat
Kullanıcıların profil bilgileri misafirlere kapatılmıştır.
IF Ticaret Sayısı: (0)
IF Ticaret Yüzdesi:(%)
Zıplayan Toplar (Çarpışma Kuralına Göre)




C++ Builder 6 projesidir. Bu program da Timer nesnesi kullanılarak RadioButton ve Shape nesnelerinin hızlı bir hareketi sağlanmıştır. Eğer RadioButton ile Shape nesneleri çarpışma durumuna gelirlerse bulundukları istikamete göre zıt yönde hareket ederler. Böylece çarpışmada gerçeklik durumuna da değinilmiş olur. Çalışma zamanında formun boyutları pencerede kayma şeklinde olmayacak şekilde değiştirilirse çarpışma kuralı bağlı özellikler daha rahat gözlemlenebilir.

Kod:   Kodu kopyalamak için üzerine çift tıklayın!
//--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Timer1Timer(TObject *Sender) { static int sx=5; static int sy=5; static int ax=5; static int by=5; int x,y,a,b; x=RadioButton1->Left; y=RadioButton1->Top; a=Shape1->Left; b=Shape1->Top; if(y<=0) sy=-sy; if(b<=0) by=-by; if(y+RadioButton1->Height>=Form1->ClientRect.Bottom) sy=-sy; if(b+Shape1->Height>=Form1->ClientRect.Bottom) by=-by; if(x<=0) sx=-sx; if(a<=0) ax=-ax; if(x+RadioButton1->Width>=Form1->ClientRect.right) sx=-sx; if(a+Shape1->Width>=Form1->ClientRect.right) ax=-ax; if(RadioButton1->Left+RadioButton1->Width>Shape1->Left && RadioButton1->Left+RadioButton1->Width<Shape1->Left+Shape1->Width && RadioButton1->Top+RadioButton1->Height>Shape1->Top && RadioButton1->Top+RadioButton1->Height<Shape1->Top+Shape1->Height) {ax=-ax; sx=-sx; } if( RadioButton1->Top+RadioButton1->Height>Shape1->Top&&RadioButton1->Top+RadioButton1->Height<Shape1->Top+Shape1->Height && RadioButton1->Left+RadioButton1->Width>Shape1->Left && RadioButton1->Left+RadioButton1->Width<Shape1->Left+Shape1->Width) {by=-by; sy=-sy; } x+=sx; y+=sy; a+=ax; b+=by; RadioButton1->Left=x; RadioButton1->Top=y; Shape1->Left=a; Shape1->Top=b; } //---------------------------------------------------------------------------


 
Alıntı ile Cevapla

IRCForumlari.NET Reklamlar
sohbet odaları reklam ver Benimmekan Mobil Sohbet