Hareketli Top Uygulaması[C#]

03 Nisan 2010 – 10:23 Eğer dxball tarzı 1oyun yapmak istiyorsanız bu kodlar size referans olabilir.Top form kenarlarına sekerek sürekli olarak form için dönüyor.
![hareketlitop hareketlitop Hareketli Top Uygulaması[C#]](http://www.csharptr.com/wp-content/uploads/2010/04/hareketlitop.jpg)
Kodlar
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace HareketliTop { public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.RadioButton radioButton1; private System.Windows.Forms.Timer timer1; private System.ComponentModel.IContainer components; public Form1() { InitializeComponent(); } protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.radioButton1 = new System.Windows.Forms.RadioButton(); this.timer1 = new System.Windows.Forms.Timer(this.components); this.SuspendLayout(); // // radioButton1 // this.radioButton1.Location = new System.Drawing.Point(116, 200); this.radioButton1.Name = "radioButton1"; this.radioButton1.Size = new System.Drawing.Size(104, 24); this.radioButton1.TabIndex = 0; this.radioButton1.Text = "radioButton1"; // // timer1 // this.timer1.Tick += new System.EventHandler(this.timer1_Tick); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(292, 266); this.Controls.Add(this.radioButton1); this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); this.ResumeLayout(false); } #endregion [STAThread] static void Main() { Application.Run(new Form1()); } private void Form1_Load(object sender, System.EventArgs e) { radioButton1.Text = ""; radioButton1.Width = 10; timer1.Interval = 50; timer1.Enabled = true; } int sx = 5, sy = 5; private void timer1_Tick(object sender, System.EventArgs e) { if (radioButton1.Top < = 0 || radioButton1.Bottom >= this.ClientSize.Height) //Formun üstüne veya altına ulaşıldı ise artımı ters çevir sy = -sy; //artış yönünü ters çevir if (radioButton1.Left < = 0 || radioButton1.Right >= this.ClientSize.Width) //Formun soluna veya sağına ulaşıldı ise artımı ters çevir. sx = -sx; //artış yönünü ters çevir radioButton1.Left += sx; radioButton1.Top += sy; } } } |
Projede öncelikle radiobuttonu top gibi düşünüyoruz:) timer ile hareket ettirerek ilerlemesini,çarpmasını ve sekme işlemlerini yapıyoruz..
Linkler
RapidShare
SendSpace
Csharptr
Etiketler: ”C# hareketli top, dxball uygulaması”