|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using C3.XNA; |
| 5 | +using Microsoft.Xna.Framework; |
| 6 | +using Microsoft.Xna.Framework.Audio; |
| 7 | +using Microsoft.Xna.Framework.Content; |
| 8 | +using Microsoft.Xna.Framework.GamerServices; |
| 9 | +using Microsoft.Xna.Framework.Graphics; |
| 10 | +using Microsoft.Xna.Framework.Input; |
| 11 | +using Microsoft.Xna.Framework.Media; |
| 12 | + |
| 13 | +namespace Primitives2DSample |
| 14 | +{ |
| 15 | + /// <summary> |
| 16 | + /// This is the main type for your game |
| 17 | + /// </summary> |
| 18 | + public class Game1 : Microsoft.Xna.Framework.Game |
| 19 | + { |
| 20 | + GraphicsDeviceManager graphics; |
| 21 | + SpriteBatch spriteBatch; |
| 22 | + |
| 23 | + public Game1() |
| 24 | + { |
| 25 | + graphics = new GraphicsDeviceManager(this); |
| 26 | + Content.RootDirectory = "Content"; |
| 27 | + } |
| 28 | + |
| 29 | + /// <summary> |
| 30 | + /// Allows the game to perform any initialization it needs to before starting to run. |
| 31 | + /// This is where it can query for any required services and load any non-graphic |
| 32 | + /// related content. Calling base.Initialize will enumerate through any components |
| 33 | + /// and initialize them as well. |
| 34 | + /// </summary> |
| 35 | + protected override void Initialize() |
| 36 | + { |
| 37 | + // TODO: Add your initialization logic here |
| 38 | + |
| 39 | + base.Initialize(); |
| 40 | + } |
| 41 | + |
| 42 | + /// <summary> |
| 43 | + /// LoadContent will be called once per game and is the place to load |
| 44 | + /// all of your content. |
| 45 | + /// </summary> |
| 46 | + protected override void LoadContent() |
| 47 | + { |
| 48 | + // Create a new SpriteBatch, which can be used to draw textures. |
| 49 | + spriteBatch = new SpriteBatch(GraphicsDevice); |
| 50 | + |
| 51 | + // TODO: use this.Content to load your game content here |
| 52 | + } |
| 53 | + |
| 54 | + /// <summary> |
| 55 | + /// UnloadContent will be called once per game and is the place to unload |
| 56 | + /// all content. |
| 57 | + /// </summary> |
| 58 | + protected override void UnloadContent() |
| 59 | + { |
| 60 | + // TODO: Unload any non ContentManager content here |
| 61 | + } |
| 62 | + |
| 63 | + /// <summary> |
| 64 | + /// Allows the game to run logic such as updating the world, |
| 65 | + /// checking for collisions, gathering input, and playing audio. |
| 66 | + /// </summary> |
| 67 | + /// <param name="gameTime">Provides a snapshot of timing values.</param> |
| 68 | + protected override void Update(GameTime gameTime) |
| 69 | + { |
| 70 | + // Allows the game to exit |
| 71 | + if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) |
| 72 | + this.Exit(); |
| 73 | + |
| 74 | + // TODO: Add your update logic here |
| 75 | + |
| 76 | + base.Update(gameTime); |
| 77 | + } |
| 78 | + |
| 79 | + /// <summary> |
| 80 | + /// This is called when the game should draw itself. |
| 81 | + /// </summary> |
| 82 | + /// <param name="gameTime">Provides a snapshot of timing values.</param> |
| 83 | + protected override void Draw(GameTime gameTime) |
| 84 | + { |
| 85 | + GraphicsDevice.Clear(Color.CornflowerBlue); |
| 86 | + spriteBatch.Begin(); |
| 87 | + |
| 88 | + spriteBatch.DrawRectangle(new Rectangle(100, 100, 100, 200), Color.Purple, 20); |
| 89 | + |
| 90 | + spriteBatch.DrawRectangle(new Rectangle(10, 10, 100, 200), Color.Yellow, 2); |
| 91 | + spriteBatch.DrawRectangle(new Rectangle(20, 20, 100, 200), Color.Yellow, 1); |
| 92 | + spriteBatch.DrawRectangle(new Vector2(30, 30), new Vector2(100, 200), Color.Yellow); |
| 93 | + spriteBatch.DrawRectangle(new Vector2(40, 40), new Vector2(100, 200), Color.Yellow, 5); |
| 94 | + |
| 95 | + spriteBatch.DrawCircle(400, 100, 90, 3, Color.White * 0.2f); |
| 96 | + spriteBatch.DrawCircle(400, 100, 90, 4, Color.White * 0.3f); |
| 97 | + spriteBatch.DrawCircle(400, 100, 90, 5, Color.White * 0.4f); |
| 98 | + spriteBatch.DrawCircle(400, 100, 90, 6, Color.White * 0.5f); |
| 99 | + spriteBatch.DrawCircle(400, 100, 90, 7, Color.White * 0.6f); |
| 100 | + spriteBatch.DrawCircle(400, 100, 90, 8, Color.White * 0.7f); |
| 101 | + spriteBatch.DrawCircle(400, 100, 90, 9, Color.White * 0.8f); |
| 102 | + spriteBatch.DrawCircle(400, 100, 90, 10, Color.White * 0.9f); |
| 103 | + spriteBatch.DrawCircle(400, 100, 90, 20, Color.Red); |
| 104 | + |
| 105 | + spriteBatch.DrawCircle(600, 100, 100, 50, Color.Green, 10); |
| 106 | + spriteBatch.DrawCircle(new Vector2(600, 100), 40, 30, Color.Green, 30); |
| 107 | + |
| 108 | + spriteBatch.FillRectangle(350, 340, 100, 100, Color.Red * 0.4f); |
| 109 | + spriteBatch.FillRectangle(new Rectangle(350, 340, 100, 100), Color.Red * 0.3f, (float)Math.PI / 4f); |
| 110 | + spriteBatch.FillRectangle(new Vector2(350, 340), new Vector2(100, 100), Color.Red * 0.2f, (float)Math.PI / 3f); |
| 111 | + spriteBatch.FillRectangle(350, 340, 100, 100, Color.Red * 0.5f, (float)Math.PI); |
| 112 | + |
| 113 | + spriteBatch.DrawArc(new Vector2(600, 350), 100, 180, MathHelper.ToRadians(180), MathHelper.ToRadians(180), Color.Navy, 1); |
| 114 | + spriteBatch.DrawArc(new Vector2(600, 350), 100, 180, MathHelper.ToRadians(180), MathHelper.ToRadians(160), Color.Navy * 0.9f, 2); |
| 115 | + spriteBatch.DrawArc(new Vector2(600, 350), 100, 180, MathHelper.ToRadians(180), MathHelper.ToRadians(140), Color.Navy * 0.8f, 4); |
| 116 | + spriteBatch.DrawArc(new Vector2(600, 350), 100, 180, MathHelper.ToRadians(180), MathHelper.ToRadians(120), Color.Navy * 0.7f, 6); |
| 117 | + spriteBatch.DrawArc(new Vector2(600, 350), 100, 180, MathHelper.ToRadians(180), MathHelper.ToRadians(90), Color.Navy * 0.6f, 8); |
| 118 | + spriteBatch.DrawArc(new Vector2(600, 350), 100, 180, MathHelper.ToRadians(180), MathHelper.ToRadians(80), Color.Navy * 0.5f, 10); |
| 119 | + spriteBatch.DrawArc(new Vector2(600, 350), 100, 180, MathHelper.ToRadians(180), MathHelper.ToRadians(65), Color.Navy * 0.4f, 12); |
| 120 | + spriteBatch.DrawArc(new Vector2(600, 350), 100, 180, MathHelper.ToRadians(180), MathHelper.ToRadians(45), Color.Navy * 0.3f, 14); |
| 121 | + spriteBatch.DrawArc(new Vector2(600, 350), 100, 180, MathHelper.ToRadians(180), MathHelper.ToRadians(12), Color.Navy * 0.2f, 16); |
| 122 | + |
| 123 | + spriteBatch.DrawArc(new Vector2(600, 400), 80, 90, MathHelper.ToRadians(90), MathHelper.ToRadians(220), Color.Navy, 10); |
| 124 | + |
| 125 | + base.Draw(gameTime); |
| 126 | + spriteBatch.End(); |
| 127 | + } |
| 128 | + } |
| 129 | +} |
0 commit comments