private void GetBoundingBoxFromRelative(Rectangle rectKeyboard, Texture2D texture, Vector2 relativePosition, float sizeX, out Vector2 center, out Vector2 scale) { scale = new Vector2(VirtualCoords.ComputePixelScale(sizeX) / texture.Width); center = new Vector2(rectKeyboard.X + 0.5f, rectKeyboard.Y + 0.5f) + relativePosition * rectKeyboard.Width; }
public void Update(GameTime gameTime, Dictionary dictionary) { var mouseState = Mouse.GetState(); SwipeKeyboard.GetBoundingBox(_centerPosition, out Vector2 cornerKeyboard, out Vector2 sizeKeyboard); Rectangle interactRect = VirtualCoords.ComputePixelRect(cornerKeyboard - new Vector2(CONSTELLATION_WIDTH * 0.01f), sizeKeyboard + new Vector2(CONSTELLATION_WIDTH * 0.02f)); if (interactRect.Contains(mouseState.Position)) // TODO: or intersects word rect { _selectionInterpolation = _selectionInterpolation + (float)gameTime.ElapsedGameTime.TotalSeconds / SELECTION_ANIMATION_DURATION; _selectionInterpolation = Math.Min(1f, _selectionInterpolation); } else { _selectionInterpolation = _selectionInterpolation - (float)gameTime.ElapsedGameTime.TotalSeconds / SELECTION_ANIMATION_DURATION; _selectionInterpolation = Math.Max(0f, _selectionInterpolation); } _swipeLine.Update(gameTime, _centerPosition); _associatedWord.ActiveWord = dictionary.ClosestWordToSwipePattern(_swipeLine.HandlePositionsRelative); _associatedWord.UpdateConstallationWord(_selectionInterpolation); }
protected override void Initialize() { VirtualCoords.OnResize(new Point(_graphics.PreferredBackBufferWidth, _graphics.PreferredBackBufferHeight)); Window.ClientSizeChanged += (sender, args) => VirtualCoords.OnResize(this.Window.ClientBounds.Size); _dictionary = new Dictionary(); _dictionary.Load(); base.Initialize(); }
private Rectangle DrawArea() { var tailAspect = (float)StyleSheet.ShootingTailTexture.Width / StyleSheet.ShootingTailTexture.Height; var tailSize = new Vector2(Size * tailAspect, Size); var offset = new Vector2(-tailSize.X * 0.5f, 0.0f); return(VirtualCoords.ComputePixelRect(_centerPosition + offset, tailSize)); }
public void Draw(SpriteBatch spriteBatch) { float scaleInterpolation = 1.0f + 0.2f * _interpolation; Color color = Color.Lerp(StyleSheet.HighlightColor, StyleSheet.BackgroundColor, _interpolation); spriteBatch.DrawString(StyleSheet.DefaultFont, text: ActiveWord, position: VirtualCoords.ComputePixelPosition(CenterPosition), color: color, rotation: 0.0f, origin: StyleSheet.DefaultFont.MeasureString(ActiveWord) * 0.5f, scale: VirtualCoords.ComputePixelScale(StyleSheet.ScalingFontToWorld * _temporaryScaling * scaleInterpolation), effects: SpriteEffects.None, layerDepth: 0.0f); }
public void DrawLetters(SpriteBatch spriteBatch, float selectionInterpolation, Vector2 centerPosition) { // Hidden if not selected. if (selectionInterpolation == 0) { return; } GetBoundingBox(centerPosition, out Vector2 corner, out Vector2 size); Rectangle screenRect = VirtualCoords.ComputePixelRect(corner, size); Color color = StyleSheet.BackgroundColor * 0.2f; color.A = 255; color *= selectionInterpolation; //Color letterColor = Color.Black * selectionInterpolation; spriteBatch.Draw(StyleSheet.LettersTexture, screenRect, color); }
private void DrawRatingStars() { var rating = _activeLevel.CurrentSentenceRating; if (rating == 0) { const float ratingStarYOffset = 0.3f; const float ratingStarSize = 0.1f; const float ratingStarSpacing = 0.02f; var totalWidth = ratingStarSize * rating + (rating - 1) * ratingStarSpacing; var currentX = (VirtualCoords.RELATIVE_MAX.X - totalWidth) * 0.5f; for (int i = 0; i < rating; ++i) { currentX += ratingStarSize * 0.5f; _spriteBatch.Draw(StyleSheet.StarTexture, destinationRectangle: VirtualCoords.ComputePixelRect_Centered(new Vector2(currentX, ratingStarYOffset), ratingStarSize), Color.LightYellow); currentX += ratingStarSize * 0.5f + ratingStarSpacing; } } var text = rating switch { 0 => "Are you sure? Try again!", 1 => "Better than before, but not good enough!", 2 => "Pretty good, on to the next level", 3 => "Excellent", _ => "" }; var centerPos = new Vector2(0.8f, 0.8f); _spriteBatch.DrawString(StyleSheet.DefaultFont, text: text, position: VirtualCoords.ComputePixelPosition(centerPos), color: Color.White, rotation: 0.0f, origin: StyleSheet.DefaultFont.MeasureString(text) * 0.5f, scale: VirtualCoords.ComputePixelScale(StyleSheet.ScalingFontToWorld), effects: SpriteEffects.None, layerDepth: 0.0f); }
public void Draw(SpriteBatch spriteBatch, float swipeErrorAllowedPercentage, bool showPlayButton) { var area = DrawArea(); for (var index = 0; index < Math.Min(sparcles.Count, sparcles.Count * swipeErrorAllowedPercentage + 0.5f); index++) { var sparcle = sparcles[index]; spriteBatch.Draw(StyleSheet.DotTexture, VirtualCoords.ComputePixelRect_Centered(sparcle.Position, sparcle.Size), sparcle.Color); } //spriteBatch.Draw(StyleSheet.ShootingTailTexture, area, Color.White * swipeErrorAllowedPercentage); spriteBatch.Draw(StyleSheet.ShootingStarTexture, destinationRectangle: area, Color.White); if (showPlayButton && swipeErrorAllowedPercentage > 0.0f) { spriteBatch.Draw(StyleSheet.ShootingButtonTexture, destinationRectangle: area, Color.DarkGreen); } }
public void Draw(SpriteBatch spriteBatch, float selectionInterpolation, Vector2 centerPosition) { SwipeKeyboard.GetBoundingBox(centerPosition, out Vector2 cornerKeyboard, out Vector2 sizeKeyboard); Rectangle rectKeyboard = VirtualCoords.ComputePixelRect(cornerKeyboard, sizeKeyboard); float thicknessScaled = VirtualCoords.ComputePixelScale(BASE_LINE_THICKNESS); float dashLengthScaled = VirtualCoords.ComputePixelScale(BASE_LINE_DASH * selectionInterpolation); float dashTotalScaled = VirtualCoords.ComputePixelScale(BASE_LINE_DASH); float radiusScaled = VirtualCoords.ComputePixelScale(BASE_LINE_THICKNESS); for (int h = 0; h < Length; ++h) { if (h > 0) { Vector2 pos0 = OriginalHandlePositionsRelative[h - 1] * rectKeyboard.Width + new Vector2(rectKeyboard.X, rectKeyboard.Y); Vector2 pos1 = OriginalHandlePositionsRelative[h] * rectKeyboard.Width + new Vector2(rectKeyboard.X, rectKeyboard.Y); LineRendering.DrawLineDashed(spriteBatch, pos0, pos1, StyleSheet.BackgroundColor * selectionInterpolation, dashLengthScaled, dashTotalScaled * 2 - dashLengthScaled, thicknessScaled * 0.7f, radiusScaled * 2f, radiusScaled * 2f); } //DrawFromRelative(spriteBatch, rectKeyboard, StyleSheet.DotTexture, // StyleSheet.BackgroundColor * selectionInterpolation, OriginalHandlePositionsRelative[h], BASE_LINE_THICKNESS * 1.5f, 0); } for (int h = 0; h < Length; ++h) { Color color = Color.Lerp(StyleSheet.BackgroundColor, StyleSheet.HighlightColor, selectionInterpolation); float radius = MathHelper.Lerp(BASE_STAR_SIZE, SELECTED_STAR_SIZE, _selectIntepolationHandles[h]); if (h > 0) { Vector2 pos0 = HandlePositionsRelative[h - 1] * rectKeyboard.Width + new Vector2(rectKeyboard.X, rectKeyboard.Y); Vector2 pos1 = HandlePositionsRelative[h] * rectKeyboard.Width + new Vector2(rectKeyboard.X, rectKeyboard.Y); LineRendering.DrawLineDashed(spriteBatch, pos0, pos1, color * (0.5f + 0.5f * selectionInterpolation), dashTotalScaled + dashLengthScaled, dashTotalScaled - dashLengthScaled, thicknessScaled, radiusScaled * 2f, radiusScaled * 2f); } DrawFromRelative(spriteBatch, rectKeyboard, StyleSheet.StarTexture, color, HandlePositionsRelative[h], radius * 2, _selectIntepolationHandles[h] + selectionInterpolation + h); } }
public void Update(GameTime gameTime, Vector2 centerPosition) { var mouseState = Mouse.GetState(); SwipeKeyboard.GetBoundingBox(centerPosition, out Vector2 cornerKeyboard, out Vector2 sizeKeyboard); Rectangle rectKeyboard = VirtualCoords.ComputePixelRect(cornerKeyboard, sizeKeyboard); bool mouseInside = rectKeyboard.Contains(mouseState.Position); if (_selectedHandle != -1 && mouseInside) { HandlePositionsRelative[_selectedHandle] = (mouseState.Position - rectKeyboard.Location).ToVector2() / rectKeyboard.Width; } bool clicked = mouseState.LeftButton == ButtonState.Pressed && _lastMouseState.LeftButton == ButtonState.Released && mouseInside; bool released = mouseState.LeftButton == ButtonState.Released && _lastMouseState.LeftButton == ButtonState.Pressed; float radius = SELECTED_STAR_SIZE; float radiusScaled = VirtualCoords.ComputePixelScale(radius); int closestStar = -1; if (_selectedHandle == -1 && mouseInside) { float minDist = float.MaxValue; for (int h = 0; h < Length; ++h) { Point centerStar = new Point((int)(rectKeyboard.X + rectKeyboard.Width * HandlePositionsRelative[h].X + 0.5f), (int)(rectKeyboard.Y + rectKeyboard.Width * HandlePositionsRelative[h].Y + 0.5f)); float distStar = (centerStar - mouseState.Position).ToVector2().Length(); if (minDist > distStar && distStar < radiusScaled) { minDist = distStar; closestStar = h; if (clicked) { _selectedHandle = h; } } } } for (int h = 0; h < Length; ++h) { Point centerStar = new Point((int)(rectKeyboard.X + rectKeyboard.Width * HandlePositionsRelative[h].X + 0.5f), (int)(rectKeyboard.Y + rectKeyboard.Width * HandlePositionsRelative[h].Y + 0.5f)); if (closestStar == h || _selectedHandle == h) { _selectIntepolationHandles[h] += (float)gameTime.ElapsedGameTime.TotalSeconds / SELECTION_ANIMATION_DURATION; _selectIntepolationHandles[h] = Math.Min(1f, _selectIntepolationHandles[h]); } else if (h != closestStar) { _selectIntepolationHandles[h] -= (float)gameTime.ElapsedGameTime.TotalSeconds / SELECTION_ANIMATION_DURATION; _selectIntepolationHandles[h] = Math.Max(0f, _selectIntepolationHandles[h]); } if (_selectedHandle == h && released) { _selectedHandle = -1; } } if (mouseState.LeftButton != ButtonState.Pressed) { _selectedHandle = -1; } _lastMouseState = mouseState; }