/// <summary> /// The main game constructor. /// </summary> public CritterCampGame() { Content.RootDirectory = "Content"; ContentManager cm = new ContentManager(Services, "Content"); graphics = new GraphicsDeviceManager(this); graphics.IsFullScreen = true; //graphics.SynchronizeWithVerticalRetrace = false; // Create the screen factory and add it to the Services screenFactory = new ScreenFactory(); Services.AddService(typeof(IScreenFactory), screenFactory); // Add event handlers for tombstoning PhoneApplicationService.Current.Activated += Activation; PhoneApplicationService.Current.Deactivated += Deactivation; // Create a new instance of the Screen Manager screenManager = new ScreenManager(this); Components.Add(screenManager); // Create a Sound Library soundLibrary = new SoundLibrary(); Services.AddService(typeof(SoundLibrary), soundLibrary); // Create a Sprite Drawer Services.RemoveService(typeof(SpriteDrawer)); SpriteDrawer spriteDrawer = new SpriteDrawer(screenManager); Services.AddService(typeof(SpriteDrawer), spriteDrawer); // Add new screens screenManager.AddScreen(new OfflineScreen(), null); string isOn; if(IsolatedStorageSettings.ApplicationSettings.TryGetValue<String>("music", out isOn)) { if(!Boolean.Parse(isOn)) { MediaPlayer.IsMuted = true; } } if(IsolatedStorageSettings.ApplicationSettings.TryGetValue<String>("sound", out isOn)) { if(!Boolean.Parse(isOn)) { SoundEffect.MasterVolume = 0; } } Song s = Content.Load<Song>("Sounds/adventure"); TryMediaPlay(s); }
// Draws map using a SpriteDrawer public void Draw(SpriteDrawer sd) { for(int i = 0; i < map.GetLength(0); i++) { for(int j = 0; j < map.GetLength(1); j++) { if(map[i, j] == -1) { continue; } // All coordinates are scaled to WinRT resolutions and rendered correctly through SpriteDrawer int x = Constants.BUFFER_SPRITE_DIM * j + Constants.BUFFER_SPRITE_DIM / 2; int y = Constants.BUFFER_SPRITE_DIM * i + Constants.BUFFER_SPRITE_DIM / 2 - Constants.BUFFER_OFFSET + offset; int spriteNum = map[i, j]; sd.Draw(mapTextures, new Vector2(x, y), spriteNum, cache: true, align: true); } } }
/// <summary> /// Draws the UIElement. This should be called by other elements and not overriden /// </summary> /// <param name="screen">The screen drawing the button</param> public void Draw(GameScreen screen, GameTime gameTime, SpriteBatch spriteBatch, SpriteDrawer spriteDrawer) { if (!Visible) { // element is not visible. don't draw it return; } MyScreen = screen; MyScreenManager = screen.ScreenManager; MyGameTime = gameTime; MySpriteBatch = spriteBatch; MySpriteDrawer = spriteDrawer; // can set more properties to the screen like opacity/overlay here // also can set boundries to not allow drawthis to drow outside the given size and position DrawThis(); }
protected void DrawLaunchpad(SpriteDrawer sd, Vector2 coord, int color) { int dim = Constants.BUFFER_SPRITE_DIM; // Draw the square for(int i = 0; i < 5; i++) { for(int j = 0; j < 5; j++) { if(i == 0) { sd.Draw(textureList["jetpack"], coord + new Vector2(dim / 2, dim * (j + 0.5f)), (int)TextureData.jetpackTextures.cautionLeft, cache: true, align: true); if(j == 0) { sd.Draw(textureList["jetpack"], coord + new Vector2(dim / 2), (int)TextureData.jetpackTextures.orangeL + color * 5, SpriteEffects.FlipVertically, cache: true, align: true); } else if(j == 4) { sd.Draw(textureList["jetpack"], coord + new Vector2(dim / 2, dim * 4.5f), (int)TextureData.jetpackTextures.orangeL + color * 5, cache: true, align: true); } else { sd.Draw(textureList["jetpack"], coord + new Vector2(dim / 2, dim * (j + 0.5f)), (int)TextureData.jetpackTextures.orange_ + color * 5, spriteRotation: Constants.ROTATE_90, cache: true, align: true); } } else if(i == 4) { sd.Draw(textureList["jetpack"], coord + new Vector2(dim * 4.5f, dim * (j + 0.5f)), (int)TextureData.jetpackTextures.cautionRight, cache: true, align: true); if(j == 0) { sd.Draw(textureList["jetpack"], coord + new Vector2(dim * 4.5f, dim / 2), (int)TextureData.jetpackTextures.orangeL + color * 5, SpriteEffects.FlipVertically | SpriteEffects.FlipHorizontally, cache: true, align: true); } else if(j == 4) { sd.Draw(textureList["jetpack"], coord + new Vector2(dim * 4.5f), (int)TextureData.jetpackTextures.orangeL + color * 5, SpriteEffects.FlipHorizontally, cache: true, align: true); } else { sd.Draw(textureList["jetpack"], coord + new Vector2(dim * 4.5f, dim * (j + 0.5f)), (int)TextureData.jetpackTextures.orange_ + color * 5, spriteRotation: Constants.ROTATE_90 * 3, cache: true, align: true); } } if(j == 0) { sd.Draw(textureList["jetpack"], coord + new Vector2(dim * (i + 0.5f), dim / 2), (int)TextureData.jetpackTextures.cautionTop, cache: true, align: true); if(i != 0 && i != 4) { sd.Draw(textureList["jetpack"], coord + new Vector2(dim * (i + 0.5f), dim / 2), (int)TextureData.jetpackTextures.orange_ + color * 5, spriteRotation: Constants.ROTATE_90 * 2, cache: true, align: true); } } else if(j == 4) { sd.Draw(textureList["jetpack"], coord + new Vector2(dim * (i + 0.5f), dim * 4.5f), (int)TextureData.jetpackTextures.cautionBottom, cache: true, align: true); if(i != 0 && i != 4) { sd.Draw(textureList["jetpack"], coord + new Vector2(dim * (i + 0.5f), dim * 4.5f), (int)TextureData.jetpackTextures.orange_ + color * 5, cache: true, align: true); } } } } // Draw the circle sd.Draw(textureList["jetpack"], coord + new Vector2(dim * 1.5f, dim * 1.5f), (int)TextureData.jetpackTextures.orangeLCurve + color * 5, cache: true, align: true); sd.Draw(textureList["jetpack"], coord + new Vector2(dim * 2.5f, dim * 1.5f), (int)TextureData.jetpackTextures.orangeTCurve + color * 5, cache: true, align: true); sd.Draw(textureList["jetpack"], coord + new Vector2(dim * 3.5f, dim * 1.5f), (int)TextureData.jetpackTextures.orangeLCurve + color * 5, SpriteEffects.FlipHorizontally, cache: true, align: true); sd.Draw(textureList["jetpack"], coord + new Vector2(dim * 1.5f, dim * 2.5f), (int)TextureData.jetpackTextures.orangeTCurve + color * 5, spriteRotation: Constants.ROTATE_90 * 3, cache: true, align: true); sd.Draw(textureList["jetpack"], coord + new Vector2(dim * 2.5f, dim * 2.5f), (int)TextureData.jetpackTextures.orangeCross + color * 5, cache: true, align: true); sd.Draw(textureList["jetpack"], coord + new Vector2(dim * 3.5f, dim * 2.5f), (int)TextureData.jetpackTextures.orangeTCurve + color * 5, spriteRotation: Constants.ROTATE_90, cache: true, align: true); sd.Draw(textureList["jetpack"], coord + new Vector2(dim * 1.5f, dim * 3.5f), (int)TextureData.jetpackTextures.orangeLCurve + color * 5, SpriteEffects.FlipVertically, cache: true, align: true); sd.Draw(textureList["jetpack"], coord + new Vector2(dim * 2.5f, dim * 3.5f), (int)TextureData.jetpackTextures.orangeTCurve + color * 5, spriteRotation: Constants.ROTATE_90 * 2, cache: true, align: true); sd.Draw(textureList["jetpack"], coord + new Vector2(dim * 3.5f, dim * 3.5f), (int)TextureData.jetpackTextures.orangeLCurve + color * 5, SpriteEffects.FlipHorizontally | SpriteEffects.FlipVertically, cache: true, align: true); }
public void DrawBuckets(SpriteDrawer sd) { int i = 0; foreach(string user in scores.Keys) { float scale = 0.5f; if(scores[user] > displayScore[user]) { scale += (float)(Math.Sqrt(scores[user] - displayScore[user])) / 40f; displayScore[user] += 2; } sd.Draw(textureList["fishing"], new Vector2((float)Constants.BUFFER_SPRITE_DIM * (6f + i), BUCKET_Y + waveOffset), (int)TextureData.fishingTextures.bucket); sd.Draw(textureList["fishing"], new Vector2((float)Constants.BUFFER_SPRITE_DIM * (7f + i), BUCKET_Y + waveOffset), (int)TextureData.fishingTextures.bucket, SpriteEffects.FlipHorizontally); sd.DrawString(ScreenManager.Fonts["museoslab"], displayScore[user].ToString(), new Vector2((float)Constants.BUFFER_SPRITE_DIM * (6.5f + i), (float)Constants.BUFFER_SPRITE_DIM * 2.5f + waveOffset - 35), spriteScale: scale); if(i == 2) i++; i += 2; } }
protected void DrawGrid(SpriteDrawer sd) { sd.FillRectangle(new Rectangle(1920 * 3 / 4 - 10, 0, 20, 1080), Color.Red); sd.FillRectangle(new Rectangle(1920 * 2 / 4 - 10, 0, 20, 1080), Color.Red); sd.FillRectangle(new Rectangle(1920 * 1 / 4 - 10, 0, 20, 1080), Color.Red); sd.FillRectangle(new Rectangle(0, 1080 / 2 - 10, 1920, 20), Color.Red); }
protected void DrawCoordinates(SpriteDrawer sd) { sd.DrawString(ScreenManager.Fonts["gillsans"], "raw: X " + rawInput.X + " Y: " + rawInput.Y, new Vector2(0, 1000), Color.Red, centerX: false, spriteScale: 0.8f); sd.DrawString(ScreenManager.Fonts["gillsans"], "scaled: X " + scaledInput.X + " Y: " + scaledInput.Y, new Vector2(0, 1050), Color.Red, centerX: false, spriteScale: 0.8f); }