コード例 #1
0
ファイル: LogoFactory.cs プロジェクト: whztt07/DeltaEngine
		public Logo Create()
		{
			Randomizer random = Randomizer.Current;
			Size size = new Size(random.Get(0.02f, 0.08f));
			var halfWidth = size.Width / 2f;
			var doubleWidth = size.Width * 2f;
			Rectangle view = screen.Viewport;
			Vector2D position = new Vector2D(random.Get(doubleWidth, view.Width - doubleWidth), view.Bottom - size.Height / 2);
			float direction = position.X > 0.5f ? -1 : 1;
			if (random.Get(1, 100) >= 30) direction *= -1;
			float r = direction > 0
				? random.Get(0, view.Width - position.X - doubleWidth)
				: random.Get(0, position.X - doubleWidth);
			var h = random.Get(0.3f, view.Height - 0.05f);
			var angle = Math.Atan((4 * h) / r);
			if (angle == 0)
				angle = 1.57079f;
			var v0 = Math.Sqrt(r * MovingSprite.Gravity / Math.Sin(2 * angle));
			var v_x = (float)(v0 * Math.Cos(angle));
			var v_y = (float)(v0 * Math.Sin(angle));
			v_x *= direction;
			var data = new SimplePhysics.Data()
			{
				Gravity = new Vector2D(0f, MovingSprite.Gravity),
				Velocity = new Vector2D(v_x, -v_y),
				RotationSpeed = random.Get(10, 50) * direction
			};
			return new Logo("DeltaEngineLogo", Color.GetRandomBrightColor(), position, size, data);
		}
コード例 #2
0
ファイル: Earth.cs プロジェクト: whztt07/DeltaEngine
		public Earth(Vector2D position)
			: base(ContentLoader.Load<Material>("Earth"), position)
		{
			var data = new SimplePhysics.Data { Gravity = new Vector2D(0.0f, 0.1f) };
			Add(data);
			Start<SimplePhysics.BounceIfAtScreenEdge>();
			Start<SimplePhysics.Move>();
		}
コード例 #3
0
ファイル: Enemy.cs プロジェクト: whztt07/DeltaEngine
		public Enemy()
			: base(ContentLoader.Load<Material>("Earth"), Rectangle.FromCenter(
				new Vector2D(Randomizer.Current.Get(), 0.1f), new Size(0.1f * 1.35f, 0.1f)))
		{
			var data = new SimplePhysics.Data { Gravity = new Vector2D(0.0f, 0.1f), Duration = 10 };
			Add(data);
			Start<SimplePhysics.Move>();
			Start<SimplePhysics.KillAfterDurationReached>();
		}
コード例 #4
0
ファイル: Earth.cs プロジェクト: whztt07/DeltaEngine
		public Earth(Vector2D position)
			: base(ContentLoader.Load<Material>("Earth"), position)
		{
			Add(new OutlineColor(Color.Red));
			OnDraw<DrawPolygon2DOutlines>();
			var data = new SimplePhysics.Data { Gravity = new Vector2D(0.0f, 0.1f) };
			Add(data);
			Start<SimplePhysics.BounceIfAtScreenEdge>();
			Start<SimplePhysics.Move>();
		}
コード例 #5
0
ファイル: Projectile.cs プロジェクト: whztt07/DeltaEngine
		//ncrunch: no coverage start
		public Projectile(Vector2D startPosition, float angle)
			: base(Rectangle.FromCenter(startPosition, new Size(.02f)))
		{
			Rotation = angle;
			RenderLayer = (int)AsteroidsRenderLayer.Rockets;
			missileAndTrails =
				new ParticleSystem(ContentLoader.Load<ParticleSystemData>("MissileEffect"));
			//Replacing usage of the ContentLoader we could do the following to dynamically create data:
			//missileAndTrails = new ParticleSystem();
			//var rocketData = new ParticleEmitterData
			//{
			//	ParticleMaterial = ContentLoader.Load<Material>("Missile2D"),
			//	Size = new RangeGraph<Size>(new Size(0.025f, 0.025f), new Size(0.025f, 0.025f)),
			//	LifeTime = 0,
			//	SpawnInterval = 0.001f,
			//	MaximumNumberOfParticles = 1
			//};
			//var trailData = new ParticleEmitterData
			//{
			//	ParticleMaterial = ContentLoader.Load<Material>("Projectile2D"),
			//	Size = new RangeGraph<Size>(new Size(0.02f, 0.03f), new Size(0.02f, 0.04f)),
			//	StartPosition =
			//		new RangeGraph<Vector3D>(new Vector3D(0.0f, 0.02f, 0.0f), new Vector3D(0.0f, 0.02f, 0.0f)),
			//	LifeTime = 2.2f,
			//	SpawnInterval = 0.2f,
			//	MaximumNumberOfParticles = 8
			//};
			//missileAndTrails.AttachEmitter(new ParticleEmitter(trailData, Vector3D.Zero));
			//missileAndTrails.AttachEmitter(new ParticleEmitter(rocketData, Vector3D.Zero));
			//missileAndTrails.AttachedEmitters[0].EmitterData.DoParticlesTrackEmitter = true;
			//missileAndTrails.AttachedEmitters[1].EmitterData.DoParticlesTrackEmitter = true;
			//foreach (var emitter in missileAndTrails.AttachedEmitters)
			//	emitter.EmitterData.StartRotation =
			//		new RangeGraph<ValueRange>(new ValueRange(Rotation, Rotation),
			//			new ValueRange(Rotation, Rotation));
			missileAndTrails.Orientation = Quaternion.FromAxisAngle(Vector3D.UnitZ, Rotation);
			var data = new SimplePhysics.Data
			{
				Gravity = Vector2D.Zero,
				Velocity =
					new Vector2D(MathExtensions.Sin(angle) * ProjectileVelocity,
						-MathExtensions.Cos(angle) * ProjectileVelocity)
			};
			Add(data);
			Start<MoveAndDisposeOnBorderCollision>();
		}
コード例 #6
0
ファイル: Projectile.cs プロジェクト: remy22/DeltaEngine
 //ncrunch: no coverage start
 public Projectile(Vector2D startPosition, float angle)
     : base(Rectangle.FromCenter(startPosition, new Size(.02f)))
 {
     Rotation = angle;
     RenderLayer = (int)AsteroidsRenderLayer.Rockets;
     // ParticleSystemData can very well be loaded by a ContentLoader, unused for simplicity in M5
     //missileAndTrails =
     //	new ParticleSystem(ContentLoader.Load<ParticleSystemData>("MissileEffect"));
     missileAndTrails = new ParticleSystem();
     var rocketData = new ParticleEmitterData
     {
         ParticleMaterial = ContentLoader.Load<Material>("Missile2D"),
         Size = new RangeGraph<Size>(new Size(0.025f, 0.025f), new Size(0.025f, 0.025f)),
         LifeTime = 0,
         SpawnInterval = 0.001f,
         MaximumNumberOfParticles = 1
     };
     var trailData = new ParticleEmitterData
     {
         ParticleMaterial = ContentLoader.Load<Material>("Projectile2D"),
         Size = new RangeGraph<Size>(new Size(0.02f, 0.03f), new Size(0.02f, 0.04f)),
         StartPosition =
             new RangeGraph<Vector3D>(new Vector3D(0.0f, 0.02f, 0.0f), new Vector3D(0.0f, 0.02f, 0.0f)),
         LifeTime = 2.2f,
         SpawnInterval = 0.2f,
         MaximumNumberOfParticles = 8
     };
     missileAndTrails.AttachEmitter(new ParticleEmitter(trailData, Vector3D.Zero));
     missileAndTrails.AttachEmitter(new ParticleEmitter(rocketData, Vector3D.Zero));
     missileAndTrails.AttachedEmitters[0].EmitterData.DoParticlesTrackEmitter = true;
     missileAndTrails.AttachedEmitters[1].EmitterData.DoParticlesTrackEmitter = true;
     foreach (var emitter in missileAndTrails.AttachedEmitters)
         emitter.EmitterData.StartRotation =
             new RangeGraph<ValueRange>(new ValueRange(Rotation, Rotation),
                 new ValueRange(Rotation, Rotation));
     var data = new SimplePhysics.Data
     {
         Gravity = Vector2D.Zero,
         Velocity =
             new Vector2D(MathExtensions.Sin(angle) * ProjectileVelocity,
                 -MathExtensions.Cos(angle) * ProjectileVelocity)
     };
     Add(data);
     Start<MoveAndDisposeOnBorderCollision>();
 }
コード例 #7
0
ファイル: Asteroid.cs プロジェクト: remy22/DeltaEngine
 private Asteroid(Rectangle drawArea, InteractionLogic interactionLogic, int sizeModifier)
     : base(new Material(Shader.Position2DColorUV, "Asteroid"), drawArea)
 {
     var randomizer = Randomizer.Current;
     this.interactionLogic = interactionLogic;
     this.sizeModifier = sizeModifier;
     RenderLayer = (int)AsteroidsRenderLayer.Asteroids;
     var data = new SimplePhysics.Data
     {
         Gravity = Vector2D.Zero,
         Velocity = GetInitialVelocity(randomizer),
         RotationSpeed = randomizer.Get(.1f, 50)
     };
     Add(data);
     Start<SimplePhysics.Move>();
     Start<MoveCrossingScreenEdges>();
     Start<SimplePhysics.Rotate>();
 }
コード例 #8
0
ファイル: BouncingLogo.cs プロジェクト: whztt07/DeltaEngine
 public BouncingLogo()
     : base(new Material(ShaderFlags.Position2DColoredTextured, "DeltaEngineLogo"), Vector2D.Half)
 {
     Color = Color.GetRandomColor();
     var data = new SimplePhysics.Data
     {
         RotationSpeed = random.Get(-50, 50),
         Velocity = new Vector2D(random.Get(-0.4f, 0.4f), random.Get(-0.4f, 0.4f)),
         Bounced = () =>
         {
             if (sound.NumberOfPlayingInstances < 4)
                 sound.Play(0.1f);
         }
     };
     Add(data);
     Start<SimplePhysics.BounceIfAtScreenEdge>();
     Start<SimplePhysics.Rotate>();
     new Command(Command.Click, position => Center = position);
 }
コード例 #9
0
ファイル: Grid.cs プロジェクト: whztt07/DeltaEngine
		} //ncrunch: no coverage end

		private static void AddFallingBrick(Entity2D brick, Material material)
		{
			var fallingBrick = new Sprite(material, brick.DrawArea)
			{
				Color = brick.Color,
				RenderLayer = (int)BlocksRenderLayer.FallingBrick,
			};
			var random = Randomizer.Current;
			var data = new SimplePhysics.Data
			{
				Velocity = new Vector2D(random.Get(-0.5f, 0.5f), random.Get(-1.0f, 0.0f)),
				RotationSpeed = random.Get(-360, 360),
				Duration = 5.0f,
				Gravity = new Vector2D(0.0f, 2.0f)
			};
			fallingBrick.Add(data);
			fallingBrick.Start<SimplePhysics.Move>();
		}