Skip to content

Commit

Permalink
Fixes fixes and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
XyperCode committed Jun 10, 2024
1 parent 3bdfbb1 commit c62a834
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 29 deletions.
29 changes: 20 additions & 9 deletions core/src/main/java/dev/ultreon/bubbles/BubbleBlaster.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ public final class BubbleBlaster extends ApplicationAdapter implements CrashFill
public Player player;

// Values
@IntRange(from = 0) int fps;
@IntRange(from = 0)
int fps;
private int currentTps;

// Game states.
Expand Down Expand Up @@ -231,8 +232,8 @@ private BubbleBlaster() {
this.unsupportedGL = true;
}

this.arrowCursor = this.createCursor("textures/cursor/arrow.png", 0, 0);
this.handCursor = this.createCursor("textures/cursor/pointer.png", 10, 10);
this.arrowCursor = this.createCursor("textures/cursor/arrow.png", 4, 5);
this.handCursor = this.createCursor("textures/cursor/pointer.png", 7, 5);

instance = this;
this.notifications = new Notifications();
Expand Down Expand Up @@ -1469,15 +1470,25 @@ private void gameTick() {
// Tick input
var screen = this.screen;
if (screen != null) {
this.controllerInput.tickScreen(screen);
this.desktopInput.tickScreen(screen);
this.mobileInput.tickScreen(screen);
try {
this.controllerInput.tickScreen(screen);
this.desktopInput.tickScreen(screen);
this.mobileInput.tickScreen(screen);
} catch (Throwable t) {
var crashLog = new CrashLog("Ticking screen.", t);
BubbleBlaster.crash(crashLog.createCrash());
}
}
final var player = this.player;
if (player != null && screen == null) {
this.controllerInput.tickPlayer(player);
this.desktopInput.tickPlayer(player);
this.mobileInput.tickPlayer(player);
try {
this.controllerInput.tickPlayer(player);
this.desktopInput.tickPlayer(player);
this.mobileInput.tickPlayer(player);
} catch (Throwable t) {
var crashLog = new CrashLog("Ticking player.", t);
BubbleBlaster.crash(crashLog.createCrash());
}
}

if (this.isLoaded()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package dev.ultreon.bubbles.input;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import dev.ultreon.bubbles.BubbleBlaster;
import dev.ultreon.bubbles.GamePlatform;
import dev.ultreon.bubbles.LoadedGame;
import dev.ultreon.bubbles.entity.player.Player;
import dev.ultreon.bubbles.render.gui.screen.Screen;
import dev.ultreon.bubbles.shop.ShopScreen;
import dev.ultreon.bubbles.world.World;
import dev.ultreon.libs.commons.v0.Mth;

Expand All @@ -15,6 +17,10 @@ public class ControllerInputHandler extends InputHandler<ControllerInput> {
private static final float DEAD_ZONE = 0.2f;
private static final float MOUSE_SPEED = 200f;
private final BubbleBlaster game = BubbleBlaster.getInstance();
private boolean backPressed;
private boolean leftPressed;
private boolean rightPressed;
private boolean middlePressed;

public ControllerInputHandler() {
super(ControllerInput.get(), InputType.Controller);
Expand All @@ -28,22 +34,55 @@ public boolean tickScreen(Screen screen) {

var mapping = controller.getMapping();

var moveX = controller.getAxis(mapping.axisLeftX);
var moveY = controller.getAxis(mapping.axisLeftY);
var moveX = controller.getAxis(mapping.axisLeftX) * 2;
var moveY = controller.getAxis(mapping.axisLeftY) * 2;

var scroll = controller.getAxis(mapping.axisRightY);

if (moveX > -DEAD_ZONE && moveX < DEAD_ZONE) moveX = 0f;
if (moveY > -DEAD_ZONE && moveY < DEAD_ZONE) moveY = 0f;
if (scroll > -DEAD_ZONE && scroll < DEAD_ZONE) scroll = 0f;

var cursorPos = DesktopInput.getMousePos();
if (moveX > 0 || moveY > 0) {
if (moveX != 0 || moveY != 0) {
cursorPos.add(moveX * MOUSE_SPEED / TPS, moveY * MOUSE_SPEED / TPS);
cursorPos.x = Mth.clamp(cursorPos.x, 0, Gdx.graphics.getWidth());
cursorPos.y = Mth.clamp(cursorPos.y, 0, Gdx.graphics.getHeight());
cursorPos.x = Mth.clamp(cursorPos.x, 0, Gdx.graphics.getWidth() - 1);
cursorPos.y = Mth.clamp(cursorPos.y, 0, Gdx.graphics.getHeight() - 1);

// Vector2 screenCoordinates = this.game.viewport.toScreenCoordinates(cursorPos, this.game.getTransform());
// Gdx.input.setCursorPosition((int) screenCoordinates.x, (int) screenCoordinates.y);
Gdx.input.setCursorPosition((int) cursorPos.x, (int) cursorPos.y);
}
screen.mouseWheel((int) cursorPos.x, (int) cursorPos.y, scroll);

if (controller.getButton(mapping.buttonL1) || controller.getButton(mapping.buttonA)) {
this.leftPressed = true;
screen.mousePress((int) cursorPos.x, (int) cursorPos.y, Input.Buttons.LEFT);
} else if (this.leftPressed) {
this.leftPressed = false;
screen.mouseRelease((int) cursorPos.x, (int) cursorPos.y, Input.Buttons.LEFT);
}
if (controller.getButton(mapping.buttonR1)) {
this.rightPressed = true;
screen.mousePress((int) cursorPos.x, (int) cursorPos.y, Input.Buttons.RIGHT);
} else if (this.rightPressed) {
this.rightPressed = false;
screen.mouseRelease((int) cursorPos.x, (int) cursorPos.y, Input.Buttons.RIGHT);
}
if (controller.getButton(mapping.buttonStart)) {
this.middlePressed = true;
screen.mousePress((int) cursorPos.x, (int) cursorPos.y, Input.Buttons.MIDDLE);
} else if (this.middlePressed) {
this.middlePressed = false;
screen.mouseRelease((int) cursorPos.x, (int) cursorPos.y, Input.Buttons.MIDDLE);
}
if (controller.getButton(mapping.buttonB)) {
this.backPressed = true;
screen.keyPress(Input.Keys.BACK);
} else if (this.backPressed) {
this.backPressed = false;
screen.keyRelease(Input.Keys.BACK);
}

return true;
}
Expand All @@ -64,18 +103,16 @@ public boolean tickPlayer(Player player) {
var moveX = controller.getAxis(mapping.axisLeftX);
var moveY = controller.getAxis(mapping.axisLeftY);

if (GamePlatform.get().isDesktop()) {
var triggerL = controller.getAxis(4);
var triggerR = controller.getAxis(5);
if (triggerL < DEAD_ZONE) triggerL = 0;
if (triggerR < DEAD_ZONE) triggerR = 0;
if (triggerL > 0) {
player.moving(triggerL);
} else if (triggerR > 0.5f) {
player.setBrake(true);
} else if (triggerR <= 0.5f) {
player.setBrake(false);
}
var triggerL = controller.getAxis(4);
var triggerR = controller.getAxis(5);
if (triggerL < DEAD_ZONE) triggerL = 0;
if (triggerR < DEAD_ZONE) triggerR = 0;
if (triggerR > 0.5f) {
player.setBrake(true);
} else if (triggerR <= 0.5f) {
player.setBrake(false);
} else if (triggerL > 0) {
player.moving(triggerL);
}

if (moveX > -DEAD_ZONE && moveX < DEAD_ZONE) moveX = 0f;
Expand All @@ -84,6 +121,7 @@ public boolean tickPlayer(Player player) {

if (controller.getButton(mapping.buttonA)) player.shoot();
if (controller.getButton(mapping.buttonB)) player.boost();
if (controller.getButton(mapping.buttonY)) this.game.showScreen(new ShopScreen());

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@ public boolean tickWorld(World world, LoadedGame loadedGame) {

@Override
public boolean tickPlayer(Player player) {
if (!GamePlatform.get().isDesktop()) return false;
if (!GamePlatform.get().isDesktop() || BubbleBlaster.getInstance().controllerInput.input.controller != null) return false;

var rotating = 0f;
var moving = 0f;

if (KeyBindings.FORWARD.isPressed()) moving += 1f;
if (KeyBindings.ROTATE_LEFT.isPressed()) rotating -= 1f;
if (KeyBindings.ROTATE_RIGHT.isPressed()) rotating += 1f;

player.moving(moving);
player.rotating(rotating);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void forceClose() {

@Override
public boolean keyPress(int keyCode) {
if (keyCode == Input.Keys.ESCAPE) {
if (keyCode == Input.Keys.ESCAPE || keyCode == Input.Keys.BACK) {
if (this.backScreen != null) {
this.game.showScreen(this.backScreen);
return true;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c62a834

Please sign in to comment.