Skip to content

Commit

Permalink
Bunch of fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
XyperCode committed Sep 29, 2023
1 parent 19b9b7d commit 3848ce7
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 127 deletions.
92 changes: 40 additions & 52 deletions core/src/main/java/com/ultreon/bubbles/BubbleBlaster.java
Original file line number Diff line number Diff line change
Expand Up @@ -700,8 +700,7 @@ private void showGuiModifier(Renderer renderer) {

if (exactWidgetAt != null) {
var bounds = exactWidgetAt.getBounds();
renderer.setColor(Color.rgb(0xff0000));
renderer.box(bounds.x, bounds.y, bounds.width, bounds.height);
renderer.box(bounds.x, bounds.y, bounds.width, bounds.height, Color.RED);
}

ImGui.setNextWindowSize(400, 200, ImGuiCond.Once);
Expand Down Expand Up @@ -830,6 +829,7 @@ public static boolean isDebugMode() {
return debugMode;
}

@Deprecated
public static boolean isDevEnv() {
return FabricLoader.getInstance().isDevelopmentEnvironment();
}
Expand Down Expand Up @@ -941,30 +941,28 @@ private void onKeyPress(int keyCode, boolean holding) {
if (loadedGame != null) {
final var environment = loadedGame.getEnvironment();

if (keyCode == Keys.F1 && BubbleBlaster.isDevEnv()) {
environment.triggerBloodMoon();
} else if (keyCode == Keys.F3 && BubbleBlaster.isDevEnv()) {
Objects.requireNonNull(environment.getPlayer()).destroy();
} else if (keyCode == Keys.F4 && BubbleBlaster.isDevEnv()) {
Objects.requireNonNull(environment.getPlayer()).levelUp();
} else if (keyCode == Keys.F5 && BubbleBlaster.isDevEnv()) {
Objects.requireNonNull(environment.getPlayer()).awardScore(1000);
} else if (keyCode == Keys.F6 && BubbleBlaster.isDevEnv()) {
var player = loadedGame.getGamemode().getPlayer();

if (player != null) {
Objects.requireNonNull(player).setHealth(player.getMaxHealth());
}
} else if (keyCode == Keys.F7 && BubbleBlaster.isDevEnv()) {
this.isGlitched = true;
Player player = environment.getPlayer();
if (this.canExecuteDevCommands()) {
this.executeDevCommand(keyCode, environment, player, loadedGame);
}
}

if (keyCode == Keys.F8 && BubbleBlaster.isDevEnv() && !holding) {
if (this.canExecuteDevCommands() && keyCode == Keys.F8 && !holding) {
this.renderer.triggerScissorLog();
}
}

private void executeDevCommand(int keyCode, Environment environment, Player player, LoadedGame loadedGame) {
switch (keyCode) {
case Keys.F1 -> environment.triggerBloodMoon();
case Keys.F3 -> player.destroy();
case Keys.F4 -> player.levelUp();
case Keys.F5 -> player.awardScore(1000);
case Keys.F6 -> DevCommands.resetHealth(loadedGame);
case Keys.F7 -> this.isGlitched = true;
}
}

private void onMouseClick(int x, int y, int button, int clicks) {
var loadedGame = this.loadedGame;
if (isDevEnv()) {
Expand Down Expand Up @@ -1325,7 +1323,7 @@ public void startGame(long seed, Gamemode gamemode, Difficulty difficulty, GameS
var screen = new MessengerScreen();

// Show environment loader screen.
showScreen(screen);
this.showScreen(screen);
try {
var directory = save.getDirectory();
if (create && directory.exists()) {
Expand Down Expand Up @@ -1670,15 +1668,6 @@ private void gameTick() {
if (screen != null)
screen.tick();

if (player != null && GameInput.isKeyDown(Keys.SPACE))
player.shoot();

if (player != null) {
if (GameInput.isKeyDown(Keys.CONTROL_LEFT)) {
player.boost();
}
}

if (this.ticker.advance() == 40) {
this.ticker.reset();
if (this.isLoaded())
Expand Down Expand Up @@ -1731,7 +1720,7 @@ private void onFirstFrame() {
private void renderGame(Renderer renderer, int mouseX, int mouseY, float frameTime) {
// Call to game environment rendering.
// Get field and set local variable. For multithreaded null-safety.
@Nullable Screen screen = screenManager.getCurrentScreen();
@Nullable Screen screen = this.getCurrentScreen();
@Nullable Environment environment = this.environment;
@Nullable EnvironmentRenderer environmentRenderer = this.environmentRenderer;

Expand Down Expand Up @@ -1760,7 +1749,7 @@ private void renderGame(Renderer renderer, int mouseX, int mouseY, float frameTi
});

// Post render.
profiler.section("Post Render", () -> postRender(renderer));
profiler.section("Post Render", () -> this.postRender(renderer));

// Post event after rendering the game.
RenderEvents.RENDER_GAME_AFTER.factory().onRenderGameAfter(this, renderer, frameTime);
Expand All @@ -1770,22 +1759,14 @@ private void postRender(Renderer renderer) {
if (this.fadeIn) {
final var timeDiff = System.currentTimeMillis() - this.fadeInStart;
if (timeDiff <= this.fadeInDuration) {
var clamp = (int) Mth.clamp(255 * (1f - ((float) timeDiff) / this.fadeInDuration), 0, 255);
var color = Color.rgba(0, 0, 0, clamp);
GuiComponent.fill(renderer, 0, 0, getWidth(), getHeight(), color);
int clamp = Mth.clamp((int) (255 * (1f - timeDiff / this.fadeInDuration)), 0, 255);
renderer.fill(0, 0, getWidth(), getHeight(), Color.BLACK.withAlpha(clamp));
} else {
this.fadeIn = false;
}
}
}

/**
* Loads the game environment.
*/
private void loadEnvironment() {
preparePlayer();
}

/**
* Starts loading the game.
*/
Expand Down Expand Up @@ -1856,7 +1837,7 @@ public void loadPlayEnvironment() {
this.playerController = new PlayerController(this.input);
this.player = player;

loadEnvironment();
this.preparePlayer();
}

/////////////////////
Expand Down Expand Up @@ -2035,7 +2016,7 @@ public boolean registerFont(BitmapFont font) {

public void finish() {
this.glitchRenderer = new GlitchRenderer(this);
showScreen(new TitleScreen());
this.showScreen(new TitleScreen());
this.loaded = true;

this.afterLoading.values().forEach(Runnable::run);
Expand Down Expand Up @@ -2095,7 +2076,7 @@ public boolean keyPress(int keycode) {
notifications.notify(new Notification("Screenshot saved!", screenshot.fileHandle().name(), "SCREENSHOT MANAGER"));
return true;
} else if (environment != null) {
if (keyPressEnv(keycode, environment)) return true;
if (keyPressEnv(environment, keycode)) return true;
}

if (currentScreen != null) {
Expand All @@ -2109,28 +2090,35 @@ public boolean keyPress(int keycode) {

@ApiStatus.Internal
@CanIgnoreReturnValue
private boolean keyPressEnv(int keycode, Environment environment) {
private boolean keyPressEnv(Environment environment, int keycode) {
Player player = this.player;
boolean shouldTriggerDevCommand = debugMode || isDevEnv();
boolean isDev = this.canExecuteDevCommands();

if (this.isInGame() && player != null) {
if (keycode == Keys.UP) player.forward(true);
if (keycode == Keys.DOWN) player.backward(true);
if (keycode == Keys.LEFT) player.left(true);
if (keycode == Keys.RIGHT) player.right(true);
if (keycode == Keys.LEFT) player.rotateLeft(true);
if (keycode == Keys.RIGHT) player.rotateRight(true);

if (keycode == Keys.SPACE) player.shoot();
if (keycode == Keys.CONTROL_LEFT) player.boost();
}

if (keycode == Keys.F10 && (shouldTriggerDevCommand)) {
if (isDev && keycode == Keys.F10) {
environment.triggerBloodMoon();
return true;
} else if (keycode == Keys.SLASH && !hasScreenOpen()) {
} else if (keycode == Keys.SLASH && !this.hasScreenOpen()) {
BubbleBlaster.getInstance().showScreen(new CommandScreen());
return true;
}

return false;
}

private boolean canExecuteDevCommands() {
return BubbleBlaster.debugMode || FabricLoader.getInstance().isDevelopmentEnvironment();
}

@ApiStatus.Internal
@CanIgnoreReturnValue
public boolean keyRelease(int keycode) {
Expand All @@ -2140,8 +2128,8 @@ public boolean keyRelease(int keycode) {
if (this.isInGame() && player != null) {
if (keycode == Keys.UP) player.forward(false);
if (keycode == Keys.DOWN) player.backward(false);
if (keycode == Keys.LEFT) player.left(false);
if (keycode == Keys.RIGHT) player.right(false);
if (keycode == Keys.LEFT) player.rotateLeft(false);
if (keycode == Keys.RIGHT) player.rotateRight(false);
}

return false;
Expand Down
11 changes: 11 additions & 0 deletions core/src/main/java/com/ultreon/bubbles/DevCommands.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.ultreon.bubbles;

import java.util.Objects;

public class DevCommands {
public static void resetHealth(LoadedGame loadedGame) {
var player = loadedGame.getGamemode().getPlayer();
if (player != null)
player.setHealth(player.getMaxHealth());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,25 @@ public int getModifiers() {
}

public boolean isShiftPressed() {
return GameInput.isShiftDown(modifiers);
return GameInput.isShiftDown();
}

public boolean isCtrlPressed() {
return GameInput.isCtrlDown(modifiers);
return GameInput.isCtrlDown();
}

@Deprecated(forRemoval = true)
public boolean isMetaPressed() {
return GameInput.isMetaDown(modifiers);
return GameInput.isMetaDown();
}

public boolean isAltPressed() {
return GameInput.isAltDown(modifiers);
return GameInput.isAltDown();
}

@Deprecated(forRemoval = true)
public boolean isAltGraphPressed() {
return GameInput.isAltGraphDown(modifiers);
return GameInput.isAltGraphDown();
}

public boolean isDown(int keyCode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ public void backward(boolean bool) {
*
* @param bool true to activate, false to deactivate.
*/
public void left(boolean bool) {
public void rotateLeft(boolean bool) {
this.left = bool;
}

Expand All @@ -659,7 +659,7 @@ public void left(boolean bool) {
*
* @param bool true to activate, false to deactivate.
*/
public void right(boolean bool) {
public void rotateRight(boolean bool) {
this.right = bool;
}

Expand Down
27 changes: 17 additions & 10 deletions core/src/main/java/com/ultreon/bubbles/input/GameInput.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ultreon.bubbles.input;

import com.badlogic.gdx.Input;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.math.GridPoint2;
Expand Down Expand Up @@ -31,24 +32,26 @@ public class GameInput implements InputProcessor {
private static final int ALT_MASK = 1 << 3;
private static final int ALT_GRAPH_MASK = 1 << 5;

public static boolean isShiftDown(int modifiers) {
return (modifiers & SHIFT_MASK) != 0;
public static boolean isShiftDown() {
return isAnyKeyDownOf(Keys.SHIFT_LEFT, Keys.SHIFT_RIGHT);
}

public static boolean isCtrlDown(int modifiers) {
return (modifiers & CTRL_MASK) != 0;
public static boolean isCtrlDown() {
return isAnyKeyDownOf(Keys.CONTROL_LEFT, Keys.CONTROL_RIGHT);
}

public static boolean isMetaDown(int modifiers) {
return (modifiers & META_MASK) != 0;
@Deprecated
public static boolean isMetaDown() {
return false;
}

public static boolean isAltDown(int modifiers) {
return (modifiers & ALT_MASK) != 0;
public static boolean isAltDown() {
return isAnyKeyDownOf(Keys.ALT_LEFT, Keys.ALT_RIGHT);
}

public static boolean isAltGraphDown(int modifiers) {
return (modifiers & ALT_GRAPH_MASK) != 0;
@Deprecated
public static boolean isAltGraphDown() {
return isCtrlDown() && isAltDown();
}

public static GridPoint2 getPos() {
Expand All @@ -63,6 +66,10 @@ public static boolean areKeysDown(int... keys) {
return Arrays.stream(keys).allMatch(GameInput::isKeyDown);
}

public static boolean isAnyKeyDownOf(int... keys) {
return Arrays.stream(keys).anyMatch(GameInput::isKeyDown);
}

@Override
public boolean keyDown(int keycode) {
if (isKeyDown(keycode)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public interface InputController {

void backward(boolean backward);

void left(boolean left);
void rotateLeft(boolean left);

void right(boolean right);
void rotateRight(boolean right);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public void tick() {
// logger.info("PlayerController[8c217398]: " + this.player);
this.controller.forward(GameInput.isKeyDown(Input.Keys.UP) || GameInput.isKeyDown(Input.Keys.W));
this.controller.backward(GameInput.isKeyDown(Input.Keys.DOWN) || GameInput.isKeyDown(Input.Keys.S));
this.controller.right(GameInput.isKeyDown(Input.Keys.RIGHT) || GameInput.isKeyDown(Input.Keys.D));
this.controller.left(GameInput.isKeyDown(Input.Keys.LEFT) || GameInput.isKeyDown(Input.Keys.A));
this.controller.rotateRight(GameInput.isKeyDown(Input.Keys.RIGHT) || GameInput.isKeyDown(Input.Keys.D));
this.controller.rotateLeft(GameInput.isKeyDown(Input.Keys.LEFT) || GameInput.isKeyDown(Input.Keys.A));
}
}
}
Loading

0 comments on commit 3848ce7

Please sign in to comment.