Ejemplo n.º 1
0
 /// <summary>
 /// Constructs a SwayEffect
 /// </summary>
 /// <param name="parms">SwayEffectParams object</param>
 public SwayEffect(SwayEffectParms parms) : base(parms)
 {
     this.currentSway = 0f;
     this.SwayBy      = parms.SwayBy;
     this.SwayUpTo    = parms.SwayUpTo;
     this.SwayDownTo  = parms.SwayDownTo;
     this.direction   = parms.Direction;
 }
Ejemplo n.º 2
0
		public TextButton (Vector2 position, BitmapFont font, Color foreColor, string text, Rectangle? touchRectangle, float scale)
		{
			_position = position;
			_currentPosition = position;
			_font = font;
			_foreColor = foreColor;
			_text = text;

			SetTouchRectangle (touchRectangle, _position, _font, _text, scale);

			_minScale = scale;
			_currentScale = scale;
			_maxScale = scale * PulseFactor;
			_scaleStep = (_maxScale - _minScale) / PulseSteps;
			_pulseDirection = PulseDirection.Grow;
		}	
Ejemplo n.º 3
0
        public Body(ContentManager content, Vector2 position, Vector2 heading, float rotation, List <TargetPosition> targetPositions)
            : base(content, true)
        {
            StaticDrawable2DParams bodyParms = new StaticDrawable2DParams();

            bodyParms.Texture     = LoadingUtils.load <Texture2D>(content, "Snakebody");
            bodyParms.Position    = position;
            bodyParms.Rotation    = rotation;
            bodyParms.Origin      = new Vector2(Constants.TILE_SIZE / 2);
            bodyParms.LightColour = Constants.SNAKE_LIGHT;
            base.init(new StaticDrawable2D(bodyParms));

            this.heading         = heading;
            this.targetPositions = targetPositions;
            this.pulseDirection  = PulseDirection.Up;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Runs the effect
 /// </summary>
 public override void update(float elapsed)
 {
     if (this.pulseDirection == PulseDirection.Up)
     {
         this.Reference.Scale += new Vector2((this.ScaleBy / 1000f) * elapsed);
         if (this.Reference.Scale.X >= this.ScaleUpTo)
         {
             this.pulseDirection = PulseDirection.Down;
         }
     }
     else
     {
         this.Reference.Scale -= new Vector2((this.ScaleBy / 1000f) * elapsed);
         if (this.Reference.Scale.X <= this.ScaleDownTo)
         {
             this.pulseDirection = PulseDirection.Up;
         }
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Runs the effect
 /// </summary>
 public override void update(float elapsed)
 {
     if (this.pulseDirection == PulseDirection.Up)
     {
         this.lerp += (this.LerpBy / 1000f) * elapsed;
         if (this.lerp >= 1)
         {
             this.pulseDirection = PulseDirection.Down;
         }
     }
     else
     {
         this.lerp -= (this.LerpBy / 1000f) * elapsed;
         if (this.lerp <= 0)
         {
             this.pulseDirection = PulseDirection.Up;
         }
     }
     this.Reference.LightColour = Color.Lerp(this.LerpUpTo, this.LerpDownTo, this.lerp);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Runs the effect
 /// </summary>
 public override void update(float elapsed)
 {
     if (this.direction == PulseDirection.Up)
     {
         this.currentSway        += ((SwayBy.X + SwayBy.Y) / 1000f) * elapsed;
         this.Reference.Position += (SwayBy / 1000f) * elapsed;
         if (this.currentSway >= this.SwayUpTo)
         {
             this.direction = PulseDirection.Down;
         }
     }
     else if (this.direction == PulseDirection.Down)
     {
         this.currentSway        -= ((SwayBy.X + SwayBy.Y) / 1000f) * elapsed;
         this.Reference.Position -= (SwayBy / 1000f) * elapsed;
         if (this.currentSway <= this.SwayDownTo)
         {
             this.direction = PulseDirection.Up;
         }
     }
 }
Ejemplo n.º 7
0
        public override void update(float elapsed)
        {
            float newScale;

            if (this.pulseDirection == PulseDirection.Up)
            {
                newScale = base.Scale.X + PULSE_BY;
                if (newScale >= PULSE_UP)
                {
                    this.pulseDirection = PulseDirection.Down;
                }
            }
            else
            {
                newScale = base.Scale.X - PULSE_BY;
                if (newScale <= PULSE_DOWN)
                {
                    this.pulseDirection = PulseDirection.Up;
                }
            }
            updatePulse(newScale);
        }
Ejemplo n.º 8
0
        public override void createParticle()
        {
            Vector2 heading = HEADINGS[base.RANDOM.Next(HEADINGS.Length)];

            BaseParticle2DParams particleParms = new BaseParticle2DParams();

            particleParms.TimeToLive   = 500;
            particleParms.Origin       = this.origin;
            particleParms.Texture      = base.particleTexture;
            particleParms.Scale        = new Vector2(.5f);
            particleParms.Position     = this.position;
            particleParms.Direction    = heading;
            particleParms.Acceleration = new Vector2(25f, 35f);

            ConstantSpeedParticle     particle    = new ConstantSpeedParticle(particleParms);
            ScaleOverTimeEffectParams effectParms = new ScaleOverTimeEffectParams {
                ScaleBy = new Vector2(1.75f)
            };

            particle.addEffect(new ScaleOverTimeEffect(effectParms));

            if (this.sway)
            {
                PulseDirection  direction       = EnumUtils.numberToEnum <PulseDirection>(base.RANDOM.Next(2));
                SwayEffectParms swayEffectParms = new SwayEffectParms {
                    SwayBy     = new Vector2(50f, 0f),
                    SwayDownTo = -5f,
                    SwayUpTo   = 5f,
                    Direction  = direction
                };
                particle.addEffect(new SwayEffect(swayEffectParms));
            }
            SoundManager.getInstance().playSoundEffect(this.sfxEmitter, this.idleSFX);
            base.particles.Add(particle);

            base.createParticle();
        }
 /// <summary>
 /// Handles incrementing the animation steps
 /// </summary>
 /// <param name="maxFrameCount">Max frames used to reset reverse sprites</param>
 protected override void setNextFrame(int maxFrameCount)
 {
     if (base.animationState == AnimationState.PulseForwardBack)
     {
         if (base.currentFrame == 0)
         {
             base.currentFrame++;
             this.PulseDirection = PulseDirection.Up;
         }
         else if (base.currentFrame == maxFrameCount)
         {
             this.PulseDirection = Logic.PulseDirection.Down;
             base.currentFrame--;
         }
         else
         {
             base.currentFrame--;
         }
     }
     else
     {
         base.setNextFrame(maxFrameCount);
     }
 }
 /// <summary>
 /// Constructs a PuleAnimationManager based on the params passed in
 /// </summary>
 /// <param name="parms">PulseAnmationManagerParams object</param>
 public PulseAnimationManager(PulseAnimationManagerParams parms)
     : base(parms)
 {
     this.PulseDirection = PulseDirection;
 }
Ejemplo n.º 11
0
		public void Update(IEnumerable<Vector2> touchLocations) {
			if (Pulse) {
				if (_pulseDirection == PulseDirection.Grow && _currentScale < _maxScale) {
					_currentScale += _scaleStep;
				} else if (_pulseDirection == PulseDirection.Grow && _currentScale >= _maxScale) {
					_pulseDirection = PulseDirection.Shrink;
				} else if (_pulseDirection == PulseDirection.Shrink && _currentScale > _minScale) {
					_currentScale -= _scaleStep;
				} else if (_pulseDirection == PulseDirection.Shrink && _currentScale <= _minScale) {
					_pulseDirection = PulseDirection.Grow;
				}

				_currentPosition = _position - _font.MeasureString(_text) * Math.Max (0, (_currentScale - _minScale) / 2);
			}

			var pressed = touchLocations.Where (
				tl => 
					tl.X >= _touchRectangle.Left 
					&& tl.X <= _touchRectangle.Right
					&& tl.Y >= _touchRectangle.Top 
					&& tl.Y <= _touchRectangle.Bottom
			).Any ();

			if (pressed && (_lastTouchTime == null || (DateTime.Now - _lastTouchTime.Value).TotalSeconds > TouchDelay)) {
				_lastTouchTime = DateTime.Now;
				Pressed = pressed;
			} else {
				Pressed = false;
			}
		}