public async virtual ValueTask Update(CanvasTimingInformation timing) { if (Visible) { _showTimer.Run(timing); if (Vector2s.AreNear(_pacman.Position, Position, 4)) { await _mediator.Publish(new FruitEatenEvent(this)); Visible = false; } return; } if (_playerStats == null) { throw new InvalidOperationException("no player stats set!"); } var levelStats = _playerStats.LevelStats; if (levelStats.FruitSession.ShouldShow && !_isDemo) { Visible = true; _showTimer.Reset(); } SetFruitItem(levelStats.GetLevelProps().Fruit1); }
public void Draw(CanvasSpriteBatch sb, CanvasTimingInformation timing) { foreach (IDrawable drawable in drawables.Values) { drawable.Draw(this, sb, timing); } }
public override void Draw(CanvasDrawingSession drawingSession, CanvasTimingInformation timing) { drawingSession.FillRoundedRectangle(Center.X - Size.X / 2, Center.Y - Size.Y / 2, Size.X, Size.Y, 5, 5, Colors.LimeGreen); }
public async ValueTask Update(CanvasTimingInformation timing) { foreach (IGhost eachGhost in Ghosts) { await eachGhost.Update(timing); } }
public async ValueTask Update(CanvasTimingInformation timing) { _colorTweener.Update(timing); var col = (int)(_colorTweener.Position * 255); _color = Color.FromArgb(255, col, col, col); _tweener?.Update(timing); _timer.Run(timing); if (_state == State.Idle) { await idle(); } if (_state == State.ScrollingIn) { await scrollingIn(); } if (_state == State.Stationary) { await stationary(); } if (_state == State.ScrollingOut) { await scrollingOut(); } }
public static ValueTask Update(CanvasTimingInformation info, IHumanInterfaceParser input) { TotalTime = info.TotalTime; if (info.TotalTime - _lastTimeKeyboardChecked > .25f.Seconds()) { _lastTimeKeyboardChecked = info.TotalTime; if (input.IsKeyCurrentlyDown(Keys.D)) { ShouldShow = !ShouldShow; } } if (input.WasKeyPressedAndReleased(Keys.A)) { Constants.FramesPerSecond -= 5; Constants.FramesPerSecond = Math.Max(5, Constants.FramesPerSecond); } if (input.WasKeyPressedAndReleased(Keys.S)) { Constants.FramesPerSecond += 5; } return(default);
ValueTask updateAnimation(CanvasTimingInformation context) { _animDirection.Run(context); setSpriteSheetPointers(); return(default);
public override void Update(CanvasTimingInformation timing) { if (_currentGame.DownKeys.Contains(VirtualKey.Left)) { Center.X -= 2; } if (_currentGame.DownKeys.Contains(VirtualKey.Right)) { Center.X += 2; } if (_currentGame.DownKeys.Contains(VirtualKey.Space)) { if (timing.TotalTime.TotalMilliseconds - lastShooting < 200) { return; } Bullet bullet = new Bullet(Size, Center); _currentGame.NewGameEntities.Add(bullet); lastShooting = timing.TotalTime.TotalMilliseconds; } }
public void Update(CanvasTimingInformation timing) { fpsCounter.Update(timing); InputManager.Update(); Matrix3x2.Invert(Camera.Transform, out Matrix3x2 inverse); if (LocalPlayer != null) { HandlePlayerInput(); } nowTime = timing.ElapsedTime.TotalSeconds; gameServer.ProcessMessages(); foreach (Message message in gameServer.ReceivedMessages) { if (message is InputAckMessage ackMessage) { lastProcessedInputSeqNumber = ackMessage.SequenceNumber; } } foreach (Message message in gameServer.ReceivedMessages) { HandleServerMessage(message); } EntityManager.Update((float)timing.ElapsedTime.TotalSeconds); Camera.Update(); InputManager.AfterUpdate(); if (nowTime - lastTimeProcessed > timeToDisconnect && timeToDisconnect > 1) { gameServer.Disconnect(); this.SetConnectScreen(); } }
async Task CaptureThumbnailFromAnimatedControl(ICanvasAnimatedControl animatedControl, MethodInfo drawMethod) { // Wait for the control to be ready. while (!animatedControl.ReadyToDraw) { await Task.Delay(1); } // Wait a while for any animations to settle into a good looking state. await Task.Delay(TimeSpan.FromSeconds(animationDelay)); // We will mess with the control device from somewhere other than its game loop thread, // so must first pause the control to stop the game loop. There's no good way to // synchronize this, so we just wait a moment to give the game loop a chance to exit. animatedControl.Paused = true; // TODO #3317: once we can RunAsync on the update/render thread, use that instead of this await Task.Delay(TimeSpan.FromSeconds(0.1f)); // Capture a thumbnail from the control. var timing = new CanvasTimingInformation { TotalTime = TimeSpan.FromSeconds(animationDelay), UpdateCount = (int)(animationDelay * 60), }; await CaptureThumbnailFromControl(animatedControl, animatedControl.Size, drawMethod, ds => new CanvasAnimatedDrawEventArgs(ds, timing)); }
public virtual async ValueTask <MovementResult> Update(CanvasTimingInformation context) { var tile = Ghost.Tile; // if a ghost is near the center of a cell, then get the 'next cell' and // store where to go from there if (tile.IsInCenter) { CellIndex targetCell = await _getTargetCellPoint(); TargetCell = targetCell; Directions direction = _intersectionLogic.GetWhichWayToGo(targetCell); if (direction != Directions.None) { setDirection(direction); } } Ghost.MoveForwards(); return(MovementResult.NotFinished); }
internal void Update(CanvasTimingInformation timing, KeyboardState keyboardState) { if (GameOver) { return; } if (currentShape == null) { if (blocksToRemove != null) { RemoveBlocks(); } else { CreateShape(); } return; } if (keyboardState.LeftPressed) { TryMove(currentShape.Blocks, -1, 0); } if (keyboardState.RightPressed) { TryMove(currentShape.Blocks, 1, 0); } if (keyboardState.RotatePressed) { TryRotate(); } var timeBetweenUpdates = betweenBlockUpdates; if (keyboardState.DownPressed) { timeBetweenUpdates = fastBetweenBlockUpdates; } if (lastBlockUpdate == null || timing.TotalTime.Subtract(lastBlockUpdate) >= timeBetweenUpdates) { lastBlockUpdate = timing.TotalTime; if (currentShape.Blocks.All(o => IsFree(o.X, o.Y + 1))) { OnDroppingShape(); foreach (var block in currentShape.Blocks) { block.Y += 1; } } else { CheckForLines(); currentShape = null; } } }
public void Update(CanvasTimingInformation timing) { var elapsed = timing.ElapsedTime; _timer.Run(timing); _timeLeft -= elapsed; _timeLeftToStartFlashing -= elapsed; }
public void Draw(EntityRenderer renderer, CanvasSpriteBatch sb, CanvasTimingInformation timing) { sb.Draw(renderer.Sprites[entity.Shape], Matrix3x2.CreateTranslation(-entity.Shape.Origin * SpriteBuilder.SCALE_FACTOR) * Matrix3x2.CreateRotation(entity.Direction) * Matrix3x2.CreateScale(1f / SpriteBuilder.SCALE_FACTOR) * Matrix3x2.CreateTranslation(entity.Position), entity.Color); }
private void Draw(CanvasDrawingSession drawingSession, CanvasTimingInformation timing) { Debug.WriteLine("Canvas Draw {0}", timing.UpdateCount); foreach (GameEntity gameEntity in GameEntities) { gameEntity.Draw(drawingSession, timing); } }
public void Update(CanvasTimingInformation gameTime) { if (_tweener.Running) { _tweener.Update(gameTime); _whenRunning(this); } }
public override void Draw(CanvasDrawingSession drawingSession, CanvasTimingInformation timing) { drawingSession.FillRectangle(Center.X - Size.X / 2, Center.Y - Size.Y / 2, Size.X, Size.Y, Colors.Blue); }
public void Update(CanvasTimingInformation context) { _pillConsumptionTimeIdle += context.ElapsedTime; if (_pillConsumptionTimeIdle.TotalMilliseconds > 4000) { whenNoPillsEaten(); } }
public ValueTask Update(CanvasTimingInformation timing) { if (_animator != null) { _animator.Run(timing); _currentFrame = _animator.Flag ? _frame2 : _frame1; } return(default);
public override void Update(CanvasTimingInformation timing) { if (patrolX < 0 || patrolX > 40) { _velocity.X = -_velocity.X; } Center.X += _velocity.X; patrolX += _velocity.X; }
private void DrawWalls(CanvasTimingInformation timing) { // We draw the text into a rendertarget, and update this every frame to make it scroll. // The resulting rendertarget is then mapped as a texture onto the Direct3D teapot model. using (var drawingSession = TextRenderTarget.CreateDrawingSession()) { drawingSession.Clear(Colors.White); drawingSession.DrawRectangle(0, 0, TextRenderTargetSize - 1, TextRenderTargetSize - 1, Colors.Red); } }
public async ValueTask <ActUpdateResult> Update(CanvasTimingInformation timing) { if (_finished) { return(ActUpdateResult.Finished); } _tempTimers.Update(timing); if (_ghostsChasing) { await _powerPillLegend.Update(timing); await _powerPillToEat.Update(timing); _ghostTimer.Run(timing); _pacTimer.Run(timing); _ghostEatenTimer.Run(timing); } await _pillLegend.Update(timing); _tempSprites.Update(timing); lerpPacMan(); foreach (var g in _ghosts) { if (!g.Alive) { continue; } lerpGhost(g); await g.Update(timing); if (Vector2s.AreNear(_pacMan.Position, g.Position, 2)) { ghostEaten(g); if (g.NickName == GhostNickname.Clyde) { _tempTimers.Add(new EggTimer(1.Seconds(), () => { _finished = true; })); } } } await _pacMan.Update(timing); return(ActUpdateResult.Running); }
public void Update(CanvasTimingInformation context) { ModeAndDuration item = _items[_index]; item.DecreaseDurationBy(context.ElapsedTime); if (item.Duration < TimeSpan.Zero) { incrementIndex(); } }
public void Run(CanvasTimingInformation timing) { _currentTime -= timing.ElapsedTime; if (_currentTime < TimeSpan.Zero) { _currentTime += _firesEvery; _callback(); } }
private void ConfigureEffect(CanvasTimingInformation timing) { // Animate the flame by shifting the Perlin noise upwards (-Y) over time. flameAnimation.TransformMatrix = Matrix3x2.CreateTranslation(0, -(float)timing.TotalTime.TotalSeconds * 60.0f); // Scale the flame effect 2x vertically, aligned so it starts above the text. float verticalOffset = fontSize * 1.4f; var centerPoint = new Vector2(0, verticalOffset); flamePosition.TransformMatrix = Matrix3x2.CreateScale(1, 2, centerPoint); }
void updateAnimation(CanvasTimingInformation args) { if (Math.Abs(_speed) < .0001) { return; } _animDirection.Run(args); _frame1InSpriteMap = _framePointers[_direction].Frame1; _frame2InSpriteMap = _framePointers[_direction].Frame2; _spriteSheetPos = _animDirection.Flag ? _frame1InSpriteMap : _frame2InSpriteMap; }
public async ValueTask <ActUpdateResult> Update(CanvasTimingInformation timing) { var gameOverAct = await resolveGameOverAct(); var result = await gameOverAct.Update(timing); if (result == ActUpdateResult.Finished) { await _mediator.Publish(new GameOverEvent()); } return(result); }
public void Update(CanvasTimingInformation timing) { if (FrightSession != null && !FrightSession.IsFinished) { FrightSession.Update(timing); } else { _ghostMovementConductor.Update(timing); } _ghostHouseDoor.Update(timing); }
async ValueTask <MovementResult> navigateEyesBackToJustOutsideHouse(CanvasTimingInformation context) { await base.Update(context); if (isNearHouseEntrance()) { await _mediator.Publish(new GhostInsideHouseEvent()); Ghost.Position = Maze.PixelHouseEntrancePoint; _currentAction = navigateToCenterOfHouse; } return(MovementResult.NotFinished); }
void DrawScrollingText(CanvasTimingInformation timing) { // We draw the text into a rendertarget, and update this every frame to make it scroll. // The resulting rendertarget is then mapped as a texture onto the Direct3D teapot model. using (var drawingSession = textRenderTarget.CreateDrawingSession()) { drawingSession.Clear(Colors.Firebrick); drawingSession.DrawRectangle(0, 0, textRenderTargetSize - 1, textRenderTargetSize - 1, Colors.DarkRed); float wrapPosition = (float)textLayout.LayoutBounds.Height + textRenderTargetSize; float scrollOffset = textRenderTargetSize - ((float)timing.TotalTime.TotalSeconds * textScrollSpeed) % wrapPosition; drawingSession.DrawTextLayout(textLayout, new Vector2(textMargin, scrollOffset), Colors.Black); } }
public void Draw(ICanvasAnimatedControl sender, CanvasTimingInformation timingInformation, CanvasDrawingSession ds) { ds.DrawCachedGeometry(clockFaceCachedFill, backgroundBrush); double fractionSecond; int seconds; if (sender.IsFixedTimeStep) { double updatesPerSecond = 1000.0 / sender.TargetElapsedTime.TotalMilliseconds; seconds = (int)((timingInformation.UpdateCount / updatesPerSecond) % 10); double updates = (double)timingInformation.UpdateCount; fractionSecond = (updates / updatesPerSecond) % 1.0; } else { double totalMilliseconds = timingInformation.TotalTime.TotalMilliseconds; double millisecondsThisIteration = totalMilliseconds % 1000; fractionSecond = millisecondsThisIteration / 1000.0f; seconds = (int)timingInformation.TotalTime.TotalSeconds % 10; } hueRotationEffect.Angle = (float)Math.PI * (seconds / 10.0f) * 2.0f; using (var timeSegmentGeometry = CreateTimeSegmentGeometry(ds, fractionSecond)) { ds.FillGeometry(timeSegmentGeometry, foregroundBrush); DrawSecondsText(ds, new Vector2(center), seconds); ds.DrawGeometry(timeSegmentGeometry, Colors.White, 1, hairlineStrokeStyle); } ds.DrawCachedGeometry(clockFaceCachedStroke18, Colors.White); ds.DrawCachedGeometry(clockFaceCachedStroke16, Colors.Black); }