Skip to content

Commit f49cd23

Browse files
committed
Football added notifications
1 parent f615dc1 commit f49cd23

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

back/src/scripts/footballScript.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ const sphereParams = {
1212
},
1313
meshUrl: 'https://notbloxo.fra1.cdn.digitaloceanspaces.com/Notblox-Assets/base/Ball.glb',
1414
physicsProperties: {
15-
mass: 1,
15+
mass: 1.5,
1616
// Enable continuous collision detection to prevent the ball from going through the walls
1717
enableCcd: true,
1818
angularDamping: 0.3,
1919
linearDamping: 0.2,
2020
},
2121
colliderProperties: {
22-
friction: 0.1,
22+
friction: 0.2,
2323
restitution: 0.8,
2424
},
2525
}
@@ -46,10 +46,24 @@ const chatEntity = EntityManager.getFirstEntityWithComponent(
4646
EntityManager.getInstance().getAllEntities(),
4747
ChatComponent
4848
)
49+
50+
// Message sending functions
4951
function sendGlobalChatMessage(author, message) {
5052
EventSystem.addEvent(new MessageEvent(chatEntity.id, author, message, SerializedMessageType.GLOBAL_CHAT))
5153
}
5254

55+
function sendGlobalNotification(author, message) {
56+
EventSystem.addEvent(new MessageEvent(chatEntity.id, author, message, SerializedMessageType.GLOBAL_NOTIFICATION))
57+
}
58+
59+
function sendTargetedNotification(author, message, targetPlayerIds) {
60+
EventSystem.addEvent(new MessageEvent(chatEntity.id, author, message, SerializedMessageType.TARGETED_NOTIFICATION, targetPlayerIds))
61+
}
62+
63+
function sendTargetedChat(author, message, targetPlayerIds) {
64+
EventSystem.addEvent(new MessageEvent(chatEntity.id, author, message, SerializedMessageType.TARGETED_CHAT, targetPlayerIds))
65+
}
66+
5367
const updateScore = () => {
5468
sendGlobalChatMessage('⚽', `Score: 🔴 Red ${redScore} - ${blueScore} Blue 🔵`)
5569
scoreText.updateText(`🔴 ${redScore} - ${blueScore} 🔵`)
@@ -77,6 +91,10 @@ function createTeamTrigger(x, y, z, color, spawnX) {
7791
collidedWithEntity
7892
.getComponent(DynamicRigidBodyComponent)
7993
.body.setTranslation(new Rapier.Vector3(spawnX, 5, -350), true)
94+
95+
// Broadcast join message
96+
const teamEmoji = color === '#f0513c' ? '🔴' : '🔵'
97+
sendGlobalNotification(`${teamEmoji} New Player`, `${collidedWithEntity.getComponent(TextComponent).text} joined the team ${teamEmoji}`)
8098
}
8199
},
82100
() => {},
@@ -92,7 +110,9 @@ function handleGoal(scoringTeam) {
92110
if (scoringTeam === 'blue') blueScore++
93111
else redScore++
94112

113+
// Send both chat message and global notification
95114
sendGlobalChatMessage('⚽', `${scoringTeam === 'blue' ? '🔵 Blue' : '🔴 Red'} team scores! 🎉`)
115+
sendGlobalNotification('⚽ GOAL!', `${scoringTeam === 'blue' ? '🔵 Blue' : '🔴 Red'} team scores!`)
96116
updateScore()
97117

98118
const body = ball.entity.getComponent(DynamicRigidBodyComponent).body
@@ -135,6 +155,7 @@ ScriptableSystem.update = (dt, entities) => {
135155
if (!hasPlayers) {
136156
// No players are present. Reset the game
137157
sendGlobalChatMessage('⚽', 'No players, resetting game...')
158+
sendGlobalNotification('⚽ Game Reset', 'Waiting for players to join...')
138159

139160
const ballBody = ball.entity.getComponent(DynamicRigidBodyComponent).body
140161
ballBody.setTranslation(
@@ -163,8 +184,11 @@ const proximityPromptComponent = new ProximityPromptComponent(ball.entity.id, {
163184
if (ballRigidbody && playerRotationComponent && playerEntity.getComponent(InputComponent)) {
164185
// Convert rotation to direction vector
165186
const direction = playerRotationComponent.getForwardDirection()
187+
188+
// Send targeted notification to the player who kicked the ball
189+
sendTargetedNotification('⚽', 'You kicked the ball!', [playerEntity.id])
190+
166191
// Calculate player looking direction
167-
// sendChatMessage('⚽', `Player shot the ball !`)
168192
const playerLookingDirectionVector = new Rapier.Vector3(
169193
direction.x * 750,
170194
0,

0 commit comments

Comments
 (0)