-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* prototyping color change * restructure packages and add ui * better menu * fix for mouse pressed continouusly * fix for mouse pressed continouusly * bugfix fullscreen on osx * fix fullscreen on osx * fix
- Loading branch information
Showing
15 changed files
with
184 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...meoflife/systems/CameraControlSystem.java → ...ameoflife/camera/CameraControlSystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...oflife/systems/GridInteractionSystem.java → ...ameoflife/grid/GridInteractionSystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...e/src/main/java/io/github/srcimon/screwbox/examples/gameoflife/grid/GridRenderSystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.github.srcimon.screwbox.examples.gameoflife.grid; | ||
|
||
import io.github.srcimon.screwbox.core.Bounds; | ||
import io.github.srcimon.screwbox.core.Engine; | ||
import io.github.srcimon.screwbox.core.Vector; | ||
import io.github.srcimon.screwbox.core.entities.Archetype; | ||
import io.github.srcimon.screwbox.core.entities.EntitySystem; | ||
import io.github.srcimon.screwbox.core.graphics.Color; | ||
import io.github.srcimon.screwbox.core.graphics.World; | ||
import io.github.srcimon.screwbox.examples.gameoflife.grid.GridComponent; | ||
|
||
public class GridRenderSystem implements EntitySystem { | ||
|
||
private static final Archetype GRID_HOLDER = Archetype.of(GridComponent.class); | ||
|
||
@Override | ||
public void update(final Engine engine) { | ||
final var gridComponent = engine.entities().forcedFetch(GRID_HOLDER).get(GridComponent.class); | ||
final World world = engine.graphics().world(); | ||
for (final var node : gridComponent.grid.nodes()) { | ||
if (gridComponent.grid.isBlocked(node)) { | ||
final int neighbors = gridComponent.grid.blockedNeighbors(node).size(); | ||
final var color = colorByCountOf(neighbors, gridComponent); | ||
final Bounds worldBounds = gridComponent.grid.worldArea(node); | ||
world.fillCircle(worldBounds.position(), (int) worldBounds.width(), color); | ||
} | ||
} | ||
|
||
final Vector snappedMousePosition = gridComponent.grid.snap(engine.mouse().worldPosition()); | ||
world.fillCircle(snappedMousePosition, 2, Color.YELLOW); | ||
} | ||
|
||
private Color colorByCountOf(final int neighbors, final GridComponent gridComponent) { | ||
if (neighbors == 1) { | ||
return gridComponent.oneNeighboursColor; | ||
} | ||
if (neighbors == 2) { | ||
return gridComponent.twoNeighboursColor; | ||
} | ||
return gridComponent.noNeighboursColor; | ||
} | ||
|
||
} |
4 changes: 2 additions & 2 deletions
4
.../gameoflife/systems/GridUpdateSystem.java → ...les/gameoflife/grid/GridUpdateSystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...src/main/java/io/github/srcimon/screwbox/examples/gameoflife/sidebar/SidebarLayouter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.github.srcimon.screwbox.examples.gameoflife.sidebar; | ||
|
||
import io.github.srcimon.screwbox.core.graphics.Screen; | ||
import io.github.srcimon.screwbox.core.graphics.WindowBounds; | ||
import io.github.srcimon.screwbox.core.ui.UiLayouter; | ||
import io.github.srcimon.screwbox.core.ui.UiMenu; | ||
import io.github.srcimon.screwbox.core.ui.UiMenuItem; | ||
|
||
public class SidebarLayouter implements UiLayouter { | ||
|
||
@Override | ||
public WindowBounds calculateBounds(UiMenuItem item, UiMenu menu, Screen screen) { | ||
var index = menu.itemIndex(item); | ||
return new WindowBounds(20, 30 * index + 30, 200, 30); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...ple/src/main/java/io/github/srcimon/screwbox/examples/gameoflife/sidebar/SidebarMenu.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.github.srcimon.screwbox.examples.gameoflife.sidebar; | ||
|
||
import io.github.srcimon.screwbox.core.Engine; | ||
import io.github.srcimon.screwbox.core.graphics.Color; | ||
import io.github.srcimon.screwbox.core.ui.UiMenu; | ||
import io.github.srcimon.screwbox.examples.gameoflife.grid.GridComponent; | ||
import io.github.srcimon.screwbox.examples.gameoflife.grid.GridUpdateSystem; | ||
|
||
public class SidebarMenu extends UiMenu { | ||
|
||
public SidebarMenu() { | ||
addItem(engine -> "fps: " + engine.loop().fps()).activeCondition(engine -> false); | ||
addItem(engine -> "frame: " + engine.loop().frameNumber()).activeCondition(engine -> false); | ||
addItem("colors").onActivate(engine -> { | ||
var grid = engine.entities().forcedFetchHaving(GridComponent.class).get(GridComponent.class); | ||
grid.noNeighboursColor = Color.random(); | ||
grid.oneNeighboursColor = Color.random(); | ||
grid.twoNeighboursColor = Color.random(); | ||
}); | ||
|
||
addItem(engine -> engine.entities().isSystemPresent(GridUpdateSystem.class) ? "pause" : "resume") | ||
.onActivate(engine -> engine.entities().toggleSystem(new GridUpdateSystem())); | ||
|
||
addItem(engine -> engine.graphics().configuration().isUseAntialising() ? "high quality" : "low quality").onActivate(engine -> engine.graphics().configuration().toggleAntialising()); | ||
addItem("mode").onActivate(engine -> engine.graphics().configuration().toggleFullscreen()); | ||
addItem("save").onActivate(engine -> engine.savegame().create("save")); | ||
addItem("load").onActivate(engine -> engine.savegame().load("save")).activeCondition(engine -> engine.savegame().exists("save")); | ||
addItem("exit").onActivate(Engine::stop); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...ain/java/io/github/srcimon/screwbox/examples/gameoflife/sidebar/SidebarOpacitySystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.github.srcimon.screwbox.examples.gameoflife.sidebar; | ||
|
||
import io.github.srcimon.screwbox.core.Engine; | ||
import io.github.srcimon.screwbox.core.Percent; | ||
import io.github.srcimon.screwbox.core.entities.EntitySystem; | ||
|
||
public class SidebarOpacitySystem implements EntitySystem { | ||
|
||
@Override | ||
public void update(Engine engine) { | ||
Percent opacity = Percent.of((300 - engine.mouse().position().x()) / 300.0); | ||
engine.ui().setRenderer(new SidebarRenderer(opacity)); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...src/main/java/io/github/srcimon/screwbox/examples/gameoflife/sidebar/SidebarRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.github.srcimon.screwbox.examples.gameoflife.sidebar; | ||
|
||
import io.github.srcimon.screwbox.core.Percent; | ||
import io.github.srcimon.screwbox.core.graphics.Font; | ||
import io.github.srcimon.screwbox.core.graphics.Screen; | ||
import io.github.srcimon.screwbox.core.graphics.WindowBounds; | ||
import io.github.srcimon.screwbox.core.ui.UiRenderer; | ||
|
||
import static io.github.srcimon.screwbox.core.graphics.Color.*; | ||
import static io.github.srcimon.screwbox.core.graphics.Offset.at; | ||
|
||
public class SidebarRenderer implements UiRenderer { | ||
|
||
private final Percent opacity; | ||
|
||
public SidebarRenderer(final Percent opacity) { | ||
this.opacity = opacity; | ||
} | ||
|
||
private static final Font FONT = new Font("Arial", 18, Font.Style.BOLD); | ||
|
||
@Override | ||
public void renderSelectableItem(String label, WindowBounds bounds, Screen screen) { | ||
if (!opacity.isMinValue()) { | ||
screen.drawText(at(bounds.offset().x(), bounds.center().y()), label, FONT, WHITE.opacity(opacity)); | ||
} | ||
} | ||
|
||
@Override | ||
public void renderSelectedItem(String label, WindowBounds bounds, Screen screen) { | ||
if (!opacity.isMinValue()) { | ||
screen.drawText(at(bounds.offset().x(), bounds.center().y()), label, FONT, RED.opacity(opacity)); | ||
} | ||
} | ||
|
||
@Override | ||
public void renderInactiveItem(String label, WindowBounds bounds, Screen screen) { | ||
if (!opacity.isMinValue()) { | ||
screen.drawText(at(bounds.offset().x(), bounds.center().y()), label, FONT, GREY.opacity(opacity)); | ||
} | ||
} | ||
|
||
} |
43 changes: 0 additions & 43 deletions
43
...rc/main/java/io/github/srcimon/screwbox/examples/gameoflife/systems/GridRenderSystem.java
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
...ple/src/main/java/io/github/srcimon/screwbox/examples/gameoflife/systems/PauseSystem.java
This file was deleted.
Oops, something went wrong.