-
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.
allows players to pick up items in game
- Loading branch information
Showing
18 changed files
with
138 additions
and
101 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
7 changes: 0 additions & 7 deletions
7
spring-backend/src/main/java/com/baloise/collab/springbackend/ButtonMessageDTO.java
This file was deleted.
Oops, something went wrong.
50 changes: 0 additions & 50 deletions
50
spring-backend/src/main/java/com/baloise/collab/springbackend/ButtonWebSocketHandler.java
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
spring-backend/src/main/java/com/baloise/collab/springbackend/ColorProvider.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,12 @@ | ||
package com.baloise.collab.springbackend; | ||
|
||
import lombok.Getter; | ||
|
||
public class ColorProvider { | ||
|
||
@Getter | ||
private static final String[] colors = | ||
{ | ||
"primary", "grey", "success", "warning", "danger" | ||
}; | ||
} |
23 changes: 0 additions & 23 deletions
23
spring-backend/src/main/java/com/baloise/collab/springbackend/ScheduledUpdater.java
This file was deleted.
Oops, something went wrong.
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
...g-backend/src/main/java/com/baloise/collab/springbackend/chat/IncomingChatMessageDTO.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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package com.baloise.collab.springbackend.chat; | ||
|
||
record IncomingChatMessageDTO( | ||
public record IncomingChatMessageDTO( | ||
String text, | ||
String clientTimestamp | ||
) {} |
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
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
69 changes: 69 additions & 0 deletions
69
spring-backend/src/main/java/com/baloise/collab/springbackend/game/PickUpHandler.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,69 @@ | ||
package com.baloise.collab.springbackend.game; | ||
|
||
import com.baloise.collab.springbackend.ColorProvider; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.messaging.simp.SimpMessagingTemplate; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class PickUpHandler { | ||
|
||
|
||
private final SimpMessagingTemplate messageSender; | ||
private long lastSpawn; | ||
private final List<Pickup> pickups = new ArrayList<>(); | ||
|
||
@Getter | ||
private static final String[] icons = | ||
{ | ||
"star-shape", "star-full", "web", "twitter" | ||
}; | ||
|
||
Random random = new Random(); | ||
|
||
public int collectPickups(Character character) { | ||
var pickupsToCollect = new ArrayList<Pickup>(); | ||
pickups.forEach(pickup -> { | ||
var distance = Math.abs(character.getPosX() - pickup.posX()) | ||
+ Math.abs(character.getPosY() - pickup.posY()); | ||
if(distance < 10) { | ||
pickupsToCollect.add(pickup); | ||
} | ||
}); | ||
|
||
pickups.removeAll(pickupsToCollect); | ||
return pickupsToCollect.size(); | ||
} | ||
|
||
public void spawnPickupsAndSendToClients() { | ||
var currentTime = System.currentTimeMillis(); | ||
if (currentTime - lastSpawn > 3000) { | ||
lastSpawn = currentTime; | ||
pickups.add( | ||
new Pickup( | ||
icons[random.nextInt(0, icons.length)], | ||
ColorProvider.getColors()[random.nextInt(0, icons.length)], | ||
random.nextInt(0, 1000), | ||
random.nextInt(0, 300) | ||
) | ||
); | ||
} | ||
sendPickupsToClients(); | ||
} | ||
|
||
public void clearPickupsAndSendToClients() { | ||
pickups.clear(); | ||
sendPickupsToClients(); | ||
} | ||
|
||
public void sendPickupsToClients() { | ||
messageSender.convertAndSend("/topic/game/pickups", pickups); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
spring-backend/src/main/java/com/baloise/collab/springbackend/game/Pickup.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,9 @@ | ||
package com.baloise.collab.springbackend.game; | ||
|
||
public record Pickup( | ||
String icon, | ||
String color, | ||
int posX, | ||
int posY | ||
) { | ||
} |
Oops, something went wrong.