public BloomTest(RenderTexture target_tex, RenderTarget target) { _target = target; _bloom = new Shader(null, "bloom.glsl"); _texture = new RenderTexture((uint)GlobalProps.Width, (uint)GlobalProps.Height); _states.BlendMode = BlendMode.Alpha; _states.Shader = _bloom; _states.Transform = Transform.Identity; _states.Texture = target_tex.Texture; _bloom.SetParameter("referenceTex", Shader.CurrentTexture); _bloom.SetParameter("pixelWidth", 4); _bloom.SetParameter("pixelHeight", 4); int w = GlobalProps.Width, h = GlobalProps.Height; Vector2f v0 = new Vector2f(0, 0); Vector2f v1 = new Vector2f(w, 0); Vector2f v2 = new Vector2f(w, h); Vector2f v3 = new Vector2f(0, h); _verts = new Vertex[4]; _verts[0] = new Vertex(v0, Color.White, v0); _verts[1] = new Vertex(v1, Color.White, v1); _verts[2] = new Vertex(v2, Color.White, v2); _verts[3] = new Vertex(v3, Color.White, v3); }
public Edge() : base("edge post-effect") { // Create the off-screen surface mySurface = new RenderTexture(800, 600); mySurface.Smooth = true; // Load the textures myBackgroundTexture = new Texture("resources/sfml.png"); myBackgroundTexture.Smooth = true; myEntityTexture = new Texture("resources/devices.png"); myEntityTexture.Smooth = true; // Initialize the background sprite myBackgroundSprite = new Sprite(myBackgroundTexture); myBackgroundSprite.Position = new Vector2f(135, 100); // Load the moving entities myEntities = new Sprite[6]; for (int i = 0; i < myEntities.Length; ++i) { myEntities[i] = new Sprite(myEntityTexture, new IntRect(96 * i, 0, 96, 96)); } // Load the shader myShader = new Shader(null, "resources/edge.frag"); myShader.SetParameter("texture", Shader.CurrentTexture); }
public GraphicsDisplay(uint width, uint height) { Width = width; Height = height; _data = new Image(width, height, Color.Black); _dataTexture = new Texture(_data); _palette = new Image("Data/palette.png"); _paletteTexture = new Texture(_palette); _display = new Sprite(_dataTexture); _renderer = new Shader("Data/display.vert", "Data/display.frag"); _renderer.SetParameter("data", _dataTexture); _renderer.SetParameter("dataSize", width, height); _renderer.SetParameter("palette", _paletteTexture); }
public Pixelate() : base("pixelate") { // Load the texture and initialize the sprite myTexture = new Texture("resources/background.jpg"); mySprite = new Sprite(myTexture); // Load the shader myShader = new Shader(null, "resources/pixelate.frag"); myShader.SetParameter("texture", Shader.CurrentTexture); }
public LightLayer(Vector2u gameRez, Vector2u windowRez) { Lights = new List<Light>(); Polygons = new List<Polygon>(); renText = new RenderTexture(gameRez.X, gameRez.Y); lightMap = new RenderTexture(gameRez.X, gameRez.Y); lightMap.Smooth = true; scene = new Texture(windowRez.X, windowRez.Y); lightShader = new Shader(null, "Content/shaders/light.frag"); lightShader.SetParameter("screenHeight", gameRez.Y); lightState = new RenderStates(BlendMode.Add, Transform.Identity, renText.Texture, lightShader); shadowShader = new Shader(null, "Content/shaders/shadows.frag"); //shadowState = new RenderStates(shadowShader); shadowState = new RenderStates(BlendMode.Multiply); }
public LightEffectManager(Map parent) { Parent = parent; DynamicEffects = new List<LightEffect>(); StaticEffects = new List<LightEffect>(); GlobalColor = DEFAUT_GLOBAL_COLOR; IsRefreshed = false; RenderTexture = new RenderTexture(GameData.WINDOW_WIDTH, GameData.WINDOW_HEIGHT); BlurEffect = new Shader(GameData.DATAS_DEFAULT_PATH + "gfx/blur.sfx"); BlurEffect.SetCurrentTexture("texture"); BlurEffect.SetParameter("offset", 0.005F * SMOOTHNESS); Walls = null; OpacityBoxes = null; }
public void Start() { System.Drawing.Rectangle r = System.Windows.Forms.Screen.PrimaryScreen.Bounds; RenderWindow window = new RenderWindow(new VideoMode(1024, 786), "One Bullet", Styles.Titlebar | Styles.Close, settings); window.LostFocus += (s, e) => { focus = false; }; window.GainedFocus += (s, e) => { focus = true; }; Width = (int)window.Size.X; Height = (int)window.Size.Y; window.Closed += window_Closed; window.KeyPressed += window_KeyPressed; window.KeyReleased += window_KeyReleased; Finish(); player.OnShoot += Shoot; window.SetFramerateLimit(60); Font font = new Font("Content/consolas.ttf"); Text healthText = new Text("", font, 72); healthText.Color = Color.Red; Text dialog = new Text("", font, 48); dialog.Color = new Color(128, 128, 128); Texture bulletUI = new Texture("Content/bulletUI.png"); RectangleShape bulletRect = new RectangleShape(); bulletRect.Size = new Vector2f(72, 108); bulletRect.Origin = new Vector2f(72, 108); bulletRect.Texture = bulletUI; light = new RenderTexture(window.Size.X, window.Size.Y); lightCircle = new CircleShape(0, 20); RectangleShape lightDisplay = new RectangleShape(); lightDisplay.Size = new Vector2f(window.Size.X, window.Size.Y); lightDisplay.Position = new Vector2f(); blur = new Shader("Content/blur.vs", "Content/blur.fs"); blur.SetParameter("rad", 0.004f); RenderStates blurStates = new RenderStates(RenderStates.Default); blurStates.Shader = blur; RectangleShape imageFrame = new RectangleShape(); imageFrame.Position = new Vector2f(Width / 2 - 400, 16); imageFrame.Size = new Vector2f(800, 600); Texture white = new Texture(1, 1); Texture blood = new Texture("Content/bloodOverlay.png"); Text startBtn = new Text("START GAME", font, 100); startBtn.Position = new Vector2f(Width / 2 - startBtn.GetGlobalBounds().Width / 2, Height / 5); bloodSystem = new ParticleSystem(new Texture("Content/bloodParticle.png")); Texture aimImage = new Texture("Content/finalScene.png"); Text copyright = new Text("Game by WebFreak001. Made for Ludum Dare 28", font, 48); copyright.Position = new Vector2f(Width / 2 - copyright.GetLocalBounds().Width / 2, 32); bool mouseOld = false; #region Achivements if (!File.Exists("ach.txt")) { File.WriteAllText("ach.txt", "0:0\n1:0\n2:0"); } achivements = new Dictionary<int, Achivement>(); string[] achs = File.ReadAllLines("ach.txt"); bool done1 = false; bool done2 = false; bool done3 = false; if (achs.Length > 2) { if (achs[0].StartsWith("0")) { char c = achs[0].Last(); if (c == '1') done1 = true; } if (achs[1].StartsWith("1")) { char c = achs[1].Last(); if (c == '1') done2 = true; } if (achs[2].StartsWith("1")) { char c = achs[2].Last(); if (c == '1') done3 = true; } } achivements.Add(0, new Achivement() { Done = done1, Text = "Start the game" }); achivements.Add(1, new Achivement() { Done = done2, Text = "You Missed" }); achivements.Add(2, new Achivement() { Done = done3, Text = "Finish the Game" }); Texture achiveTex = new Texture("Content/achivement.png"); achiveTex.Smooth = true; RectangleShape achTL = new RectangleShape(); RectangleShape achT = new RectangleShape(); RectangleShape achTR = new RectangleShape(); RectangleShape achL = new RectangleShape(); RectangleShape achR = new RectangleShape(); RectangleShape achBL = new RectangleShape(); RectangleShape achB = new RectangleShape(); RectangleShape achBR = new RectangleShape(); RectangleShape ach = new RectangleShape(); achTL.TextureRect = new IntRect(0, 0, 32, 32); achT.TextureRect = new IntRect(31, 0, 2, 32); achTR.TextureRect = new IntRect(32, 0, 32, 32); achL.TextureRect = new IntRect(0, 31, 32, 2); achR.TextureRect = new IntRect(32, 31, 32, 2); achBL.TextureRect = new IntRect(0, 32, 32, 32); achB.TextureRect = new IntRect(31, 32, 2, 32); achBR.TextureRect = new IntRect(32, 32, 32, 32); ach.TextureRect = new IntRect(31, 31, 2, 2); achTL.Position = new Vector2f(Width / 2 - 232, 16); achT.Position = new Vector2f(Width / 2 - 200, 16); achTR.Position = new Vector2f(Width / 2 + 200, 16); achL.Position = new Vector2f(Width / 2 - 232, 48); achR.Position = new Vector2f(Width / 2 + 200, 48); achBL.Position = new Vector2f(Width / 2 - 232, 118); achB.Position = new Vector2f(Width / 2 - 200, 118); achBR.Position = new Vector2f(Width / 2 + 200, 118); ach.Position = new Vector2f(Width / 2 - 200, 48); achTL.Size = new Vector2f(32, 32); achT.Size = new Vector2f(400, 32); achTR.Size = new Vector2f(32, 32); achL.Size = new Vector2f(32, 70); achR.Size = new Vector2f(32, 70); achBL.Size = new Vector2f(32, 32); achB.Size = new Vector2f(400, 32); achBR.Size = new Vector2f(32, 32); ach.Size = new Vector2f(400, 70); achTL.Texture = achiveTex; achT.Texture = achiveTex; achTR.Texture = achiveTex; achL.Texture = achiveTex; achR.Texture = achiveTex; achBL.Texture = achiveTex; achB.Texture = achiveTex; achBR.Texture = achiveTex; ach.Texture = achiveTex; Text achivementGetText = new Text("Achivement Get!", font, 40); achivementGetText.Position = new Vector2f(Width / 2 - 200, 32); achivementGetText.Color = Color.Black; Text achivementContent = new Text("", font, 26); achivementContent.Position = new Vector2f(Width / 2 - 200, 80); achivementContent.Color = Color.Black; Text fps = new Text("", font, 20); fps.Position = new Vector2f(16, 16); #endregion while (window.IsOpen()) { window.DispatchEvents(); light.Clear(Color.Transparent); window.Clear(Color.Black); if (playing) { if (aiming) { imageFrame.Texture = aimImage; window.Draw(imageFrame); if (Mouse.IsButtonPressed(Mouse.Button.Left) && !mouseOld) { Vector2i m = Mouse.GetPosition(window); if (m.X > imageFrame.Position.X && m.Y > imageFrame.Position.Y && m.X < imageFrame.Position.X + imageFrame.Size.X && m.Y < imageFrame.Position.Y + imageFrame.Size.Y) { Finish(); } else { Achivement(1); Finish(); } } mouseOld = Mouse.IsButtonPressed(Mouse.Button.Left); } else { if (focus) { if (up) player.MoveAbsolute(0, -1); if (down) player.MoveAbsolute(0, 1); if (left) player.MoveAbsolute(-1, 0); if (right) player.MoveAbsolute(1, 0); int result = level.Move(player.PreUpdate()); if (result == 1 || result == 2) player.Update(); else if (result == 3) Finish(); else if (result == 4) { WriteLn("I must kill IT"); WriteLn("I've found a gun... But it has only 1 Bullet."); level.RemoveGun(); player.Arm(); player.Update(); } else if (result == 5) { WriteLn("But I have only 1 try. If i don't hit him he will call the police"); WriteLn("In there is the man who had sex with my wife!"); WriteLn("That's the Office..."); player.Update(); } else player.Stuck(); if (level.Intersect(player) || suiciding) { player.Health--; recentAttack = 10; bloodSystem.Emit(player.Location); level.ShakeScreen(0.4f, 1); if (player.Health <= 0) { Dead(); } } if (Mouse.IsButtonPressed(Mouse.Button.Left) && !mouseOld) { player.Shoot(); } mouseOld = Mouse.IsButtonPressed(Mouse.Button.Left); } if (drawCliparts) { imageFrame.Texture = cliparts[clipart]; window.Draw(imageFrame); } else { player.Rotate(Mouse.GetPosition(window) - level.offset.Vec2i); level.Draw(window, player); foreach (Location l in level.Lights) { Lighten(l * 32 + 16 + level.offset, 150.0f); } bloodSystem.Draw(window, level.offset); player.Draw(window, level.offset); Lighten(player.Location + level.offset, 100.0f, 0.5f); light.Display(); lightDisplay.Texture = light.Texture; lightDisplay.TextureRect = new IntRect(0, 0, (int)light.Size.X, (int)light.Size.Y); blurStates.Texture = light.Texture; window.Draw(lightDisplay, blurStates); if (player.canShoot) { bulletRect.Position = new Vector2f(window.Size.X - 16, window.Size.Y - 16); window.Draw(bulletRect); } } healthText.DisplayedString = (player.Health * 0.1f) + "%"; healthText.Position = new Vector2f(16, window.Size.Y - healthText.GetGlobalBounds().Height - 48); window.Draw(healthText); dialog.CharacterSize = 42; dialog.DisplayedString = ln1; dialog.Position = new Vector2f(window.Size.X / 2 - dialog.GetGlobalBounds().Width / 2, window.Size.Y - 135); window.Draw(dialog); dialog.CharacterSize = 34; dialog.DisplayedString = ln2; dialog.Position = new Vector2f(window.Size.X / 2 - dialog.GetGlobalBounds().Width / 2, window.Size.Y - 90); window.Draw(dialog); dialog.CharacterSize = 26; dialog.DisplayedString = ln3; dialog.Position = new Vector2f(window.Size.X / 2 - dialog.GetGlobalBounds().Width / 2, window.Size.Y - 50); window.Draw(dialog); lightDisplay.Texture = blood; lightDisplay.TextureRect = new IntRect(0, 0, 800, 600); lightDisplay.FillColor = new Color(255, 255, 255, (byte)(recentAttack / 10.0f * 200)); window.Draw(lightDisplay); recentAttack--; recentAttack = Math.Max(recentAttack, 0); lightDisplay.Texture = white; lightDisplay.FillColor = new Color(255, 20, 23, (byte)((1000 - player.Health) / 1000.0f * 50)); window.Draw(lightDisplay); lightDisplay.FillColor = Color.White; } } else { window.Draw(startBtn); if (Mouse.IsButtonPressed(Mouse.Button.Left) && !mouseOld) { Vector2i p = Mouse.GetPosition(window); if (p.Y > startBtn.Position.Y && p.Y < startBtn.Position.Y + 150) { ResumeGame(); } } mouseOld = Mouse.IsButtonPressed(Mouse.Button.Left); } if (achivement) { window.Draw(achTL); window.Draw(achT); window.Draw(achTR); window.Draw(achL); window.Draw(ach); window.Draw(achR); window.Draw(achBL); window.Draw(achB); window.Draw(achBR); window.Draw(achivementGetText); achivementContent.DisplayedString = achivementtext; window.Draw(achivementContent); } window.Display(); } }
/// <summary> /// Constructs a text display. /// </summary> /// <param name="width">Width in characters</param> /// <param name="height">Height in characters</param> /// <param name="fontFile">Font texture</param> /// <param name="convertFont">Enable support for masked fonts</param> /// <param name="paletteFile">Palette texture</param> public TextDisplay(uint width, uint height, string fontFile = "font.png", bool convertFont = true, string paletteFile = "palette.png") { if (string.IsNullOrEmpty(fontFile)) throw new ArgumentNullException("fontFile"); if (string.IsNullOrEmpty(paletteFile)) throw new ArgumentNullException("paletteFile"); Width = width; Height = height; _data = new Image(width, height, Color.Black); _dataTexture = new Texture(_data); var fontImage = new Image(Path.Combine(DataFolder, fontFile)); CharacterWidth = fontImage.Size.X / 16; CharacterHeight = fontImage.Size.Y / 16; if (convertFont) { var fontWidth = fontImage.Size.X; var fontHeight = fontImage.Size.Y; var fontPixels = fontImage.Pixels; fontImage.Dispose(); // use top left pixel of space as mask color var maskX = (32 % 16) * CharacterWidth; var maskY = (32 / 16) * CharacterHeight * (fontWidth * 4); var maskI = maskX + maskY; var maskR = fontPixels[maskI + 0]; var maskG = fontPixels[maskI + 1]; var maskB = fontPixels[maskI + 2]; var maskA = fontPixels[maskI + 3]; for (int i = 0; i < fontPixels.Length; i += 4) { var r = fontPixels[i + 0]; var g = fontPixels[i + 1]; var b = fontPixels[i + 2]; var a = fontPixels[i + 3]; if (r == maskR && g == maskG && b == maskB && a == maskA) { // mask color, set to transparent fontPixels[i + 3] = 0; } else { // set alpha channel to average of rgb var level = (r + b + g) / 3f; var alpha = a / 256f; fontPixels[i + 3] = (byte)(level * alpha); } } fontImage = new Image(fontWidth, fontHeight, fontPixels); //fontImage.SaveToFile("result.png"); } _fontTexture = new Texture(fontImage); _palette = new Image(Path.Combine(DataFolder, paletteFile)); _paletteTexture = new Texture(_palette); _display = new VertexArray(PrimitiveType.Quads, 4); _display[0] = new Vertex(new Vector2f(0, 0), new Vector2f(0, 0)); _display[1] = new Vertex(new Vector2f(width * CharacterWidth, 0), new Vector2f(1, 0)); _display[2] = new Vertex(new Vector2f(width * CharacterWidth, height * CharacterHeight), new Vector2f(1, 1)); _display[3] = new Vertex(new Vector2f(0, height * CharacterHeight), new Vector2f(0, 1)); var displayVertexSource = File.ReadAllText(Path.Combine(DataFolder, "texter.vert")); var displayFragmentSource = File.ReadAllText(Path.Combine(DataFolder, "texter.frag")) .Replace("#W#", CharacterWidth.ToString("D")) .Replace("#H#", CharacterHeight.ToString("D")); _renderer = Shader.FromString(displayVertexSource, displayFragmentSource); _renderer.SetParameter("data", _dataTexture); _renderer.SetParameter("dataSize", width, height); _renderer.SetParameter("font", _fontTexture); _renderer.SetParameter("palette", _paletteTexture); }