bulletsprite.cs

来自「Beginning C# Game Programming 的源代码」· CS 代码 · 共 37 行

CS
37
字号
using System;using System.Drawing;using Microsoft.DirectX.Direct3D;namespace SpaceDonuts {
	public class BulletSprite : BasicSprite {

		public BulletSprite(TileSet ts) : base(ts) {
			this.VisuallyRotates = true;
		}
		public new float Angle {			get {				return Geometry.RadianToDegree(zAngle);			}			set {				zAngle = Geometry.DegreeToRadian(value);				visualAngle = zAngle;
			}		}	
		public override void BoundaryCheck(Rectangle boundingBox) {
			// Angle of reflection = angle of incidence, measured from the 
			// surface normal.  So for perpendicular surfaces, all we have to do 
			// is negate the current angle. 
			int height = boundingBox.Height - this.Tiles.ExtentY*2;
			int width = boundingBox.Width - this.Tiles.ExtentX*2;
			if (this.PositionX > (width) || this.PositionX < 0) {
				this.Angle = -this.Angle;
				this.VelocityX *= -1; 
			}
			if (this.PositionY > (height) || this.PositionY < 0) { 
				this.Angle = -this.Angle;
				this.VelocityY *= -1;
			}
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?