public static void DoDebugLogic(GameLoopObject glo, List <Bug> bugs, AnimationService animationService, Ship ship) { //for debugging purposes if (MouseHelper.MouseIsDown) { bugs.ForEach(a => a.OutputDebugInfo = false); bugs.ForEach(a => { var bugrect = new RectangleF(a.Location.X, a.Location.Y, 32, 32); var mouserect = new RectangleF(MouseHelper.Position.X, MouseHelper.Position.Y, 10, 10); if (bugrect.IntersectsWith(mouserect)) { a.OutputDebugInfo = true; } }); } //for debugging purposes if (glo.captureship) { bugs.ForEach(a => { a.Location = BugFactory.EnemyGrid.GetPointByRowCol(a.HomePoint.X, a.HomePoint.Y); a.CurPathPointIndex = 0; a.PathPoints.Clear(); a.Paths.Clear(); a.IsMoving = false; a.StartDelay = 0; a.Started = true; }); var bug = bugs.FirstOrDefault(a => a.Sprite.SpriteType == Sprite.SpriteTypes.GreenBug); EnemyDiveManager.DoEnemyDive(bugs, animationService, ship, Constants.BugDiveSpeed, bug, true); } //for debugging purposes if (glo.morphbug) { ship.Sprite = new Sprite(Sprite.SpriteTypes.DoubleShip); bugs.Where(a => a.IsInIntro).ToList().ForEach(a => { a.Location = BugFactory.EnemyGrid.GetPointByRowCol(a.HomePoint.X, a.HomePoint.Y); a.CurPathPointIndex = 0; a.PathPoints.Clear(); a.Paths.Clear(); a.IsMoving = false; a.StartDelay = 0; a.Started = true; }); var redblubugs = bugs.Where(a => (a.Sprite.SpriteType == Sprite.SpriteTypes.BlueBug || a.Sprite.SpriteType == Sprite.SpriteTypes.RedBug) && a.MorphState != Bug.enMorphState.Started && !a.IsDiving).ToList(); var bug = redblubugs[Utils.Rnd(0, redblubugs.Count - 1)]; bug.MorphState = Bug.enMorphState.Started; } //for debugging purposes if (glo.killbugs) { bugs.All(a => a.IsExploding = true); } }
public static void EditCurves(AnimationService animationService, GameLoopObject glo) { if (MouseHelper.MouseIsDown) { foreach (var animatable in animationService.Animatables.Where(a => a.Sprite.SpriteType != Sprite.SpriteTypes.Ship)) { animatable.PathDrawn = false; foreach (var path in animatable.Paths.Where(a => a.OutPutDebug)) { if (Utils.GetDistance(MouseHelper.Position, path.StartPoint) <= 5) { path.StartPointDragged = true; } else if (Utils.GetDistance(MouseHelper.Position, path.EndPoint) <= 5) { path.EndPointDragged = true; } else if (Utils.GetDistance(MouseHelper.Position, path.ControlPoint1) <= 5) { path.ControlPoint1Dragged = true; } else if (Utils.GetDistance(MouseHelper.Position, path.ControlPoint2) <= 5) { path.ControlPoint2Dragged = true; } if (path.StartPointDragged) { path.StartPoint = MouseHelper.Position; isDraggingCurve = true; break; } else if (path.EndPointDragged) { path.EndPoint = MouseHelper.Position; isDraggingCurve = true; break; } else if (path.ControlPoint1Dragged) { path.ControlPoint1 = MouseHelper.Position; isDraggingCurve = true; break; } else if (path.ControlPoint2Dragged) { path.ControlPoint2 = MouseHelper.Position; isDraggingCurve = true; break; } } } } else if (isDraggingCurve) { isDraggingCurve = false; string curvedata = ""; foreach (var animatable in animationService.Animatables.Where(a => a.DrawPath)) { foreach (var path in animatable.Paths.Where(a => a.OutPutDebug == true)) { path.StartPointDragged = false; path.EndPointDragged = false; path.ControlPoint1Dragged = false; path.ControlPoint2Dragged = false; if (path.DrawPath) { curvedata += "<br/>new BezierCurve() {" + "StartPoint = new PointF(" + path.StartPoint.X + "F," + path.StartPoint.Y + "F),<br/>" + "ControlPoint1 = new PointF(" + path.ControlPoint1.X + "F," + path.ControlPoint1.Y + "F),<br/>" + "ControlPoint2 = new PointF(" + path.ControlPoint2.X + "F," + path.ControlPoint2.Y + "F),<br/>" + "EndPoint = new PointF(" + path.EndPoint.X + "F," + path.EndPoint.Y + "F)},<br/>"; } } } Utils.dOut("CurveData", curvedata); } }
public async void Process(float timestamp, GameLoopObject glo) { if (skipintro) { skipintro = false; hideintroscreen = true; introsounddone = true; Started = true; Ship.Visible = true; KeyBoardHelper.SpaceBarPressed = true; } if (soundoff && !SoundManager.SoundIsOff) { SoundManager.TurnSoundOff(); } //show the intro screen if the space bar hasn't been pressed yet if (!hideintroscreen) { if (KeyBoardHelper.SpaceBarPressed) { SoundManager.PlaySound(SoundManager.SoundManagerSounds.coin, true); await ConsoleManager.ClearConsole(spriteService); await ConsoleManager.DrawConsole(Lives, spriteService, Ship, true, Level + LevelOffset, Score, HighScore); Started = true; } else { spriteService.DrawBlazorImage(new PointF(25, 10)); await ConsoleManager.ClearConsole(spriteService); await ConsoleManager.DrawIntroScreen(spriteService, Ship); return; } } //if the intro sound isn't done, exit if (!introsounddone) { await ConsoleManager.DrawConsolePlayer1(spriteService); return; } var bugs = GetBugs(); //do AI if enabled for debugging if (aion) { AIManager.AI(bugs, animationService, Ship); } //dive the bugs if (timestamp - LastDiveTimeStamp > NextDiveWaitTime && EnemyGridManager.EnemyGridBreathing && !glo.editcurveschecked) { Dive(); LastDiveTimeStamp = timestamp; NextDiveWaitTime = Utils.Rnd(500, maxwaittimebetweendives); } //if the bug intro wave is done, increment to the next wave] //or start diving and firing if ((bugs.Count(a => a.Started && !a.IsMoving && a.Wave == wave) > 0 || bugs.Count(a => a.Wave == wave) == 0) && wave <= 6 && bugs.Count() > 0 && Ship.Visible) { wave += 1; if (wave == 6) { EnemyGridManager.EnemyGridBreathing = true; NextDiveWaitTime = Utils.Rnd(500, maxwaittimebetweendives); } else { GetBugs().Where(a => a.Wave == wave).ToList().ForEach(a => a.Started = true); } } //adjust score when bugs are destroyed if (bugs.Count != prevbugcount || bugs.Count == 0) { if (Score >= nextextralifescore) { Lives += 1; nextextralifescore += 30000; SoundManager.PlaySound(SoundManager.SoundManagerSounds.extralife); await ConsoleManager.ClearConsole(spriteService); await ConsoleManager.DrawConsole(Lives, spriteService, Ship, true, Level + LevelOffset, Score, HighScore); } if (Score > HighScore) { HighScore = Score; } await ConsoleManager.DrawScore(spriteService, Score, HighScore); prevbugcount = bugs.Count(); } //all bugs destroyed, increment to next level await DoLevelIncrementAsync(bugs, timestamp); //animate explosions if (timestamp - EnemyGridManager.LastEnemyGridMoveTimeStamp > 35) { EnemyExplosionManager.DoEnemyExplosions(bugs, animationService, this); if (Ship.IsExploding) { if (!Ship.IsDoubleShip) { Ship.Disabled = true; } ShipManager.DoShipExplosion(Ship, animationService, this); } } //animate child bugs ChildBugsManager.MoveChildBugs(bugs, animationService); //animated the moving enemy grid if (timestamp - EnemyGridManager.LastEnemyGridMoveTimeStamp > 100 || EnemyGridManager.LastEnemyGridMoveTimeStamp == 0) { EnemyGridManager.MoveEnemyGrid(bugs, animationService, Ship, gameover); EnemyGridManager.LastEnemyGridMoveTimeStamp = timestamp; //fire enemy missiles foreach (var bug in bugs.Where(a => (a.MissileCountDowns.Count > 0 && a.Started) && ((a.IsDiving && a.Location.Y <= Constants.CanvasSize.Height - 400 && a.IsMovingDown && !a.IsMorphedBug) || //for diving bugs (a.IsInIntro && a.Wave == wave && a.Location.Y > 100 && a.Location.X > 150 & a.Location.X < Constants.CanvasSize.Width - 150 && a.Location.Y <= Constants.CanvasSize.Height - 500)))) //for intro bugs { for (int i = 0; i <= bug.MissileCountDowns.Count - 1; i++) { bug.MissileCountDowns[i] -= 1; if (bug.MissileCountDowns[i] <= 0) { EnemyDiveManager.DoEnemyFire(bug, animationService, Ship); bug.MissileCountDowns.RemoveAll(a => a <= 0); } } } } //animate the flapping wings if (timestamp - FlapWingsManager.LastWingFlapTimeStamp > 500 || FlapWingsManager.LastWingFlapTimeStamp == 0) { FlapWingsManager.FlapWings(bugs); FlapWingsManager.LastWingFlapTimeStamp = timestamp; } //animate ship missiles if (Ship.IsFiring && !Ship.Disabled && Ship.Visible) { SoundManager.PlaySound(SoundManager.SoundManagerSounds.fire); Ship.IsFiring = false; ShipManager.Fire(Ship, animationService); } //center the ship if it's disabled //happens after a galaga capture if ((Ship.Disabled && !Ship.IsDoubleShip) || (Ship.HasExploded && !Ship.IsDoubleShip)) { if (Ship.Location.X > 320) { Ship.Speed = Constants.ShipMoveSpeed * -1; } else if (Ship.Location.X < 310) { Ship.Speed = Constants.ShipMoveSpeed; } else { Ship.Speed = 0; } } //ship missile detection if (!Ship.Disabled) { //ship mission collision with bug hits += ShipManager.CheckMissileCollisions(bugs, animationService); //bug or missile collision with ship if (!shipinvincable) { if (!Ship.IsExploding && Ship.Visible && ShipManager.CheckShipCollisions(bugs, animationService, Ship)) { SoundManager.StopAllSounds(); Ship.IsExploding = true; } } } //draw fighter captured text if a fighter is captured if (bugs.Any(a => a.FighterCapturedMessageShowing)) { await ConsoleManager.DrawConsoleFighterCaptured(spriteService); } //hide fighter captured text if a fighter is captured //and bug had flown back home if (bugs.Any(a => a.ClearFighterCapturedMessage)) { await ConsoleManager.ClearConsoleLevelText(spriteService); bugs.FirstOrDefault(a => a.ClearFighterCapturedMessage).ClearFighterCapturedMessage = false; Lives -= 1; if (Lives < 0) { gameover = true; } await ConsoleManager.ClearConsole(spriteService); await ConsoleManager.DrawConsole(Lives, spriteService, Ship, true, Level + LevelOffset, Score, HighScore); } //if morphed bugs go offscreen, destroy them immediately bugs.Where(a => a.IsMorphedBug && a.Location.Y >= Constants.CanvasSize.Height).ToList().ForEach(a => a.DestroyImmediately = true); //ship exploded if (Ship.HasExploded) { if (Ship.IsDoubleShip) { Ship.IsDoubleShip = false; Ship.HasExploded = false; Ship.IsExploding = false; Ship.Visible = true; Ship.Disabled = false; Ship.LeftShipHit = false; Ship.RightShipHit = false; return; } WaitManager.DoOnce(async() => { if (infinitelives) { Lives += 1; } if (Lives >= 1) { //display ready for next life await ConsoleManager.DrawConsoleReady(spriteService); Ship.Disabled = true; } else { //game over await ConsoleManager.DrawConsoleGameOver(spriteService); gameover = true; SoundManager.MuteAllSounds = false; SoundManager.PlaySound(SoundManager.SoundManagerSounds.gameoversong, true); } }, WaitManager.WaitStep.enStep.ShowReady); if (WaitManager.WaitFor(3000, timestamp, WaitManager.WaitStep.enStep.WaitReady)) { if (!animationService.Animatables.Any(a => a.Sprite.SpriteType == Sprite.SpriteTypes.BugMissle) && !bugs.Any(a => a.CaptureState == Bug.enCaptureState.Started) && !bugs.Any(a => a.IsDiving)) { if (infinitelives) { Lives -= 1; } Ship.HasExploded = false; Ship.IsExploding = false; if (Lives >= 0) { //load next life Ship.Visible = true; Ship.Disabled = false; await ConsoleManager.ClearConsole(spriteService); await ConsoleManager.DrawConsole(Lives, spriteService, Ship, true, Level + LevelOffset, Score, HighScore); await ConsoleManager.ClearConsoleLevelText(spriteService); } WaitManager.ClearSteps(); } } } //this should never happen if (infinitelives && gameover) { throw new Exception("game over"); } if (showdebugdetails) { Utils.dOut("hits", hits); Utils.dOut("Ship.IsExploding", Ship.IsExploding); Utils.dOut("Ship.HasExploded", Ship.HasExploded); Utils.dOut("Ship.Disabled", Ship.Disabled); Utils.dOut("gameover", gameover); Utils.dOut("Lives", Lives); Utils.dOut("Level", Level); Utils.dOut("LevelOffset", LevelOffset); Utils.dOut("Score", Score); Utils.dOut("nextextralifescore", nextextralifescore); } DebugManager.DoDebugLogic(glo, bugs, animationService, Ship); }
public async void GameLoop(GameLoopObject glo) { if (glo.pauseanimation) { lastTimeStamp = glo.timestamp; Utils.dOut("Exited GameLoop", true); return; } loopCount++; var timeStamp = glo.timestamp; //Start Animation Logic delta += (int)(timeStamp - lastTimeStamp); lastTimeStamp = timeStamp; while (delta >= targetTicksPerFrame) { sw.Restart(); animationService.Animate(); Utils.dOut("animationService.Animate()", sw.ElapsedMilliseconds); delta -= targetTicksPerFrame; } if (Utils.FPS > 50 && Utils.FPS <= 55) { drawmod = 3; } else if (Utils.FPS > 45 && Utils.FPS <= 50) { drawmod = 4; } else if (Utils.FPS <= 45) { drawmod = 5; } else { drawmod = 2; } if (loopCount % drawmod == 0 || glo.captureship || glo.morphbug) { sw.Restart(); animationService.Draw(glo.editcurveschecked); if (sw.ElapsedMilliseconds >= 8) { totaldraw += sw.ElapsedMilliseconds; } if (sw.ElapsedMilliseconds > maxdraw && sw.ElapsedMilliseconds < 50) { maxdraw = sw.ElapsedMilliseconds; } Utils.dOut("animationService.Draw()", sw.ElapsedMilliseconds + " Avg: " + ((int)totaldraw / (loopCount / drawmod)) + " Max: " + maxdraw); sw.Restart(); if (gameService.animationService != null) { if (gameService.Ship == null) { gameService.Ship = ship; } gameService.Process(timeStamp, glo); if (gameService.Started && BackGroundClass == "background") { BackGroundClass = "background backgroundmoving"; StateHasChanged(); } else if (!gameService.Started && BackGroundClass == "background backgroundmoving") { BackGroundClass = "background"; StateHasChanged(); } Utils.dOut("gameService.Process()", sw.ElapsedMilliseconds); } } //End Animation Logic //Start Curve Editor Logic if (glo.editcurveschecked) { CurveEditorHelper.EditCurves(animationService, glo); } else { CurveEditorHelper.DisableLines(animationService); } if (glo.resetanimation) { CurveEditorHelper.ResetAnimation(animationService); } ////End Curve Editor Logic Utils.LogFPS(); KeyBoardHelper.ControlShip(ship, animationService); await JsRuntime.InvokeAsync <object>("logDiagnosticInfo", Utils.DiagnosticInfo); }