Skip to content

Commit 0d45579

Browse files
committed
fix issues with game not ending
1 parent 97aff0a commit 0d45579

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ bin/
2727
# fabric
2828

2929
run/
30+
logs/

src/main/java/io/github/restioson/loopdeloop/game/LoopDeLoopActive.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public final class LoopDeLoopActive {
5656
private final List<LoopDeLoopWinner> finished;
5757
private final LoopDeLoopSpawnLogic spawnLogic;
5858
private final LoopDeLoopTimerBar timerBar = new LoopDeLoopTimerBar();
59+
// Only stores flying players, i.e non-completed players
5960
private final Object2ObjectMap<ServerPlayerEntity, LoopDeLoopPlayer> player_states;
6061
@Nullable
6162
private ServerPlayerEntity lastCompleter;
@@ -231,6 +232,7 @@ private void tickPlayers(long time) {
231232
if (nextHoop >= this.map.hoops.size()) {
232233
iterator.remove();
233234
this.finished.add(new LoopDeLoopWinner(player.getEntityName(), time));
235+
this.player_states.remove(player);
234236
int idx = this.finished.size();
235237
player.sendMessage(new LiteralText("You finished in " + ordinal(idx) + " place!"), true);
236238
player.playSound(SoundEvents.ENTITY_PLAYER_LEVELUP, SoundCategory.PLAYERS, 1.0F, 1.0F);
@@ -239,6 +241,10 @@ private void tickPlayers(long time) {
239241
continue;
240242
}
241243

244+
if (state.lastHoop != -1 && player.isOnGround()) {
245+
this.failHoop(player, state, time);
246+
}
247+
242248
LoopDeLoopHoop hoop = this.map.hoops.get(nextHoop);
243249

244250
int lastHoopZ;
@@ -263,27 +269,20 @@ private void tickPlayers(long time) {
263269
player.getX() > Math.max(centre.getX(), lastHoopX) + 30 ||
264270
player.getX() < Math.min(centre.getX(), lastHoopX) - 30;
265271

266-
// The two parts of the `or` here represent the two paths: the player is moving fast, or they are moving slow
267-
//
268-
// If they are moving fast, the line segment connecting their past and present movement will intersect the
269-
// hoop's circle and the first part will be true.
270-
//
271-
// If they are moving slow, there may not be enough precision to detect this, so the slow path is fallen back
272-
// to, simply checking if the end coordinate is inside of the hoop.
273272
if (hoop.intersectsSegment(state.lastPos, player.getPos())) {
274273
player.playSound(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.PLAYERS, 1.0F, 1.0F);
275274
giveRocket(player, 1);
276275
state.lastHoop += 1;
277-
} else if ((time - state.lastFailTp > 5) && outOfBounds) {
278-
this.failHoop(player, state, time);
276+
} else if (outOfBounds) {
277+
this.failHoop(player, state, time);
279278
}
280279

281280
state.lastPos = player.getPos();
282281
}
283282
}
284283

285284
private void failHoop(ServerPlayerEntity player, LoopDeLoopPlayer state, long time) {
286-
if (time - state.lastFailTp < 5) {
285+
if (time - state.lastFailTp < 20) {
287286
return;
288287
}
289288

src/main/java/io/github/restioson/loopdeloop/game/map/LoopDeLoopHoop.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ public LoopDeLoopHoop(BlockPos centre, int radius) {
1616
}
1717

1818
public boolean intersectsSegment(Vec3d begin, Vec3d end) {
19-
// if we contain the end position, we are inside the hoop
19+
// If the hoop contains the end position, it intersects
2020
if (this.contains(end)) {
2121
return true;
2222
}
2323

24-
// find the intersection between the line and the hoop plane
24+
// Find the intersection between the line and the hoop plane
2525
Vec3d intersection = lineIntersectsPlane(begin, end, centre.getZ() + 0.5);
2626
if (intersection == null) {
2727
// no intersection
2828
return false;
2929
}
3030

31-
// check if the intersection point is contained within the loop
31+
// Check if the intersection point is contained within the loop
3232
return this.contains(intersection.x, intersection.y);
3333
}
3434

0 commit comments

Comments
 (0)