fixed tetris player inputs
This commit is contained in:
parent
f03011e4f1
commit
81dbf16d3f
@ -7,7 +7,6 @@ import eu.mhsl.minenet.minigames.instance.game.stateless.types.tetris.game.Tetro
|
||||
import eu.mhsl.minenet.minigames.score.PointsWinScore;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.coordinate.Vec;
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.GameMode;
|
||||
import net.minestom.server.entity.Player;
|
||||
@ -73,7 +72,6 @@ class Tetris extends StatelessGame {
|
||||
@Override
|
||||
protected void onPlayerMove(@NotNull PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Pos previousPosition = event.getPlayer().getPosition();
|
||||
Pos currentPosition = event.getNewPosition();
|
||||
|
||||
TetrisGame tetrisGame = this.tetrisGames.get(player);
|
||||
@ -85,37 +83,14 @@ class Tetris extends StatelessGame {
|
||||
if(tetrisGame.lost) return;
|
||||
if(player.getGameMode() == GameMode.SPECTATOR) return;
|
||||
|
||||
if(player.inputs().forward()) tetrisGame.pressedButton(TetrisGame.Button.W);
|
||||
if(player.inputs().backward()) tetrisGame.pressedButton(TetrisGame.Button.S);
|
||||
if(player.inputs().right()) tetrisGame.pressedButton(TetrisGame.Button.D);
|
||||
if(player.inputs().left()) tetrisGame.pressedButton(TetrisGame.Button.A);
|
||||
if(player.inputs().jump()) tetrisGame.pressedButton(TetrisGame.Button.space);
|
||||
|
||||
event.setNewPosition(tetrisGame.getPlayerSpawnPosition().withView(currentPosition));
|
||||
player.setSprinting(false);
|
||||
|
||||
Vec movementVector = currentPosition.asVec().sub(previousPosition.asVec());
|
||||
|
||||
float yaw = player.getPosition().yaw();
|
||||
|
||||
double yawRadians = Math.toRadians(yaw);
|
||||
double forwardX = -Math.sin(yawRadians);
|
||||
double forwardZ = Math.cos(yawRadians);
|
||||
|
||||
Vec forward = new Vec(forwardX, 0, forwardZ).normalize();
|
||||
Vec left = forward.cross(new Vec(0, 1, 0)).normalize();
|
||||
|
||||
double forwardAmount = movementVector.dot(forward);
|
||||
double leftAmount = movementVector.dot(left);
|
||||
|
||||
double buttonPressAmount = 0.05;
|
||||
if (forwardAmount > buttonPressAmount) {
|
||||
tetrisGame.pressedButton(TetrisGame.Button.W);
|
||||
} else if (forwardAmount < -buttonPressAmount) {
|
||||
tetrisGame.pressedButton(TetrisGame.Button.S);
|
||||
}
|
||||
|
||||
if (leftAmount > buttonPressAmount) {
|
||||
tetrisGame.pressedButton(TetrisGame.Button.D);
|
||||
} else if (leftAmount < -buttonPressAmount) {
|
||||
tetrisGame.pressedButton(TetrisGame.Button.A);
|
||||
}
|
||||
|
||||
if(previousPosition.y() < currentPosition.y()) tetrisGame.pressedButton(TetrisGame.Button.space);
|
||||
}
|
||||
|
||||
protected void onPlayerInteract(@NotNull PlayerUseItemEvent event) {
|
||||
@ -142,9 +117,9 @@ class Tetris extends StatelessGame {
|
||||
getScore().insertResult(player, tetrisGame.getScore());
|
||||
|
||||
boolean allGamesLost = this.tetrisGames.values().stream()
|
||||
.filter(game -> !game.lost)
|
||||
.toList()
|
||||
.isEmpty();
|
||||
.filter(game -> !game.lost)
|
||||
.toList()
|
||||
.isEmpty();
|
||||
if(!setTimeLimit && !allGamesLost) {
|
||||
this.setTimeLimit(90);
|
||||
setTimeLimit = true;
|
||||
@ -158,13 +133,13 @@ class Tetris extends StatelessGame {
|
||||
|
||||
if(this.tetrisGames.get(p) == null) {
|
||||
this.tetrisGames.put(p, new TetrisGame(
|
||||
this,
|
||||
getSpawn().sub(6, 8, 15).add(this.tetrisGames.size()*30, 0, 0),
|
||||
Tetromino.Shape.J,
|
||||
this.nextTetrominoesCount,
|
||||
this.isFast,
|
||||
this.hasCombat,
|
||||
this.randomSeed
|
||||
this,
|
||||
getSpawn().sub(6, 8, 15).add(this.tetrisGames.size()*30, 0, 0),
|
||||
Tetromino.Shape.J,
|
||||
this.nextTetrominoesCount,
|
||||
this.isFast,
|
||||
this.hasCombat,
|
||||
this.randomSeed
|
||||
));
|
||||
this.tetrisGames.get(p).generate();
|
||||
this.tetrisGames.values().forEach(tetrisGame -> tetrisGame.updateOtherTetrisGames(this.tetrisGames.values()));
|
||||
|
Loading…
x
Reference in New Issue
Block a user