public GameLevel() { GameSettings.SetCursor(CursorType.Wand); BackgroundColor = Color.LightBlue; Enemies = new SafeList <Enemy>(); Projectiles = new SafeList <Projectile>(); int x = GameSettings.BaseWidth / 2 - 64 / 2; int y = GameSettings.FloorLevel - 64 * 5 + 4; _wizard = new Wizard(new Vector2(GameSettings.BaseWidth / 2, y + 28)); BackgroundObjects.Add(_wizard); BackgroundObjects.Add(new Tower(0) { Position = new Rectangle(x, y, 64, 64) }); y += 64; for (; y < GameSettings.FloorLevel; y += 64) { BackgroundObjects.Add(new Tower() { Position = new Rectangle(x, y, 64, 64) }); } }
/// <summary> /// /// </summary> /// <param name="gameData"></param> public void GenerateBackground(Texture2D[] backgroundTextures) { Texture = backgroundTextures[0]; var xPixelTotal = GameData.MaxXDimension * GameData.PixelsPerMeter; var yPixelTotal = GameData.MaxYDimension * GameData.PixelsPerMeter; var cols = xPixelTotal / Texture.Width; if (xPixelTotal % Texture.Width != 0) { cols++; } var rows = yPixelTotal / Texture.Height; if (yPixelTotal % Texture.Height != 0) { rows++; } for (var i = 0; i < cols; ++i) { for (var j = 0; j < rows; ++j) { var v = GameUtils.PhysicsVec(new Vector2(i * Texture.Width, j * Texture.Height)); BackgroundObjects.Add(new BackgroundObject(GameData, GameUtils, Texture, v, GameData.MaxDistanceFromCamera)); } } /*var textureRandom = new Random((int)(DateTime.UtcNow - DateTime.MinValue).TotalMilliseconds); * var positionRandom = new Random((int)(DateTime.UtcNow - DateTime.MinValue).TotalMilliseconds); * var distanceRandom = new Random((int)(DateTime.UtcNow - DateTime.MinValue).TotalMilliseconds); * for(var i = 0; i < gameData.NumBackgroundObjects; ++i) * { * var texture = backgroundTextures[textureRandom.Next(0, backgroundTextures.Length - 1)]; * var positionX = positionRandom.Next(0, (int)gameData.MaxXDimension * (int)gameData.MaxXDimension); * var positionY = positionRandom.Next(0, (int)gameData.MaxYDimension * (int)gameData.MaxYDimension); * var positionXf = ((float)positionX) / gameData.MaxXDimension; * var positionYf = ((float)positionY) / gameData.MaxYDimension; * var position = new Vec2(positionXf, positionYf); * var distance = distanceRandom.Next(gameData.MaxDistanceFromCamera, gameData.MinDistanceFromCamera); * * _backgroundObjects.Add(new BackgroundObject(texture, position, distance)); * } * * _backgroundObjects.OrderBy(x => x.DistanceFromCamera).Reverse(); */ }
private void calculateBackground() { m_leftMarginPixel = (int)(PageWidth * leftMarginPct); m_rightMarginPixel = (int)(PageWidth * (1 - rightMarginPct)); m_topMarginPixel = (int)(PageHeight * topMarginPct); m_bottomMarginPixel = (int)(PageHeight * (1 - bottomMarginPct)); m_staffHeightPlusMargin = (int)(((1.0f - (topMarginPct + bottomMarginPct)) * PageHeight) / StaffsPerPage); // Since the unit mode is set to pixels in CreateDeviceResources(), here we scale the line thickness by the composition scale so that elements // are rendered in the same position but larger as you zoom in. Whether or not the composition scale should be factored into the size or position // of elements depends on the app's scenario. // Draw grid lines. for (int j = 0; j < StaffsPerPage; j++) { for (int i = 0; i < 5; i++) { //var line = new Tuple<Point, Point>( // new Point(m_leftMarginPixel, // m_topMarginPixel + i*NOTE_HEIGHT + j*m_staffHeightPlusMargin), // new Point(m_rightMarginPixel, // m_topMarginPixel + i*NOTE_HEIGHT + j*m_staffHeightPlusMargin)); var line = new Tuple <int, int, int, int>(m_leftMarginPixel, (m_topMarginPixel + i * NOTE_HEIGHT + j * m_staffHeightPlusMargin), m_rightMarginPixel, m_topMarginPixel + i * NOTE_HEIGHT + j * m_staffHeightPlusMargin); BackgroundObjects.Add(line); } } // Draw Clefs for (int j = 0; j < StaffsPerPage; j++) { var clef = new Clef(m_leftMarginPixel + 25, m_topMarginPixel - 170 + j * m_staffHeightPlusMargin, 'G'); BackgroundObjects.Add(clef); } // Draw Key // Draw Time Signature }