상속: IDisposable
예제 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SeekMotion"/> class.
 /// </summary>
 /// <param name="target">The target object.</param>
 /// <param name="speed">The speed (under 0.1f is better).</param>
 /// <param name="defaultVector">The default vector used when no target is set yet.</param>
 /// <param name="rotationSpeed">The rotation speed.</param>
 public SeekMotion(GameObject target, float speed, Vector2D defaultVector, float rotationSpeed)
 {
     Target = target;
     _lastDirection = defaultVector;
     _speed = speed;
     _rotationSpeed = rotationSpeed;
 }
예제 #2
0
        public void Update(GameObject gameObject, float deltaTime)
        {
            if (!Script.IsNullOrUndefined(Target))
            {
                float lastAngle = _lastDirection.GetAbsoluteAngle();
                Vector2D targetVector = new Vector2D(Target.Location.X - gameObject.Location.X, Target.Location.Y - gameObject.Location.Y);

                double relativeAngle = targetVector.GetAbsoluteAngle() - lastAngle;

                if (Math.Abs(relativeAngle) > Math.PI)
                {
                    if (relativeAngle < 0) relativeAngle += Math.PI * 2;
                    else relativeAngle -= Math.PI * 2;
                }

                if (relativeAngle != 0)
                {
                    Angle = lastAngle + (Math.Min(_rotationSpeed, Math.Abs(relativeAngle)) * (relativeAngle / Math.Abs(relativeAngle)));
                    _lastDirection.X = _speed * Math.Cos(Angle);
                    _lastDirection.Y = _speed * Math.Sin(Angle);
                }
            }

            gameObject.Location.TranslateByVector(_lastDirection);
        }
예제 #3
0
 public static GameObject Create(ImageElement defaultImage, float handleX, float handleY)
 {
     GameObject gameObject = new GameObject();
     AnimationSequence sequence = new AnimationSequence();
     sequence.AddSprite(defaultImage, handleX, handleY);
     gameObject.AnimationSequences["Default"] = sequence;
     gameObject.StartAnimation("Default");
     return gameObject;
 }
예제 #4
0
        public RoadObject(long distance, float x, Scene scene)
        {
            Distance = distance;
            X = x;
            _scene = scene;

            List<AnimationSequence> sequences = EnsureSequences(scene);

            this.GameObject = new GameObject();
            this.GameObject.AnimationSequences["Default"] = sequences[Math.Floor(Math.Random() * sequences.Count)];
            this.GameObject.StartAnimation("Default");
        }
예제 #5
0
        public override void Init(Scene level)
        {
            _level = (ShooterLevel)level;
            Ship = new GameObject();

            AnimationSequence sequence = new AnimationSequence();
            sequence.Delay = 200;
            sequence.AddSprite(_level.LoadImage("Images/shooter/meteor/2.png", true), 0, 0);
            Ship.AnimationSequences["Default"] = sequence;

            sequence = new AnimationSequence();
            sequence.Delay = 200;
            sequence.AddSprite(_level.LoadImage("Images/shooter/meteor/3.png", true), 0, 0);
            Ship.AnimationSequences["Up"] = sequence;

            sequence = new AnimationSequence();
            sequence.Delay = 200;
            sequence.AddSprite(_level.LoadImage("Images/shooter/meteor/1.png", true), 0, 0);
            Ship.AnimationSequences["Down"] = sequence;

            sequence = new AnimationSequence();
            sequence.Delay = 40;
            sequence.Loop = false;
            sequence.AddSprites(new ImageElement[] {
                    _level.LoadImage("Images/shooter/meteor/e1.png", false),
                    _level.LoadImage("Images/shooter/meteor/e5.png", false),
                    _level.LoadImage("Images/shooter/meteor/e9.png", false),
                    _level.LoadImage("Images/shooter/meteor/e13.png", false),
                    _level.LoadImage("Images/shooter/meteor/e17.png", false)
                }, 0, 0);
            Ship.AnimationSequences["Crash"] = sequence;
            Ship.AnimationCompleted += new AnimationCompletedEventHandler(Ship_AnimationCompleted);

            _speed = 0.15f;

            Ship.Location = new Vector3D(20, 390, ShooterLevel.MeteorZ);
            Ship.StartAnimation("Default");
        }
예제 #6
0
 public override void Dispose()
 {
     _level = null;
     Ship = null;
 }
예제 #7
0
 public static void Remove(GameObject gameObject)
 {
     if (_visibleObjects.Contains(gameObject)) _visibleObjects.Remove(gameObject);
     if (Objects.Contains(gameObject)) Objects.Remove(gameObject);
     gameObject.Dispose();
     #if DEBUG
     gameObject._disposed = true;
     #endif
 }
예제 #8
0
        public bool Collides(GameObject target)
        {
            Sprite sprite = AnimationSequences[CurrentAnimation].Sprites[CurrentFrame];

            float x1 = Location.X - sprite.HandleX * Scale;
            float x2 = x1 + sprite.Image.NaturalWidth * Scale;
            float y1 = Location.Y - sprite.HandleY * Scale;
            float y2 = y1 + sprite.Image.NaturalHeight * Scale;

            Sprite tsprite = target.GetCurrentSprite();
            float tx1 = target.Location.X - tsprite.HandleX * Scale;
            float tx2 = tx1 + tsprite.Image.NaturalWidth * Scale;
            float ty1 = target.Location.Y - tsprite.HandleY * Scale;
            float ty2 = ty1 + tsprite.Image.NaturalHeight * Scale;

            if ((tx2 < x1) || (tx1 > x2) || (ty2 < y1) || (ty1 > y2)) return false;

            return Scene.Collision(sprite.Image.Src, tsprite.Image.Src, tx1 - x1, ty1 - y1);
        }
예제 #9
0
 public static int Compare(GameObject x, GameObject y)
 {
     if (x.Location.Z > y.Location.Z) return -1;
     if (x.Location.Z < y.Location.Z) return 1;
     return 0;
 }
예제 #10
0
        private GameObject PickNpcObject()
        {
            GameObject car = new GameObject();

            if (Math.Floor(Math.Random() * 2) == 0)
                car.AnimationSequences["Default"] = _animationSequences["Npc1"];
            else
                car.AnimationSequences["Default"] = _animationSequences["Npc2"];

            car.SetSprite("Default", 2);
            return car;
        }
예제 #11
0
 public void Update(GameObject gameObject, float deltaTime)
 {
     gameObject.Location.TranslateByCoordinates((_motionVector.X) * deltaTime, _motionVector.Y * deltaTime);
 }
 public void Update(GameObject gameObject, float deltaTime)
 {
     gameObject.Location.X += Speed * deltaTime;
     gameObject.Location.Y = _baseY + Math.Sin(ShooterLevel.Current.Ticks * _frequency) * Amplitude;
 }
예제 #13
0
 public void Update(GameObject gameObject, float deltaTime)
 {
     gameObject.Location.X += _speed * deltaTime;
     gameObject.Location.Y = (_baseY - _amplitude) + Math.Sin(gameObject.Location.X * _frequency) * _amplitude;
 }
예제 #14
0
        public override void Init(Scene level)
        {
            _level = (RaceLevel)level;

            CarObject = new GameObject();

            AnimationSequence sequence = new AnimationSequence();
            sequence.Delay = 200;
            sequence.AddSprite(_level.LoadImage("Images/Race/car/c1.png", false), 165, 134);
            sequence.AddSprite(_level.LoadImage("Images/Race/car/c1_2.png", false), 165, 134);
            CarObject.AnimationSequences["Forward"] = sequence;

            sequence = new AnimationSequence();
            sequence.Delay = 200;
            sequence.AddSprite(_level.LoadImage("Images/Race/car/b-c1.png", false), 165, 134);
            sequence.AddSprite(_level.LoadImage("Images/Race/car/b-c1_2.png", false), 165, 134);
            CarObject.AnimationSequences["b-Forward"] = sequence;

            sequence = new AnimationSequence();
            sequence.Delay = 200;
            sequence.AddSprite(_level.LoadImage("Images/Race/car/c3.png", false), 165, 134);
            sequence.AddSprite(_level.LoadImage("Images/Race/car/c3_2.png", false), 165, 134);
            CarObject.AnimationSequences["Left"] = sequence;

            sequence = new AnimationSequence();
            sequence.Delay = 200;
            sequence.AddSprite(_level.LoadImage("Images/Race/car/b-c3.png", false), 165, 134);
            sequence.AddSprite(_level.LoadImage("Images/Race/car/b-c3_2.png", false), 165, 134);
            CarObject.AnimationSequences["b-Left"] = sequence;

            sequence = new AnimationSequence();
            sequence.Delay = 200;
            sequence.AddSprite(_level.LoadImage("Images/Race/car/c13.png", false), 165, 134);
            sequence.AddSprite(_level.LoadImage("Images/Race/car/c13_2.png", false), 165, 134);
            CarObject.AnimationSequences["Right"] = sequence;

            sequence = new AnimationSequence();
            sequence.Delay = 200;
            sequence.AddSprite(_level.LoadImage("Images/Race/car/b-c13.png", false), 165, 134);
            sequence.AddSprite(_level.LoadImage("Images/Race/car/b-c13_2.png", false), 165, 134);
            CarObject.AnimationSequences["b-Right"] = sequence;

            sequence = new AnimationSequence();
            sequence.Delay = 100;
            sequence.AddSprite(_level.LoadImage("Images/Race/car/c1.png", false), 165, 134);
            sequence.AddSprite(_level.LoadImage("Images/Race/car/c5.png", false), 165, 134);
            sequence.AddSprite(_level.LoadImage("Images/Race/car/c6.png", false), 165, 134);
            sequence.AddSprite(_level.LoadImage("Images/Race/car/c7.png", false), 165, 134);
            sequence.AddSprite(_level.LoadImage("Images/Race/car/c8.png", false), 165, 134);
            sequence.AddSprite(_level.LoadImage("Images/Race/car/c9.png", false), 165, 134);
            sequence.AddSprite(_level.LoadImage("Images/Race/car/c10.png", false), 165, 134);
            sequence.AddSprite(_level.LoadImage("Images/Race/car/c11.png", false), 165, 134);
            sequence.Loop = false;
            CarObject.AnimationSequences["Crash"] = sequence;

            sequence = new AnimationSequence();
            sequence.Delay = 200;
            sequence.AddSprite(_level.LoadImage("Images/Race/car/c11.png", false), 165, 134);
            sequence.AddSprite(_level.LoadImage("Images/Race/car/c10.png", false), 165, 134);
            sequence.AddSprite(_level.LoadImage("Images/Race/car/c9.png", false), 165, 134);
            sequence.Loop = false;
            CarObject.AnimationSequences["Skid"] = sequence;

            CarObject.StartAnimation("Forward");
            CarObject.AnimationCompleted += new AnimationCompletedEventHandler(AnimationCompleted);
        }