/// <summary> /// Starts a new game. /// </summary> /// <param name="arena">Specifies whether this is an arena game. We'll use an arena game for multiplayer games, covered in Chapter 12.</param> public void NewGame(bool arena) { gameMode = GameModes.Playing; pManager.Reset(); if (arena) { map.path = "arena"; gameType = GameType.Arena; players = 2; } else { map.path = "start"; gameType = GameType.Solo; players = 1; } for (int i = 0; i < players; i++) { character[i] = new Character(new Vector2(300f + (float)i * 200f, 100f), charDef[(int)CharacterDefinitions.Guy], i, Character.TEAM_GOOD_GUYS); character[i].HP = character[i].MHP = 100; } for (int i = players; i < character.Length; i++) character[i] = null; map.GlobalFlags = new MapFlags(64); map.Read(); map.TransDir = TransitionDirection.Intro; map.transInFrame = 1f; }
public static bool CheckHit(Particle p, Character[] c, ParticleManager pMan) { bool r = false; CharDir tFace = GetFaceFromTraj(p.GetTraj()); for (int i = 0; i < c.Length; i++) { if (i != p.Owner) { if (c[i] != null) { if (c[i].DyingFrame < 0f && !c[i].ethereal) { if (c[i].InHitBounds(p.GetLoc())) { float hVal = 1f; c[i].LastHitBy = p.Owner; CharState pState = c[i].State; Vector2 pLoc = c[i].Loc; bool noAnim = false; if (c[i].StunFrame > 0f && c[i].StunFrame < 3f) noAnim = true; if (c[i].NoLifty) { if (c[i].StunFrame <= 0f || c[i].StunFrame > 5.2f) c[i].StunFrame = 5.5f; } if (typeof(Bullet).Equals(p.GetType())) { if (!r) { hVal *= 4f; c[i].Face = 1 - tFace; c[i].SetAnim("idle"); if (!noAnim) { c[i].SetAnim("hit"); c[i].Slide(-100f); } Sound.PlayCue("bullethit"); Vector2 v = new Vector2(c[i].Loc.X, p.GetLoc().Y); pMan.MakeBulletBlood(v, p.GetTraj() / 2f); pMan.MakeBulletBlood(v, -p.GetTraj()); pMan.MakeBulletDust(v, p.GetTraj()); Game1.SlowTime = 0.05f; r = true; } } else if (typeof(Rocket).Equals(p.GetType())) { pMan.MakeExplosion(p.GetLoc(), 1f); hVal *= 5f; if (!noAnim) { c[i].Trajectory.X = (p.GetTraj().X > 0f ? 600f : -600f); c[i].SetAnim("jhit"); c[i].SetJump(300f); } Game1.SlowTime = 0.25f; r = true; } else if (typeof(Hit).Equals(p.GetType())) { c[i].Face = 1 - tFace; float tX = 1f; if (tFace == CharDir.Left) tX = -1f; if (!noAnim) { c[i].SetAnim("idle"); c[i].SetAnim("hit"); } Sound.PlayCue("zomhit"); if (c[i].State == CharState.Grounded) c[i].Slide(-200f); else c[i].Slide(-50f); switch (p.GetFlag()) { case Character.TRIG_ZOMBIE_HIT: hVal *= 5f; pMan.MakeBloodSplash(p.GetLoc(), new Vector2(50f * tX, 100f)); break; case Character.TRIG_WRENCH_DIAG_DOWN: hVal *= 5f; pMan.MakeBloodSplash(p.GetLoc(), new Vector2(50f * tX, 100f)); Game1.SlowTime = 0.1f; break; case Character.TRIG_WRENCH_DIAG_UP: hVal *= 5f; pMan.MakeBloodSplash(p.GetLoc(), new Vector2(-50f * tX, -100f)); Game1.SlowTime = 0.1f; break; case Character.TRIG_WRENCH_UP: hVal *= 5f; pMan.MakeBloodSplash(p.GetLoc(), new Vector2(30f * tX, -100f)); Game1.SlowTime = 0.1f; break; case Character.TRIG_WRENCH_DOWN: hVal *= 5f; pMan.MakeBloodSplash(p.GetLoc(), new Vector2(-50f * tX, 100f)); Game1.SlowTime = 0.1f; Sound.PlayCue("zomhit"); break; case Character.TRIG_WRENCH_UPPERCUT: case Character.TRIG_CHAINSAW_UPPER: hVal *= 15f; pMan.MakeBloodSplash(p.GetLoc(), new Vector2(-50f * tX, -150f)); c[i].Trajectory.X = 100f * tX; c[i].SetAnim("jhit"); c[i].SetJump(700f); Game1.SlowTime = 0.125f; QuakeManager.SetQuake(.5f); QuakeManager.SetBlast(.5f, p.GetLoc()); break; case Character.TRIG_WRENCH_SMACKDOWN: case Character.TRIG_CHAINSAW_DOWN: hVal *= 15f; pMan.MakeBloodSplash(p.GetLoc(), new Vector2(-50f * tX, 150f)); c[i].SetAnim("jfall"); c[i].SetJump(-900f); Game1.SlowTime = 0.125f; QuakeManager.SetQuake(.5f); QuakeManager.SetBlast(.5f, p.GetLoc()); break; case Character.TRIG_KICK: hVal *= 15f; pMan.MakeBloodSplash(p.GetLoc(), new Vector2(300f * tX, 0f)); c[i].Trajectory.X = 1000f * tX; c[i].SetAnim("jhit"); c[i].SetJump(300f); Game1.SlowTime = 0.25f; QuakeManager.SetQuake(.5f); QuakeManager.SetBlast(.75f, p.GetLoc()); break; } } if (c[i].State == CharState.Air) { if (c[i].AnimName == "hit") { c[i].SetAnim("jmid"); c[i].SetJump(300f); if (typeof(Hit).Equals(p.GetType())) { if (c[p.Owner].Team == Character.TEAM_GOOD_GUYS) { c[i].Loc.Y = c[p.Owner].Loc.Y; } } } if (c[i].NoLifty) { if (pState == CharState.Grounded) { c[i].Loc = pLoc; c[i].State = pState; c[i].SetAnim("hit"); } if (c[i].Trajectory.X > 300f) c[i].Trajectory.X = 300f; if (c[i].Trajectory.X < -300f) c[i].Trajectory.X = -300f; } } c[i].HP -= (int)hVal; if (c[i].LastHitBy == 0) Game1.Score += (int)hVal * 50; if (c[i].HP < 0) { if (c[i].AnimName == "hit") c[i].SetAnim("diehit"); if (i == 0) { if (c[i].AnimName == "hit") { c[i].SetAnim("jmid"); c[i].SetJump(300f); } Game1.Menu.Die(); } } } } } } } return r; }
public Script(Character _character) { character = _character; }
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 }