public FloppyDisc(Game game, SpriteBatch spriteBatch, Texture2D texture, Texture2D overlayTexture, Color color, Color overlayColor, Vector2 position, float rotation , float scale, float layerDepth, int points) : base(game, spriteBatch, texture, color, position, rotation, scale, layerDepth, points) { this.overlayTexture = overlayTexture; this.overlayColor = overlayColor; }
public void Set(float x, float y, float w, float h, Color color, Vector2 texCoordTL, Vector2 texCoordBR) { this.vertexTL.Position.X = x; this.vertexTL.Position.Y = y; this.vertexTL.Position.Z = this.Depth; this.vertexTL.Color = color; this.vertexTL.TextureCoordinate.X = texCoordTL.X; this.vertexTL.TextureCoordinate.Y = texCoordTL.Y; this.vertexTR.Position.X = x + w; this.vertexTR.Position.Y = y; this.vertexTR.Position.Z = this.Depth; this.vertexTR.Color = color; this.vertexTR.TextureCoordinate.X = texCoordBR.X; this.vertexTR.TextureCoordinate.Y = texCoordTL.Y; this.vertexBL.Position.X = x; this.vertexBL.Position.Y = y + h; this.vertexBL.Position.Z = this.Depth; this.vertexBL.Color = color; this.vertexBL.TextureCoordinate.X = texCoordTL.X; this.vertexBL.TextureCoordinate.Y = texCoordBR.Y; this.vertexBR.Position.X = x + w; this.vertexBR.Position.Y = y + h; this.vertexBR.Position.Z = this.Depth; this.vertexBR.Color = color; this.vertexBR.TextureCoordinate.X = texCoordBR.X; this.vertexBR.TextureCoordinate.Y = texCoordBR.Y; }
public DrawStyle(Color fillColor, float fillAlpha, Color lineColor, float lineAlpha) { FillColor = fillColor; LineColor = lineColor; FillAlpha = fillAlpha; LineAlpha = lineAlpha; }
/// <summary> /// Renders the bounding box for debugging purposes. /// </summary> /// <param name="box">The box to render.</param> /// <param name="graphicsDevice">The graphics device to use when rendering.</param> /// <param name="view">The current view matrix.</param> /// <param name="projection">The current projection matrix.</param> /// <param name="color">The color to use drawing the lines of the box.</param> public static void Render( BoundingBox box, GraphicsDevice graphicsDevice, Matrix view, Matrix projection, Color color) { if (box.Min == box.Max) { return; } if (effect == null) { effect = new BasicEffect(graphicsDevice) {TextureEnabled = false, VertexColorEnabled = true, LightingEnabled = false}; } Vector3[] corners = box.GetCorners(); for (int i = 0; i < 8; i++) { verts[i].Position = corners[i]; verts[i].Color = color; } effect.View = view; effect.Projection = projection; foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); graphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.LineList, verts, 0, 8, indices, 0, indices.Length/2); } }
public TextSnippet(string text, Color color, float scale = 1f) { this.Text = text; this.TextOriginal = text; this.Color = color; this.Scale = scale; }
public Button(Vector2 position, Vector2 size, TextureE textureE) : base(position, size, Vector2.Zero, 0f, Color.White, getTexture(textureE), Animation.getAnimation(getTexture(textureE))) { disp = new Vector2(10f, 10f); selectedColor = new Color(230, 230, 230); LayerDepth = 0.5f; }
/// <summary> /// Constructor de la clase GameObject. /// </summary> /// <param name="effect">Effecto usado para dibujar.</param> /// <param name="engine">Clase principal del juego.</param> /// <param name="size">Tamaño del objeto.</param> /// <param name="position">Posicion x, y, z dada como Vector3.</param> /// <param name="color">Color del objeto.</param> public GameObject(Engine engine, Vector3 position, Color color, float size) : base(engine) { this.size = size; this.color = color; this.position = position; }
public void Set(float x, float y, float dx, float dy, float w, float h, float sin, float cos, Color color, Vector2 texCoordTL, Vector2 texCoordBR) { this.vertexTL.Position.X = (float) ((double) x + (double) dx * (double) cos - (double) dy * (double) sin); this.vertexTL.Position.Y = (float) ((double) y + (double) dx * (double) sin + (double) dy * (double) cos); this.vertexTL.Position.Z = this.Depth; this.vertexTL.Color = color; this.vertexTL.TextureCoordinate.X = texCoordTL.X; this.vertexTL.TextureCoordinate.Y = texCoordTL.Y; this.vertexTR.Position.X = (float) ((double) x + ((double) dx + (double) w) * (double) cos - (double) dy * (double) sin); this.vertexTR.Position.Y = (float) ((double) y + ((double) dx + (double) w) * (double) sin + (double) dy * (double) cos); this.vertexTR.Position.Z = this.Depth; this.vertexTR.Color = color; this.vertexTR.TextureCoordinate.X = texCoordBR.X; this.vertexTR.TextureCoordinate.Y = texCoordTL.Y; this.vertexBL.Position.X = (float) ((double) x + (double) dx * (double) cos - ((double) dy + (double) h) * (double) sin); this.vertexBL.Position.Y = (float) ((double) y + (double) dx * (double) sin + ((double) dy + (double) h) * (double) cos); this.vertexBL.Position.Z = this.Depth; this.vertexBL.Color = color; this.vertexBL.TextureCoordinate.X = texCoordTL.X; this.vertexBL.TextureCoordinate.Y = texCoordBR.Y; this.vertexBR.Position.X = (float) ((double) x + ((double) dx + (double) w) * (double) cos - ((double) dy + (double) h) * (double) sin); this.vertexBR.Position.Y = (float) ((double) y + ((double) dx + (double) w) * (double) sin + ((double) dy + (double) h) * (double) cos); this.vertexBR.Position.Z = this.Depth; this.vertexBR.Color = color; this.vertexBR.TextureCoordinate.X = texCoordBR.X; this.vertexBR.TextureCoordinate.Y = texCoordBR.Y; }
public Score(int positionX,int positionY,Color color) { this.positionX = positionX; this.positionY = positionY; this.color = color; score = 0; }
public Net(Vector3 position, int numBlocksX, int numBlocksY, float blockWidth, float blockHeight, Color color) { this.primitivesCount = numBlocksX + numBlocksY + 2; this.primitives = new IPrimitive[this.primitivesCount]; GenerateNet(numBlocksX, numBlocksY, blockWidth, blockHeight, position, color); }
/// <summary> /// Crea un objeto tipo GameObject. /// </summary> /// <param name="effect">Effecto usado para dibujar.</param> /// <param name="engine">Clase principal del juego.</param> /// <param name="position">Posición del objeto.</param> /// <param name="size">Tamaño del objeto.</param> public GameObject(Engine engine, Vector3 position, float size) : base(engine) { this.size = size; color = Color.LightGray; this.position = position; }
public DnaBar(float valueMax) : base(valueMax) { TwentyProcentColor = new Color(255, 0, 127, 200); FiftyProcentColor = new Color(255, 0, 127, 200); HundredProcentColor = new Color(255, 0, 127, 200); }
public virtual void DrawMenu(SpriteBatch spriteBatch) { // Fade the popup alpha during transitions. _color = Color.White * _transitionAlpha; // Draw the background rectangle. spriteBatch.Draw(ImageManager.GradientTexture, backgroundRectangle, _color); }
public static void DrawRoundedBlurPanel(IBatchRenderer sbatch, FRectangle bounds, Color color, float scale = 1f) { StaticTextures.ThrowIfNotInitialized(); DrawRoundedBlurPanelBackgroundPart(sbatch, bounds, scale); DrawRoundedBlurPanelSolidPart(sbatch, bounds, color, scale); }
public LevelPortal(World nWorld, Level nLevel, ContentManager nContentManager, Color nColor, Vector2 nPos, OnLevelPortalCollision nDelegate, Hashtable nConfig) { string nTextureName = "SpriteMaps/Portal"; base.Init(nWorld, nLevel, nContentManager, nTextureName, nColor, nPos); //Populate the Hashtable SpriteMap with the values for the player spritemap AddFrame(SpriteState.Portal, 0, 0, 100, 100); AddFrame(SpriteState.Portal, 100, 0, 100, 100); AddFrame(SpriteState.Portal, 200, 0, 100, 100); //Default SpriteState SetState(SpriteState.Portal); //Manually step the animation to update the sprite Source rectangle StepAnimation(); //Set callback for collisions Body.OnCollision += OnCollision; Body.OnSeparation += OnSeparation; //Other physical properties Body.BodyType = BodyType.Static; Body.IsSensor = true; Body.CollidesWith = Category.All; Body.CollisionCategories = Category.Cat30; Body.CollisionGroup = 30; Body.SleepingAllowed = false; Body.Position = nPos; OnPortalCollision = nDelegate; mLevelId = (int)nConfig["LevelId"]; }
public PreviewPanel(Board board, Rectangle bounds, Color backgroundColor) { _board = board; Bounds = bounds; _backgroundColor = backgroundColor; _texture = CreateTexture(TetrisGame.GetInstance().GraphicsDevice, bounds, backgroundColor); }
private Texture2D CreateTexture(GraphicsDevice graphicsDevice, Rectangle bounds, Color color) { var texture = new Texture2D(graphicsDevice, bounds.Width, bounds.Height); texture.FillWithColor(color); texture.AddBorder(Color.Black, 1); return texture; }
public MapRenderControl() { InitializeComponent(); _gridColor = Color.White; _gridColor.A = 15; }
public static void Write(this ContentWriter contentWriter, Color value) { contentWriter.Write(value.R); contentWriter.Write(value.G); contentWriter.Write(value.B); contentWriter.Write(value.A); }
public static void DrawString(this SpriteBatch spriteBatch, SpriteBitmapFont font, string text, Vector2 position, Color color, Color outlineColor) { var previousCharacter = ' '; var normalizedText = text.Replace("\r\n", "\n").Replace("\r", "\n"); var x = 0; var y = 0; foreach (var character in normalizedText) { if (character == '\n') { x = 0; y += font.LineHeight; continue; } var data = font[character]; var kerning = font.GetKerning(previousCharacter, character); DrawSymbol(spriteBatch, font, data, (int)position.X + (x + data.Offset.X + kerning), (int)position.Y + (y + data.Offset.Y), color, outlineColor); x += data.XAdvance + kerning; previousCharacter = character; } }
public Tile(Texture2D texture, Color color, int x, int y, bool isWall) { this.texture = texture; this.color = color; this.isWall = isWall; rect = new Rectangle(x, y, SIZE, SIZE); }
public override void Initialize() { Texture2D texture = GameInstance.Content.Load<Texture2D>("Terrain"); Color[] colorData = new Color[texture.Width * texture.Height]; texture.GetData(colorData); sbyte[,] data = new sbyte[texture.Width, texture.Height]; for (int y = 0; y < texture.Height; y++) { for (int x = 0; x < texture.Width; x++) { //If the color on the coordinate is black, we include it in the terrain. bool inside = colorData[(y * texture.Width) + x] == Color.Black; if (!inside) data[x, y] = 1; else data[x, y] = -1; } } _terrain.ApplyData(data, new Vector2(250, 250)); base.Initialize(); }
public TransitionScreen(ScreenManager sceneManager, Texture2D texture) { SetBasicParams(sceneManager); this.texture = texture; color = Color.White; }
public TextControl(string text, SpriteFont font, Color color, Vector2 position) { this.text = text; this.font = font; this.Position = position; this.Color = color; }
/// <summary> /// A transition between two scenes /// </summary> /// <param name="game">The game</param> public TransitionScreen(ScreenManager sceneManager) { SetBasicParams(sceneManager); texture = CreateBlankTexture(sceneManager); color = Color.Black; }
public StorePurchaseDialog(Scene.ObjectRegistrationHandler registrationHandler, Scene.ObjectUnregistrationHandler unregistrationHandler) : base(registrationHandler, unregistrationHandler) { Height = Purchase_Dialog_Height; TopYWhenActive = Definitions.Back_Buffer_Height - (Purchase_Dialog_Height + Bopscotch.Scenes.NonGame.StoreScene.Dialog_Margin); CarouselCenter = new Vector2(Definitions.Back_Buffer_Center.X, Carousel_Center_Y); CarouselRadii = new Vector2(Carousel_Horizontal_Radius, Carousel_Vertical_Radius); _itemRenderDepths = new Range(Minimum_Item_Render_Depth, Maximum_Item_Render_Depth); _itemScales = new Range(Minimum_Item_Scale, Maximum_Item_Scale); AddIconButton("previous", new Vector2(Definitions.Back_Buffer_Center.X - 450, 175), Button.ButtonIcon.Previous, Color.DodgerBlue); AddIconButton("next", new Vector2(Definitions.Back_Buffer_Center.X + 450, 175), Button.ButtonIcon.Next, Color.DodgerBlue); AddButton("Back", new Vector2(Definitions.Left_Button_Column_X, 400), Button.ButtonIcon.Back, Color.DodgerBlue, 0.7f); AddButton("Buy", new Vector2(Definitions.Right_Button_Column_X, 400), Button.ButtonIcon.Tick, Color.Orange, 0.7f); _nonSpinButtonCaptions.Add("Buy"); ActionButtonPressHandler = HandleActionButtonPress; TopYWhenInactive = Definitions.Back_Buffer_Height; SetupButtonLinkagesAndDefaultValues(); registrationHandler(this); _textTransitionTimer = new Timer(""); GlobalTimerController.GlobalTimer.RegisterUpdateCallback(_textTransitionTimer.Tick); _textTransitionTimer.NextActionDuration = 1; _textTint = Color.White; _font = Game1.Instance.Content.Load<SpriteFont>("Fonts\\arial"); }
public Circle2D(Vector3 position, float innerRadius, float thickness, Color color) { Position = position; InnerRadius = innerRadius; Thickness = thickness; Color = color; }
public FontDescription(string assetName, string text, Color color, Vector2 position) { AssetName = assetName; Text = text; Color = color; Position = position; }
private Texture2D CreateTexture(Shape shape, object[] textureData) { // ignore any texture data. var bounds = shape.Bounds; Color[] colorArr = new Color[bounds.Width * bounds.Height]; int index = 0; for (int x = 0; x < bounds.Width; x++) { for (int y = 0; y < bounds.Height; y++) { index = y * bounds.Width + x; if (shape.Contains(x + bounds.X, y + bounds.Y)) colorArr[index] = Color.White; else colorArr[index] = Color.Transparent; } } Texture2D texture = new Texture2D(_renderer.GraphicsDevice, bounds.Width, bounds.Height); texture.SetData(colorArr); return texture; }
public SpriteToRender(Texture2D setTexture, Rectangle setRect, Rectangle? setSourceRect, Color setColor) { texture = setTexture; rect = setRect; sourceRect = setSourceRect; color = setColor; } // SpriteToRender(setTexture, setRect, setColor)
public int UseVertex(XY position, float z, Microsoft.Xna.Framework.Color color, XY uv) { var v = new VERTEX { Position = new Microsoft.Xna.Framework.Vector3(position.X, position.Y, z), Color = color, TextureCoordinate = uv.ToXna() }; return(_Vertices.Use(v)); }
public override bool PreDraw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, Microsoft.Xna.Framework.Color lightColor) { Texture2D texture = Main.projectileTexture[projectile.type]; Vector2 origin = new Vector2(texture.Width * 0.5f, texture.Height * 0.5f); for (int i = 0; i < 3; ++i) { Vector2 vector2_2 = projectile.oldPos[i]; Microsoft.Xna.Framework.Color color2 = lightColor * projectile.Opacity; color2.R = (byte)(0.5 * (double)color2.R * (double)(10 - i) / 20.0); color2.G = (byte)(0.5 * (double)color2.G * (double)(10 - i) / 20.0); color2.B = (byte)(0.5 * (double)color2.B * (double)(10 - i) / 20.0); color2.A = (byte)(0.5 * (double)color2.A * (double)(10 - i) / 20.0); Main.spriteBatch.Draw(texture, new Vector2(projectile.oldPos[i].X - Main.screenPosition.X + (projectile.width / 2), projectile.oldPos[i].Y - Main.screenPosition.Y + projectile.height / 2), new Rectangle?(), color2, projectile.rotation, origin, projectile.scale, SpriteEffects.None, 0.0f); } ProjectileDrawing.DrawAroundOrigin(projectile.whoAmI, spriteBatch, lightColor); return(false); }
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) { SpriteEffects spriteEffects = SpriteEffects.FlipHorizontally; Microsoft.Xna.Framework.Color color25 = Lighting.GetColor((int)((double)projectile.position.X + (double)projectile.width * 0.5) / 16, (int)(((double)projectile.position.Y + (double)projectile.height * 0.5) / 16.0)); Texture2D texture2D3 = Main.projectileTexture[projectile.type]; int num156 = Main.projectileTexture[projectile.type].Height / Main.projFrames[projectile.type]; int y3 = num156 * projectile.frame; Microsoft.Xna.Framework.Rectangle rectangle = new Microsoft.Xna.Framework.Rectangle(0, y3, texture2D3.Width, num156); Vector2 origin2 = rectangle.Size() / 2f; int arg_5ADA_0 = projectile.type; int arg_5AE7_0 = projectile.type; int arg_5AF4_0 = projectile.type; int num157 = 10; int num158 = 2; int num159 = 1; float value3 = 1f; float num160 = 0f; Main.spriteBatch.Draw(Main.projectileTexture[projectile.type], projectile.position - (7 * projectile.velocity) + projectile.Size / 2f - Main.screenPosition + new Vector2(0f, projectile.gfxOffY), new Microsoft.Xna.Framework.Rectangle?(rectangle), lightColor, projectile.rotation, origin2, projectile.scale, SpriteEffects.None, 0f); Main.spriteBatch.Draw(ModContent.GetTexture("Critters/Glowmask/CapturePod"), projectile.position - (7 * projectile.velocity) + projectile.Size / 2f - Main.screenPosition + new Vector2(0f, projectile.gfxOffY), new Microsoft.Xna.Framework.Rectangle?(rectangle), Color.White, projectile.rotation, origin2, projectile.scale, SpriteEffects.None, 0f); return(false); int num161 = num159; while ((num158 > 0 && num161 < num157) || (num158 < 0 && num161 > num157)) { Microsoft.Xna.Framework.Color color26 = color25; color26 = projectile.GetAlpha(color26); { goto IL_6899; } color26 = Microsoft.Xna.Framework.Color.Lerp(color26, Microsoft.Xna.Framework.Color.Red, 0.5f); IL_6881: num161 += num158; continue; IL_6899: float num164 = (float)(num157 - num161); if (num158 < 0) { num164 = (float)(num159 - num161); } color26 *= num164 / ((float)ProjectileID.Sets.TrailCacheLength[projectile.type] * 1.5f); Vector2 value4 = projectile.oldPos[num161]; float num165 = projectile.rotation; SpriteEffects effects = spriteEffects; if (ProjectileID.Sets.TrailingMode[projectile.type] == 2) { num165 = projectile.oldRot[num161]; effects = ((projectile.oldSpriteDirection[num161] == -1) ? SpriteEffects.FlipHorizontally : SpriteEffects.None); } Main.spriteBatch.Draw(texture2D3, value4 + projectile.Size / 2f - Main.screenPosition + new Vector2(0f, projectile.gfxOffY), new Microsoft.Xna.Framework.Rectangle?(rectangle), color26, num165 + projectile.rotation * num160 * (float)(num161 - 1) * -(float)spriteEffects.HasFlag(SpriteEffects.FlipHorizontally).ToDirectionInt(), origin2, projectile.scale, effects, 0f); goto IL_6881; } Microsoft.Xna.Framework.Color color29 = projectile.GetAlpha(color25); Main.spriteBatch.Draw(texture2D3, projectile.Center - Main.screenPosition + new Vector2(0f, projectile.gfxOffY), new Microsoft.Xna.Framework.Rectangle?(rectangle), color29, projectile.rotation, origin2, projectile.scale, spriteEffects, 0f); return(false); }
public override bool Cache(ResourceManager pack) { if (_cached) { return(true); } _cached = true; if (!Model.Textures.TryGetValue("layer0", out var texture)) { texture = Model.Textures.FirstOrDefault(x => x.Value != null).Value; } if (texture == null) { return(false); } List <VertexPositionColor> vertices = new List <VertexPositionColor>(); if (pack.TryGetBitmap(texture, out var bitmap)) { if (Model.ParentName.Contains("handheld", StringComparison.InvariantCultureIgnoreCase)) { bitmap.Mutate( x => { x.Flip(FlipMode.Horizontal); x.Rotate(RotateMode.Rotate90); }); } try { if (bitmap.TryGetSinglePixelSpan(out var pixels)) { var pixelSize = new Vector3(16f / bitmap.Width, 16f / bitmap.Height, 1f); for (int y = 0; y < bitmap.Height; y++) { for (int x = 0; x < bitmap.Width; x++) { var pixel = pixels[(bitmap.Width * (bitmap.Height - 1 - y)) + (x)]; if (pixel.A == 0) { continue; } Color color = new Color(pixel.R, pixel.G, pixel.B, pixel.A); var origin = new Vector3((x * pixelSize.X), y * pixelSize.Y, 0f); ItemModelCube built = new ItemModelCube(pixelSize, color); vertices.AddRange( Modify( built.Front.Concat(built.Bottom).Concat(built.Back).Concat(built.Top) .Concat(built.Left).Concat(built.Right), origin)); } } this.Size = new Vector3(16f, 16f, 1f); } } finally { bitmap.Dispose(); } } Vertices = vertices.ToArray(); return(true); }
/// <summary> /// Creates a cell with the specified foreground, background, and glyph, with no mirror effect. /// </summary> /// <param name="foreground">Foreground color.</param> /// <param name="background">Background color.</param> /// <param name="glyph">The glyph index.</param> public Cell(Color foreground, Color background, int glyph) : this(foreground, background, glyph, SpriteEffects.None) { }
/// <summary> /// Creates a cell with the specified foreground, specified background, glyph 0, and no mirror effect. /// </summary> /// <param name="foreground">Foreground color.</param> /// <param name="background">Background color.</param> public Cell(Color foreground, Color background) : this(foreground, background, 0, SpriteEffects.None) { }
/// <summary> /// Creates a cell with the specified foreground, black background, glyph 0, and no mirror effect. /// </summary> /// <param name="foreground">Foreground color.</param> public Cell(Color foreground) : this(foreground, Color.Black, 0, SpriteEffects.None) { }
protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } //if(GenNewNoise.Contains(SignalPass.ReInit.None)) //{ // ; //} if (GenNewNoise.Any()) { if (GenNewNoise.Contains(SignalPass.ReInit.All)) { NoiseArray = PerlinGenerator.PerlinGenerator.GenerateNoiseDimensions(height: tracedSize.Height, width: tracedSize.Width, depth: 1, octaves: PerlinVars.PerlinOctaves, persistence: PerlinVars.PerlinPersistence, frequency: PerlinVars.PerlinFrequency, amplitude: PerlinVars.PerlinAmplitude ); } if (GenNewNoise.Contains(SignalPass.ReInit.All) || GenNewNoise.Contains(SignalPass.ReInit.NumGradients)) { NoiseColors = PerlinGenerator.PerlinGenerator.Map3DNoiseArrayToImage(PerlinVars.NumberOfColorGradients, NoiseArray); } BackingNoiseR = PerlinGenerator.PerlinGenerator.Multiply2dArray(NoiseColors.Clone() as int[, ], PerlinVars.RedValueMultiplier); BackingNoiseG = PerlinGenerator.PerlinGenerator.Multiply2dArray(NoiseColors.Clone() as int[, ], PerlinVars.GreenValueMultiplier); BackingNoiseB = PerlinGenerator.PerlinGenerator.Multiply2dArray(NoiseColors.Clone() as int[, ], PerlinVars.BlueValueMultiplier); var height = BackingNoiseR.GetLength(0); var width = BackingNoiseR.GetLength(1); for (int h = 0; h < height; h++) { for (int w = 0; w < width; w++) { Color hexVal; //if (j > lastX - 5 && j < lastX + 5 && i < lastY + 5 && i > lastY - 5) //{ // hexVal = Color.Red; // lastX = currentX; // lastY = currentY; //} //else hexVal = new Color(BackingNoiseR[h, w], BackingNoiseG[h, w], BackingNoiseB[h, w]); pixels[h * width + w] = hexVal; ; } } #region 1dlines //fetch once var pH = PerlinVars.HorizontalLines; var pV = PerlinVars.VerticalLines; //give this a discrete signal as well if (pH || pV) { //fetch once var hort = PerlinVars.HorizontalLinesPer; var vert = PerlinVars.VerticalLinesPer; var wiggleMultiplier = 10f; for (int h = 0; h < height; h++) //variabalize 100 { for (int w = 0; w < width; w++) //^inverse for other directional line^ { //depth can always be 0 for a 1d line //this is between 0 and 1 right now right double noiseVal = NoiseArray[h, w, 0] - 1 * -1; //this one d thing is realy easy to reason about... if (h % hort == 0 && pH) { pixels[ (int) Math.Min(Math.Max((h * width + w) + ((int)(noiseVal * wiggleMultiplier) * width), 0), height * width - 1) ] = Color.Black; } if (w % vert == 0 && pV) { //this needs to be thought out pixels[ (int) Math.Min(Math.Max((h * width + w) + (int)(noiseVal * wiggleMultiplier), 0), height * width - 1) ] = Color.Black; } } ; } } #endregion canvas.SetData <Color>(pixels, 0, tracedSize.Width * tracedSize.Height); Stream stream = File.Create(Path.Combine(Environment.CurrentDirectory, "ActualCanvas.png")); canvas.SaveAsPng(stream, canvas.Width, canvas.Height); stream.Dispose(); GenNewNoise.Clear(); } // TODO: Add your update logic here base.Update(gameTime); }
private static void LoadObjectDbXml(string file) { var xmlSettings = XElement.Load(file); // Load Colors foreach (var xElement in xmlSettings.Elements("GlobalColors").Elements("GlobalColor")) { string name = (string)xElement.Attribute("Name"); XNA.Color color = XnaColorFromString((string)xElement.Attribute("Color")); GlobalColors.Add(name, color); } foreach (var xElement in xmlSettings.Elements("Tiles").Elements("Tile")) { var curTile = new TileProperty(); // Read XML attributes curTile.Color = ColorFromString((string)xElement.Attribute("Color")); curTile.Name = (string)xElement.Attribute("Name"); curTile.Id = (int?)xElement.Attribute("Id") ?? 0; curTile.IsFramed = (bool?)xElement.Attribute("Framed") ?? false; curTile.IsSolid = (bool?)xElement.Attribute("Solid") ?? false; curTile.IsSolidTop = (bool?)xElement.Attribute("SolidTop") ?? false; curTile.IsLight = (bool?)xElement.Attribute("Light") ?? false; curTile.FrameSize = StringToVector2Short((string)xElement.Attribute("Size"), 1, 1); curTile.Placement = InLineEnumTryParse <FramePlacement>((string)xElement.Attribute("Placement")); curTile.TextureGrid = StringToVector2Short((string)xElement.Attribute("TextureGrid"), 16, 16); foreach (var elementFrame in xElement.Elements("Frames").Elements("Frame")) { var curFrame = new FrameProperty(); // Read XML attributes curFrame.Name = (string)elementFrame.Attribute("Name"); curFrame.Variety = (string)elementFrame.Attribute("Variety"); curFrame.UV = StringToVector2Short((string)elementFrame.Attribute("UV"), 0, 0); curFrame.Anchor = InLineEnumTryParse <FrameAnchor>((string)elementFrame.Attribute("Anchor")); // Assign a default name if none existed if (string.IsNullOrWhiteSpace(curFrame.Name)) { curFrame.Name = curTile.Name; } curTile.Frames.Add(curFrame); Sprites.Add(new Sprite { Anchor = curFrame.Anchor, IsPreviewTexture = false, Name = curFrame.Name + ", " + curFrame.Variety, Origin = curFrame.UV, Size = curTile.FrameSize, Tile = (byte)curTile.Id, TileName = curTile.Name }); if (curTile.FrameSize.X == 0 && curTile.FrameSize.Y == 0) { int z = 0; } } if (curTile.Frames.Count == 0 && curTile.IsFramed) { var curFrame = new FrameProperty(); // Read XML attributes curFrame.Name = curTile.Name; curFrame.Variety = string.Empty; curFrame.UV = new Vector2Short(0, 0); //curFrame.Anchor = InLineEnumTryParse<FrameAnchor>((string)xElement.Attribute("Anchor")); // Assign a default name if none existed if (string.IsNullOrWhiteSpace(curFrame.Name)) { curFrame.Name = curTile.Name; } curTile.Frames.Add(curFrame); Sprites.Add(new Sprite { Anchor = curFrame.Anchor, IsPreviewTexture = false, Name = curFrame.Name + ", " + curFrame.Variety, Origin = curFrame.UV, Size = curTile.FrameSize, Tile = (byte)curTile.Id, TileName = curTile.Name }); } TileProperties.Add(curTile); if (!curTile.IsFramed) { TileBricks.Add(curTile); } } for (int i = TileProperties.Count; i < 255; i++) { TileProperties.Add(new TileProperty(i, "UNKNOWN", Color.FromArgb(255, 255, 0, 255), true)); } foreach (var xElement in xmlSettings.Elements("Walls").Elements("Wall")) { var curWall = new WallProperty(); curWall.Color = ColorFromString((string)xElement.Attribute("Color")); curWall.Name = (string)xElement.Attribute("Name"); curWall.Id = (int?)xElement.Attribute("Id") ?? -1; curWall.IsHouse = (bool?)xElement.Attribute("IsHouse") ?? false; WallProperties.Add(curWall); } foreach (var xElement in xmlSettings.Elements("Items").Elements("Item")) { var curItem = new ItemProperty(); curItem.Id = (int?)xElement.Attribute("Id") ?? -1; curItem.Name = (string)xElement.Attribute("Name"); ItemProperties.Add(curItem); } foreach (var xElement in xmlSettings.Elements("Npcs").Elements("Npc")) { int id = (int?)xElement.Attribute("Id") ?? -1; string name = (string)xElement.Attribute("Name"); NpcIds.Add(name, id); } foreach (var xElement in xmlSettings.Elements("ItemPrefix").Elements("Prefix")) { int id = (int?)xElement.Attribute("Id") ?? -1; string name = (string)xElement.Attribute("Name"); ItemPrefix.Add((byte)id, name); } foreach (var xElement in xmlSettings.Elements("ShortCutKeys").Elements("Shortcut")) { var key = InLineEnumTryParse <Key>((string)xElement.Attribute("Key")); var tool = (string)xElement.Attribute("Tool"); ShortcutKeys.Add(key, tool); } }
private void LoadThreaded() { // Ensure we're using the invariant culture. Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; LoadStatus = LoadingStatus.Loading; SetLoadingMessage("Initializing ..."); while (GraphicsDevice == null) { Thread.Sleep(100); } Thread.Sleep(1000); #if CREATE_CRASH_LOGS try #endif #if !DEBUG try { #endif bool fileExists = !string.IsNullOrEmpty(ExistingFile); SetLoadingMessage("Creating Sky..."); Sky = new SkyRenderer( TextureManager.GetTexture(ContentPaths.Sky.moon), TextureManager.GetTexture(ContentPaths.Sky.sun), Content.Load <TextureCube>(ContentPaths.Sky.day_sky), Content.Load <TextureCube>(ContentPaths.Sky.night_sky), TextureManager.GetTexture(ContentPaths.Gradients.skygradient), Content.Load <Model>(ContentPaths.Models.sphereLowPoly), Content.Load <Effect>(ContentPaths.Shaders.SkySphere), Content.Load <Effect>(ContentPaths.Shaders.Background)); #region Reading game file if (fileExists) { SetLoadingMessage("Loading " + ExistingFile); gameFile = SaveGame.CreateFromDirectory(ExistingFile); if (gameFile == null) { throw new InvalidOperationException("Game File does not exist."); } // Todo: REMOVE THIS WHEN THE NEW SAVE SYSTEM IS COMPLETE. if (gameFile.Metadata.Version != Program.Version && !Program.CompatibleVersions.Contains(gameFile.Metadata.Version)) { throw new InvalidOperationException(String.Format("Game file is from version {0}. Compatible versions are {1}.", gameFile.Metadata.Version, TextGenerator.GetListString(Program.CompatibleVersions))); } Sky.TimeOfDay = gameFile.Metadata.TimeOfDay; Time = gameFile.Metadata.Time; WorldOrigin = gameFile.Metadata.WorldOrigin; WorldScale = gameFile.Metadata.WorldScale; WorldSize = gameFile.Metadata.NumChunks; GameID = gameFile.Metadata.GameID; if (gameFile.Metadata.OverworldFile != null && gameFile.Metadata.OverworldFile != "flat") { SetLoadingMessage("Loading world " + gameFile.Metadata.OverworldFile); Overworld.Name = gameFile.Metadata.OverworldFile; DirectoryInfo worldDirectory = Directory.CreateDirectory(DwarfGame.GetWorldDirectory() + ProgramData.DirChar + Overworld.Name); var overWorldFile = new NewOverworldFile(worldDirectory.FullName); Overworld.Map = overWorldFile.Data.Data; Overworld.Name = overWorldFile.Data.Name; } else { SetLoadingMessage("Generating flat world.."); Overworld.CreateUniformLand(GraphicsDevice); } } #endregion #region Initialize static data { Vector3 origin = new Vector3(WorldOrigin.X, 0, WorldOrigin.Y); Vector3 extents = new Vector3(1500, 1500, 1500); CollisionManager = new CollisionManager(new BoundingBox(origin - extents, origin + extents)); CraftLibrary = new CraftLibrary(); new PrimitiveLibrary(GraphicsDevice, Content); NewInstanceManager = new NewInstanceManager(GraphicsDevice, new BoundingBox(origin - extents, origin + extents), Content); Color[] white = new Color[1]; white[0] = Color.White; pixel = new Texture2D(GraphicsDevice, 1, 1); pixel.SetData(white); Tilesheet = TextureManager.GetTexture(ContentPaths.Terrain.terrain_tiles); AspectRatio = GraphicsDevice.Viewport.AspectRatio; DefaultShader = new Shader(Content.Load <Effect>(ContentPaths.Shaders.TexturedShaders), true); DefaultShader.ScreenWidth = GraphicsDevice.Viewport.Width; DefaultShader.ScreenHeight = GraphicsDevice.Viewport.Height; VoxelLibrary.InitializeDefaultLibrary(GraphicsDevice, Tilesheet); GrassLibrary.InitializeDefaultLibrary(); DecalLibrary.InitializeDefaultLibrary(); bloom = new BloomComponent(Game) { Settings = BloomSettings.PresetSettings[5] }; bloom.Initialize(); fxaa = new FXAA(); fxaa.Initialize(); SoundManager.Content = Content; if (PlanService != null) { PlanService.Restart(); } JobLibrary.Initialize(); MonsterSpawner = new MonsterSpawner(this); EntityFactory.Initialize(this); } #endregion SetLoadingMessage("Creating Planner ..."); PlanService = new PlanService(); SetLoadingMessage("Creating Shadows..."); Shadows = new ShadowRenderer(GraphicsDevice, 1024, 1024); SetLoadingMessage("Creating Liquids ..."); #region liquids WaterRenderer = new WaterRenderer(GraphicsDevice); LiquidAsset waterAsset = new LiquidAsset { Type = LiquidType.Water, Opactiy = 0.8f, Reflection = 1.0f, WaveHeight = 0.1f, WaveLength = 0.05f, WindForce = 0.001f, BumpTexture = TextureManager.GetTexture(ContentPaths.Terrain.water_normal), BaseTexture = TextureManager.GetTexture(ContentPaths.Terrain.cartoon_water), MinOpacity = 0.4f, RippleColor = new Vector4(0.6f, 0.6f, 0.6f, 0.0f), FlatColor = new Vector4(0.3f, 0.3f, 0.9f, 1.0f) }; WaterRenderer.AddLiquidAsset(waterAsset); LiquidAsset lavaAsset = new LiquidAsset { Type = LiquidType.Lava, Opactiy = 0.95f, Reflection = 0.0f, WaveHeight = 0.1f, WaveLength = 0.05f, WindForce = 0.001f, MinOpacity = 0.8f, BumpTexture = TextureManager.GetTexture(ContentPaths.Terrain.water_normal), BaseTexture = TextureManager.GetTexture(ContentPaths.Terrain.lava), RippleColor = new Vector4(0.5f, 0.4f, 0.04f, 0.0f), FlatColor = new Vector4(0.9f, 0.7f, 0.2f, 1.0f) }; WaterRenderer.AddLiquidAsset(lavaAsset); #endregion SetLoadingMessage("Generating Initial Terrain Chunks ..."); if (!fileExists) { GameID = MathFunctions.Random.Next(0, 1024); } ChunkGenerator = new ChunkGenerator(VoxelLibrary, Seed, 0.02f, this.WorldScale) { SeaLevel = SeaLevel }; #region Load Components if (fileExists) { ChunkManager = new ChunkManager(Content, this, Camera, GraphicsDevice, ChunkGenerator, WorldSize.X, WorldSize.Y, WorldSize.Z); ChunkRenderer = new ChunkRenderer(this, Camera, GraphicsDevice, ChunkManager.ChunkData); SetLoadingMessage("Loading Terrain..."); gameFile.ReadChunks(ExistingFile); ChunkManager.ChunkData.LoadFromFile(gameFile, SetLoadingMessage); ChunkManager.ChunkData.SetMaxViewingLevel(gameFile.Metadata.Slice > 0 ? gameFile.Metadata.Slice : ChunkManager.ChunkData.MaxViewingLevel, ChunkManager.SliceMode.Y); SetLoadingMessage("Loading Entities..."); gameFile.LoadPlayData(ExistingFile, this); Camera = gameFile.PlayData.Camera; ChunkManager.camera = Camera; ChunkRenderer.camera = Camera; DesignationDrawer = gameFile.PlayData.Designations; Vector3 origin = new Vector3(WorldOrigin.X, 0, WorldOrigin.Y); Vector3 extents = new Vector3(1500, 1500, 1500); CollisionManager = new CollisionManager(new BoundingBox(origin - extents, origin + extents)); if (gameFile.PlayData.Resources != null) { foreach (var resource in gameFile.PlayData.Resources) { if (!ResourceLibrary.Resources.ContainsKey(resource.Key)) { ResourceLibrary.Add(resource.Value); } } } ComponentManager = new ComponentManager(gameFile.PlayData.Components, this); foreach (var component in gameFile.PlayData.Components.SaveableComponents) { if (!ComponentManager.HasComponent(component.GlobalID) && ComponentManager.HasComponent(component.Parent.GlobalID)) { // Logically impossible. throw new InvalidOperationException("Component exists in save data but not in manager."); } } Factions = gameFile.PlayData.Factions; ComponentManager.World = this; Sky.TimeOfDay = gameFile.Metadata.TimeOfDay; Time = gameFile.Metadata.Time; WorldOrigin = gameFile.Metadata.WorldOrigin; WorldScale = gameFile.Metadata.WorldScale; // Restore native factions from deserialized data. Natives = new List <Faction>(); foreach (Faction faction in Factions.Factions.Values) { if (faction.Race.IsNative && faction.Race.IsIntelligent && !faction.IsRaceFaction) { Natives.Add(faction); } } Diplomacy = gameFile.PlayData.Diplomacy; GoalManager = new Goals.GoalManager(); GoalManager.Initialize(gameFile.PlayData.Goals); TutorialManager = new Tutorial.TutorialManager(Program.CreatePath("Content", "tutorial.txt")); TutorialManager.SetFromSaveData(gameFile.PlayData.TutorialSaveData); } else { Time = new WorldTime(); // WorldOrigin is in "map" units. Convert to voxels var globalOffset = new Vector3(WorldOrigin.X, 0, WorldOrigin.Y) * WorldScale; Camera = new OrbitCamera(this, new Vector3(VoxelConstants.ChunkSizeX, VoxelConstants.ChunkSizeY - 1.0f, VoxelConstants.ChunkSizeZ) + new Vector3(WorldOrigin.X, 0, WorldOrigin.Y) * WorldScale, new Vector3(VoxelConstants.ChunkSizeY, VoxelConstants.ChunkSizeY - 1.0f, VoxelConstants.ChunkSizeZ) + new Vector3(WorldOrigin.X, 0, WorldOrigin.Y) * WorldScale + Vector3.Up * 10.0f + Vector3.Backward * 10, MathHelper.PiOver4, AspectRatio, 0.1f, GameSettings.Default.VertexCullDistance); ChunkManager = new ChunkManager(Content, this, Camera, GraphicsDevice, ChunkGenerator, WorldSize.X, WorldSize.Y, WorldSize.Z); ChunkRenderer = new ChunkRenderer(this, Camera, GraphicsDevice, ChunkManager.ChunkData); var chunkOffset = GlobalVoxelCoordinate.FromVector3(globalOffset).GetGlobalChunkCoordinate(); //var chunkOffset = ChunkManager.ChunkData.RoundToChunkCoords(globalOffset); //globalOffset.X = chunkOffset.X * VoxelConstants.ChunkSizeX; //globalOffset.Y = chunkOffset.Y * VoxelConstants.ChunkSizeY; //globalOffset.Z = chunkOffset.Z * VoxelConstants.ChunkSizeZ; WorldOrigin = new Vector2(globalOffset.X, globalOffset.Z); Camera.Position = new Vector3(0, 10, 0) + globalOffset; Camera.Target = new Vector3(0, 10, 1) + globalOffset; // If there's no file, we have to initialize the first chunk coordinate if (gameFile == null) // Todo: Always true? { ChunkManager.GenerateInitialChunks( GlobalVoxelCoordinate.FromVector3(globalOffset).GetGlobalChunkCoordinate(), SetLoadingMessage); } ComponentManager = new ComponentManager(this); ComponentManager.SetRootComponent(new Body(ComponentManager, "root", Matrix.Identity, Vector3.Zero, Vector3.Zero, false)); if (Natives == null) // Todo: Always true?? { FactionLibrary library = new FactionLibrary(); library.Initialize(this, CompanyMakerState.CompanyInformation); Natives = new List <Faction>(); for (int i = 0; i < 10; i++) { Natives.Add(library.GenerateFaction(this, i, 10)); } } #region Prepare Factions foreach (Faction faction in Natives) { faction.World = this; if (faction.RoomBuilder == null) { faction.RoomBuilder = new RoomBuilder(faction, this); } if (faction.CraftBuilder == null) { faction.CraftBuilder = new CraftBuilder(faction, this); } } Factions = new FactionLibrary(); if (Natives != null && Natives.Count > 0) { Factions.AddFactions(this, Natives); } Factions.Initialize(this, CompanyMakerState.CompanyInformation); Point playerOrigin = new Point((int)(WorldOrigin.X), (int)(WorldOrigin.Y)); Factions.Factions["Player"].Center = playerOrigin; Factions.Factions["The Motherland"].Center = new Point(playerOrigin.X + 50, playerOrigin.Y + 50); #endregion Diplomacy = new Diplomacy(this); Diplomacy.Initialize(Time.CurrentDate); // Initialize goal manager here. GoalManager = new Goals.GoalManager(); GoalManager.Initialize(new List <Goals.Goal>()); TutorialManager = new Tutorial.TutorialManager(Program.CreatePath("Content", "tutorial.txt")); TutorialManager.TutorialEnabled = !GameSettings.Default.TutorialDisabledGlobally; Tutorial("new game start"); } Camera.World = this; //Drawer3D.Camera = Camera; #endregion ChunkManager.camera = Camera; SetLoadingMessage("Creating Particles ..."); ParticleManager = new ParticleManager(GraphicsDevice, ComponentManager); SetLoadingMessage("Creating GameMaster ..."); Master = new GameMaster(Factions.Factions["Player"], Game, ComponentManager, ChunkManager, Camera, GraphicsDevice); if (gameFile != null) { if (gameFile.PlayData.Spells != null) { Master.Spells = gameFile.PlayData.Spells; } if (gameFile.PlayData.Tasks != null) { Master.TaskManager = gameFile.PlayData.Tasks; } } if (Master.Faction.Economy.Company.Information == null) { Master.Faction.Economy.Company.Information = new CompanyInformation(); } CreateInitialEmbarkment(); foreach (var chunk in ChunkManager.ChunkData.ChunkMap) { chunk.CalculateInitialSunlight(); } VoxelHelpers.InitialReveal(ChunkManager.ChunkData, new VoxelHandle( ChunkManager.ChunkData.GetChunkEnumerator().FirstOrDefault(), new LocalVoxelCoordinate(0, VoxelConstants.ChunkSizeY - 1, 0))); foreach (var chunk in ChunkManager.ChunkData.ChunkMap) { ChunkManager.InvalidateChunk(chunk); } ChunkManager.StartThreads(); SetLoadingMessage("Presimulating ..."); ShowingWorld = false; OnLoadedEvent(); Thread.Sleep(1000); ShowingWorld = true; SetLoadingMessage("Complete."); // GameFile is no longer needed. gameFile = null; LoadStatus = LoadingStatus.Success; #if !DEBUG } catch (Exception exception) { Game.CaptureException(exception); LoadingException = exception; LoadStatus = LoadingStatus.Failure; } #endif }
public static void DrawIndicator(Animation image, Vector3 position, float time, float scale, Vector2 offset, Color tint, bool flip) { lock (IndicatorLock) { Indicators.Add(new AnimatedIndicator { CurrentTime = new Timer(time, true), Image = null, Animation = image, Position = position, MaxScale = scale, Offset = offset, Tint = tint, Grow = false, Flip = flip }); } }
public static void DrawIndicator(string indicator, Vector3 position, float time, Color color) { lock (IndicatorLock) { Indicators.Add(new TextIndicator(DefaultFont) { Text = indicator, Tint = color, CurrentTime = new Timer(time, true, Timer.TimerMode.Real), Image = null, Position = position, Grow = false, }); } }
public static void DrawIndicator(StandardIndicators indicator, Vector3 position, float time, float scale, Vector2 offset, Color tint) { DrawIndicator(StandardFrames[indicator], position, time, scale, offset, tint); }
public static void DrawIndicator(NamedImageFrame image, Vector3 position, float time, float scale, Vector2 offset, Color tint) { lock (IndicatorLock) { Indicators.Add(new Indicator { CurrentTime = new Timer(time, true), Image = image, Position = position, MaxScale = scale, Offset = offset, Tint = tint }); } }
public void DrawCenteredString(SpriteBatch currentSpriteBatch, string text, Vector2 position, Microsoft.Xna.Framework.Color color, Vector2 offset) { var measures = text.Split('\n').Select(MeasureString).ToArray(); var totalMeasure = MeasureString(text); var fontDict = FontDict; var positionX = 0; var currentMeasure = 0; position.Y -= (float)totalMeasure.Y / 2; var measure = measures[currentMeasure]; positionX = (int)-measure.X / 2; foreach (var @char in text) { if (@char == '\n') { currentMeasure++; measure = measures[currentMeasure]; position.Y += (float)measure.Y; positionX = (int)-measure.X / 2; continue; } var rectangle = fontDict[@char]; currentSpriteBatch.Draw(Font, new Vector2(position.X + positionX, (float)(position.Y)), rectangle, color); positionX += rectangle.Width + kerning; } }
public override void Update(DwarfTime time) { Position += Speed * Vector3.Up * (float)time.ElapsedGameTime.TotalSeconds; Tint = new Color(Tint.R, Tint.G, Tint.B, (byte)(255 * (1.0f - CurrentTime.CurrentTimeSeconds / CurrentTime.TargetTimeSeconds))); CurrentTime.Update(time); }
public override void PostDraw(SpriteBatch spriteBatch, Color drawColor) { SpriteEffects spriteEffects = SpriteEffects.None; float addY = 0.0f; float addHeight = -4f; float addWidth = 0f; Vector2 vector2_3 = new Vector2((float)(Main.projectileTexture[projectile.type].Width / 2), (float)(Main.projectileTexture[projectile.type].Height / 1 / 2)); Texture2D texture2D = ModContent.GetTexture("SpiritMod/Textures/Circle_Outline"); if (projectile.velocity.X == 0) { addHeight = -8f; addWidth = -6f; texture2D = ModContent.GetTexture("SpiritMod/Textures/Circle_Outline"); } Vector2 origin = new Vector2((float)(texture2D.Width / 2), (float)(texture2D.Height / 8 + 14)); int num1 = (int)projectile.ai[1] / 2; float num2 = -1.570796f * (float)projectile.rotation; float amount = projectile.ai[1] / 45f; if ((double)amount > 1.0) { amount = 1f; } int num3 = num1 % 4; for (int index = 10; index >= 0; --index) { Vector2 oldPo = projectile.oldPos[index]; Microsoft.Xna.Framework.Color color2 = Microsoft.Xna.Framework.Color.Lerp(new Color(b, r, g), new Color(r, g, b), amount); color2 = Microsoft.Xna.Framework.Color.Lerp(color2, new Color(g, b, r), (float)index / 12f); color2.A = (byte)(64.0 * (double)amount); color2.R = (byte)((int)color2.R * (10 - index) / 20); color2.G = (byte)((int)color2.G * (10 - index) / 20); color2.B = (byte)((int)color2.B * (10 - index) / 20); color2.A = (byte)((int)color2.A * (10 - index) / 20); color2 *= amount; int frameY = (num3 - index) % 4; if (frameY < 0) { frameY += 4; } Microsoft.Xna.Framework.Rectangle rectangle = texture2D.Frame(1, 4, 0, frameY); Main.spriteBatch.Draw(texture2D, new Vector2((float)((double)projectile.oldPos[index].X - (double)Main.screenPosition.X + (double)(projectile.width / 2) - (double)Main.projectileTexture[projectile.type].Width * (double)projectile.scale / 2.0 + (double)vector2_3.X * (double)projectile.scale) + addWidth, (float)((double)projectile.oldPos[index].Y - (double)Main.screenPosition.Y + (double)projectile.height - (double)Main.projectileTexture[projectile.type].Height * (double)projectile.scale / (double)1 + 4.0 + (double)vector2_3.Y * (double)projectile.scale) + addHeight), new Microsoft.Xna.Framework.Rectangle?(rectangle), color2, num2, origin, MathHelper.Lerp(0.05f, 1.4f, (float)((10.0 - (double)index) / -20.0)), spriteEffects, 0.0f); } for (int index = 10; index >= 0; --index) { Vector2 oldPo = projectile.oldPos[index]; Microsoft.Xna.Framework.Color color2 = Microsoft.Xna.Framework.Color.Lerp(new Color(r, g, b), new Color(b, r, g), amount); color2 = Microsoft.Xna.Framework.Color.Lerp(color2, new Color(b, g, r), (float)index / 12f); color2.A = (byte)(64.0 * (double)amount); color2.R = (byte)((int)color2.R * (10 - index) / 20); color2.G = (byte)((int)color2.G * (10 - index) / 20); color2.B = (byte)((int)color2.B * (10 - index) / 20); color2.A = (byte)((int)color2.A * (10 - index) / 20); color2 *= amount; int frameY = (num3 - index) % 4; if (frameY < 0) { frameY += 4; } Microsoft.Xna.Framework.Rectangle rectangle = texture2D.Frame(1, 4, 0, frameY); Main.spriteBatch.Draw(texture2D, new Vector2((float)((double)projectile.oldPos[index].X - (double)Main.screenPosition.X + (double)(projectile.width / 2) - (double)Main.projectileTexture[projectile.type].Width * (double)projectile.scale / 2.0 + (double)vector2_3.X * (double)projectile.scale) + addWidth, (float)((double)projectile.oldPos[index].Y - (double)Main.screenPosition.Y + (double)projectile.height - (double)Main.projectileTexture[projectile.type].Height * (double)projectile.scale / (double)1 + 4.0 + (double)vector2_3.Y * (double)projectile.scale) + addHeight), new Microsoft.Xna.Framework.Rectangle?(rectangle), color2, num2, origin, MathHelper.Lerp(0.05f, 1.2f, (float)((10.0 - (double)index) / 30.0)), spriteEffects, 0.0f); } }
public void DrawString(SpriteBatch currentSpriteBatch, string text, Vector2 position, Microsoft.Xna.Framework.Color color, Vector2 offset) { var fontDict = FontDict; var tallestFontThisLine = 0; foreach (var @char in text) { if (@char == '\n') { position.X = 0; position.Y += tallestFontThisLine + kerning; tallestFontThisLine = 0; continue; } tallestFontThisLine = tallestFontThisLine > fontDict[@char].Height ? tallestFontThisLine : fontDict[@char].Height; var rectangle = fontDict[@char]; currentSpriteBatch.Draw(Font, position, rectangle, color); position.X += rectangle.Width + kerning; } }
/// <summary> /// Convert Color value of XNA Framework to ccColor3B type /// </summary> public ccColor3B(Microsoft.Xna.Framework.Color color) { r = color.R; g = color.G; // was color.B b = color.B; }
public static void DrawString(int index, Vector2 to = default(Vector2)) { Projectile projectile = Main.projectile[index]; Vector2 mountedCenter = Main.player[projectile.owner].MountedCenter; Vector2 vector = mountedCenter; vector.Y += Main.player[projectile.owner].gfxOffY; if (to != default(Vector2)) { vector = to; } float num3 = projectile.Center.X - vector.X; float num4 = projectile.Center.Y - vector.Y; Math.Sqrt((double)(num3 * num3 + num4 * num4)); float rotation = (float)Math.Atan2((double)num4, (double)num3) - 1.57f; if (!projectile.counterweight) { int num5 = -1; if (projectile.position.X + (float)(projectile.width / 2) < Main.player[projectile.owner].position.X + (float)(Main.player[projectile.owner].width / 2)) { num5 = 1; } num5 *= -1; Main.player[projectile.owner].itemRotation = (float)Math.Atan2((double)(num4 * (float)num5), (double)(num3 * (float)num5)); } bool flag = true; if (num3 == 0f && num4 == 0f) { flag = false; } else { float num6 = (float)Math.Sqrt((double)(num3 * num3 + num4 * num4)); num6 = 12f / num6; num3 *= num6; num4 *= num6; vector.X -= num3 * 0.1f; vector.Y -= num4 * 0.1f; num3 = projectile.position.X + (float)projectile.width * 0.5f - vector.X; num4 = projectile.position.Y + (float)projectile.height * 0.5f - vector.Y; } while (flag) { float num7 = 12f; float num8 = (float)Math.Sqrt((double)(num3 * num3 + num4 * num4)); float num9 = num8; if (float.IsNaN(num8) || float.IsNaN(num9)) { flag = false; } else { if (num8 < 20f) { num7 = num8 - 8f; flag = false; } num8 = 12f / num8; num3 *= num8; num4 *= num8; vector.X += num3; vector.Y += num4; num3 = projectile.position.X + (float)projectile.width * 0.5f - vector.X; num4 = projectile.position.Y + (float)projectile.height * 0.1f - vector.Y; if (num9 > 12f) { float num10 = 0.3f; float num11 = Math.Abs(projectile.velocity.X) + Math.Abs(projectile.velocity.Y); if (num11 > 16f) { num11 = 16f; } num11 = 1f - num11 / 16f; num10 *= num11; num11 = num9 / 80f; if (num11 > 1f) { num11 = 1f; } num10 *= num11; if (num10 < 0f) { num10 = 0f; } num10 *= num11; num10 *= 0.5f; if (num4 > 0f) { num4 *= 1f + num10; num3 *= 1f - num10; } else { num11 = Math.Abs(projectile.velocity.X) / 3f; if (num11 > 1f) { num11 = 1f; } num11 -= 0.5f; num10 *= num11; if (num10 > 0f) { num10 *= 2f; } num4 *= 1f + num10; num3 *= 1f - num10; } } rotation = (float)Math.Atan2((double)num4, (double)num3) - 1.57f; int stringColor = Main.player[projectile.owner].stringColor; Microsoft.Xna.Framework.Color color = WorldGen.paintColor(stringColor); if (color.R < 75) { color.R = 75; } if (color.G < 75) { color.G = 75; } if (color.B < 75) { color.B = 75; } if (stringColor == 13) { color = new Microsoft.Xna.Framework.Color(20, 20, 20); } else if (stringColor == 14 || stringColor == 0) { color = new Microsoft.Xna.Framework.Color(200, 200, 200); } else if (stringColor == 28) { color = new Microsoft.Xna.Framework.Color(163, 116, 91); } else if (stringColor == 27) { color = new Microsoft.Xna.Framework.Color(Main.DiscoR, Main.DiscoG, Main.DiscoB); } color.A = (byte)((float)color.A * 0.4f); float num12 = 0.5f; color = Lighting.GetColor((int)vector.X / 16, (int)(vector.Y / 16f), color); color = new Microsoft.Xna.Framework.Color((int)((byte)((float)color.R * num12)), (int)((byte)((float)color.G * num12)), (int)((byte)((float)color.B * num12)), (int)((byte)((float)color.A * num12))); Main.spriteBatch.Draw(Main.fishingLineTexture, new Vector2(vector.X - Main.screenPosition.X + (float)Main.fishingLineTexture.Width * 0.5f, vector.Y - Main.screenPosition.Y + (float)Main.fishingLineTexture.Height * 0.5f) - new Vector2(6f, 0f), new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(0, 0, Main.fishingLineTexture.Width, (int)num7)), color, rotation, new Vector2((float)Main.fishingLineTexture.Width * 0.5f, 0f), 1f, SpriteEffects.None, 0f); } } }
public void DrawManaBar(float X, float Y, int Mana, int MaxMana, float alpha, float scale = 1f) { if (Mana <= 0) { return; } float num = (float)Mana / (float)MaxMana; if (num > 1f) { num = 1f; } int num2 = (int)(36f * num); float num3 = X - 18f * scale; float num4 = Y; if (Main.player[Main.myPlayer].gravDir == -1f) { num4 -= Main.screenPosition.Y; num4 = Main.screenPosition.Y + (float)Main.screenHeight - num4; } float num5 = 0f; float num6 = 255f; num -= 0.1f; float num7; float num8; num8 = 255f; num7 = 255f * (1f - num); float darkr = 255f - 0.8f * (255f * (1 - num)); float darkb = 255f - 0.8f * (255f * (1 - num)); num7 = System.Math.Min(num7, darkr); num8 = System.Math.Min(num8, darkb); /* * if ((double)num > 0.5) * { * num8 = 255f; * num7 = 255f * (1f - num) * 2f; * } * else * { * num7 = 255f - 0.5f*(255f* (1-num)); * num8 = 255f - 0.5f * (255f * (1 - num)); * }*/ float num9 = 0.95f; num8 = num8 * alpha * num9; num7 = num7 * alpha * num9; num6 = num6 * alpha * num9; if (num8 < 0f) { num8 = 0f; } if (num8 > 255f) { num8 = 255f; } if (num7 < 0f) { num7 = 0f; } if (num7 > 255f) { num7 = 255f; } if (num6 < 0f) { num6 = 0f; } if (num6 > 255f) { num6 = 255f; } Microsoft.Xna.Framework.Color color = new Microsoft.Xna.Framework.Color((int)((byte)num7), (int)((byte)num5), (int)((byte)num8), (int)((byte)num6)); if (num2 < 3) { num2 = 3; } if (num2 < 34) { if (num2 < 36) { Main.spriteBatch.Draw(Main.hbTexture2, new Vector2(num3 - Main.screenPosition.X + (float)num2 * scale, num4 - Main.screenPosition.Y), new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(2, 0, 2, Main.hbTexture2.Height)), color, 0f, new Vector2(0f, 0f), scale, SpriteEffects.None, 0f); } if (num2 < 34) { Main.spriteBatch.Draw(Main.hbTexture2, new Vector2(num3 - Main.screenPosition.X + (float)(num2 + 2) * scale, num4 - Main.screenPosition.Y), new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(num2 + 2, 0, 36 - num2 - 2, Main.hbTexture2.Height)), color, 0f, new Vector2(0f, 0f), scale, SpriteEffects.None, 0f); } if (num2 > 2) { Main.spriteBatch.Draw(Main.hbTexture1, new Vector2(num3 - Main.screenPosition.X, num4 - Main.screenPosition.Y), new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(0, 0, num2 - 2, Main.hbTexture1.Height)), color, 0f, new Vector2(0f, 0f), scale, SpriteEffects.None, 0f); } Main.spriteBatch.Draw(Main.hbTexture1, new Vector2(num3 - Main.screenPosition.X + (float)(num2 - 2) * scale, num4 - Main.screenPosition.Y), new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(32, 0, 2, Main.hbTexture1.Height)), color, 0f, new Vector2(0f, 0f), scale, SpriteEffects.None, 0f); return; } if (num2 < 36) { Main.spriteBatch.Draw(Main.hbTexture2, new Vector2(num3 - Main.screenPosition.X + (float)num2 * scale, num4 - Main.screenPosition.Y), new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(num2, 0, 36 - num2, Main.hbTexture2.Height)), color, 0f, new Vector2(0f, 0f), scale, SpriteEffects.None, 0f); } Main.spriteBatch.Draw(Main.hbTexture1, new Vector2(num3 - Main.screenPosition.X, num4 - Main.screenPosition.Y), new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(0, 0, num2, Main.hbTexture1.Height)), color, 0f, new Vector2(0f, 0f), scale, SpriteEffects.None, 0f); }
public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); if (otherScreenHasFocus || IsExiting) { return; } //xpos++; //if (xpos == 320*3) xpos = 0; playerShip.Update(gameTime, map); waterLevel = 260; waterParallax.Position.Y = waterLevel; underwaterBGParallax.Position.Y = waterLevel + 20; if (playerShip.Position.X < 0f) { playerShip.Position.X = (map.TileWidth * map.Width) + playerShip.Speed.X; camera.Position.X = (playerShip.Position.X + playerShip.Speed.X * 20f) - (camera.Target.X - camera.Position.X); //particleController.Wrap((map.TileWidth*map.Width)); //projectileController.Wrap((map.TileWidth * map.Width)); } if (playerShip.Position.X >= (map.TileWidth * map.Width)) { playerShip.Position.X = 0f + playerShip.Speed.X; camera.Position.X = (playerShip.Position.X + playerShip.Speed.X * 20f) - (camera.Target.X - camera.Position.X); //particleController.Wrap(-(map.TileWidth * map.Width)); //projectileController.Wrap(-(map.TileWidth * map.Width)); //camera.Target.X += playerShip.Speed.X * 20f; } if (!playerShip.underWater) { if (playerShip.Position.Y > waterLevel + 10) { playerShip.underWater = true; AudioController.PlaySFX("water_enter", 1f, -0.1f, 0.1f); AudioController._songs["overwater-theme"].Volume = 0f; AudioController._songs["underwater-theme"].Volume = AudioController.MusicVolume; } waterParallax.HeightScale = MathHelper.Lerp(waterParallax.HeightScale, 0.65f, 0.1f); } if (playerShip.underWater) { if (playerShip.Position.Y < waterLevel - 10) { AudioController.PlaySFX("water_leave", 0.8f, -0.1f, 0.1f); AudioController._songs["overwater-theme"].Volume = AudioController.MusicVolume; AudioController._songs["underwater-theme"].Volume = 0f; playerShip.underWater = false; for (int i = 0; i < 30; i++) { Vector2 pos = new Vector2(Helper.RandomFloat(-5f, 5f), 0f); Color col = Color.Lerp(new Color(0, 81, 147), new Color(211, 234, 254), Helper.RandomFloat(0f, 1f)); particleController.Add(playerShip.Position + pos, (pos * 0.1f) + new Vector2(playerShip.Speed.X, playerShip.Speed.Y * Helper.RandomFloat(0.25f, 2f)), 0, 2000, 500, true, true, new Rectangle(0, 0, 3, 3), col, particle => { ParticleFunctions.FadeInOut(particle); if (particle.Position.Y > waterLevel) { particle.State = ParticleState.Done; } }, 1f, 0f, Helper.RandomFloat(-0.1f, 0.1f), 1, ParticleBlend.Alpha); } } waterParallax.HeightScale = MathHelper.Lerp(waterParallax.HeightScale, 0.1f, 0.05f); } particleController.Update(gameTime, map); if (!_endOfWave) { enemyController.Update(gameTime, map); } projectileController.Update(gameTime, map); powerupController.Update(gameTime, map); camera.Target = playerShip.Position; camera.Target.X += playerShip.Speed.X * 20f; //Enemy head = EnemyController.Instance.Enemies.FirstOrDefault(en => en is Boss && ((Boss) en).Head); //if (head != null) //{ // playerShip.Position = head.Position + new Vector2(0, -16); // camera.Target = head.Position; //} camera.Update(gameTime, playerShip.underWater, waterLevel); waterParallax.Update(gameTime, (camera.Target.X - camera.Position.X) * camera.Speed, (int)camera.Position.X); underwaterBGParallax.Update(gameTime, ((camera.Target.X - camera.Position.X) * camera.Speed) * 0.5f, (int)camera.Position.X); skyBGParallax.Update(gameTime, ((camera.Target.X - camera.Position.X) * camera.Speed) * 0.1f, (int)camera.Position.X); rocksParallax.Update(gameTime, (camera.Target.X - camera.Position.X) * camera.Speed, (int)camera.Position.X); cloudsParallax.Update(gameTime, (camera.Target.X - camera.Position.X) * camera.Speed, (int)camera.Position.X); hud.Update(gameTime, new Viewport(0, 0, ScreenManager.Game.RenderWidth, ScreenManager.Game.RenderHeight)); if (enemyController.Enemies.Count == 0 && enemyController.NumToSpawn == 0 && !_endOfWave) { _endOfWave = true; TimerController.Instance.Create("", () => { GameController.Wave++; TweenController.Instance.Create("", TweenFuncs.QuadraticEaseIn, tweenin => { _waveFade = tweenin.Value; if (tweenin.State == TweenState.Finished) { MapGeneration.Generate(map); enemyController.SpawnInitial(GameController.Wave, map); playerShip.Reset(); projectileController.Reset(); _firstWave = false; TweenController.Instance.Create("", TweenFuncs.Linear, eowtween => { //playerShip.Life += 0.2f; _eowTimer = eowtween.Value; if (eowtween.State == TweenState.Finished) { TweenController.Instance.Create("", TweenFuncs.QuadraticEaseIn, tweenout => { _waveFade = 1f - tweenout.Value; if (tweenout.State == TweenState.Finished) { _endOfWave = false; } }, 500, false, false); } }, _tradecost == 0?2000:5000, false, false); } }, 500, false, false); }, GameController.Wave > 0?2000:0, false); } if (playerShip.Life <= 0f && !_gameOver) { _gameOver = true; TimerController.Instance.Create("", () => { TweenController.Instance.Create("", TweenFuncs.QuadraticEaseIn, tweenin => { _goFade = tweenin.Value; if (tweenin.State == TweenState.Finished) { TweenController.Instance.Create("", TweenFuncs.Linear, eowtween => { _goTimer = eowtween.Value; }, 2000, false, false); } }, 1000, false, false); }, 2000, false); } TweenController.Instance.Update(gameTime); TimerController.Instance.Update(gameTime); _tradecost = (int)Math.Ceiling((GameController.Wave * 2f) * (0.01f * (100f - playerShip.Life))); }
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) { Vector2 mountedCenter = Main.player[projectile.owner].MountedCenter; Microsoft.Xna.Framework.Color color25 = Lighting.GetColor((int)((double)projectile.position.X + (double)projectile.width * 0.5) / 16, (int)(((double)projectile.position.Y + (double)projectile.height * 0.5) / 16.0)); if (projectile.hide && !ProjectileID.Sets.DontAttachHideToAlpha[projectile.type]) { color25 = Lighting.GetColor((int)mountedCenter.X / 16, (int)(mountedCenter.Y / 16f)); } Vector2 projPos = projectile.position; projPos = new Vector2((float)projectile.width, (float)projectile.height) / 2f + Vector2.UnitY * projectile.gfxOffY - Main.screenPosition; //f**k it Texture2D texture2D22 = Main.projectileTexture[projectile.type]; Microsoft.Xna.Framework.Color alpha3 = projectile.GetAlpha(color25); if (projectile.velocity == Vector2.Zero) { return(false); } float num230 = projectile.velocity.Length() + 16f; bool flag24 = num230 < 100f; Vector2 value28 = Vector2.Normalize(projectile.velocity); Microsoft.Xna.Framework.Rectangle rectangle8 = new Microsoft.Xna.Framework.Rectangle(0, 0, texture2D22.Width, 42); //2 and 40 Vector2 value29 = new Vector2(0f, Main.player[projectile.owner].gfxOffY); float rotation24 = projectile.rotation + 3.14159274f; Main.spriteBatch.Draw(texture2D22, projectile.Center.Floor() - Main.screenPosition + value29, new Microsoft.Xna.Framework.Rectangle?(rectangle8), alpha3, rotation24, rectangle8.Size() / 2f - Vector2.UnitY * 4f, projectile.scale, SpriteEffects.None, 0f); num230 -= 40f * projectile.scale; Vector2 vector31 = projectile.Center.Floor(); vector31 += value28 * projectile.scale * 24f; rectangle8 = new Microsoft.Xna.Framework.Rectangle(0, 68, texture2D22.Width, 18); //68 and 18 if (num230 > 0f) { float num231 = 0f; while (num231 + 1f < num230) { if (num230 - num231 < (float)rectangle8.Height) { rectangle8.Height = (int)(num230 - num231); } Main.spriteBatch.Draw(texture2D22, vector31 - Main.screenPosition + value29, new Microsoft.Xna.Framework.Rectangle?(rectangle8), alpha3, rotation24, new Vector2((float)(rectangle8.Width / 2), 0f), projectile.scale, SpriteEffects.None, 0f); num231 += (float)rectangle8.Height * projectile.scale; vector31 += value28 * (float)rectangle8.Height * projectile.scale; } } Vector2 value30 = vector31; vector31 = projectile.Center.Floor(); vector31 += value28 * projectile.scale * 24f; rectangle8 = new Microsoft.Xna.Framework.Rectangle(0, 46, texture2D22.Width, 18); //46 and 18 int num232 = 18; if (flag24) { num232 = 9; } float num233 = num230; if (num230 > 0f) { float num234 = 0f; float num235 = num233 / (float)num232; num234 += num235 * 0.25f; vector31 += value28 * num235 * 0.25f; for (int num236 = 0; num236 < num232; num236++) { float num237 = num235; if (num236 == 0) { num237 *= 0.75f; } Main.spriteBatch.Draw(texture2D22, vector31 - Main.screenPosition + value29, new Microsoft.Xna.Framework.Rectangle?(rectangle8), alpha3, rotation24, new Vector2((float)(rectangle8.Width / 2), 0f), projectile.scale, SpriteEffects.None, 0f); num234 += num237; vector31 += value28 * num237; } } rectangle8 = new Microsoft.Xna.Framework.Rectangle(0, 90, texture2D22.Width, 48); //90 and 48 Main.spriteBatch.Draw(texture2D22, value30 - Main.screenPosition + value29, new Microsoft.Xna.Framework.Rectangle?(rectangle8), alpha3, rotation24, texture2D22.Frame(1, 1, 0, 0).Top(), projectile.scale, SpriteEffects.None, 0f); return(false); }
public static Color ToDotNet(this XnaColor color) => Color.FromArgb(color.A, color.R, color.G, color.B);
private void PaintLayer(float weight) { // Cursor Position on Landscape Vector2 position = new Vector2(MouseCoords.X - ((float)BrushSize / 2), MouseCoords.Z - ((float)BrushSize / 2)); // Rectangle to draw on Rectangle rec = new Rectangle((int)position.X, (int)position.Y, BrushSize, BrushSize); // Make sure we are not larger/smaller then the actual landscapes paint mask texture if (rec.Right > PaintMask1.Width || rec.Left > PaintMask1.Width || rec.Top > PaintMask1.Height || rec.Bottom > PaintMask1.Height || rec.Right < 0 || rec.Left < 0 || rec.Top < 0 || rec.Bottom < 0) { return; } Color pixel = Color.Transparent; // Brush texture to use Bitmap brush = new Bitmap(Resource1.RoundBrush, BrushSize, BrushSize); // Build a color array to grab our pixels off our brush texture Color[] col = new Color[brush.Width * brush.Height]; for (int x = 0; x < brush.Width; x++) { for (int y = 0; y < brush.Height; y++) { int index = x + y * brush.Width; System.Drawing.Color c = brush.GetPixel(x, y); switch (CurrentPaintLayer) { case 0: pixel.R += (byte)(c.R / weight); break; case 1: pixel.G += (byte)(c.G / weight); break; case 2: pixel.B += (byte)(c.B / weight); break; case 3: pixel.A += (byte)(c.A / weight); break; } col[index] = new Color(pixel.R, pixel.G, pixel.B, pixel.A); } } #region old routine //for (int x = 0; x < BrushSize; x++) //{ // for (int y = 0; y < BrushSize; y++) // { // int index = x + y*BrushSize; // int red = col[index].R + pixel.R; // Layer1 // int green = col[index].G + pixel.G; // Layer2 // int blue = col[index].B + pixel.B; // Layer3 // int alpha = col[index].A + pixel.A; // Layer4 // // Apply our new found color goodness to our pixel // col[index] = new Color(red, green, blue, alpha); // } //} #endregion old routine // Unset the [4]th samplers (0-based) texture so we can set data to it on the graphics device GraphicsDevice.Textures[4] = null; // Set the new paint mask texture data on the gpu PaintMask1.SetData(0, rec, col, 0, col.Length); }
public override void Cache(McResourcePack pack) { string t = string.Empty; if (!Model.Textures.TryGetValue("layer0", out t)) { t = Model.Textures.FirstOrDefault(x => x.Value != null).Value; } if (t == default) { return; } List <VertexPositionColor> vertices = new List <VertexPositionColor>(); List <short> indexes = new List <short>(); if (pack.TryGetBitmap(t, out var rawTexture)) { var texture = rawTexture.CloneAs <Rgba32>(); int i = 0; float toolPosX = 0.0f; float toolPosY = 1.0f; float toolPosZ = (1f / 16f) * 7.5f; int verticesPerTool = texture.Width * texture.Height * 36; for (int y = 0; y < texture.Height; y++) { for (int x = 0; x < texture.Width; x++) { var pixel = texture[x, y]; if (pixel.A == 0) { continue; } Color color = new Color(pixel.R, pixel.G, pixel.B, pixel.A); ItemModelCube built = new ItemModelCube(new Vector3(1f / texture.Width, 1f / texture.Height, 1f / 16f)); built.BuildCube(color); var origin = new Vector3( (toolPosX + (1f / texture.Width) * x), toolPosY - (1f / texture.Height) * y, toolPosZ ); vertices = ModifyCubeIndexes(vertices, ref built.Front, origin); vertices = ModifyCubeIndexes(vertices, ref built.Back, origin); vertices = ModifyCubeIndexes(vertices, ref built.Top, origin); vertices = ModifyCubeIndexes(vertices, ref built.Bottom, origin); vertices = ModifyCubeIndexes(vertices, ref built.Left, origin); vertices = ModifyCubeIndexes(vertices, ref built.Right, origin); var indices = built.Front.indexes .Concat(built.Back.indexes) .Concat(built.Top.indexes) .Concat(built.Bottom.indexes) .Concat(built.Left.indexes) .Concat(built.Right.indexes) .ToArray(); indexes.AddRange(indices); } } } Vertices = vertices.ToArray(); for (var index = 0; index < Vertices.Length; index++) { var vertice = Vertices[index]; Vertices[index] = vertice; } Indexes = indexes.ToArray(); }
public override bool PreDraw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, Microsoft.Xna.Framework.Color lightColor) { ProjectileDrawing.DrawSpear(projectile.whoAmI, spriteBatch, lightColor); return(false); }
public override bool PreDrawExtras(SpriteBatch spriteBatch) //this draws the fishing line correctly { Lighting.AddLight(projectile.Center, 0.13f, 0.86f, 0.59f); //this defines the projectile/bobber light color Player player = Main.player[projectile.owner]; if (projectile.bobber && Main.player[projectile.owner].inventory[Main.player[projectile.owner].selectedItem].holdStyle > 0) { float pPosX = player.MountedCenter.X; float pPosY = player.MountedCenter.Y; pPosY += Main.player[projectile.owner].gfxOffY; int type = Main.player[projectile.owner].inventory[Main.player[projectile.owner].selectedItem].type; float gravDir = Main.player[projectile.owner].gravDir; if (type == mod.ItemType("LunarFishingGun")) //add your Fishing Pole name here { pPosX += (float)(50 * Main.player[projectile.owner].direction); if (Main.player[projectile.owner].direction < 0) { pPosX -= 13f; } pPosY -= 15f * gravDir; } if (gravDir == -1f) { pPosY -= 12f; } Vector2 value = new Vector2(pPosX, pPosY); value = Main.player[projectile.owner].RotatedRelativePoint(value + new Vector2(8f), true) - new Vector2(8f); float projPosX = projectile.position.X + (float)projectile.width * 0.5f - value.X; float projPosY = projectile.position.Y + (float)projectile.height * 0.5f - value.Y; Math.Sqrt((double)(projPosX * projPosX + projPosY * projPosY)); float rotation2 = (float)Math.Atan2((double)projPosY, (double)projPosX) - 1.57f; bool flag2 = true; if (projPosX == 0f && projPosY == 0f) { flag2 = false; } else { float projPosXY = (float)Math.Sqrt((double)(projPosX * projPosX + projPosY * projPosY)); projPosXY = 12f / projPosXY; projPosX *= projPosXY; projPosY *= projPosXY; value.X -= projPosX; value.Y -= projPosY; projPosX = projectile.position.X + (float)projectile.width * 0.5f - value.X; projPosY = projectile.position.Y + (float)projectile.height * 0.5f - value.Y; } while (flag2) { float num = 12f; float num2 = (float)Math.Sqrt((double)(projPosX * projPosX + projPosY * projPosY)); float num3 = num2; if (float.IsNaN(num2) || float.IsNaN(num3)) { flag2 = false; } else { if (num2 < 20f) { num = num2 - 8f; flag2 = false; } num2 = 12f / num2; projPosX *= num2; projPosY *= num2; value.X += projPosX; value.Y += projPosY; projPosX = projectile.position.X + (float)projectile.width * 0.5f - value.X; projPosY = projectile.position.Y + (float)projectile.height * 0.1f - value.Y; if (num3 > 12f) { float num4 = 0.3f; float num5 = Math.Abs(projectile.velocity.X) + Math.Abs(projectile.velocity.Y); if (num5 > 16f) { num5 = 16f; } num5 = 1f - num5 / 16f; num4 *= num5; num5 = num3 / 80f; if (num5 > 1f) { num5 = 1f; } num4 *= num5; if (num4 < 0f) { num4 = 0f; } num5 = 1f - projectile.localAI[0] / 100f; num4 *= num5; if (projPosY > 0f) { projPosY *= 1f + num4; projPosX *= 1f - num4; } else { num5 = Math.Abs(projectile.velocity.X) / 3f; if (num5 > 1f) { num5 = 1f; } num5 -= 0.5f; num4 *= num5; if (num4 > 0f) { num4 *= 2f; } projPosY *= 1f + num4; projPosX *= 1f - num4; } } rotation2 = (float)Math.Atan2((double)projPosY, (double)projPosX) - 1.57f; Microsoft.Xna.Framework.Color color2 = Lighting.GetColor((int)value.X / 16, (int)(value.Y / 16f), new Microsoft.Xna.Framework.Color(34, 221, 151, 100)); Main.spriteBatch.Draw(Main.fishingLineTexture, new Vector2(value.X - Main.screenPosition.X + (float)Main.fishingLineTexture.Width * 0.5f, value.Y - Main.screenPosition.Y + (float)Main.fishingLineTexture.Height * 0.5f), new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(0, 0, Main.fishingLineTexture.Width, (int)num)), color2, rotation2, new Vector2((float)Main.fishingLineTexture.Width * 0.5f, 0f), 1f, SpriteEffects.None, 0f); } } } return(false); }
/// <summary> /// Convert Color value of XNA Framework to CCColor3B type /// </summary> public CCColor3B(Microsoft.Xna.Framework.Color color) { R = color.R; G = color.G; B = color.B; }
public override void draw(Microsoft.Xna.Framework.Graphics.GraphicsDevice _GraphicsDevice, Microsoft.Xna.Framework.Graphics.SpriteBatch _SpriteBatch, Microsoft.Xna.Framework.Vector3 _DrawPositionExtra, Microsoft.Xna.Framework.Color _Color) { //TODO: An das Attribut Scale anpassen Vector2 var_PositionShadow = new Vector2(this.Bounds.X + _DrawPositionExtra.X, this.Bounds.Y + _DrawPositionExtra.Y); _SpriteBatch.Draw(Ressourcen.RessourcenManager.ressourcenManager.Texture["Character/Shadow"], var_PositionShadow, Color.White); Vector2 var_PositionState = new Vector2(this.Position.X, this.Position.Y) + new Vector2(-13, -7); //if (this.IsHovered) //{ if (this is PlayerObject) { _SpriteBatch.Draw(Ressourcen.RessourcenManager.ressourcenManager.Texture["Character/CreatureState"], var_PositionState, Color.BlueViolet); //Color.DarkOrange); } else { _SpriteBatch.Draw(Ressourcen.RessourcenManager.ressourcenManager.Texture["Character/CreatureState"], var_PositionState, Color.Red); } //} base.draw(_GraphicsDevice, _SpriteBatch, _DrawPositionExtra, _Color); }