IRCForumları - IRC ve mIRC Kullanıcılarının Buluşma Noktası

IRCForumları - IRC ve mIRC Kullanıcılarının Buluşma Noktası (https://www.ircforumlari.net/)
-   C ve C++ (https://www.ircforumlari.net/c-ve-c/)
-   -   Zıplayan Toplar (Çarpışma Kuralına Göre) (https://www.ircforumlari.net/c-ve-c/600409-ziplayan-toplar-carpisma-kuralina-gore.html)

Swat 11 Temmuz 2014 10:21

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:

//---------------------------------------------------------------------------
 
#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;
}
//---------------------------------------------------------------------------



Tüm Zamanlar GMT +3 Olarak Ayarlanmış. Şuanki Zaman: 22:28.

Powered by vBulletin® Version 3.8.8 Beta 3
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO
Copyright ©2004 - 2024 IRCForumlari.Net