a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 編程 > C# > 正文

用C#編寫物體碰撞的程序

2023-05-16 12:36:05
字體:
供稿:網(wǎng)友

本文講解了使用C#編寫物體碰撞的一個源代碼,本實例來自一個老外的網(wǎng)站,從源代碼就可以看出,編寫的很專業(yè),大家可以學(xué)一學(xué)。

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

public class Form1 : System.Windows.Forms.Form {
    private int dx = 4;
    private System.Windows.Forms.PictureBox picTarget;
    private System.Windows.Forms.PictureBox picBall;
    private System.Windows.Forms.Timer timer1;

    public Form1() {
        InitializeComponent();
    }
    private void InitializeComponent() {
      this.picTarget = new System.Windows.Forms.PictureBox();
      this.picBall = new System.Windows.Forms.PictureBox();
      this.timer1 = new System.Windows.Forms.Timer(new System.ComponentModel.Container());
      this.SuspendLayout();

      this.picTarget.BackColor = Color.Red;
      this.picTarget.Location = new System.Drawing.Point(160240);
      this.picTarget.Name = "picTarget";
      this.picTarget.Size = new System.Drawing.Size(5656);
      this.picTarget.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
      this.picTarget.TabIndex = 0;
      this.picTarget.TabStop = false;

      this.picBall.Image = new Bitmap("winter.jpg");
      this.picBall.Location = new System.Drawing.Point(24136);
      this.picBall.Name = "picBall";
      this.picBall.Size = new System.Drawing.Size(3232);
      this.picBall.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
      this.picBall.TabIndex = 1;
      this.picBall.TabStop = false;

      this.timer1.Enabled = true;
      this.timer1.Tick += new System.EventHandler(this.timer1_Tick);

      this.AutoScaleBaseSize = new System.Drawing.Size(513);
      this.BackColor = System.Drawing.Color.White;
      this.ClientSize = new System.Drawing.Size(392341);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                  this.picBall,
                                                                  this.picTarget});
      this.Name = "Form1";
      this.Text = "Crasher";
      this.ResumeLayout(false);

    }
    [STAThread]
    static void Main() {
      Application.Run(new Form1());
    }

    private void timer1_Tick(object sender, System.EventArgs e) {
      int newX, newY;
      newX = picBall.Location.X + dx;
      newY = picBall.Location.Y + dx;
      
      if (newX > this.Width - picBall.Width){
        dx = - dx;
      
      
      if (newX < 0){
        dx = - dx;
      }
      
      if (picBall.Bounds.IntersectsWith(picTarget.Bounds)){
        this.BackColor = Color.Black;
      else {
        this.BackColor = Color.White;
      }
      
      picBall.Location = new Point(newX, newY);
    }
}

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 日韩欧美在线播放 | 国产乱码精品一区二区三区忘忧草 | 一区二区三区不卡视频 | 精品一区二区三区蜜桃 | 成人免费视频视频在线观看 免费 | 99久久视频| 久久久久久亚洲 | 欧美理论视频 | 免费的黄色网 | 看一级黄色大片 | 欧美亚洲一区二区三区 | 日日爱夜夜爱 | 99视频在线看 | 99国产精品 | 一区二区三区在线免费看 | 一区二区三区亚洲 | 天堂福利影院 | 欧美v亚洲 | 天天澡天天狠天天天做 | a天堂在线 | 亚洲免费成人 | 久久五月天色 | 狠狠色伊人亚洲综合成人 | 久久一区二区视频 | 亚洲一区二区三区视频 | 欧洲亚洲一区二区三区 | 亚洲码欧美码一区二区三区 | 成人黄色大片 | 日韩精品极品视频在线 | 国产日韩欧美精品一区二区 | 日韩视频中文字幕在线观看 | 亚洲精区 | 青青草亚洲 | 亚洲一区亚洲二区 | 欧美综合一区二区 | 亚洲成色www久久网站瘦与人 | 在线视频日韩 | 欧洲一级毛片 | 巨大荫蒂视频欧美大片 | 欧美激情一区二区三区蜜桃视频 | 亚洲国产视频网站 |