/// <summary> /// Draw. /// </summary> /// <param name="cds">The surface to draw on.</param> public override void Draw(Microsoft.Graphics.Canvas.CanvasDrawingSession cds) { // the bounding rectangle Windows.Foundation.Rect r = new Windows.Foundation.Rect(Location.X, Location.Y, Size.Width, Size.Height); // create the text description Microsoft.Graphics.Canvas.Text.CanvasTextFormat ctf = new Microsoft.Graphics.Canvas.Text.CanvasTextFormat(); ctf.VerticalAlignment = Microsoft.Graphics.Canvas.Text.CanvasVerticalAlignment.Center; ctf.HorizontalAlignment = Microsoft.Graphics.Canvas.Text.CanvasHorizontalAlignment.Center; ctf.FontSize = 26; ctf.FontFamily = "Snap ITC"; // draw the border if (IsHover) { // cds.DrawRectangle(r, HighlightBorderColor); // draw the text cds.DrawText(Text, r, HighlightBorderColor, ctf); } else { // cds.DrawRectangle(r, BorderColor); // draw the text cds.DrawText(Text, r, ForegroundColor, ctf); } }
private void Canvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.ICanvasAnimatedControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasAnimatedDrawEventArgs args) { if (!mainMenu.gameStarted) { if (mainMenu.onInstructions == false && mainMenu.onCredits == false) { mainMenu.DrawMainMenu(args.DrawingSession); } else if (mainMenu.onInstructions == true && mainMenu.onCredits == false) { mainMenu.DrawInstructions(args.DrawingSession); } else { mainMenu.DrawCredits(args.DrawingSession); } } else if (!game.gameOver) { game.DrawAllGameObjects(args.DrawingSession); } else { var fontFormat = new Microsoft.Graphics.Canvas.Text.CanvasTextFormat { FontSize = 48 }; args.DrawingSession.DrawImage(spaceImage);//would put rect in here args.DrawingSession.DrawText(" Game over! Do you want to play again? (Y/N)", 0, 200, Colors.LightYellow, fontFormat); } }
public DrawStringPainter(Rectangle clip, string str, int x, int y, Microsoft.Graphics.Canvas.Text.CanvasTextFormat font, int color, int alpha) : base(clip) { this.clip = clip; this.str = str; this.x = x; this.y = y; this.font = font; this.color = color; this.alpha = alpha; }
public void DrawCredits(CanvasDrawingSession drawingSession) { //drawingSession.DrawImage(spaceImage);//would put rect in here drawingSession.Clear(Colors.Red); var fontFormat3 = new Microsoft.Graphics.Canvas.Text.CanvasTextFormat { FontSize = 34 }; drawingSession.DrawText("Press \"B\" to exit", 765, 0, Colors.LightYellow, fontFormat3); drawingSession.DrawText("Created By: \n\n Joseph Cornell \n\n Jason Soltis \n\n Daniel Haacke \n\n Aleksandra Shor", 250, 200, Colors.LightYellow, fontFormat3); }
private void Canvas_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args) { if (!pong.gameOver) { pong.DrawPong(args.DrawingSession); } else { var fontFormat = new Microsoft.Graphics.Canvas.Text.CanvasTextFormat { FontSize = 48 }; args.DrawingSession.DrawText("Game over! Do you want to play again? ( Y/N )", 400, 400, Colors.Azure, fontFormat); } }
public void DrawInstructions(CanvasDrawingSession drawingSession) { //drawingSession.DrawImage(spaceImage);//would put rect in here drawingSession.Clear(Colors.Red); var fontFormat3 = new Microsoft.Graphics.Canvas.Text.CanvasTextFormat { FontSize = 36 }; var fontFormat = new Microsoft.Graphics.Canvas.Text.CanvasTextFormat { FontSize = 12 }; drawingSession.DrawText("HEALTH is shown at the top through a health bar\nAvoid the virus envelopes to not take damage\nIf your health goes to 0, you lose!", 100, 100, Colors.LightYellow, fontFormat); drawingSession.DrawText("Shoot virus envelopes to split them until they're small enough to be destroyed\nDestroy the viruses to survive!", 400, 100, Colors.LightYellow, fontFormat); drawingSession.DrawText("Press \"B\" to exit", 765, 0, Colors.LightYellow, fontFormat3); drawingSession.DrawText("Instructions", 250, 300, Colors.LightYellow, fontFormat3); drawingSession.DrawText("UP: (Use W or up arrow key)", 300, 350, Colors.LightYellow, fontFormat3); drawingSession.DrawText("DOWN: (Use S or down arrow key)", 300, 400, Colors.LightYellow, fontFormat3); drawingSession.DrawText("LEFT: (Use A or left arrow key)", 300, 450, Colors.LightYellow, fontFormat3); drawingSession.DrawText("RIGHT: (Use D or right arrow key)", 300, 500, Colors.LightYellow, fontFormat3); drawingSession.DrawText("SHOOT: (Use SPACEBAR key)", 300, 550, Colors.LightYellow, fontFormat3); }
public void DrawMainMenu(CanvasDrawingSession drawingSession) { //drawingSession.DrawImage(spaceImage);//would put rect in here drawingSession.Clear(Colors.Red); var fontFormat = new Microsoft.Graphics.Canvas.Text.CanvasTextFormat { FontSize = 72, }; var fontFormat2 = new Microsoft.Graphics.Canvas.Text.CanvasTextFormat { FontSize = 15, }; var fontFormat3 = new Microsoft.Graphics.Canvas.Text.CanvasTextFormat { FontSize = 36 }; drawingSession.DrawText("CoronAsteroids", 300, 300, Colors.LightYellow, fontFormat); drawingSession.DrawText("The Lone white blood cell Osmosis Jones braves the bloodstream to fight against the invisible \n and lifeless virus, COVID-19....Shoot the virus envelopes to survive and thwart the pandemic!", 300, 400, Colors.LightYellow, fontFormat2); drawingSession.DrawText("1 : Start Game", 350, 450, Colors.LightYellow, fontFormat3); drawingSession.DrawText("2 : Instructions", 350, 500, Colors.LightYellow, fontFormat3); drawingSession.DrawText("3 : Credits", 350, 550, Colors.LightYellow, fontFormat3); }
//Main game loop, should be fired 60 times per second void canvas_DrawAnimated(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args) { //Calling actions expected before first draw starts if (FirstDraw) { BeforeFirstDraw(); } //Exception during Act is fatal. We encapsulate it as a plain text and throw it. IAct problemActor = null; try { ForEachActor <IAct> ( a => { problemActor = a; a.Act(); return(false); } ); } catch (Exception e) { Log.e(this, "Exception happened during Act on an Actor.\n" + e.ToString()); if (problemActor != null) { Log.e(this, "Problem Actor was " + problemActor.ToString()); } //sender.RunOnGameLoopThreadAsync(async() => { await Utility.GetMusic("Sounds", "alarm_to_the_extreme"); }).AsTask(); //throw new Exception("Exception happened during Act on an Actor.\n" + e.ToString(), e); } //Background draw cycle try { BackgroundImage.Draw(args.DrawingSession); } catch (Exception e) { Log.e(this, "Problem happened during Background Draw.\n" + e.ToString()); } //Actor draw cycle //No problem should happen, but this makes debugging easier, plus any error during a single frame Draw is irrelevant anyway try { //Draw all actors ForEachActor <IActor> ( a => { a.Draw(args.DrawingSession); return(false); } ); //Draw last error log DrawErrorLog(args.DrawingSession); } catch (Exception e) { Log.e(this, "Problem happened during Draw.\n" + e.ToString()); } //Draws a broadcast message, if there is any if (MessageBroadcastCounter < MessageBroadcastTime) { var format = new Microsoft.Graphics.Canvas.Text.CanvasTextFormat(); format.FontSize = 120; format.FontStyle = Windows.UI.Text.FontStyle.Oblique; format.FontFamily = "Comic Sans"; //If I ever implement multi-line messages, this calculation has to take the longest line instead of length int moveToLeft = MessageBroadcastText.Length * 5; args.DrawingSession.DrawText(MessageBroadcastText, new Vector2(500 - moveToLeft, 200), Colors.Aquamarine, format); MessageBroadcastCounter++; } //Draws current Score { var format = new Microsoft.Graphics.Canvas.Text.CanvasTextFormat(); format.FontSize = 30; format.FontFamily = "Arial"; args.DrawingSession.DrawText("Score: " + PlayerController.CacheScore(), new Vector2(15, 15), Colors.ForestGreen, format); } //Calling actions expected after first draw finishes if (FirstDraw) { FirstDraw = false; AfterFirstDraw(); } }
//***************************Drawing stuff starts from here*********************************** private void canvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { dynamic format = new Microsoft.Graphics.Canvas.Text.CanvasTextFormat(); format.FontSize = 14; //Top left, length and height //print platform args.DrawingSession.DrawRectangle(100, 140 + 15, 200, 200, Colors.Black); //Print metal motor plate args.DrawingSession.DrawRectangle(120, 60, 160, 60, Colors.Black); //Center of plate where motor shafts area float tempcalc1 = Convert.ToSingle(LeftMotorEndX); //Draw Left Motor Circle args.DrawingSession.DrawCircle(tempcalc1, 90, 25, Colors.Green); tempcalc1 = Convert.ToSingle(LeftMotorEndX); args.DrawingSession.DrawCircle(tempcalc1, 90, 5, Colors.Green); tempcalc1 = Convert.ToSingle(LeftMotorStartXARM1); float tempcalc2 = Convert.ToSingle(LeftMotorStartYARM1); args.DrawingSession.DrawCircle(tempcalc1, tempcalc2, 12, Colors.Green); //draw x-y tempcalc1 = Convert.ToSingle(100 + xtarget); tempcalc2 = Convert.ToSingle(340 - ytarget + 15); args.DrawingSession.DrawCircle(tempcalc1, tempcalc2, 18, Colors.Red); tempcalc1 = Convert.ToSingle(100 + xtarget); tempcalc2 = Convert.ToSingle(340 - ytarget + 15); args.DrawingSession.DrawCircle(tempcalc1, tempcalc2, 12, Colors.Green); tempcalc1 = Convert.ToSingle(100 + xtarget); tempcalc2 = Convert.ToSingle(335 - ytarget); args.DrawingSession.DrawText("" + xtarget + "," + ytarget, tempcalc1, tempcalc2, Colors.Red, format); //Draw Motor 1 ARM1 tempcalc1 = Convert.ToSingle(LeftMotorStartXARM1); tempcalc2 = Convert.ToSingle(LeftMotorStartYARM1); aaMotor1ARM1 = new System.Numerics.Vector2(tempcalc1, tempcalc2); // Start aaX aaY So Start of line point that is extended out tempcalc1 = Convert.ToSingle(LeftMotorEndX); bbMotor1ARM1 = new System.Numerics.Vector2(tempcalc1, 90); // Finish bbX bbY So Finish of line point in middle of motor shaft args.DrawingSession.DrawLine(aaMotor1ARM1, bbMotor1ARM1, Colors.Blue); //Draw Motor 1 ARM2 tempcalc1 = Convert.ToSingle(100 + xtarget); tempcalc2 = Convert.ToSingle(340 - ytarget + 15); aaMotor1ARM2 = new System.Numerics.Vector2(tempcalc1, tempcalc2); // Start aaX aaY So Start of line point that is extended out tempcalc1 = Convert.ToSingle(LeftMotorStartXARM1); tempcalc2 = Convert.ToSingle(LeftMotorStartYARM1); bbMotor1ARM2 = new System.Numerics.Vector2(tempcalc1, tempcalc2); // Finish bbX bbY So Finish of line point in middle of motor shaft args.DrawingSession.DrawLine(aaMotor1ARM2, bbMotor1ARM2, Colors.Blue); //Draw Right Motor Circle tempcalc1 = Convert.ToSingle(RightMotorEndX); args.DrawingSession.DrawCircle(tempcalc1, 90, 25, Colors.Green); tempcalc1 = Convert.ToSingle(RightMotorEndX); args.DrawingSession.DrawCircle(tempcalc1, 90, 5, Colors.Green); tempcalc1 = Convert.ToSingle(RightMotorStartXARM1); tempcalc2 = Convert.ToSingle(RightMotorStartYARM1); args.DrawingSession.DrawCircle(tempcalc1, tempcalc2, 12, Colors.Green); //Draw Motor 2 ARM1 tempcalc1 = Convert.ToSingle(RightMotorStartXARM1); tempcalc2 = Convert.ToSingle(RightMotorStartYARM1); aaMotor2ARM1 = new System.Numerics.Vector2(tempcalc1, tempcalc2); // Start aaX aaY So Start of line point that is extended out tempcalc1 = Convert.ToSingle(RightMotorEndX); bbMotor2ARM1 = new System.Numerics.Vector2(tempcalc1, 90); // Finish bbX bbY So Finish of line point in middle of motor shaft args.DrawingSession.DrawLine(aaMotor2ARM1, bbMotor2ARM1, Colors.Blue); //Draw Motor 2 ARM2 tempcalc1 = Convert.ToSingle(100 + xtarget); tempcalc2 = Convert.ToSingle(340 - ytarget + 15); aaMotor2ARM2 = new System.Numerics.Vector2(tempcalc1, tempcalc2); // Start aaX aaY So Start of line point that is extended out tempcalc1 = Convert.ToSingle(RightMotorStartXARM1); tempcalc2 = Convert.ToSingle(RightMotorStartYARM1); bbMotor2ARM2 = new System.Numerics.Vector2(tempcalc1, tempcalc2); // Finish bbX bbY So Finish of line point in middle of motor shaft args.DrawingSession.DrawLine(aaMotor2ARM2, bbMotor2ARM2, Colors.Blue); }