public Animation() { name = ""; keyFrame = new KeyFrame[64]; for (int i = 0; i < keyFrame.Length; i++) keyFrame[i] = new KeyFrame(); }
public void DoScript(int animIdx, int keyFrameIdx) { CharDef charDef = character.GetCharDef(); Animation animation = charDef.GetAnimation(animIdx); KeyFrame keyFrame = animation.GetKeyFrame(keyFrameIdx); bool done = false; for (int i = 0; i < keyFrame.GetScriptArray().Length; i++) { if (done) { break; } else { ScriptLine line = keyFrame.GetScript(i); if (line != null) { switch (line.GetCommand()) { case Commands.SetAnim: character.SetAnim(line.GetSParam()); break; case Commands.Goto: character.SetFrame(line.GetIParam()); done = true; break; case Commands.IfUpGoto: if (character.KeyUp) { character.SetFrame(line.GetIParam()); done = true; } break; case Commands.IfDownGoto: if (character.KeyDown) { character.SetFrame(line.GetIParam()); done = true; } break; case Commands.Float: character.Floating = true; break; case Commands.UnFloat: character.Floating = false; break; case Commands.Slide: character.Slide((float)line.GetIParam()); break; case Commands.Backup: character.Slide((float)-line.GetIParam()); break; case Commands.SetJump: character.SetJump((float)line.GetIParam()); break; case Commands.JoyMove: if (character.KeyLeft) { character.Trajectory.X = -character.Speed; } if (character.KeyRight) { character.Trajectory.X = character.Speed; } break; case Commands.ClearKeys: character.PressedKey = PressedKeys.None; break; case Commands.SetUpperGoto: character.GotoGoal[(int)PressedKeys.Upper] = line.GetIParam(); break; case Commands.SetLowerGoto: character.GotoGoal[(int)PressedKeys.Lower] = line.GetIParam(); break; case Commands.SetAtkGoto: character.GotoGoal[(int)PressedKeys.Attack] = line.GetIParam(); break; case Commands.SetAnyGoto: character.GotoGoal[(int)PressedKeys.Upper] = line.GetIParam(); character.GotoGoal[(int)PressedKeys.Lower] = line.GetIParam(); character.GotoGoal[(int)PressedKeys.Attack] = line.GetIParam(); break; case Commands.SetSecondaryGoto: character.GotoGoal[(int)PressedKeys.Secondary] = line.GetIParam(); character.GotoGoal[(int)PressedKeys.SecUp] = line.GetIParam(); character.GotoGoal[(int)PressedKeys.SecDown] = line.GetIParam(); break; case Commands.SetSecUpGoto: character.GotoGoal[(int)PressedKeys.SecUp] = line.GetIParam(); break; case Commands.SetSecDownGoto: character.GotoGoal[(int)PressedKeys.SecDown] = line.GetIParam(); break; case Commands.CanCancel: character.CanCancel = true; break; case Commands.PlaySound: Sound.PlayCue(line.GetSParam()); break; case Commands.Ethereal: character.ethereal = true; break; case Commands.Solid: character.ethereal = false; break; case Commands.Speed: character.Speed = (float)line.GetIParam(); break; case Commands.HP: character.HP = character.MHP = line.GetIParam(); break; case Commands.DeathCheck: if (character.HP < 0) { character.KillMe(); } break; case Commands.IfDyingGoto: if (character.HP < 0) { character.SetFrame(line.GetIParam()); done = true; } break; case Commands.KillMe: character.KillMe(); break; case Commands.AI: switch (line.GetSParam()) { case "zombie": character.Ai = new Zombie(); break; case "wraith": character.Ai = new Wraith(); break; case "carlos": character.Ai = new Carlos(); break; default: character.Ai = new Zombie(); break; } break; case Commands.Size: character.Scale = (float)(line.GetIParam()) / 200f; break; case Commands.NoLifty: character.NoLifty = true; break; } } } } }
public void Update(Map map, ParticleManager pMan, Character[] c) { if (Ai != null) { Ai.Update(c, ID, map); } PressedKey = PressedKeys.None; if (KeyAttack) { PressedKey = PressedKeys.Attack; if (KeyUp) { PressedKey = PressedKeys.Lower; } if (KeyDown) { PressedKey = PressedKeys.Upper; } } if (KeySecondary) { PressedKey = PressedKeys.Secondary; if (KeyUp) { PressedKey = PressedKeys.SecUp; } if (KeyDown) { PressedKey = PressedKeys.SecDown; } } if (PressedKey > PressedKeys.None) { if (GotoGoal[(int)PressedKey] > -1) { SetFrame(GotoGoal[(int)PressedKey]); if (KeyLeft) { Face = CharDir.Left; } if (KeyRight) { Face = CharDir.Right; } PressedKey = PressedKeys.None; for (int i = 0; i < GotoGoal.Length; i++) { GotoGoal[i] = -1; } frame = 0f; } } if (StunFrame > 0f) { StunFrame -= Game1.FrameTime; } #region Update Dying if (DyingFrame > -1f) { DyingFrame += Game1.FrameTime; } #endregion #region Update Animation if (DyingFrame < 0f) { Animation animation = charDef.GetAnimation(Anim); KeyFrame keyframe = animation.GetKeyFrame(AnimFrame); frame += Game1.FrameTime * 30.0f; if (frame > (float)keyframe.Duration) { int pframe = AnimFrame; script.DoScript(Anim, AnimFrame); CheckTrig(pMan); frame -= (float)keyframe.Duration; if (AnimFrame == pframe) { AnimFrame++; } keyframe = animation.GetKeyFrame(AnimFrame); if (AnimFrame >= animation.getKeyFrameArray().Length) { AnimFrame = 0; } } if (keyframe.FrameRef < 0) { AnimFrame = 0; } if (AnimName == "jhit") { if (Trajectory.Y > -100f) { SetAnim("jmid"); } } } #endregion #region Collison w/ other characters for (int i = 0; i < c.Length; i++) { if (i != ID) { if (c[i] != null) { if (!ethereal && !c[i].ethereal) { if (Loc.X > c[i].Loc.X - 90f * c[i].Scale && Loc.X <c[i].Loc.X + 90f * c[i].Scale && Loc.Y> c[i].Loc.Y - 120f * c[i].Scale && Loc.Y < c[i].Loc.Y + 10f * c[i].Scale) { float dif = (float)Math.Abs(Loc.X - c[i].Loc.X); dif = 180f * c[i].Scale - dif; dif *= 2f; if (Loc.X < c[i].Loc.X) { ColMove = -dif; c[i].ColMove = dif; } else { ColMove = dif; c[i].ColMove = -dif; } } } } } } if (ColMove > 0f) { ColMove -= 400f * Game1.FrameTime; if (ColMove < 0f) { ColMove = 0f; } } if (ColMove < 0f) { ColMove += 400f * Game1.FrameTime; if (ColMove > 0f) { ColMove = 0f; } } #endregion #region Update loc by trajectory Vector2 pLoc = new Vector2(Loc.X, Loc.Y); if (State == CharState.Grounded || (State == CharState.Air && Floating)) { if (Trajectory.X > 0f) { Trajectory.X -= Game1.Friction * Game1.FrameTime; if (Trajectory.X < 0f) { Trajectory.X = 0f; } } if (Trajectory.X < 0f) { Trajectory.X += Game1.Friction * Game1.FrameTime; if (Trajectory.X > 0f) { Trajectory.X = 0f; } } } Loc.X += Trajectory.X * Game1.FrameTime; Loc.X += ColMove * Game1.FrameTime; if (State == CharState.Air) { Loc.Y += Trajectory.Y * Game1.FrameTime; } #endregion #region Collision detection if (State == CharState.Air) { #region Air State if (Floating) { Trajectory.Y += Game1.FrameTime * Game1.Gravity * 0.5f; if (Trajectory.Y > 100f) { Trajectory.Y = 100f; } if (Trajectory.Y < -100f) { Trajectory.Y = -100f; } } else { Trajectory.Y += Game1.FrameTime * Game1.Gravity; } CheckXCol(map, pLoc); #region Land on ledge if (Trajectory.Y > 0.0f) { for (int i = 0; i < 16; i++) { if (map.GetLedgeTotalNodes(i) > 1) { int ts = map.GetLedgeSec(i, pLoc.X); int s = map.GetLedgeSec(i, Loc.X); float fY; float tfY; if (s > -1 && ts > -1) { tfY = map.GetLedgeYLoc(i, s, pLoc.X); fY = map.GetLedgeYLoc(i, s, Loc.X); if (pLoc.Y <= tfY && Loc.Y >= fY) { if (Trajectory.Y > 0.0f) { Loc.Y = fY; ledgeAttach = i; Land(); } } else if (map.GetLedgeFlags(i) == (int)LedgeFlags.Solid && Loc.Y >= fY) { Loc.Y = fY; ledgeAttach = i; Land(); } } } } } #endregion #region Land on col if (State == CharState.Air) { if (Trajectory.Y > 0f) { if (map.CheckCol(new Vector2(Loc.X, Loc.Y + 15f))) { Loc.Y = (float)((int)((Loc.Y + 15f) / 64f) * 64); Land(); } } } #endregion #endregion } else if (State == CharState.Grounded) { #region Grounded State if (ledgeAttach > -1) { if (map.GetLedgeSec(ledgeAttach, Loc.X) == -1) { FallOff(); } else { Loc.Y = map.GetLedgeYLoc(ledgeAttach, map.GetLedgeSec(ledgeAttach, Loc.X), Loc.X); } } else { if (!map.CheckCol(new Vector2(Loc.X, Loc.Y + 15f))) { FallOff(); } } CheckXCol(map, pLoc); #endregion } #endregion #region Key input if (AnimName == "idle" || AnimName == "run" || (State == CharState.Grounded && CanCancel)) { if (AnimName == "idle" || AnimName == "run") { if (KeyLeft) { SetAnim("run"); Trajectory.X = -Speed; Face = CharDir.Left; } else if (KeyRight) { SetAnim("run"); Trajectory.X = Speed; Face = CharDir.Right; } else { SetAnim("idle"); } } if (KeyAttack) { SetAnim("attack"); } if (KeySecondary) { SetAnim("second"); } if (KeyJump) { SetAnim("jump"); } if (RightAnalog.X > 0.2f || RightAnalog.X < -0.2f) { SetAnim("roll"); if (AnimName == "roll") { if (RightAnalog.X > 0f) { Face = CharDir.Right; } else { Face = CharDir.Left; } } } } if (AnimName == "fly" || (State == CharState.Air && CanCancel)) { if (KeyLeft) { Face = CharDir.Left; if (Trajectory.X > -Speed) { Trajectory.X -= 500f * Game1.FrameTime; } } if (KeyRight) { Face = CharDir.Right; if (Trajectory.X < Speed) { Trajectory.X += 500f * Game1.FrameTime; } } if (KeySecondary) { SetAnim("fsecond"); } if (KeyAttack) { SetAnim("fattack"); } } #endregion }
public void SetKeyFrame(int idx, KeyFrame _keyFrame) { keyFrame[idx] = _keyFrame; }
public void DoScript(int animIdx, int animFrame) { KeyFrame keyFrame = animation[animIdx].GetKeyFrame(animFrame); }