麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > C# > 正文

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

2023-05-16 12:36:05
字體:
來源:轉載
供稿:網友

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

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);
    }
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 黄色aaa视频 | 毛片在线看免费 | 成人午夜精品久久久久久久3d | 中国成人在线视频 | 久久99精品久久久久久236 | 国产精品久久久久久久久久尿 | 轻点插视频 | 国产成人精品免费视频大全最热 | 欧美成人精品一区 | av播放在线 | 午夜视频播放 | 91色综合综合热五月激情 | 欧美一级欧美 | 黄污视频在线看 | 精品亚洲午夜久久久久91 | 91麻豆精品国产91久久久无需广告 | 亚洲性视频 | 久久人人人| 日韩欧美精品中文字幕 | 久久久久久久99 | 久久久国产一级片 | 国产大片全部免费看 | chinesexxxx刘婷hd| 播色网| 久久精品观看 | 国产一级在线免费观看 | av资源在线| 国产一区二区欧美 | 萌白酱福利视频在线网站 | 手机免费看一级片 | 成人性爱视频在线观看 | 欧美大穴| 国产精品久久久久久久久粉嫩 | 免费一级a毛片在线播放视 日日草夜夜操 | 成人视屏免费看 | 欧美日韩在线播放 | 国产精品久久久久久一区二区三区 | 亚洲成人自拍电影 | 国产精品久久久久久久久久久久久久久 | 久久久久久久高清 | www久久艹 |