bool JumpAnimation(GameTime gameTime) { #region 1、初期化 if (time <= gameTime.ElapsedGameTime) { mi.recVisible.Copy(normalRectangle); normalizeRectangle = false; jumpFlg++; velocity.Y = 0; mi.recCollision = normalRectangle; if (jumpFlg <= 1) { // 1段目のジャンプなら jumpSpeed = jumpSpeed1; Vector2 v = Vector2.Zero; v.Y = (float)RecVisible.Bottom3D; v.X = (float)(RecVisible.Center.X); ParticleManager pm = new ParticleManager(scene, "SmokeParticles", v); Follow(this); scene.EntityList.Add(pm); } else { // 2段目以上のジャンプなら jumpSpeed = jumpSpeed2; } Cue c = GLOBAL.soundBank.GetCue("jump"); c.Play(); } #endregion #region 2.アニメーション double dt = gameTime.ElapsedGameTime.TotalSeconds; if (time < TimeSpan.FromSeconds(jumpTime1)) { mi.recVisible.Top3D = normalRectangle.Top3D - jumpA * Math.Sin(MathHelper.Pi * time.TotalSeconds / jumpTime1); } else { mi.recVisible.Top3D = normalRectangle.Top3D; velocity.Y = (float)jumpSpeed; velocity.X = (float)maxJumpSpeedX * input.Stick(player.dev).X; endAnimation = true; } OffsetWithAdjust(gameTime); #endregion #region 3、次のアニメーションへの遷移判定 Animation prevAnim = anim; NextAnimation[] nextAnim = new NextAnimation[]{ new NextAnimation(Animation.Dead,false,CheckDead,true), new NextAnimation(Animation.Attacked,false,CheckAttacked,true), new NextAnimation(Animation.Float,false,null,endAnimation), new NextAnimation(Animation.Jump,true,null,!endAnimation), }; anim = FindNextAnimation(nextAnim, gameTime); if (anim == Animation.None) { anim = prevAnim; mi.rotation = Vector3.Zero; } #endregion #region 4、アニメーションが遷移するときの処理 if (anim != prevAnim) { commandFlg[(int)Animation.Jump] = false; normalizeRectangle = true; mi.recCollision = mi.recVisible; mi.recVisible.Copy(normalRectangle); } #endregion return true; }
bool WalkAnimation(GameTime gameTime) { #region 1、初期化 if (time <= gameTime.ElapsedGameTime) { if (input.isOn(BUTTON.LEFT, player.dev)) { direction = new Vector3(-1, 0, 0); } if (input.isOn(BUTTON.RIGHT, player.dev)) { direction = new Vector3(1, 0, 0); } Vector2 v = Vector2.Zero; v.Y = (float)RecVisible.Bottom3D; v.X = (float)(direction.X > 0 ? RecVisible.Left : RecVisible.Right); ParticleManager pm = new ParticleManager(scene, "SmokeParticles", v); pm.Follow(this); scene.EntityList.Add(pm); } #endregion #region 2.アニメーション double dt = gameTime.ElapsedGameTime.TotalSeconds; // 速度のy方向は0に velocity.Y = 0; // x方向には適度に加速度をかける if (input.isOn(BUTTON.LEFT, player.dev)) { velocity.X = (float)Math.Max(velocity.X - walkAccel * gameTime.ElapsedGameTime.TotalSeconds, -maxWalkSpeed); direction = new Vector3(-1, 0, 0); } if (input.isOn(BUTTON.RIGHT, player.dev)) { velocity.X = (float)Math.Min(velocity.X + walkAccel * gameTime.ElapsedGameTime.TotalSeconds, maxWalkSpeed); direction = new Vector3(1, 0, 0); } // 速度*時間だけ動かす OffsetWithAdjust(gameTime); #endregion #region 3、次のアニメーションへの遷移判定 Animation prevAnim = anim; NextAnimation[] nextAnim = new NextAnimation[]{ new NextAnimation(Animation.Dead,false,CheckDead,true), new NextAnimation(Animation.Attacked,false,CheckAttacked,true), new NextAnimation(Animation.UpB,true,null,upBFlg), new NextAnimation(Animation.DownB,true,null,true), new NextAnimation(Animation.B,true,NotFullGage,true), new NextAnimation(Animation.SpecialB,true,FullGage,true), new NextAnimation(Animation.UpSmash,true,null,true), new NextAnimation(Animation.DownSmash,true,null,true), new NextAnimation(Animation.SideSmash,true,null,true), new NextAnimation(Animation.UpA,true,null,true), new NextAnimation(Animation.DownA,true,null,true), new NextAnimation(Animation.SideA,true,null,true), new NextAnimation(Animation.A,true,null,true), new NextAnimation(Animation.Float,false,CheckFloat,true), new NextAnimation(Animation.AvoidR,true,null,true), new NextAnimation(Animation.AvoidG,true,null,true), new NextAnimation(Animation.Jump,true,CheckJump,true), new NextAnimation(Animation.Shield,true,null,true), new NextAnimation(Animation.Sit,true,null,true), new NextAnimation(Animation.Run,true,null,true), new NextAnimation(Animation.Walk,true,null,true), new NextAnimation(Animation.Stop,false,null,true), }; anim = FindNextAnimation(nextAnim, gameTime); if (anim == Animation.None) { anim = prevAnim; } #endregion #region 4、アニメーションが遷移するときの処理 if (anim != prevAnim) { } #endregion return true; }
bool CheckAttacked(GameTime gameTime) { bool ans = false; // Write your algorithm int cur = cnt_ColStateWithAttacker; int prev = cur - 1 + MAX_COLSTATEWithAttacker; prev %= MAX_COLSTATEWithAttacker; if (colStateWithAttacker[cur] == null) return false; ParticleManager pm; foreach (DictionaryEntry de in colStateWithAttacker[cur]) { AttackArea a = (AttackArea)(de.Key); if (a.IsTarget[player.id] == false) continue; // 今回のフレームで初めてぶつかった if (colStateWithAttacker[prev][de.Key] == null) { Character he; if (player.id == 0) he = scene.Character2P; else he = scene.Character1P; // キャラクターの直接攻撃は食らう if (attackedAbsorb == true && Collision.Intersect(mi.recCollision, he.RecCollision) == false) { // ダメージを吸収する damage -= a.Damage * 0.5; damage = Math.Max(0, damage); pm = new ParticleManager(scene, "AbsorbParticles", RecVisible.Center); pm.Follow(this); scene.EntityList.Add(pm); colStateWithAttacker[cur].Remove(de); Cue sound = GLOBAL.soundBank.GetCue("absorb"); sound.Play(); break; } ans = true; Vector2 v; if (a.Force == Vector2.Zero) { v = mi.recCollision.Center - a.RecCollision.Center; if (v.Length() <= 0.00001) v = new Vector2(1, 0); v.Normalize(); v.X *= (float)a.Power; v.Y *= (float)a.Power; } else { v = a.Force; } if (v.X == 0) v.X = 0.0001f; double angle = MathHelper.ToDegrees((float)Math.Atan2(v.Y, v.X)); if (0 <= angle && angle < brownAngle) { angle = brownAngle; } else if (-brownAngle < angle && angle < 0) { angle = -brownAngle; } else if (180 - brownAngle < angle && angle <= 180) { angle = 180 - brownAngle; } else if (-180 < angle && angle < -180 + brownAngle) { angle = -180 + brownAngle; } double x = damage / maxDamage; double ratio = minAttackedRatio * (1 - x) + maxAttackedRatio * x; double pow = v.Length() * ratio; velocity += new Vector2( (float)(pow * Math.Cos(MathHelper.ToRadians((float)angle))), (float)(pow * Math.Sin((MathHelper.ToRadians((float)angle))))); damage += a.Damage; damage = Math.Min(damage, maxDamage); x = damage / maxGetDamage; brownTime = minBrownTime * (1 - x) + maxBrownTime * x; pm = new ParticleManager(scene, "AttackedParticles", RecVisible.Center); pm.Follow(this); scene.EntityList.Add(pm); Cue s = GLOBAL.soundBank.GetCue("attacked"); s.Play(); break; } } checkResult &= ans; return ans; }