public bool Load(Texture tileSet, Vector2u tileSize, byte[] tiles, uint width, uint height) { _tileSet = tileSet; _vertices = new VertexArray(PrimitiveType.Quads); _vertices.Resize(width * height * 4); for (uint x = 0; x < width; x++) { for (uint y = 0; y < height; y++) { var index = x + y * width; var tileNumber = tiles[x + y * width] + new Random().Next(6); var tu = tileNumber % (_tileSet.Size.X / tileSize.X); var tv = tileNumber / (_tileSet.Size.X / tileSize.X); var vertex1 = new Vertex(new Vector2f(x * tileSize.X, y * tileSize.Y), new Vector2f(tu * tileSize.X, tv * tileSize.Y)); var vertex2 = new Vertex(new Vector2f((x + 1) * tileSize.X, y * tileSize.Y), new Vector2f((tu + 1) * tileSize.X, tv * tileSize.Y)); var vertex3 = new Vertex(new Vector2f((x + 1) * tileSize.X, (y + 1) * tileSize.Y), new Vector2f((tu + 1) * tileSize.X, (tv + 1) * tileSize.Y)); var vertex4 = new Vertex(new Vector2f(x * tileSize.X, (y + 1) * tileSize.Y), new Vector2f(tu * tileSize.X, (tv + 1) * tileSize.Y)); _vertices.Append(vertex1); _vertices.Append(vertex2); _vertices.Append(vertex3); _vertices.Append(vertex4); } } return(true); }
public void OnScreenResized(Vector2u newSize) { foreach (Camera cam in _cameras) { cam.OnScreenResized(newSize); } }
private void setupMainMenu(RenderWindow window) { Vector2u windowSize = new Vector2u(window.Size.X, window.Size.Y); mainMenu = new Menu(menuFont, 1, window); Components.Button tmpBtn; // New Game button // 0 tmpBtn = new Components.Button(null, menuFont, textureStyles[1]); tmpBtn.centerButton(windowSize, true, false); tmpBtn.setPositionY(130.0f); mainMenu.addButton(tmpBtn); Vector2f mainBtnPos = new Vector2f(tmpBtn.getSprite().Position.X, tmpBtn.getSprite().Position.Y); // Credits button // 1 tmpBtn = new Components.Button(null, menuFont, textureStyles[2]); tmpBtn.setPosition(new Vector2f((mainBtnPos.X + textureStyles[1].Size.X), mainBtnPos.Y + 140)); mainMenu.addButton(tmpBtn); // Options button // 2 tmpBtn = new Components.Button(null, menuFont, textureStyles[3]); tmpBtn.setPosition(new Vector2f((mainBtnPos.X - tmpBtn.getSprite().GetLocalBounds().Width), mainBtnPos.Y + 140)); mainMenu.addButton(tmpBtn); // Quit button // 3 tmpBtn = new Components.Button(null, menuFont, textureStyles[4]); tmpBtn.centerButton(windowSize, true, false); tmpBtn.setPositionY(mainBtnPos.Y + textureStyles[1].Size.Y); mainMenu.addButton(tmpBtn); // Setup selectRect mainMenu.setSelectRectSize(new Vector2f(mainMenu.buttonList[0].getSprite().GetLocalBounds().Width, mainMenu.buttonList[0].getSprite().GetLocalBounds().Height)); mainMenu.setSelectRectPos(mainMenu.buttonList[0].getSprite().Position); }
public LightSystem(World worldRef, Vector2u screenSize) { world = worldRef; lightShader = Assets.shaders["light"]; _screenShadowSprite = new Sprite(); _screenShadowSprite.Origin = new Vector2f(0, 0); _lightSprite = new Sprite(); _atlasFrames = new int[(ATLAS_SIZE / ATLAS_FRAME_SIZE) * (ATLAS_SIZE / ATLAS_FRAME_SIZE)]; for (int i = 0; i < _atlasFrames.Length; ++i) { _atlasFrames[i] = -1; } lightAtlas = new RenderTexture(ATLAS_SIZE, ATLAS_SIZE, false); lightAtlas.Clear(Color.Black); lightAtlas.Display(); lightAtlas.Smooth = false; filterFrame = new RenderTexture(ATLAS_FRAME_SIZE, ATLAS_FRAME_SIZE, false); filterFrame.Clear(Color.White); filterFrame.Display(); filterFrame.Smooth = false; OnScreenResized(screenSize); }
/// <summary> /// Attempts to load a vector from an xml element. /// </summary> /// <param name="ele"> /// The element to load from. /// </param> /// <returns> /// A valid vector on success or null on failure. /// </returns> public static Vector2u?ToVec2u(XmlElement ele) { if (ele is null) { return(Logger.LogReturn <Vector2u?>("Unable to load Vector2u from null xml element.", null, LogType.Error)); } if (!ele.HasAttribute(nameof(Vector2u.X))) { return(Logger.LogReturn <Vector2u?>("Unable to load Vector2u: No X attribute.", null, LogType.Error)); } if (!ele.HasAttribute(nameof(Vector2i.Y))) { return(Logger.LogReturn <Vector2u?>("Unable to load Vector2u: No Y attribute.", null, LogType.Error)); } Vector2u vec; try { vec = new Vector2u(uint.Parse(ele.GetAttribute(nameof(Vector2u.X))), uint.Parse(ele.GetAttribute(nameof(Vector2u.Y)))); } catch (Exception e) { return(Logger.LogReturn <Vector2u?>($"Unable to load Vector2u: { e.Message }", null, LogType.Error)); } return(vec); }
public Background(Game _ref) { Vector2u starTextureSize = Globals.starTexture.Size; gameReference = _ref; generateTexture(); //create bg tiles for (int i = 0; i < bgSprites.Length; i++) { bgSprites[i] = new Sprite(bgRenderTexture.Texture); //set the sprite positions to a 3x3 grid int x = (i % 3) - 1; int y = (i / 3) - 1; bgSprites[i].Position = new Vector2f(x * bgRenderTexture.Size.X, y * bgRenderTexture.Size.Y); bgRects[i] = bgSprites[i].GetGlobalBounds(); testShapes[i] = new RectangleShape(new Vector2f(bgRects[i].Width, bgRects[i].Height)); testShapes[i].Position = new Vector2f(bgRects[i].Left, bgRects[i].Top); if (x == 0 ^ y == 0) { testShapes[i].FillColor = Color.White; } else { testShapes[i].FillColor = Color.Green; } } }
protected override void initParticle(cEmissionInfo emission) { Particle particle = emission.Particle; particle.Pos = emission.StartPosition; particle.LastPos = particle.Pos; particle.ViewPos = particle.Pos; particle.MaxSpeed = cAppMath.GetRandomNumber(200, 400); //700, 900 | (400, 600); //3, 8//Math->GetRandomNumber(510, 800); // 2000.0f //------------------------------------------------------------------------------------------------ float angle = (float)cAppMath.DegressToRadian(cAppMath.GetRandomNumber(0, 360));//sDivisions * m_Angles; particle.Vel = new Vector2f((float)Math.Cos(angle) * particle.MaxSpeed, (float)Math.Sin(angle) * particle.MaxSpeed); //------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------ //particle.m_Vel = sf::Vector2f(Math->GetRandomClamped() * particle.m_MaxSpeed, Math->GetRandomClamped() *particle.m_MaxSpeed); particle.SlowDown = 0.98f; //0.92f; //particle.m_SlowDown = (float)Math->GetRandomDoubleInRange(0.55, 0.7); //0.6f; //phs->AddForce( sf::Vector2f(Math->GetRandomClamped() * phs->MaxSpeed, Math->GetRandomClamped() * phs->MaxSpeed) ); Vector2u uSize = particleManager.ExplosionTexture.Size; particle.Scale = (float)cAppMath.GetRandomDoubleInRange(this.minScale, this.maxScale); particle.Dims = new Vector2f(uSize.X * particle.Scale, uSize.Y * particle.Scale); particle.ScaleSpeed = -cAppMath.GetRandomNumber(10, 50); particle.Color = Utils.GetRandomRedColor(); particle.Opacity = 255.0f; particle.Life = 1.0f; particle.Fade = 60; //Math->GetRandomNumber(100, 240); particle.Intersects = false; }
public void UseSpawnOfItems(Vector2u window) { foreach (CircleItem item in circleItems) { item.ChangePosition(item.RandomSpawn(window)); } }
public static IIndexedPathfindingMap BuildMap(GridType type, Vector2i nodeSize, Vector2u bounds, Dictionary<CellState, Color> colorMap) { switch (type) { case GridType.SquareEuclidean: var gridEuc = new Vector2i((int)(bounds.X / nodeSize.X), (int)(bounds.Y / nodeSize.Y)); return new SquareGrid(nodeSize, gridEuc, colorMap) { UseManhattanMetric = false }; case GridType.SquareManhattan: var gridMan = new Vector2i((int)(bounds.X / nodeSize.X), (int)(bounds.Y / nodeSize.Y)); return new SquareGrid(nodeSize, gridMan, colorMap) { UseManhattanMetric = true }; case GridType.Hex: var floatHexSize = new Vector2f(nodeSize.X, nodeSize.Y); var testHex = new HexShape(new Layout(Orientation.Flat, floatHexSize, new Vector2f(0, 0))); var size = new Vector2f(testHex.GetLocalBounds().Width, testHex.GetLocalBounds().Height); //We subtract one to handle the center hex var vertRadius = bounds.Y / (2f * size.Y) - 1; var horizRadius = bounds.X / (2f * size.X) - 1; return new HexGrid((int)Math.Min(vertRadius, horizRadius), Orientation.Flat, floatHexSize, colorMap) { Position = new Vector2f(bounds.X / 2f, bounds.Y / 2f) }; } throw new ArgumentException("Cannot build a grid of type " + type); }
protected override void DoCreate() { Vector2u centerPosition = new Vector2u(_screenSize.X / 2, _screenSize.Y / 2); float distanceToCenterMax = (float)Math.Sqrt(centerPosition.X * centerPosition.X + centerPosition.Y * centerPosition.Y); Image fadeUpImage = new Image(_screenSize.X, _screenSize.Y); Image fadeDownImage = new Image(_screenSize.X, _screenSize.Y); Image fadeRadialImage = new Image(_screenSize.X, _screenSize.Y); Color newCol = Color.Black; for (uint i = 0; i != _screenSize.X; i++) { for (uint j = 0; j != _screenSize.Y; j++) { Vector2u distanceToCenter = new Vector2u(centerPosition.X - i, centerPosition.Y - j); float newAlpha = 255.0f * 0.75f * (float)Math.Sqrt(distanceToCenter.X * distanceToCenter.X + distanceToCenter.Y * distanceToCenter.Y) / distanceToCenterMax; newCol.A = (byte)newAlpha; fadeRadialImage.SetPixel(i, j, newCol); } } _fadeRadialTexture = new Texture(fadeRadialImage); _fadeRadialSprite = new Sprite(_fadeRadialTexture); _fadeRadialSprite.Scale = new Vector2f(1.0f, 1.5f); IsEffectActive = true; }
private void HandleWindowResize(Event e) { var evt = (WindowResizeEvent)e; m_windowSize = evt.Size; UpdateViewSize(); }
/// <summary> /// Create a view manager. /// </summary> /// <param name="em"></param> /// <param name="window"></param> /// <exception cref="ArgumentNullException"> /// em or window is null. /// </exception> public ViewManager(EventManager em, Window window) { if (em == null) { throw new ArgumentNullException("em"); } if (window == null) { throw new ArgumentNullException("window"); } m_eventManager = em; m_windowSize = window.Size; View = new View { Center = new Vector2f(0, 0), Viewport = new FloatRect(0, 0, 1, 1) }; UpdateViewSize(); m_eventManager.AddListener <WindowResizeEvent>(HandleWindowResize); m_eventManager.AddListener <MapDragEvent>(HandleMapDrag); m_eventManager.AddListener <MapZoomEvent>(HandleMapZoom); }
public static Vector2f EnsureObjectIsOnscreen(Vector2f pos, Vector2u windowSize) { Vector2f newpos = new Vector2f(pos.X, pos.Y); // make sure enemy stays on the screen if (pos.Y < 0) { newpos = pos; newpos.Y = 10; pos = newpos; } if (pos.X < 0) { newpos = pos; newpos.X = 10; pos = newpos; } if (pos.X > windowSize.X) { newpos = pos; newpos.X = windowSize.X - 10; pos = newpos; } if (pos.Y > windowSize.Y) { newpos = pos; newpos.Y = windowSize.Y - 10; pos = newpos; } return(newpos); }
public static void CreateRadialGlow(out Texture targetTexture, uint size, Color col, float opacity = 0.2f, PennerDoubleAnimation.EquationType type = PennerDoubleAnimation.EquationType.Linear) { Image targetImage = new Image(size, size); Vector2u centerPosition = new Vector2u(size / 2, size / 2); float distanceToCenterMax = (float)Math.Sqrt(centerPosition.X * centerPosition.X + centerPosition.Y * centerPosition.Y) / 1.5f; for (uint i = 0; i != size; i++) { for (uint j = 0; j != size; j++) { Color pixelCol = col; Vector2u distanceToCenter = new Vector2u(centerPosition.X - i, centerPosition.Y - j); float distance = (float)Math.Sqrt(distanceToCenter.X * distanceToCenter.X + distanceToCenter.Y * distanceToCenter.Y); float newAlpha = 255.0f * opacity * (1.0f - (float)PennerDoubleAnimation.GetValue(type, distance, 0, 1, distanceToCenterMax)); if (newAlpha < 0.0f) { newAlpha = 0.0f; } //Console.WriteLine(newAlpha); pixelCol.A = (byte)newAlpha; targetImage.SetPixel(i, j, pixelCol); } } targetTexture = new Texture(targetImage); }
public bool load(Int32 x, Int32 y, string tileset, Vector2u tileSize, List <List <Int32> > tiles, Int32 baseMin, Int32 baseMax) { m_tileset = new Texture(tileset); _tileSize = tileSize; _baseMin = baseMin; m_vertices.PrimitiveType = PrimitiveType.Quads; for (Int32 i = 0; i < tiles.Count; ++i) { for (Int32 j = 0; j < tiles[0].Count; ++j) { if (tiles[i][j] >= baseMin && tiles[i][j] <= baseMax) { m_vertices.Append(new Vertex(new Vector2f(j * tileSize.X + x, i * tileSize.Y + y))); m_vertices.Append(new Vertex(new Vector2f((j + 1) * tileSize.X + x, i * tileSize.Y + y))); m_vertices.Append(new Vertex(new Vector2f((j + 1) * tileSize.X + x, (i + 1) * tileSize.Y + y))); m_vertices.Append(new Vertex(new Vector2f(j * tileSize.X + x, (i + 1) * tileSize.Y + y))); _tiles.Add(tiles[i][j]); } } } return(true); }
internal MouseCoordinates(Application application, EntityGameView view) { Vector2i mousePosition = Mouse.GetPosition(application.Window); View = view; if (view.Camera != null && view.Camera.View != null) { View cameraView = view.Camera.View; Vector2f viewCenter = cameraView.Center; Vector2u windowSize = application.Window.Size; Camera defaultCamera = view.Camera; Vector2f offset = new Vector2f( viewCenter.X - (windowSize.X / 2) + mousePosition.X, viewCenter.Y - (windowSize.Y / 2) + mousePosition.Y ); WorldPosition = offset.Rotate(cameraView.Rotation); WindowPosition = new Vector2f(mousePosition.X, mousePosition.Y); } else { WindowPosition = new Vector2f(mousePosition.X, mousePosition.Y); WorldPosition = WindowPosition; } }
public static void Init(Vector2u screenSize) { _screenSize = screenSize; _dynamicEffectList = new System.Collections.Generic.Dictionary <string, IScreenEffect>(); _staticEffectList = new System.Collections.Generic.Dictionary <string, IScreenEffect>(); _dynamicEffectList.Add("shake", new ScreenShakeEffect()); _dynamicEffectList.Add("fadeIn", new ScreenFlashInEffect()); _dynamicEffectList.Add("fadeOut", new ScreenFlashOutEffect()); _dynamicEffectList.Add("darkenLines", new ScreenDarkenLineEffect()); _staticEffectList.Add("scanlines", new ScreenScanLinesEffect()); _staticEffectList.Add("vignette", new ScreenVignetteEffect()); foreach (var kvp in _dynamicEffectList) { kvp.Value.Create(_screenSize); } foreach (var kvp in _staticEffectList) { kvp.Value.Create(_screenSize); } GlobalSpriteOffset = new Vector2f(0.0f, 0.0f); CreateFadeSprites(); }
private static void CreateFadeSprites() { Vector2u centerPosition = new Vector2u(_screenSize.X / 2, _screenSize.Y / 2); float distanceToCenterMax = (float)Math.Sqrt(centerPosition.X * centerPosition.X + centerPosition.Y * centerPosition.Y); Image fadeUpImage = new Image(_screenSize.X, _screenSize.Y); Image fadeDownImage = new Image(_screenSize.X, _screenSize.Y); Image fadeRadialImage = new Image(_screenSize.X, _screenSize.Y); for (uint i = 0; i != _screenSize.X; i++) { for (uint j = 0; j != _screenSize.Y; j++) { Color newCol = _fadeColor; float newAlpha = 255.0f * 0.35f * (float)(_screenSize.Y - j) / (float)(_screenSize.Y) + 0.0f; newCol.A = (byte)newAlpha; fadeUpImage.SetPixel(i, j, newCol); newAlpha = 255.0f * 0.25f * (float)(j) / (float)(_screenSize.Y) + 0.0f; newCol.A = (byte)newAlpha; fadeDownImage.SetPixel(i, j, newCol); Vector2u distanceToCenter = new Vector2u(centerPosition.X - i, centerPosition.Y - j); newAlpha = 255.0f * 0.75f * (float)Math.Sqrt(distanceToCenter.X * distanceToCenter.X + distanceToCenter.Y * distanceToCenter.Y) / distanceToCenterMax; newCol.A = (byte)newAlpha; fadeRadialImage.SetPixel(i, j, newCol); } } _fadeUpTexture = new Texture(fadeUpImage); _fadeUpSprite = new Sprite(_fadeUpTexture); _fadeDownTexture = new Texture(fadeDownImage); _fadeDownSprite = new Sprite(_fadeDownTexture); }
private void AddHearts(HeartState heartState, uint count = 1) { string imageName = string.Empty; if (heartState == HeartState.Empty) { imageName = "ui_heart_empty"; } else if (heartState == HeartState.Half) { imageName = "ui_heart_half"; } else if (heartState == HeartState.Full) { imageName = "ui_heart_full"; } Vector2u imageSize = ImageManager.Get(imageName).Size; for (int i = 0; i < count; i++) { Vector2f heartPosition = new Vector2f(Position.X + (imageSize.X * Config.TextureScale.X * hearts.Count), Position.Y); hearts.Add(new DisplayComponent(imageName, heartPosition)); } }
public InfoDisplay(Vector2f position, Vector2u size) : base(size, position) { _text = new Text("", Game.Font) { Position = new Vector2f(8, 8), CharacterSize = 16 }; _upgradeBackground = new RectangleShape(new Vector2f(size.X, Game.TileSize * 2)) { FillColor = new Color(50, 150, 60, 255), Position = new Vector2f(0, size.Y - Game.TileSize * 4) }; _upgradeText = new Text("Upgrade (U)", Game.Font) { Position = Utils.RoundV(_upgradeBackground.Position + _upgradeBackground.Size / 2), CharacterSize = 32 }; _upgradeText.Origin = Utils.RoundV(new Vector2f(_upgradeText.GetLocalBounds().Width / 2, 20)); _sellBackground = new RectangleShape(new Vector2f(size.X, Game.TileSize * 2)) { FillColor = new Color(150, 50, 50, 255), Position = new Vector2f(0, size.Y - Game.TileSize * 2) }; _sellText = new Text("Sell", Game.Font) { Position = Utils.RoundV(_sellBackground.Position + _sellBackground.Size / 2), CharacterSize = 22 }; }
public override void Init(RenderWindow window) { this.size = window.Size; this.center = new Vector2u(size.X / 2, size.Y / 2); base.RequestExtendedUpdate(); }
public void UpdatePosition() { Vector2u ss = Application.instance.ScreenSize; bg.Position = new Vector2f(16 + 4, ss.Y - 16 - 4); arrow.Position = bg.Position; }
public bool CrossedBorder() { Vector2u windowSize = Scene.Window.Size; return(Position.X - Width / 2 < 0 || Position.X + Width / 2 > windowSize.X || Position.Y - Height / 2 < 0 || Position.Y + Height / 2 > windowSize.Y); }
public Drawer() { Atlas = new Texture("rsc/atlas.png"); Prealloc_Sprite = new Sprite(Atlas); Prealloc_Text = new Text("", BasicFont, 60); Prealloc_Text.Scale = new Vector2f(0.14f, 0.14f); Prealloc_Text.OutlineColor = new Color(0, 0, 0); Prealloc_RectangleShape = new RectangleShape(); Prealloc_Vertex_2 = new Vertex[2]; Window = new RenderWindow(new VideoMode(WindowSize.X, WindowSize.Y), "Rotstein", Styles.Titlebar | Styles.Close | Styles.Resize); Window.Closed += (_, __) => Window.Close(); Window.Resized += (_, args) => { WindowSize = new Vector2u(args.Width, args.Height); View view = Window.GetView(); view.Size = new Vector2f(WindowSize.X / Scale, WindowSize.Y / Scale); Window.SetView(view); }; Window.MouseWheelScrolled += MouseWheelScrolled; Window.KeyPressed += HandleKeyPress; Window.KeyReleased += HandleKeyRelease; Window.TextEntered += HandleTextEnter; Window.MouseButtonPressed += HandleMouseButtonPress; Window.SetKeyRepeatEnabled(true); Window.SetVerticalSyncEnabled(true); Game = new Game(PLAYGROUND_SIZE); Window.SetView(new View(new Vector2f(Game.Player.Position.X + TEXTURE_SIZE / 2, Game.Player.Position.Y + 2 * TEXTURE_SIZE / 2), // Player center new Vector2f(WindowSize.X / Scale, WindowSize.Y / Scale))); }
public bool load(Vector2u tileSize, int[] tiles, uint width, uint height) { // resize the vertex array to fit the level size // m_vertices.PrimitiveType(Quads); m_vertices.Resize(width * height * 4); // populate the vertex array, with one quad per tile for (uint i = 0; i < width; ++i) { for (uint j = 0; j < height; ++j) { // get the current tile number int tileNumber = tiles[i + j * width]; // find its position in the tileset texture long tu = tileNumber % (m_tileset.Size.X / tileSize.X); long tv = tileNumber / (m_tileset.Size.X / tileSize.X); // get a pointer to the current tile's quad uint index = (i + j * width) * 4; // define its 4 corners m_vertices[index + 0] = new Vertex(new Vector2f(i * tileSize.X, j * tileSize.Y), new Vector2f(tu * tileSize.X, tv * tileSize.Y)); m_vertices[index + 1] = new Vertex(new Vector2f((i + 1) * tileSize.X, j * tileSize.Y), new Vector2f((tu + 1) * tileSize.X, tv * tileSize.Y)); m_vertices[index + 2] = new Vertex(new Vector2f((i + 1) * tileSize.X, (j + 1) * tileSize.Y), new Vector2f((tu + 1) * tileSize.X, (tv + 1) * tileSize.Y)); m_vertices[index + 3] = new Vertex(new Vector2f(i * tileSize.X, (j + 1) * tileSize.Y), new Vector2f(tu * tileSize.X, (tv + 1) * tileSize.Y)); } } return(true); }
public Map(String XML, string tilesset) { using (FileStream fs = File.OpenRead(XML)) using (StreamReader sr = new StreamReader(fs, true)) { XElement xml = XElement.Load(sr); tileheight = uint.Parse(xml.Attribute("tileheight").Value); Console.WriteLine(tileheight); tilewidth = tileheight; height = int.Parse(xml.Attribute("height").Value); width = int.Parse(xml.Attribute("width").Value); Console.WriteLine(height); /* * * IEnumerable<XAttribute> levelInfo = xml.Descendants("layer") * .Single(l => l.Attribute("name").Value == "terrain1").Attributes(); * IEnumerator<XAttribute> attributes = levelInfo.GetEnumerator(); * while (attributes.MoveNext()) * if (attributes.Current.Name == "width") width = int.Parse(attributes.Current.Value); * else if (attributes.Current.Name == "height") height = int.Parse(attributes.Current.Value); */ string level = xml.Descendants("layer") .Single((l) => { return(l.Attribute("name").Value == "terrain1"); }) .Element("data").Value; string level_layer2 = xml.Descendants("layer") .Single(l => l.Attribute("name").Value == "terrain2") .Element("data").Value; string level_layer3 = xml.Descendants("layer") .Single(l => l.Attribute("name").Value == "spawn") .Element("data").Value; string level_layer4 = xml.Descendants("layer") .Single(l => l.Attribute("name").Value == "collide") .Element("data").Value; level_array1 = level.Split(','); level_array2 = level_layer2.Split(','); level_array3 = level_layer3.Split(','); level_array4 = level_layer4.Split(','); total_array.Add(0, level_array1); total_array.Add(1, level_array2); total_array.Add(2, level_array3); total_array.Add(3, level_array4); level_layers_length = total_array.Count; tileSize = new Vector2u(tileheight, tilewidth); tileset = new Texture(tilesset); // _ctxround = ctxRound; ConstructMap(); } }
public static Texture GeneratePlanetTexture(Vector2u texSize) { var imgSize = texSize; perlin = new Perlin(random.Next(2, 3), 0.2, NoiseQuality.Best, 4, 0.7, random.Next(0, 1024)); ridgedMulti = new RidgedMulti(random.NextDouble() * 2, 0.3, 2, NoiseQuality.Best, random.Next(0, 1024)); voronoi = new Voronoi(0.1, random.NextDouble() * 2, true, random.Next(0, 1024)); selectModule = new Select(1.0, 1.0, 0.0); selectModule.SetSourceModule(0, perlin); selectModule.SetSourceModule(1, ridgedMulti); selectModule.SetSourceModule(2, voronoi); heightMapBuilder = new PlanarNoiseMapBuilder(imgSize.X, imgSize.Y, 0, selectModule, 1, 5, 1, 5, true); heightMap = heightMapBuilder.Build(); var texColors = new GradientColour(); texColors.AddGradientPoint(-1, GenerateProceduralColor()); texColors.AddGradientPoint(-0.2 + random.NextDouble() * 0.4, GenerateProceduralColor()); texColors.AddGradientPoint(1, GenerateProceduralColor()); var renderer = new ImageBuilder(heightMap, texColors); var renderedImg = renderer.Render(); var img = new Bitmap(renderedImg); var sfmlImg = new SFML.Graphics.Image(imgSize.X, imgSize.Y); for (uint x = 0; x < imgSize.X; x++) { for (uint y = 0; y < imgSize.Y; y++) { var col = img.GetPixel((int)x, (int)y); sfmlImg.SetPixel(x, y, new Color(col.R, col.G, col.B, col.A)); } } var returnTex = new Texture(sfmlImg); return returnTex; }
public cWorld(cGameScene p_scene, Vector2u window_size) { pScene = p_scene; windowSize = window_size; drawTileBounds = new cAABB(0, 0, 1, 1); m_Level1 = new cMapData(); //m_Level1.Create(100, 100); this.LoadLevel("levels/level1.txt"); //("levels/level1.txt"); m_TextureOfTiles = new RenderTexture((uint)m_WorldBounds.dims.X, (uint)m_WorldBounds.dims.Y); //(windowSize.X, windowSize.Y); m_TextureOfTiles.SetActive(true); m_TileSetTexture = cAssetManager.GetTexture("tileSet_16"); m_TileSetTexture.Smooth = true; m_BGtexture = cAssetManager.GetTexture(Constants.BG_TEXTURE); m_BGtexture.Repeated = true; m_BGtexture.Smooth = true; background = new Sprite(m_BGtexture); background.TextureRect = new IntRect(0, 0, (int)m_WorldBounds.dims.X, (int)m_WorldBounds.dims.Y); // (int)m_TextureOfTiles.Size.X, (int)m_TextureOfTiles.Size.Y); background.Color = Constants.BACKGROUND_COLOR; tempSprite = new Sprite(m_TileSetTexture); }
public static PlanetGenerator getGenerator(PlanetType type, Vector2u size, int seed) { switch (type) { case PlanetType.GasGiant: throw new NotImplementedException(); return(null); break; case PlanetType.Ice: return(new SnowGenerator(size, seed)); break; case PlanetType.Terran: return(new TerraGenerator(size, seed)); break; case PlanetType.Water: return(new BluePlanetGenerator(size, seed)); break; case PlanetType.Red: return(new RedGenerator(size, seed)); break; default: throw new NotSupportedException(); break; } }
public void PlaceTile(Vector2u v, Tile tile) { (uint x, uint y) = (v.X, v.Y); Tiles[x, y] = tile; UpdateTiles(); }
public MainMenuScreen() { // Initialize the `menuButtons` dictionary menuButtons = new Dictionary <string, UIButton>(); // Create and load the `font` used in the game font = new Font("res/fonts/font.ttf"); Vector2u windowSize = Application.Instance.Window.Size; // Initialize the `nextButtonPosition` to a start // position for the buttons nextButtonPosition = new Vector2f(windowSize.X / 2.0f, windowSize.Y / 2.0f); // Create some buttons for the menu CreateMenuButton("mainmenu.playbutton", 20, OnPlayButtonClicked); CreateMenuButton("mainmenu.customizationbutton", 20, OnCustomizeButtonClicked); CreateMenuButton("mainmenu.settingsbutton", 20, OnSettingsButtonClicked); CreateMenuButton("mainmenu.quitbutton", 20, OnQuitButtonClicked); // Create the title CreateTitle(); }
public MainMenuScreen(Vector2u gameResolution, Vector2u windowResolution) { this.GameResolution = gameResolution; this.WindowResolution = windowResolution; this.IsDrawn = true; this.IsUpdated = true; this.ParentScreen = null; //mPlayer = new MusicPlayer(); //mPlayer.add("bg", new Music(@"Content/music/never_short.ogg")); //mPlayer.currentMusic.Volume = 50; //mPlayer.currentMusic.Loop = true; //mPlayer.play(); contentManager = new ContentManager(Game1.defaultWorldParameters); IO.loadLevel(contentManager, @"Content/levels/menuLevel.xml"); backGround = new Sprite(contentManager.Media.loadTexture("Content/images/bg.jpg", true)); backGround.Scale = new Vector2f(gameResolution.X / (float)backGround.Texture.Size.X, gameResolution.Y / (float)backGround.Texture.Size.Y); lightLayer = new LightLayer(this.GameResolution, this.WindowResolution); lightLayer.add(new Light(new Vector2f(700, 350), new Color(255, 255, 200), .55f)); lightLayer.add(new Light(new Vector2f(1920 - 700, 350), new Color(255, 255, 200), .55f)); contentManager.foreceBlocks(); lightLayer.setPolygons(contentManager.getLightPolygons()); mainMenu = new MenuScreen(this, this.contentManager, null, new Vector2i(0, 0), true, true, false); mainMenu.Title.Color = Color.Black; mainMenu.ButtonColor = Color.Black; mainMenu.addButtons(new string[] { "Play", "Level Editor", "Options", "Help", "Credits", "Quit"}); mainMenu.MouseClick += mainMenu_ButtonClick; mainMenu.MouseEnter += mainMenu_MouseEnter; mainMenu.MouseLeave += mainMenu_MouseLeave; }
private void SetupGrid(Vector2u mapSize) { const int gridSize = 16; _gridTexture = new RenderTexture(2000, 2000); var col = new Color(120, 120, 120); var verticies = new List<Vertex>(); for (int x = 0; x < mapSize.X; x += gridSize) { verticies.Add(new Vertex(new Vector2f(x, 0), col)); verticies.Add(new Vertex(new Vector2f(x, mapSize.Y), col)); } for (int y = 0; y < mapSize.Y; y += gridSize) { verticies.Add(new Vertex(new Vector2f(0, y), col)); verticies.Add(new Vertex(new Vector2f(mapSize.X, y), col)); } _gridlines = verticies.ToArray(); _gridTexture.Clear(new Color(190, 190, 190)); //_view = new View(new FloatRect(0,0,displaySize.X, displaySize.Y)); _view = new View(new FloatRect(0, 0, DisplayView.Size.X, DisplayView.Size.Y)); DisplayView = _view; //_gridTexture.SetView(_view); _gridTexture.Draw(_gridlines, PrimitiveType.Lines); _gridTexture.Display(); _grid = new Sprite(_gridTexture.Texture); AddItemToDraw(_grid, 0); }
/// Is this tile active in direction "direction"? private bool IsRedActive(Vector2u v, Tile.TDirection direction) { (uint x, uint y) = (v.X, v.Y); switch (Tiles[x, y].Kind) { case Tile.TKind.RedstoneBlock: return(true); case Tile.TKind.RedstoneWire: case Tile.TKind.RedstoneBridge: return(isRedReachable(v, direction)); case Tile.TKind.NotGate: case Tile.TKind.OrGate: case Tile.TKind.AndGate: case Tile.TKind.XorGate: return((Tile.TDirectionAdd(Tiles[x, y].Direction, Tile.TDirection.North) == direction) && Tiles[x, y].Activity); case Tile.TKind.Repeater: return((Tile.TDirectionAdd(Tiles[x, y].Direction, Tile.TDirection.North) == direction) && Tiles[x, y].Variant == 4); case Tile.TKind.Lever: return(Tiles[x, y].Activity); default: return(false); } }
public Construct(uint x, uint y, MapField baseField, Color color) { Size = new Vector2u(x, y); Location = new MapFieldList(this); BaseField = baseField; color_ = color; newColor_ = color; SetTextureFromColor(); BuildJob = new ConstructingJob(this); }
public PlayerView(Vector2u displaySize) : base(displaySize) { BackgroundColor = new Color(40,40,40); playerBox = new GroupBox(GuiCanvas); playerBox.SetBounds(20, 20, displaySize.X - 40, displaySize.Y - 40); playerNameLabel = new GroupBox(playerBox); playerNameLabel.SetBounds(20, 20, 256, 32); }
void IWorldEngine.Initialise(ViewPortCollection viewports) { var area = new Vector2u( (uint)viewports.WorkingArea.Width, (uint)viewports.WorkingArea.Height); _glyphsStreams = new List<GlyphStreamManager>(); foreach (var setting in _settings.RenderLayers) { _glyphsStreams.Add(new GlyphStreamManager(setting, area)); } }
public DrawableBase(Vector2u displaySize) { toUpdate = new List<IUpdatable>(); toDraw = new Dictionary<uint, List<Drawable>>(); _targetSpr = new Sprite(); BackgroundColor = Color.Transparent; Target = new RenderTexture(displaySize.X, displaySize.Y) { Smooth = true }; }
public override void createWindow(SFML.Window.VideoMode mode, string title, SFML.Window.Styles styles, SFML.Window.ContextSettings context) { if (fullScreen) { screenResolution = new Vector2u(VideoMode.DesktopMode.Width, VideoMode.DesktopMode.Height); styles = Styles.None; } else { styles = Styles.Close; } //context.AntialiasingLevel = 4; title = "Platformer"; mode = new VideoMode(Game1.screenResolution.X, Game1.screenResolution.Y); base.createWindow(mode, title, styles, context); }
public GlyphStreamManager(GlyphStreamManagerConfig settings, Vector2u workingArea) { _workingArea = workingArea.ToRectangle(); streams = new List<GlyphStream>(); _settings = settings; if (!string.IsNullOrEmpty(settings.ShaderType)) // TODO: configurable shader { shader = ShaderWrapper.Get(settings.ShaderType); tempCanvas = new RenderTexture(workingArea.X, workingArea.Y, true); tempCanvas.Display(); } _maximumStreams = settings.MaximumGlyphStreams; _chanceOfNewStream = settings.ChanceOfNewGlyphStream; }
public SpaceMap(Vector2u mapSize, Vector2u displaySize) : base(displaySize) { SetupGrid(mapSize); OnLostFocus += SpaceGrid_OnLostFocus; OnMouseMove += SpaceGrid_OnMouseMove; OnMousePress += SpaceGrid_OnMousePress; OnMouseRelease += SpaceGrid_OnMouseRelease; OnKeyPress += SpaceGrid_OnKeyPress; var planet = new Planet(new Vector2u(80, 80)); planet.Position = new Vector2f(40, 120); planet.EventSubscribe(true, PEGame.ActiveGame.Window); AddItemToDraw(planet, 1); }
public static bool SpritePixelHit(Sprite toCheck, Vector2f clickPos) { var clickPoint = new Vector2f(clickPos.X, clickPos.Y); if (!toCheck.GetLocalBounds().Contains(clickPoint.X, clickPoint.Y)) return false; var spritePosition = new Vector2u((uint) clickPos.X - (uint) toCheck.Position.X ,//+ (int) toCheck.ImageOffset.X, (uint) clickPos.Y - (uint) toCheck.Position.Y ); //+ (int) toCheck.ImageOffset.Y); Image imgData = toCheck.Texture.CopyToImage(); //imgData.Lock(false); Color pixColour = imgData.GetPixel(spritePosition.X, spritePosition.Y); imgData.Dispose(); //imgData.Unlock(); return pixColour.A != 0; }
public SpriteSheet(Texture source, Vector2u spriteSize) { this.source = source; this.size = spriteSize; uint w = source.Size.X / size.X; uint h = source.Size.Y / size.Y; var scale = v2f(1F / size.X, 1F / size.Y); Sprites = new Sprite[w * h]; for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { IntRect rect = new IntRect(v2i((int)(x * size.X), (int)(y * size.Y)), v2i((int)size.X, (int)size.Y)); var s = new Sprite(source, rect); s.Scale = scale; Sprites[y * w + x] = s; } } }
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 Planet(Vector2u displaySize) : base(displaySize) { _planet = new CircleShape(0.9f*displaySize.X / 2f, 4 + 2 * (uint)Math.Sqrt(displaySize.X)) { Position = new Vector2f(1.1f*displaySize.X/2f, 1.1f*displaySize.Y/2f), OutlineThickness = 3, OutlineColor = new Color(20, 20, 20), Origin = new Vector2f(displaySize.X / 2f, displaySize.Y / 2f) }; //_planet.FillColor = SFML.Graphics.Color.Magenta; _planet.Texture = GeneratePlanetTexture(new Vector2u((uint)_planet.Radius, (uint)_planet.Radius)); AddItemToDraw(_planet, 5); //_hoverText = new Label("Planet", FontManager.ActiveFontManager, new Vector2u(100, 40)); OnMouseMove += Planet_OnMouseMove; }
public PSSGame(Vector2u screenSize) : base(screenSize) { worldDB = new WorldDatabase(); }
public static void LayoutSprite(Sprite sprite, Vector2i pos, Vector2u size, IntRect screenrect) { LayoutSprite(sprite, (int)pos.X, (int)pos.Y, (int)size.X, (int)size.Y, screenrect); }
public static void LayoutControl(UI.Control ctrl, Vector2u pos, int width, int height, IntRect screenrect) { LayoutControl(ctrl, (int)pos.X, (int)pos.Y, width, height, screenrect); }
public static void LayoutControl(UI.Control ctrl, int x, int y, Vector2u size, IntRect screenrect) { LayoutControl(ctrl, x, y, (int)size.X, (int)size.Y, screenrect); }
public static void LayoutControl(UI.Control ctrl, Vector2u pos, Vector2u size, IntRect screenrect) { LayoutControl(ctrl, (int)pos.X, (int)pos.Y, (int)size.X, (int)size.Y, screenrect); }
public static void LayoutSprite(Sprite sprite, Vector2u pos, int width, int height, IntRect screenrect) { LayoutSprite(sprite, (int)pos.X, (int)pos.Y, width, height, screenrect); }
public Display(Vector2u displaySize) : base(displaySize) { }
public static void Read(Stream stream, out Vector2u value) { var buffer = new byte[sizeof(uint)]; stream.Read(buffer, 0, buffer.Length); var x = BitConverter.ToUInt32(buffer, 0); stream.Read(buffer, 0, buffer.Length); var y = BitConverter.ToUInt32(buffer, 0); value = new Vector2u(x, y); }
private static extern void sfRenderWindow_setSize(IntPtr CPointer, Vector2u size);
public TileEntity(string path, Vector2u tileindex, Vector2f position = new Vector2f(), int depth = 0) : this(path, tileindex.X, tileindex.Y, position, depth) { }
public PEGame(Vector2u screensize) { ActiveGame = this; Screensize = screensize; }
public static void Write(Stream stream, Vector2u value) { stream.Write(BitConverter.GetBytes(value.X), 0, sizeof(uint)); stream.Write(BitConverter.GetBytes(value.Y), 0, sizeof(uint)); }
public static void LayoutSprite(Sprite sprite, int x, int y, Vector2u size, IntRect screenrect) { LayoutSprite(sprite, x, y, (int)size.X, (int)size.Y, screenrect); }
static extern void sfWindow_setSize(IntPtr CPointer, Vector2u size);
public static uint Dot(this Vector2u left, Vector2u right) { return left.X * right.X + left.Y * right.Y; }