public override void onActionPerformed(Button button) { if (button.Id == 0) { EvolvinaryMain.get().openGui(null); } }
private void loadChunks() { var texture = EvolvinaryMain.loadContent <Texture2D>("Maps/" + this.Name); var data = new Color[texture.Width * texture.Height]; texture.GetData(data); var chunkAmountX = toChunkCoord(texture.Width); var chunkAmountY = toChunkCoord(texture.Height); this.chunks = new Chunk[chunkAmountX, chunkAmountY]; for (var x = 0; x < chunkAmountX; x++) { for (var y = 0; y < chunkAmountY; y++) { this.chunks[x, y] = new Chunk(this, x, y); } } for (var x = 0; x < texture.Width; x++) { for (var y = 0; y < texture.Height; y++) { var color = data[x + y * texture.Width]; var tile = GameData.getTileByColor(color); this.setTile(x, y, tile); } } }
public override void update(GameTime time) { base.update(time); if (this.FadeTime < 256) { this.FadeTime += MathHelp.ceil((256 - this.FadeTime) / 10D); if (this.FadeTime >= 256) { if (this.ShouldClose) { EvolvinaryMain.get().openGui(null); } else { this.ButtonList.Add(new ButtonTextOnly(1, this, 60, 30, 150, 20, "Save Game", 2F)); this.ButtonList.Add(new ButtonTextOnly(2, this, 60, 80, 150, 20, "Load Game", 2F)); this.ButtonList.Add(new ButtonTextOnly(3, this, 60, 130, 150, 20, "Start New Game", 2F)); this.ButtonList.Add(new ButtonTextOnly(4, this, 60, 180, 150, 20, "Options", 2F)); this.ButtonList.Add(new ButtonTextOnly(5, this, 60, 230, 150, 20, "To Title Screen", 2F)); this.ButtonList.Add(new ButtonTextOnly(6, this, 60, 280, 150, 20, "Quit Game", 2F)); this.hasButtons = true; } } } }
private void openIngame() { var ingame = new GuiIngame(this.CurrentPlayer); EvolvinaryMain.get().openGui(ingame); ingame.setSelectedEntity(this.SelectedEntity); }
public static void init() { var game = EvolvinaryMain.get(); WhiteGradient = new Texture2D(game.GraphicsDevice, 256, 128); var gradientData = new Color[WhiteGradient.Width * WhiteGradient.Height]; for (var x = 0; x < WhiteGradient.Width; x++) { for (var y = 0; y < WhiteGradient.Height; y++) { gradientData[x + y * WhiteGradient.Width] = new Color(1F, 1F, 1F, 1F - x / ((float)WhiteGradient.Width + 50)); } } WhiteGradient.SetData(gradientData); TranslucentWhite = new Texture2D(game.GraphicsDevice, game.RenderManager.getScreenWidth(), game.RenderManager.getScreenHeight()); var translucentData = new Color[TranslucentWhite.Width * TranslucentWhite.Height]; for (var i = 0; i < translucentData.Length; i++) { translucentData[i] = new Color(1F, 1F, 1F, 0.5F); } TranslucentWhite.SetData(translucentData); SolidWhite = new Texture2D(game.GraphicsDevice, game.RenderManager.getScreenWidth(), game.RenderManager.getScreenHeight()); var whiteData = new Color[SolidWhite.Width * SolidWhite.Height]; for (var i = 0; i < whiteData.Length; i++) { whiteData[i] = new Color(1F, 1F, 1F, 1F); } SolidWhite.SetData(whiteData); }
public RenderManager(EvolvinaryMain game) { this.Graphics = new GraphicsDeviceManager(game); this.game = game; this.Graphics.PreferredBackBufferWidth = 1280; this.Graphics.PreferredBackBufferHeight = 720; this.game.IsMouseVisible = true; }
public void loadContent() { this.Batch = new SpriteBatch(this.game.GraphicsDevice); this.TileTexture = EvolvinaryMain.loadContent <Texture2D>("Textures/Tiles"); this.StaticEntityTexture = EvolvinaryMain.loadContent <Texture2D>("Textures/Entities/Static"); this.NormalFont = EvolvinaryMain.loadContent <SpriteFont>("Fonts/Normal"); GraphicsHelper.init(); }
public void draw(RenderManager manager, GameTime time) { var cam = EvolvinaryMain.get().Camera; var entities = new List <Entity>(); //top left culling var chunkStart = Vector2.Max(Vector2.Zero, cam.toWorldPos(Vector2.Zero)); var chunkStartX = World.toChunkCoord(MathHelp.floor(chunkStart.X)); var chunkStartY = World.toChunkCoord(MathHelp.floor(chunkStart.Y)); //bottom right culling var chunkEnd = cam.toWorldPos(new Vector2(manager.getScreenWidth(), manager.getScreenHeight())); var chunkEndX = Math.Min(this.world.getChunkSizeX() - 1, World.toChunkCoord(MathHelp.floor(chunkEnd.X))); var chunkEndY = Math.Min(this.world.getChunkSizeY() - 1, World.toChunkCoord(MathHelp.floor(chunkEnd.Y))); for (var chunkX = chunkStartX; chunkX <= chunkEndX; chunkX++) { for (var chunkY = chunkStartY; chunkY <= chunkEndY; chunkY++) { var chunk = this.world.getChunkFromChunkCoords(chunkX, chunkY); for (var y = 0; y < Chunk.Size; y++) { for (var x = 0; x < Chunk.Size; x++) { var tile = chunk.getTile(x, y); if (tile.Renderer != null) { var pos = new Vector2(chunkX * Chunk.Size + x, chunkY * Chunk.Size + y); tile.Renderer.draw(tile, pos * Tile.Size, manager, time); } } } if (chunk.Entities.Count > 0) { entities.AddRange(chunk.Entities); } } } if (entities.Count > 0) { entities.Sort(EntityComparer.Instance); foreach (var entity in entities) { if (entity.CurrentRenderer != null) { entity.CurrentRenderer.draw(entity, entity.Pos * Tile.Size, manager, time); } } } }
public override void onActionPerformed(Button button) { switch (button.Id) { case 0: this.onTryClose(); break; case 6: EvolvinaryMain.get().Exit(); break; } }
public static void update(GameTime time, EvolvinaryMain game) { foreach (var bind in KeyBindings) { bind.update(); } game.Camera.checkInputs(); var scroll = getMouseWheel(); currentScrollDelta = scroll - lastScroll; lastScroll = scroll; }
public override bool onMousePress(MouseSetting mouse) { if (!base.onMousePress(mouse)) { if (mouse == InputProcessor.LeftMouse && this.canMoveCamera()) { var selected = this.List.getSelectedComponent() as ListComponentItem; if (selected != null) { var stack = selected.getStack(); if (stack != null) { var entity = stack.getHeldEntity(); if (entity != null) { var pos = EvolvinaryMain.get().Camera.toWorldPos(InputProcessor.getMousePos().ToVector2()); if (entity.canPlace(GameData.MainPlayer, GameData.WorldTest, pos)) { entity.place(GameData.MainPlayer, GameData.WorldTest, pos); stack.Amount--; if (stack.Amount <= 0) { selected.removeStack(); this.List.removeComponent(selected); } if (!InputProcessor.Shift.IsDown) { this.List.unselectAllExcept(null); } return(true); } } } } } return(false); } this.List.unselectAllExcept(null); return(true); }
public void checkInputs() { var game = EvolvinaryMain.get(); if (game.IsActive && game.CurrentGui.canMoveCamera()) { var shouldReloadMatrix = false; var mouseX = InputProcessor.getMouseX(); var mouseY = InputProcessor.getMouseY(); if (this.lastX != mouseX || this.lastY != mouseY) { if (InputProcessor.RightMouse.IsDown) { this.pos.X -= mouseX - this.lastX; this.pos.Y -= mouseY - this.lastY; shouldReloadMatrix = true; } this.lastX = mouseX; this.lastY = mouseY; } var delta = InputProcessor.getScrollDelta(); var zoomDiff = delta / 1000F; var newZoom = Math.Max(0.5F, Math.Min(10F, this.Zoom + zoomDiff * this.Zoom)); if (newZoom != this.Zoom) { var zoomChange = 1 - newZoom / this.Zoom; this.pos.X -= (this.pos.X + mouseX) * zoomChange; this.pos.Y -= (this.pos.Y + mouseY) * zoomChange; this.Zoom = newZoom; shouldReloadMatrix = true; } if (shouldReloadMatrix) { this.reloadMatrix(); } } }
public override void update(GameTime time) { base.update(time); if (this.selectableEntities.Count > 0) { foreach (var entry in this.selectableEntities) { var pos = EvolvinaryMain.get().Camera.toCameraPos(entry.Value.Pos) / Scale; var button = entry.Key; button.Area.X = (int)pos.X; button.Area.Y = (int)pos.Y; } } if (this.SelectionGui != null) { this.SelectionGui.update(time); } }
private void openSubGui(GuiSelection gui) { if (this.SelectionGui != null) { this.SelectionGui.onClosed(); } var renderer = EvolvinaryMain.get().RenderManager.CurrentGuiRenderer as GuiRendererIngame; if (renderer != null) { renderer.openSubGui(gui == null ? null : gui.getRenderer()); } this.SelectionGui = gui; if (this.SelectionGui != null) { this.SelectionGui.onOpened(); } }
public static void drawHoveringOverlay(SpriteBatch batch, string text, int x, int y, Color color, int length, bool canGoOffScreen) { var font = EvolvinaryMain.get().RenderManager.NormalFont; var lineHeight = font.LineSpacing; var split = splitTextToLength(text, font, length); var longestLength = 0; foreach (var s in split) { var l = font.MeasureString(s).X; if (longestLength < l) { longestLength = (int)l; } } if (!canGoOffScreen) { var diffX = x + longestLength - Gui.getUnscaledWidth(); if (diffX > 0) { x -= diffX; } x = Math.Max(4, x); y = Math.Max(Math.Min(y, Gui.getUnscaledHeight() - split.Length * lineHeight - 4), 2); } batch.Draw(GraphicsHelper.TranslucentWhite, new Vector2(x - 4, y - 2), new Rectangle(0, 0, longestLength + 4, split.Length * lineHeight + 6), Color.Black); var height = 0; foreach (var s in split) { batch.DrawString(font, s, new Vector2(x, y + height), color); height += lineHeight; } }
public override void onActionPerformed(Button button) { switch (button.Id) { case 0: EvolvinaryMain.get().openGui(new GuiIngameMenu(this.CurrentPlayer)); break; case 1: var inv = new GuiIngameInventory(this.CurrentPlayer); EvolvinaryMain.get().openGui(inv); inv.setSelectedEntity(this.SelectedEntity); break; case 3: EvolvinaryMain.get().openGui(new GuiMap(this.CurrentPlayer)); break; case 2: break; default: this.setSelectedEntity(null); if (this.selectableEntities.ContainsKey(button)) { var entity = this.selectableEntities[button]; this.setSelectedEntity(entity); } foreach (var key in this.selectableEntities.Keys) { this.ButtonList.Remove(key); } this.selectableEntities.Clear(); break; } }
public override void onTryClose() { EvolvinaryMain.get().openGui(new GuiIngameMenu(this.CurrentPlayer)); }
public override bool onMousePress(MouseSetting mouse) { if (!base.onMousePress(mouse)) { if (this.canSelectEntities()) { if (mouse == InputProcessor.LeftMouse) { if (this.selectableEntities.Count <= 0) { var mousePos = EvolvinaryMain.get().Camera.toWorldPos(InputProcessor.getMousePos().ToVector2()); var toReturn = false; if (this.SelectedEntity != null) { if (InputProcessor.Shift.IsDown) { var pathable = this.SelectedEntity as EntityPathable; if (pathable != null) { pathable.setPath(pathable.World.isWalkableExcept(MathHelp.floor(mousePos.X), MathHelp.floor(mousePos.Y), null) ? new Path(pathable, new[] { new PathWaypoint(mousePos) }, false, false) : null); toReturn = true; } } else { this.setSelectedEntity(null); toReturn = true; } } var entities = GameData.WorldTest.getEntitiesOnPoint(mousePos, null, true); if (entities.Count > 0) { if (entities.Count > 1) { foreach (var entity in entities) { if (entity.canSelect() && entity.MouseSelectBox != BoundBox.Empty) { var pos = EvolvinaryMain.get().Camera.toCameraPos(entity.Pos) / Scale; this.selectableEntities.Add(new ButtonTextOnly(this.selectableEntities.Count - 102834, this, (int)pos.X, (int)pos.Y, 30, 10, entity.getDisplayName(), 1F), entity); } } if (this.selectableEntities.Count > 0) { this.setSelectedEntity(null); this.ButtonList.AddRange(this.selectableEntities.Keys); toReturn = true; } } else { var entity = entities[0]; if (entity.canSelect()) { this.setSelectedEntity(entity); toReturn = true; } } } return(toReturn); } foreach (var key in this.selectableEntities.Keys) { this.ButtonList.Remove(key); } this.selectableEntities.Clear(); return(true); } } return(false); } return(true); }
public virtual void onTryClose() { EvolvinaryMain.get().openGui(null); }
public static int getUnscaledHeight() { return(MathHelp.ceil(EvolvinaryMain.get().RenderManager.getScreenHeight() / Scale)); }
public EntityRenderer() { EvolvinaryMain.get().RenderManager.EntityRenderers.Add(this); }
private void updatePos() { this.setPosition((EvolvinaryMain.get().Camera.toCameraPos(this.Entity.Pos) / Scale).ToPoint()); }