public void face(Hex hex) { Vector3 facingPosition = MyBoard.getCellCenter(hex); AnimationKey direction = getDirection(Location.position, facingPosition); face(direction); }
private AnimationKey KinectFrameToKeyFrame_Old(KinectFrame frame) { var keyFrame = new AnimationKey(); //Go through all the joints in a single frame //and add the rotation in that frame to a key frame for the animation foreach (var kinectjoint in frame.Joints) { LinkedJoints[kinectjoint.Key].LocalMatrix = kinectjoint.Value.HierarchicalRotation; } var mat = Matrix.Identity; foreach (var animationJoint in LinkedJoints.Values) { if (animationJoint.IsValid) { mat = animationJoint.LocalMatrix; keyFrame.BoneTransforms.Add(mat); } else { keyFrame.BoneTransforms.Add(mat); } } return keyFrame; }
private AnimationKey KinectFrameToKeyFrame(KinectFrame frame) { var f = new AnimationKey(); var mat = Matrix.Identity; var prev = Matrix.Identity; foreach (var j in frame.Joints.Where(j => LinkedJoints[j.Key].IsValid)) { LinkedJoints[j.Key].LocalMatrix = j.Value.HierarchicalRotation; } foreach (var joint in LinkedJoints.Values) { if (!joint.IsValid) { f.BoneTransforms.Add(prev); break; } mat = joint.LocalMatrix; f.BoneTransforms.Add(mat); prev = mat; } return f; }
public void RunTo(Directions Dir) { if (Dir != Directions.Any) { CurrentAnimation = (AnimationKey)Enum.Parse(typeof(AnimationKey), "Run" + Dir.ToString(), true); } }
public static PCharacter FromString(Game game, string characterString) { if (gameRef == null) { gameRef = (Game1)game; } if (characterAnimations.Count == 0) { BuildAnimations(); } PCharacter character = new PCharacter(); string[] parts = characterString.Split(','); character.name = parts[0]; Texture2D texture = game.Content.Load <Texture2D>(@"CharacterSprites\" + parts[1]); character.sprite = new AnimatedSprite(texture, gameRef.PlayerAnimations); AnimationKey key = AnimationKey.WalkDown; Enum.TryParse <AnimationKey>(parts[2], true, out key); character.sprite.CurrentAnimation = key; character.conversation = parts[3]; for (int i = 4; i < 10 && i < parts.Length; i++) { character.avatars[i - 4] = AvatarManager.GetAvatar(parts[i].ToLowerInvariant()); } return(character); }
protected BaseAnimatorTask(object owner, AnimationKind kind, int time, Action endCallback) { m_key = new AnimationKey(owner, kind); m_timeLeft = time; m_totalTime = time; m_endCallback = endCallback; }
public static Character FromString(Game game, string characterString) { if (gameRef == null) { gameRef = (Game1)game; } if (characterAnimations.Count == 0) { BuildAnimations(); } Character character = new Character(); string[] parts = characterString.Split(','); character.name = parts[0]; Texture2D texture = game.Content.Load <Texture2D>(@"CharacterSprites\" + parts[1]); character.sprite = new AnimatedSprite(texture, gameRef.PlayerAnimations); AnimationKey key = AnimationKey.WalkDown; Enum.TryParse <AnimationKey>(parts[2], true, out key); character.sprite.CurrentAnimation = key; character.conversation = parts[3]; return(character); }
public static Character FromJson(Game game, string jsonString) { if (gameRef == null) { gameRef = (Game1)game; } if (characterAnimations.Count == 0) { BuildAnimations(); } Character character = new Character(); string[] parts = jsonString.Split(','); character.Name = parts[0]; character.TextureName = parts[1]; Texture2D texture = game.Content.Load <Texture2D>(@"CharacterSprites\" + parts[1]); character.Sprite = new AnimatedSprite(texture, gameRef.PlayerAnimations); AnimationKey key = AnimationKey.WalkDown; Enum.TryParse <AnimationKey>(parts[2], true, out key); character.Sprite.CurrentAnimation = key; character.Conversation = parts[3]; character.BattleAvatar = AvatarManager.GetAvatar(parts[4].ToLowerInvariant()); return(character); }
public CharacterData(string name, string textureName, AnimationKey currentAnimation, string conversation, string battleAvatar) { Name = name; TextureName = textureName; CurrentAnimation = currentAnimation; Conversation = conversation; BattleAvatar = battleAvatar; }
public AnimatedSprite3D(LunchHourGames lhg, SpriteSheet spriteSheet) : base(lhg) { this.spriteSheet = spriteSheet; direction = AnimationKey.South; isAnimating = false; FramesPerSecond = 5; MyTexture = this.spriteSheet.getTexture(direction, 0); }
void menuItem_Click(object sender, System.EventArgs e) { AnimationTrackBar trackBar = (AnimationTrackBar)Owner; System.Type type = (System.Type)((Skill.Editor.UI.MenuItem)sender).UserData; AnimationKey newKey = ScriptableObject.CreateInstance(type) as AnimationKey; trackBar.AddKeyAt(Position.x, newKey); }
public static keyStruct GetKeyStruct(AnimationKey key) { return(new keyStruct() { frame = key.frame, value = key.value, inTangent = key.inTangent, outTangent = key.outTangent, interpolation = key.interpolation }); }
public AnimatedSprite(LunchHourGames lhg, Texture2D texture, List <Animation> animations, SpriteBatch spriteBatch) : base(lhg, texture) { this.spriteBatch = spriteBatch; this.animations = animations; currentAnimation = AnimationKey.North; isAnimating = false; width = animations[(int)currentAnimation].FrameWidth; height = animations[(int)currentAnimation].FrameHeight; center = new Vector2(width / 2, height / 2); }
private void SetAnimationKey(AnimationKey key) { if (key == null) { return; } SetPositionKey(key.Position); SetRotationKey(key.Rotation); SetScaleKey(key.Scale); Engine.Active = true; }
public AnimationKey getDirection(List <Vector3> path) { AnimationKey direction = Location.direction; // Our current direction if (path.Count() > 2) { Vector3 currentPosition = path[0]; Vector3 nextPosition = path[1]; direction = getDirection(currentPosition, nextPosition); } return(direction); }
private void Submit_Click(object sender, RoutedEventArgs e) { List <AnimationKey> SceneKeys = new List <AnimationKey>(); for (int i = 0; i < Keys.Items.Count; i++) { AnimationKey key = (Keys.Items[i] as ListBoxItem).Tag as AnimationKey; SceneKeys.Add(key); } UnrealScienceScripting.PushAnimationKeys(SceneKeys); }
public void TackleTo(Directions Dir) { LastSpecial = DateTime.Now.AddMilliseconds(800); LastAction = DateTime.Now.AddMilliseconds(350); if (Dir != Directions.Any) { CurrentAnimation = (AnimationKey)Enum.Parse(typeof(AnimationKey), "Tackle" + Dir.ToString(), true); } else { CurrentAnimation = (AnimationKey)Enum.Parse(typeof(AnimationKey), "Tackle" + Direction.ToString(), true); } }
private void OverrideAnimation(AnimationKey key, AnimationClip animation) { string keyString = key.ToString(); KeyValuePair <AnimationClip, AnimationClip> @override; if (m_overrides.TryGetValue(keyString, out @override)) { m_overrides[keyString] = new KeyValuePair <AnimationClip, AnimationClip>(@override.Key, animation); } else { Debug.LogWarningFormat("Couldn't find {0} in the m_animator", keyString); } }
/// <summary> /// add key at position /// </summary> /// <param name="x">position inside track</param> private void AddKeyAt(float x, AnimationKey newKey) { TimeLine timeLine = FindInParents <TimeLine>(); if (timeLine != null) { // convert to local position of TimeBar - because of zooming x -= timeLine.View.ScrollPosition.x; newKey.FireTime = (float)timeLine.TimeBar.GetTime(x); EventOrientedKeyView e = CreateEvent(newKey); InspectorProperties.Select(e); RebuildTrackKeys(); } }
void SetDestValue(ref AnimationKey k, Vector3D value) { if (k.KeyType == 1) { k.Destination.Position = value; } else if (k.KeyType == 2) { k.Destination.Rotation = value; } else { k.Destination.Scale = value; } }
public AnimationKey getDirection(Point point) { AnimationKey direction = Location.direction; // Our current direction /* * Hex playerHex = Location.board.MyHexBoard.getHex(Location.i, Location.j); * Hex pointHex = Location.board.MyHexBoard.FindHexMouseClick(point); * * if (playerHex != null && pointHex != null) * * return getDirection(playerHex.getCenterAsVector(), pointHex.getCenterAsVector()); * } * */ return(direction); }
private CombatLocation loadCombatLocation(CombatBoard combatBoard, Player player, XmlNode locationNode) { CombatLocation location = null; try { int row = Convert.ToInt16(locationNode.Attributes["row"].Value); int col = Convert.ToInt16(locationNode.Attributes["col"].Value); AnimationKey direction = getDirectionFromString(locationNode.Attributes["facing"].Value); location = new CombatLocation(combatBoard, row, col, direction); } catch (Exception ex) { } return(location); }
public AnimationKey getDirection(List <Hex> path) { AnimationKey direction = Location.direction; // Our current direction /* * if (path != null && path.Count() > 2) * { * Hex startHex = path[0]; * Vector2 currentPosition = startHex.getCenterAsVector(); * Hex endHex = path[path.Count() - 1]; * Vector2 nextPosition = endHex.getCenterAsVector(); * direction = getDirection(currentPosition, nextPosition); * } */ return(direction); }
//private AnimationKey _AnimationKey; public AnimationKeyView(AnimationTrackBar trackBar, AnimationKey key) : base(trackBar, key) { //_AnimationKey = key; this.ColumnDefinitions.Add(10, Framework.UI.GridUnitType.Pixel); this.ColumnDefinitions.Add(1, Framework.UI.GridUnitType.Star); _Bg = new Framework.UI.Box(); _ImgState = new Skill.Framework.UI.Image() { Row = 0, Column = 0 }; Controls.Add(_Bg); Controls.Add(_ImgState); }
public Animation(AnimationKey direction, int frameCount, int frameWidth, int frameHeight, int xOffset, int yOffset) { this.direction = direction; this.frameCount = frameCount; frames = new Rectangle[frameCount]; this.frameWidth = frameWidth; this.frameHeight = frameHeight; for (int i = 0; i < frameCount; i++) { frames[i] = new Rectangle( xOffset + (frameWidth * i), yOffset, frameWidth, frameHeight); } FramesPerSecond = 5; Reset(); }
Vector3D GetDestValue(AnimationKey k) { Vector3D v; if (k.KeyType == 1) { v = k.Destination.Position; } else if (k.KeyType == 2) { v = k.Destination.Rotation; } else { v = k.Destination.Scale; } return(v); }
private void Keys_SelectionChanged(object sender, SelectionChangedEventArgs e) { ListBoxItem item = Keys.SelectedItem as ListBoxItem; if (item != null) { AnimationKey k = item.Tag as AnimationKey; Type.SelectedIndex = k.KeyType - 1; Duration.Text = k.Duration.ToString(); KeyOrder.Text = k.StartOrder.ToString(); Value.SetVector(GetDestValue(k)); } }
/// <summary> /// Updates the animated sprite. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public void Update(GameTime gameTime) { // If the sprite has been told to switch to another animation, // it will do so when the current one finishes. if (AnimationControl.CurrentFrame == 0 && this.nextAnimation != AnimationKey.None && this.switchAnimation) { this.CurrentAnimation = this.nextAnimation; this.nextAnimation = AnimationKey.None; this.switchAnimation = false; } // Updates the animation. if (this.isAnimating) { this.animations[this.currentAnimation].Update(gameTime); } }
public Hex getHexNextTo(Hex center, AnimationKey direction) { HexDirection hexDirection; switch (direction) { default: case AnimationKey.North: hexDirection = HexDirection.North; break; case AnimationKey.NorthEast: hexDirection = HexDirection.Northeast; break; case AnimationKey.East: hexDirection = HexDirection.East; break; case AnimationKey.SouthEast: hexDirection = HexDirection.Southeast; break; case AnimationKey.South: hexDirection = HexDirection.South; break; case AnimationKey.SouthWest: hexDirection = HexDirection.Southwest; break; case AnimationKey.West: hexDirection = HexDirection.West; break; case AnimationKey.NorthWest: hexDirection = HexDirection.Northwest; break; } return(getHexNextTo(center, hexDirection)); }
string GetToolTip(AnimationKey k) { string type = ""; if (k.KeyType == 1) { type = "Position"; } else if (k.KeyType == 2) { type = "Rotation"; } else { type = "Scale"; } return(string.Format("It is a key with following parameters: \n Type: {0}, StartSlide: {1}, Duration: {2} seconds, Destination Value: {3} {4} {5}", type, k.StartOrder, k.Duration, GetDestValue(k).X, GetDestValue(k).Y, GetDestValue(k).Z)); }
/// <summary> /// Deals with enemy trainer logic /// </summary> /// <param name="game">Game state</param> /// <param name="name">Takes trainer name</param> /// <param name="trainerEnemySayingL1">Takes what the trainer says</param> /// <param name="trainerEnemySayingL2">Takes what the trainer says</param> /// <param name="x">Trainer posistion X</param> /// <param name="y">Trainer posistion Y</param> /// <param name="key"> Takes which animation to run</param> public EnemyTrainer(Game game, String name, String trainerEnemySayingL1, String trainerEnemySayingL2, int x, int y, AnimationKey key) : base(game) { Position = new Vector2(x,y); Name = name; TrainerEnemySayingL1 = trainerEnemySayingL1; TrainerEnemySayingL2 = trainerEnemySayingL2; Frames.Add(AnimationKey.Down, new Rectangle(0, 0, 16, 32)); Frames.Add(AnimationKey.Left, new Rectangle(16, 0, 16, 32)); Frames.Add(AnimationKey.Up, new Rectangle(32, 0, 16, 32)); if (key == AnimationKey.Left) CurrentFrame = AnimationKey.Left; else if (key == AnimationKey.Down) CurrentFrame = AnimationKey.Down; CollisionRectangle = new Rectangle(x, y + 16, 16, 16); game.Components.Add(this); }
/// <summary> /// Tells the sprite that it is supposed to switch to another animation. /// </summary> /// <param name="animationToSwitchTo"> /// The next animation to switch to. /// </param> public void SwitchAnimationTo(AnimationKey animationToSwitchTo) { this.switchAnimation = true; this.nextAnimation = animationToSwitchTo; }
/// <summary> /// Starts the game /// </summary> /// <param name="gameTime">provides a snapshot of the gametime</param> public void PlayGame(GameTime gameTime) { switch (_textDisplayState) { case TextDisplayState.TextDisplaying: DisplayText(gameTime); break; } PreviousMoveState = moveState; moveState = MoveState; if (PreviousMoveState != moveState) if (moveState == MoveState.Still) _encounterChecked = false; var motion = new Vector2(); // Get input if the Player is not already moving if (MoveState == MoveState.Still) { // Pause if (InputHandler.ActionKeyPressed(ActionKey.Pause, PlayerIndex.One)) _gameState = GameState.Paused; // DEBUG // Start combat if (InputHandler.ActionKeyPressed(ActionKey.Back, PlayerIndex.One)) { DataManager.RandomWildPokemon(); _gameRef.BattleScreen.InitializeBattle(DataManager.Trainers["Trond"], DataManager.Trainers["Tall Grass"]); } //If last movement brought you onto a trigger tile if (_collision == CollisionType.TrainerTriggerBush) GamePlayScreen.Trainers["Sabrina"].TriggerTrainer(AnimationKey.Right); else if (_collision == CollisionType.TrainerTrigger) GamePlayScreen.Trainers["Giovanni"].TriggerTrainer(AnimationKey.Right); else if (_collision == CollisionType.HealingHerb && InputHandler.ActionKeyPressed(ActionKey.ConfirmAndInteract, PlayerIndex.One) && !_justConfirmedPrompt) { foreach (var pokemonNr in PlayerTrainer.PokemonSet) pokemonNr.FullRestore(); TextPanel.BattleText.FirstLine = "Your pokemon ate some herbs."; TextPanel.BattleText.SecondLine = "They feel healthy!"; MoveState = MoveState.Frozen; _textDisplayState = TextDisplayState.TextDisplaying; } //Decides when to encounter wild pokemon else if (_collision == CollisionType.Bush && !_encounterChecked) { _encounterChecked = true; var rand = new Random(); int tau = rand.Next(200); //Console.WriteLine(tau); if (tau < 18) { DataManager.RandomWildPokemon(); _gameRef.BattleScreen.InitializeBattle(DataManager.Trainers["Trond"], DataManager.Trainers["Tall Grass"]); return; } } _justConfirmedPrompt = false; // Check for sprint if (InputHandler.ActionKeyDown(ActionKey.Sprint, PlayerIndex.One)) { _framesPerMovement = FramesPerMovement / 2; } else { _framesPerMovement = FramesPerMovement; } // Check for EnemyTrainer if (InputHandler.ActionKeyPressed(ActionKey.ConfirmAndInteract, PlayerIndex.One)) { var checkPoint = new Vector2(Sprite.Position.X + (float)Sprite.Width / 2 + _movementVector.X * Sprite.Speed, Sprite.Position.Y + (float)Sprite.Height / 2 * 1.5f + _movementVector.Y * Sprite.Speed); // Check for EnemyTrainer _map.CheckForCollisions(checkPoint, ref _encounteredEnemyTrainer); if (_encounteredEnemyTrainer != null && _encounteredEnemyTrainer.CurrentState != EnemyTrainerState.BattleFinished) _encounteredEnemyTrainer.TriggerTrainer(Sprite.CurrentAnimation); } else if (InputHandler.ActionKeyDown(ActionKey.Up, PlayerIndex.One)) { Sprite.CurrentAnimation = AnimationKey.Up; motion.Y = -1; _movementVector = motion; } else if (InputHandler.ActionKeyDown(ActionKey.Down, PlayerIndex.One)) { Sprite.CurrentAnimation = AnimationKey.Down; motion.Y = 1; _movementVector = motion; } else if (InputHandler.ActionKeyDown(ActionKey.Left, PlayerIndex.One)) { Sprite.CurrentAnimation = AnimationKey.Left; motion.X = -1; _movementVector = motion; } else if (InputHandler.ActionKeyDown(ActionKey.Right, PlayerIndex.One)) { Sprite.CurrentAnimation = AnimationKey.Right; motion.X = 1; _movementVector = motion; } else if (_movementJustFinished) { _movementJustFinished = false; Sprite.SetCurrentAnimationFrame(FrameKey.Idle); } } // If the player moves in a new direction if (Sprite.CurrentAnimation != _previousMovementDirection && _collision == CollisionType.Unwalkable) _collision = CollisionType.Walkable; // If the player is not already moving AND the player has initiated movement AND didn't previously try to move onto an unwalkable tile if (MoveState == MoveState.Still && motion != Vector2.Zero && _collision != CollisionType.Unwalkable) { var checkPoint = new Vector2(Sprite.Position.X + (float)Sprite.Width / 2 + motion.X * Sprite.Speed, Sprite.Position.Y + (float)Sprite.Height / 2 * 1.5f + motion.Y * Sprite.Speed); // Check for collisions _collision = _map.CheckForCollisions(checkPoint, ref _encounteredEnemyTrainer); if (_collision != CollisionType.Unwalkable) { MoveState = MoveState.Moving; Sprite.IsAnimating = true; } else { _previousMovementDirection = Sprite.CurrentAnimation; } } // Process movement if movement is initiated if (MoveState == MoveState.Moving) { // FIRST FRAME: Proceed to the next animation frame if (_frameCounter == 0) { if (_lastFoot == FrameKey.RightFoot) { Sprite.SetCurrentAnimationFrame(FrameKey.LeftFoot); _lastFoot = FrameKey.LeftFoot; } else { Sprite.SetCurrentAnimationFrame(FrameKey.RightFoot); _lastFoot = FrameKey.RightFoot; } } // Increment the frame counter _frameCounter++; // Update the position of the sprite Sprite.Position += _movementVector * Sprite.Speed / _framesPerMovement; // MIDDLE OF MOVEMENT: Proceed to the next animation frame if (_frameCounter == _framesPerMovement / 2) Sprite.SetCurrentAnimationFrame(FrameKey.Idle); // MOVEMENT FINISHED if (_frameCounter == _framesPerMovement) { _movementJustFinished = true; // Set position of the sprite to integers Sprite.Position = new Vector2((int)Math.Round(Sprite.Position.X), (int)Math.Round(Sprite.Position.Y)); // Reset the frame counter _frameCounter = 0; // Not moving anymore MoveState = MoveState.Still; // Not animating anymore Sprite.IsAnimating = false; // Save the direction of the movement _previousMovementDirection = Sprite.CurrentAnimation; } base.Update(gameTime); } Camera.LockToSprite(Sprite); Camera.Update(gameTime); // DEBUG //Console.Clear(); //Console.WriteLine("Zone: " + (_map.CurrentMapComponent != null ? _map.CurrentMapComponent.Name : "")); //Console.WriteLine("Collision: " + _collision); //Console.WriteLine("Moving: " + MoveState); //Console.WriteLine("EnemyTrainer: " + (_encounteredEnemyTrainer != null ? _encounteredEnemyTrainer.Name : "")); foreach (var drawableBattleComponent in Components) { drawableBattleComponent.Position = Sprite.Position; drawableBattleComponent.Update(gameTime); } }
/// <summary> /// What happens when you interact with enemy trainer /// </summary> /// <param name="currentAnimation"></param> public void TriggerTrainer(AnimationKey currentAnimation) { if (CurrentState == EnemyTrainerState.BattleFinished) return; GamePlayScreen.Player.MoveState = MoveState.Frozen; switch (currentAnimation) { case AnimationKey.Up: CurrentFrame = AnimationKey.Down; break; } CurrentState = EnemyTrainerState.PlayerDiscovered; }