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); }
cQuadTree <T> pSE; //south-east : right-bottom //sfml text //Text m_Text; public cQuadTree(int _level, cAABB _bounds) { this.level = _level; this.bounds = _bounds; this.shape = new RectangleShape(bounds.dims); this.shape.Position = bounds.topLeft; this.shape.OutlineColor = Color.Red; this.shape.FillColor = Color.Transparent; this.shape.OutlineThickness = 1.0f; entities = new List <T>(); label = new Text(); float xPos = bounds.rightBottom.X - level * 50; label.Position = new Vector2f(xPos, bounds.rightBottom.Y - 30); label.Font = cAssetManager.GetFont("BGOTHL"); label.CharacterSize = 24; label.Color = Color.White; label.Style = Text.Styles.Bold; SplitToRects(); }
/* * public void renderDynamicLightsToTexture() * { * dynamicLightTexture.Clear(m_ClearColor); * * for (int i = 0; i < dynamicLights.Count; ++i) * { * renderALight(dynamicLights[i], dynamicLightTexture); * } * * dynamicLightTexture.Display(); * * } */ public void Render(RenderTarget destination, cAABB viewRect) { //destination.Draw(this.lightMapDarkShape, new RenderStates(BlendMode.Multiply)); renderStaticLightsToTexture(viewRect); //cRenderFunctions.DrawTextureSimple(destination, new Vector2f(), m_LightTexture.Texture, new IntRect(0,0, (int)m_LightTexture.Size.X, (int)m_LightTexture.Size.Y),Color.White, BlendMode.Multiply); cRenderFunctions.DrawTextureSimple(destination, viewRect.topLeft, staticLightTexture.Texture, new IntRect(0, 0, (int)this.staticLightTexture.Size.X, (int)this.staticLightTexture.Size.Y), //new IntRect((int)view_rect.topLeft.X, (int)view_rect.topLeft.Y, // (int)view_rect.dims.X, (int)view_rect.dims.Y), Color.White, BlendMode.Multiply); /* renderDynamicLightsToTexture(); * * cRenderFunctions.DrawTextureSimple(destination, * view_rect.topLeft, * dynamicLightTexture.Texture, * new IntRect((int)view_rect.topLeft.X, (int)view_rect.topLeft.Y, * (int)view_rect.dims.X, (int)view_rect.dims.Y), * Color.White, * BlendMode.Multiply); */ }
public int[] getPossibleCollidableObjects(cAABB bounds) { List <int> all = new List <int>(); int topLeftIndex = GetCellIndexAtWorldPos(bounds.topLeft); int topRightIndex = GetCellIndexAtWorldPos(bounds.getTopRight()); int bottomRightIndex = GetCellIndexAtWorldPos(bounds.rightBottom); int bottomLeftIndex = GetCellIndexAtWorldPos(bounds.getLeftBottom()); if (topLeftIndex == bottomRightIndex) { all.AddRange(grid[topLeftIndex].getAll()); } else { if (topLeftIndex == bottomLeftIndex || bottomLeftIndex == bottomRightIndex) { all.AddRange(grid[topLeftIndex].getAll()); all.AddRange(grid[bottomRightIndex].getAll()); } else { all.AddRange(grid[topLeftIndex].getAll()); all.AddRange(grid[topRightIndex].getAll()); all.AddRange(grid[bottomRightIndex].getAll()); all.AddRange(grid[bottomLeftIndex].getAll()); } } return(all.ToArray()); }
public void HandleObject(int id, cAABB bounds) { int topLeftIndex = GetCellIndexAtWorldPos(bounds.topLeft); int topRightIndex = GetCellIndexAtWorldPos(bounds.getTopRight()); int bottomRightIndex = GetCellIndexAtWorldPos(bounds.rightBottom); int bottomLeftIndex = GetCellIndexAtWorldPos(bounds.getLeftBottom()); if (topLeftIndex == bottomRightIndex) { grid[topLeftIndex].add(id); } else { if (topLeftIndex == bottomLeftIndex || bottomLeftIndex == bottomRightIndex) { grid[topLeftIndex].add(id); grid[bottomRightIndex].add(id); } else { grid[topLeftIndex].add(id); grid[topRightIndex].add(id); grid[bottomRightIndex].add(id); grid[bottomLeftIndex].add(id); } } }
public List <cAABB> getCollidableBlocks(cAABB with) { List <cAABB> boxes = new List <cAABB>(); const int offset = 1; //def: 1 //Vector2i ctile = ToMapPos(with.center); Vector2i minTile = ToMapPos(with.topLeft); Vector2i maxTile = ToMapPos(with.rightBottom); //int lastTileID = -1; for (int y = minTile.Y - offset; y <= maxTile.Y + offset; y++) { for (int x = minTile.X - offset; x <= maxTile.X + offset; x++) { if (y >= 0 && x >= 0 && y < this.m_Level1.Height && x < this.m_Level1.Width) { cTile tile = this.GetCurrentLevel().GetTileAtXY(x, y); TileType tt = tile.Type; //int tid = tile.IdCode; if (/*lastTileID != tid &&*/ (tt == TileType.WALL || tt == TileType.ONEWAY_PLATFORM)) { // tile.PlayerCollidable = true; //lastTileID = tid; boxes.Add(this.getAABBFromMapPos(new Vector2i(x, y))); } } } } return(boxes); }
public cAABB getBoundingBox() { cAABB b = new cAABB(); b.SetDims(Dims); b.SetPosByCenter(Pos); return(b); }
public void LoadLevel(string file_name) { m_Level1.LoadFromFile(file_name); m_WorldBounds = new cAABB(0.0f, 0.0f, m_Level1.Width * Constants.TILE_SIZE, m_Level1.Height * Constants.TILE_SIZE); initTileSprites(); }
public void renderStaticLightsToTexture(cAABB viewRect) { staticLightTexture.Clear(m_ClearColor); foreach (cLight light in this.visibleLights) { renderALight(light, staticLightTexture, viewRect); } staticLightTexture.Display(); }
public static void DrawRectangleShape(RenderTarget destination, cAABB bounds, Color color, BlendMode blend_mode, double orientation = 0.0) { RenderStates states = new RenderStates(blend_mode); RectangleShape rs = new RectangleShape(bounds.dims); rs.Rotation = (float)orientation; rs.Position = bounds.topLeft; rs.FillColor = color; destination.Draw(rs, states); }
public void separateVisibleLights(cAABB viewRect) { visibleLights.Clear(); float viewRadius = (float)Math.Sqrt((viewRect.dims.X * viewRect.dims.X) + (viewRect.dims.Y * viewRect.dims.Y)); foreach (cLight light in staticLights) { if (cCollision.testCircleVsCirlceOverlap(light.Pos, light.Radius, viewRect.center, viewRadius)) { visibleLights.Add(light); } } }
public List <IDrawable> ListVisibles(cAABB view_region) { List <IDrawable> visibleObjects = new List <IDrawable>(); for (int i = 0; i < bullets.Count; i++) { if (cCollision.OverlapAABB(bullets[i].Bounds, view_region)) { visibleObjects.Add(bullets[i]); } } return(visibleObjects); }
private void recalculateDrawBounds(cAABB viewRect) { drawTileBounds = viewRect.ShallowCopy(); drawTileBounds.topLeft.X = (float)Math.Floor((drawTileBounds.topLeft.X / Constants.TILE_SIZE) - 1); drawTileBounds.topLeft.Y = (float)Math.Floor((drawTileBounds.topLeft.Y / Constants.TILE_SIZE) - 1); drawTileBounds.rightBottom.X = (float)Math.Ceiling((drawTileBounds.rightBottom.X / Constants.TILE_SIZE) + 1); drawTileBounds.rightBottom.Y = (float)Math.Ceiling((drawTileBounds.rightBottom.Y / Constants.TILE_SIZE) + 1); drawTileBounds.topLeft.X = Math.Max(drawTileBounds.topLeft.X, 0.0f); drawTileBounds.topLeft.Y = Math.Max(drawTileBounds.topLeft.Y, 0.0f); drawTileBounds.rightBottom.X = Math.Min(drawTileBounds.rightBottom.X, m_Level1.Width); drawTileBounds.rightBottom.Y = Math.Min(drawTileBounds.rightBottom.Y, m_Level1.Height); }
public cWaterBlock(cAABB area) { this.area = area.ShallowCopy(); int divider = Constants.TILE_SIZE; // / 2 DIVISION = (int)(this.area.dims.X / divider); unitLength = divider; // this.area.dims.X / (float)DIVISION; vertices = new VertexArray(PrimitiveType.TrianglesStrip); waterNodes = new List <cWaterNode>(); Init(); }
public void Render(RenderTarget destination, cAABB view_rect) { recalculateDrawBounds(view_rect); renderTilesToTexture(destination); /* * FloatRect ft = view_rect.AsFloatRect(); * Vector2f pos = new Vector2f(ft.Left, ft.Top); * * cRenderFunctions.DrawTextureSimple(destination, * m_WorldBounds.topLeft + pos, * m_TextureOfTiles.Texture, * new IntRect((int)pos.X, (int)pos.Y, (int)ft.Width, (int)ft.Height), //(int)m_TextureOfTiles.Texture.Size.X, (int)m_TextureOfTiles.Texture.Size.Y), //20, 20, 200, 200), * Color.White, * BlendMode.Add); */ }
private void renderALight(cLight light, RenderTarget target, cAABB viewRect) { /* * Vector3f glColor = new Vector3f(0, 0, 0); * glColor.X = ((float)light.Color.R / 255.0f); * glColor.Y = ((float)light.Color.G / 255.0f); * glColor.Z = ((float)light.Color.B / 255.0f); */ Vector2f newPos = new Vector2f(light.Pos.X - viewRect.topLeft.X, light.Pos.Y - viewRect.topLeft.Y); m_AutenuationShader.SetParameter("lightPos", newPos.X, target.Size.Y - newPos.Y); m_AutenuationShader.SetParameter("lightColor", light.GLcolor.X, light.GLcolor.Y, light.GLcolor.Z); m_AutenuationShader.SetParameter("radius", light.Radius); m_AutenuationShader.SetParameter("bleed", light.Bleed); m_AutenuationShader.SetParameter("linearizeFactor", light.LinearizeFactor); cRenderFunctions.DrawDirLightByDVec(target, newPos, light.Radius, light.Dir, light.SpreadAngle, light.Color, BlendMode.Add, m_AutenuationShader); /* * Vector2f newPos = new Vector2f(); * newPos.X = light.Pos.X - viewRect.topLeft.X; //(light.Pos.X / defaultTarget.Size.X) * target.Size.X; * newPos.Y = light.Pos.Y - viewRect.topLeft.Y;//(light.Pos.Y / defaultTarget.Size.Y) * target.Size.Y; * * lightSprite.Position = new Vector2f(light.Pos.X - viewRect.topLeft.X, light.Pos.Y - viewRect.topLeft.Y); * lightSprite.Color = light.Color; * * float scale = 1.0f + (light.Radius / (lightTexture.Size.X /2.0f)); * lightSprite.Scale = new Vector2f(scale, scale); * * * // BlendMode bm = new BlendMode(BlendMode.Factor.Zero, BlendMode.Factor.DstColor, BlendMode.Equation.Add, * // BlendMode.Factor.Zero, BlendMode.Factor.OneMinusSrcAlpha, BlendMode.Equation.Add); * * target.Draw(lightSprite, new RenderStates(BlendMode.Add)); */ }
protected cAABB bounds; //may differ from drawing bounds public cEnvironmentItem(Texture texture) { sprite = new Sprite(texture); bounds = new cAABB(); }
/// <summary> /// Itt választjuk ki és állítjuk be előre a kirjazoláshoz, hogy melyik csempéhez milyen al-textúra tartozik (több féle fal van, attól függ, hol és hány másik fal kapcsolódik az adott falhoz) /// </summary> private void initTileSprites() { cTile tempTile = null; Vector2i tilePos = new Vector2i(); Vector2f tileCenterTop = new Vector2f(); for (int y = 0; y < m_Level1.Height; y++) { for (int x = 0; x < m_Level1.Width; x++) { tempTile = m_Level1.GetTileAtXY(x, y); tilePos.X = x; tilePos.Y = y; tileCenterTop = this.ToWorldPos(tilePos); tileCenterTop.X += Constants.TILE_SIZE_HALF; tileCenterTop.Y += Constants.TILE_SIZE_HALF; tempTile.PosOnTexture = TileMask.NONE; if (tempTile.Type == TileType.WALL) { NeighInfo info = getNumOfLinearNeighsByCode(m_Level1, tilePos, TileType.WALL); if (info.NumNeighs == 1) { /* cLight l = cLightSystem.GetEnvironLight(tileCenterTop, 32.0f, Color.White); * l.Bleed = 1.6f; * l.LinearizeFactor = 0.4f; * l.Color = new Color(246, 205, 105, 255); * pScene.LightMap.AddStaticLight(l);*/ } if (info.isAlone()) { tempTile.PosOnTexture = TileMask.ALONE_BOT_WITH_TOP; // alone; /* cLight l = cLightSystem.GetEnvironLight(tileCenterTop, 32.0f, Color.White); * l.Bleed = 1.6f; * l.LinearizeFactor = 0.4f; * l.Color = new Color(246, 205, 105, 255); * pScene.LightMap.AddStaticLight(l);*/ } else { //egyedül van-e if (!info.HasTop) { if (!info.HasBottom) { if (!info.HasLeft) { tempTile.PosOnTexture = TileMask.NO_TOPBOT_LEFT; } else if (!info.HasRight) { tempTile.PosOnTexture = TileMask.NO_TOPBOT_RIGHT; } else { tempTile.PosOnTexture = TileMask.NO_TOPBOT_MIDDLE; } } else { if (info.HasLeft) { if (info.HasRight) { tempTile.PosOnTexture = TileMask.TOP_MIDDLE; } else { tempTile.PosOnTexture = TileMask.TOP_RIGHT; } } else { if (info.HasRight) { tempTile.PosOnTexture = TileMask.TOP_LEFT; } else { tempTile.PosOnTexture = TileMask.ALONE_TOP_WITH_BOT; } } } } else if (!info.HasBottom) { if (info.HasLeft) { if (info.HasRight) { tempTile.PosOnTexture = TileMask.BOTTOM_MIDDLE; } else { tempTile.PosOnTexture = TileMask.BOTTOM_RIGHT; } } else { if (info.HasRight) { tempTile.PosOnTexture = TileMask.BOTTOM_LEFT; } else { tempTile.PosOnTexture = TileMask.ALONE_BOT_WITH_TOP; } } } else if (!info.HasLeft) { if (info.HasRight) { tempTile.PosOnTexture = TileMask.MIDDLE_LEFT; } else { tempTile.PosOnTexture = TileMask.ALONE; } } else if (!info.HasRight) { tempTile.PosOnTexture = TileMask.MIDDLE_RIGHT; } else { tempTile.PosOnTexture = TileMask.MIDDLE_CENTRE; //tempTile.PosOnTexture = TileMask.EMPTY; //looks weird } } } else if (tempTile.Type == TileType.EMPTY) { } else if (tempTile.Type == TileType.ONEWAY_PLATFORM) { tempTile.PosOnTexture = TileMask.ONE_WAY_PLATFORM; /* * cLight l = cLightSystem.GetEnvironLight(tileCenterTop, 32.0f, Color.White); * l.Bleed = 2.6f; * l.LinearizeFactor = 0.3f; * pScene.LightMap.AddStaticLight(l);*/ //pScene.LightMap.AddStaticLight(cLightSystem.GetEnvironLight(this.ToWorldPos(tilePos), 50.0f, Color.Yellow)); } else if (tempTile.Type == TileType.LEVEL_START) { //top-left Vector2f levelStartGroundPos = this.ToWorldPos(new Vector2i(x, y)); Texture t = cAssetManager.GetTexture("door1_sm"); Vector2f textureSize = new Vector2f(t.Size.X, t.Size.Y); cAABB bounds = pScene.WolrdEnv.CalcBBOnGroundByTexture(levelStartGroundPos, textureSize); Vector2f texturePos = bounds.topLeft; bounds.Scale(new Vector2f(0.8f, 0.8f), new Vector2f(bounds.center.X, bounds.rightBottom.Y)); levelStartRegion = bounds; pScene.WolrdEnv.PlaceOnGround(texturePos, t, bounds); pScene.LightMap.AddStaticLight(cLightSystem.GetEnvironLight(bounds.center, bounds.halfDims.X * 3.0f, Color.Green)); } else if (tempTile.Type == TileType.LEVEL_END) { //top-left Vector2f levelEndGroundPos = this.ToWorldPos(new Vector2i(x, y)); Texture t = cAssetManager.GetTexture("door1_sm"); Vector2f textureSize = new Vector2f(t.Size.X, t.Size.Y); cAABB bounds = pScene.WolrdEnv.CalcBBOnGroundByTexture(levelEndGroundPos, textureSize); Vector2f texturePos = bounds.topLeft; bounds.Scale(new Vector2f(0.8f, 0.8f), new Vector2f(bounds.center.X, bounds.rightBottom.Y)); levelEndRegion = bounds; pScene.WolrdEnv.PlaceOnGround(texturePos, t, bounds); pScene.LightMap.AddStaticLight(cLightSystem.GetEnvironLight(bounds.center, bounds.halfDims.X * 3.0f, Color.Red)); } } } }
public cQuadTreeOccupant() { bounds = new cAABB(0, 0, 0, 0); }
public cQuadTreeOccupant(cAABB _bounds) { bounds = _bounds.ShallowCopy(); }
public override void Enter() { Vector2f worldSize = new Vector2f(m_AppController.MainWindow.Size.X, m_AppController.MainWindow.Size.Y); m_View.Size = new Vector2f(worldSize.X, worldSize.Y); m_View.Center = new Vector2f(worldSize.X / 2.0f, worldSize.Y / 2.0f); m_View.Viewport = new FloatRect(0.0f, 0.0f, 1.0f, 1.0f); m_View.Zoom(0.6f); //0.6f m_AppController.MainWindow.SetView(m_View); viewRect = new cAABB(); viewRect.SetDims(m_View.Size); worldEnvironment = new cEnvironment(); // Constants.LIGHTMAP_COLOR lightMap = new cLightSystem(Constants.LIGHTMAP_COLOR); //((uint)m_World.WorldBounds.dims.X, (uint)m_World.WorldBounds.dims.Y, Constants.LIGHTMAP_COLOR); m_World = new cWorld(this, m_AppController.MainWindow.Size); //lightMap.Create((uint)m_World.WorldBounds.dims.X, (uint)m_World.WorldBounds.dims.Y); lightMap.Create(m_AppController.MainWindow.Size.X, m_AppController.MainWindow.Size.Y); this.staticTexture = new RenderTexture((uint)m_World.WorldBounds.dims.X, (uint)m_World.WorldBounds.dims.Y); this.staticTexture.SetActive(true); this.staticTexture.Clear(new Color(0, 0, 0, 0)); //this.staticTexture.SetView(m_View); Vector2f playerStart = new Vector2f(m_World.LevelStartRegion.center.X, m_World.LevelStartRegion.rightBottom.Y); playerStart.X -= Constants.CHAR_FRAME_WIDTH / 2.0f; playerStart.Y -= Constants.CHAR_FRAME_HEIGHT; m_Player = new cPlayer(this, playerStart); entityPool = new cEntityPool(this, m_World.WorldBounds.dims, m_Player); //vizekhez adunk fényt List <cWaterBlock> waterBlocks = m_World.GetWaterBlocks(); foreach (cWaterBlock wb in waterBlocks) { cLight waterLight = new cLight(); //víz blokkokhoz adunk fényt, mert jól néz ki waterLight.Pos = new Vector2f(wb.Area.center.X, wb.Area.topLeft.Y + Constants.TILE_SIZE / 2.0f); waterLight.Radius = (wb.Area.dims.X + wb.Area.dims.Y) * 0.8f; waterLight.Bleed = 0.00001f; // 0.00001f; waterLight.LinearizeFactor = 0.95f; waterLight.Color = new Color(41, 174, 232); // 96,156,164 lightMap.AddStaticLight(waterLight); } //háttér, környezeti tárgyak megjelenítése worldEnvironment.SetWaterBlocks(waterBlocks); this.particleManager = new cParticleManager(this); // lightMap.renderStaticLightsToTexture(); gameCommands = new Queue <Action>(50); //Pálya idő start levelTimer.Start(); }
public bool onScreen(cAABB box) { return(cCollision.OverlapAABB(this.viewRect, box)); }
public void PlaceOnGround(Vector2f texture_pos, Texture texture, cAABB bounding_rect) { cEnvironmentItem item = new cEnvironmentItem(texture_pos, texture, bounding_rect); envItems.Add(item); }
public cEnvironmentItem(Vector2f pos, Texture texture, cAABB _bounds = null) { sprite = new Sprite(texture); sprite.Position = pos; bounds = _bounds ?? new cAABB(pos, new Vector2f(texture.Size.X, texture.Size.Y)); }
public void DeHandleObject(int id, cAABB last_bounds) { }