示例#1
0
        /// <summary>
        /// Конструктор
        /// </summary>
        /// <param name="shipVerts"></param>
        private Ship(PointF position, float length, float width)
        {
            float depth = 0;
            List<Vector3> shipVerts = new List<Vector3>();
            shipVerts.Add(new Vector3(-1f * width / 2 + position.X, -1f * length / 2 + position.Y, depth));
            shipVerts.Add(new Vector3(-1f * width / 2 + position.X, 0.25f * length / 2 + position.Y, depth));
            shipVerts.Add(new Vector3(0 * width / 2 + position.X, 1f * length / 2 + position.Y, depth));
            shipVerts.Add(new Vector3(1f * width / 2 + position.X, 0.25f * length / 2 + position.Y, depth));
            shipVerts.Add(new Vector3(1f * width / 2 + position.X, -1f * length / 2 + position.Y, depth));
            shipVerts.Add(new Vector3(-1f * width / 2 + position.X, -1f * length / 2 + position.Y, depth));

            //mechanics = VehicleWithGearboxAspect.Create(this);
            physics = PhysicsAspect.Create(this);
            mass = MassAspect.Create(this);
            Thruster thruster1 = Thruster.Create(this, physics.Facing);
            Thruster thruster2 = Thruster.Create(this, physics.Facing);
            IList<Thruster> thrusters = new List<Thruster>(2);
            thrusters.Add(thruster1);
            thrusters.Add(thruster2);
            thrusterController = ThrusterController.Create(this, thrusters);
            graphics = GraphicsAspect.Create(this, shipVerts, 3, Color.White, Color.Red);
            bounds = BoundSetAspect.Create(this, shipVerts);
            //bounds.GetOuterContour();
            bounds.SetAttribute(Strings.CollisionDetectionSpeedType, Strings.CollisionDetectionSpeedTypeSlowOrStatic);

            rearCannon = Weapon.Create(this, Side.Rear);
            leftCannon = Weapon.Create(this, Side.Left);
            rightCannon = Weapon.Create(this, Side.Right);
            damage = DamageAspect.Create(this, 100);

            messageHandler.Handlers.Add(typeof(Kill), HandleKill);
            messageHandler.Handlers.Add(typeof(BoundSetCollision), HandleBoundSetCollision);
        }
示例#2
0
        public Shell(Vector3 position, Vector3 cannonFacing, Vector3 cannonVelocity, float startSpeed, object shellOwner)
        {
            int segments = 8;
            List<Vector3> vertices = new List<Vector3>(segments + 1);

            //float unitradius = (float)Math.Sqrt(8);
            float angleStep = (float)(2 * Math.PI / segments);
            for (int i = 0; i < segments; i++)
            {
                vertices.Add(new Vector3((float)Math.Cos(angleStep * i) * radius, (float)Math.Sin(angleStep * i) * radius, 0));
            }
            vertices.Add(new Vector3(radius, 0, 0));

            graphics = GraphicsAspect.Create(this, vertices, position, 1, Color.White, Color.Red);

            // вычисляем вектор полёта снаряда - сумма импульса выстрела и собственной скорости оружия
            cannonFacing.NormalizeFast();
            Vector3 shootVelocity = cannonFacing * startSpeed + cannonVelocity;
            Vector2 shootDirection = shootVelocity.Xy;
            shootDirection.NormalizeFast();
            //physics = new PhysicsAspect(this, position, shootVelocity.Xy, startSpeed);

            physics = PhysicsAspect.Create(this, position, shootDirection, shootVelocity.LengthFast);
            bounds = BoundSetAspect.Create(this, null);
            BoundsAspect bound = CircleBoundsAspect.Create(bounds, position.Xy, radius);
            bounds.AddBound(bound);
            // снаряд будет быстродвижущимся объектом, для него особый алгоритм определения столкновений
            bounds.SetAttribute(Strings.CollisionDetectionSpeedType, Strings.CollisionDetectionSpeedTypeFast);
            damage = DamageAspect.Create(this, 1);

            //physics = new PhysicsAspect(this, position, Vector2.Zero, 0);
            //timer = DestroyByTimerAspect.Create(this, new TimeSpan(0, 0, 0, 2, 500));
            timer = DestroyByTimerAspect.Create(this, new TimeSpan(0, 0, 0, 1, 0));

            this.shellOwner = shellOwner;
            this.name = "shell";

            MessageDispatcher.RegisterHandler(typeof(SetPosition), bounds);
            MessageDispatcher.RegisterHandler(typeof(SetPosition), graphics);
            MessageDispatcher.RegisterHandler(typeof(DestroyChildrenOf), this);
            MessageDispatcher.RegisterHandler(typeof(Kill), this);

            messageHandler.Handlers.Add(typeof(Kill), HandleKill);
        }
示例#3
0
 public static PhysicsAspect Create(object owner, Vector3 position, Vector2 facing, float speed)
 {
     PhysicsAspect aspect = new PhysicsAspect(owner, position, facing, speed);
     aspect.RegisterAllStuff();
     return aspect;
 }
示例#4
0
 public static PhysicsAspect Create(object owner)
 {
     PhysicsAspect aspect = new PhysicsAspect(owner);
     aspect.RegisterAllStuff();
     return aspect;
 }