react-native-games 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -7
- package/lib/module/games/balloon-blaster/BalloonBlaster.js +1 -167
- package/lib/module/games/balloon-blaster/BalloonBlaster.js.map +1 -1
- package/lib/module/games/balloon-blaster/BalloonBlasterConstants.js +1 -182
- package/lib/module/games/balloon-blaster/BalloonBlasterConstants.js.map +1 -1
- package/lib/module/games/balloon-blaster/BalloonBlasterService.js +1 -318
- package/lib/module/games/balloon-blaster/BalloonBlasterStore.js +1 -183
- package/lib/module/games/balloon-blaster/components/BalloonComponent.js +1 -237
- package/lib/module/games/balloon-blaster/components/GameArea.js +1 -156
- package/lib/module/games/balloon-blaster/components/GameBackground.js +1 -476
- package/lib/module/games/balloon-blaster/components/ScoreBoard.js +1 -112
- package/lib/module/games/balloon-blaster/components/ScoreBoard.js.map +1 -1
- package/lib/module/games/balloon-blaster/components/index.js +1 -7
- package/lib/module/games/candy-crush/CandyCrush.js +1 -131
- package/lib/module/games/candy-crush/CandyCrush.js.map +1 -1
- package/lib/module/games/candy-crush/CandyCrushConstants.js +1 -125
- package/lib/module/games/candy-crush/CandyCrushConstants.js.map +1 -1
- package/lib/module/games/candy-crush/CandyCrushService.js +1 -370
- package/lib/module/games/candy-crush/CandyCrushStore.js +1 -303
- package/lib/module/games/candy-crush/components/CandyItem.js +1 -191
- package/lib/module/games/candy-crush/components/GameBackground.js +1 -85
- package/lib/module/games/candy-crush/components/GameGrid.js +1 -314
- package/lib/module/games/candy-crush/components/ScoreBoard.js +1 -79
- package/lib/module/games/candy-crush/components/index.js +1 -7
- package/lib/module/games/candy-crush/index.js +1 -6
- package/lib/module/games/colors-sort/ColorsSort.js +1 -143
- package/lib/module/games/colors-sort/ColorsSort.js.map +1 -1
- package/lib/module/games/colors-sort/ColorsSortConstants.js +1 -72
- package/lib/module/games/colors-sort/ColorsSortConstants.js.map +1 -1
- package/lib/module/games/colors-sort/ColorsSortService.js +1 -255
- package/lib/module/games/colors-sort/ColorsSortStore.js +1 -257
- package/lib/module/games/colors-sort/ColorsSortStore.js.map +1 -1
- package/lib/module/games/colors-sort/components/ColorContainer.js +1 -140
- package/lib/module/games/colors-sort/components/GameBackground.js +1 -135
- package/lib/module/games/colors-sort/components/ScoreBoard.js +1 -70
- package/lib/module/games/colors-sort/components/index.js +1 -6
- package/lib/module/games/dino-jump/DinoJump.js +1 -209
- package/lib/module/games/dino-jump/DinoJump.js.map +1 -1
- package/lib/module/games/dino-jump/DinoJumpConstants.js +1 -189
- package/lib/module/games/dino-jump/DinoJumpConstants.js.map +1 -1
- package/lib/module/games/dino-jump/DinoJumpService.js +1 -270
- package/lib/module/games/dino-jump/DinoJumpStore.js +1 -381
- package/lib/module/games/dino-jump/components/DinoSprite.js +1 -418
- package/lib/module/games/dino-jump/components/DinoSprite.js.map +1 -1
- package/lib/module/games/dino-jump/components/GameArea.js +1 -68
- package/lib/module/games/dino-jump/components/GameBackground.js +1 -444
- package/lib/module/games/dino-jump/components/ObstacleSprite.js +1 -306
- package/lib/module/games/dino-jump/components/ScoreBoard.js +1 -105
- package/lib/module/games/dino-jump/components/ScoreBoard.js.map +1 -1
- package/lib/module/games/dino-jump/components/StarSprite.js +1 -45
- package/lib/module/games/dino-jump/components/index.js +1 -9
- package/lib/module/games/flappy-bird/FlappyBird.js +1 -126
- package/lib/module/games/flappy-bird/FlappyBird.js.map +1 -1
- package/lib/module/games/flappy-bird/FlappyBirdConstants.js +1 -90
- package/lib/module/games/flappy-bird/FlappyBirdConstants.js.map +1 -1
- package/lib/module/games/flappy-bird/FlappyBirdStore.js +1 -300
- package/lib/module/games/flappy-bird/components/Bird.js +1 -87
- package/lib/module/games/flappy-bird/components/GameArea.js +1 -87
- package/lib/module/games/flappy-bird/components/GameBackground.js +1 -79
- package/lib/module/games/flappy-bird/components/Pipes.js +1 -172
- package/lib/module/games/flappy-bird/components/ScoreBoard.js +1 -73
- package/lib/module/games/flappy-bird/components/index.js +1 -8
- package/lib/module/games/fruit-merger/FruitMerger.js +1 -120
- package/lib/module/games/fruit-merger/FruitMerger.js.map +1 -1
- package/lib/module/games/fruit-merger/FruitMergerConstants.js +1 -119
- package/lib/module/games/fruit-merger/FruitMergerConstants.js.map +1 -1
- package/lib/module/games/fruit-merger/FruitMergerService.js +1 -13
- package/lib/module/games/fruit-merger/FruitMergerStore.js +1 -315
- package/lib/module/games/fruit-merger/components/FruitItem.js +1 -102
- package/lib/module/games/fruit-merger/components/GameArea.js +1 -103
- package/lib/module/games/fruit-merger/components/GameBackground.js +1 -498
- package/lib/module/games/fruit-merger/components/ScoreBoard.js +1 -58
- package/lib/module/games/fruit-merger/components/index.js +1 -7
- package/lib/module/games/fruit-ninja/FruitNinja.js +1 -134
- package/lib/module/games/fruit-ninja/FruitNinja.js.map +1 -1
- package/lib/module/games/fruit-ninja/FruitNinjaConstants.js +1 -148
- package/lib/module/games/fruit-ninja/FruitNinjaConstants.js.map +1 -1
- package/lib/module/games/fruit-ninja/FruitNinjaService.js +1 -311
- package/lib/module/games/fruit-ninja/FruitNinjaStore.js +1 -191
- package/lib/module/games/fruit-ninja/FruitNinjaStore.js.map +1 -1
- package/lib/module/games/fruit-ninja/components/FruitComponent.js +1 -99
- package/lib/module/games/fruit-ninja/components/GameArea.js +1 -215
- package/lib/module/games/fruit-ninja/components/GameBackground.js +1 -1267
- package/lib/module/games/fruit-ninja/components/ScoreBoard.js +1 -92
- package/lib/module/games/fruit-ninja/components/ScoreBoard.js.map +1 -1
- package/lib/module/games/fruit-ninja/components/index.js +1 -7
- package/lib/module/games/game-2048/Game2048.js +1 -149
- package/lib/module/games/game-2048/Game2048.js.map +1 -1
- package/lib/module/games/game-2048/Game2048Constants.js +1 -263
- package/lib/module/games/game-2048/Game2048Constants.js.map +1 -1
- package/lib/module/games/game-2048/Game2048Service.js +1 -457
- package/lib/module/games/game-2048/Game2048Store.js +1 -236
- package/lib/module/games/game-2048/components/GameBackground.js +1 -247
- package/lib/module/games/game-2048/components/GameGrid.js +1 -139
- package/lib/module/games/game-2048/components/GameTile.js +1 -72
- package/lib/module/games/game-2048/components/ScoreBoard.js +1 -52
- package/lib/module/games/game-2048/components/index.js +1 -7
- package/lib/module/games/maze-runner/MazeRunner.js +1 -267
- package/lib/module/games/maze-runner/MazeRunner.js.map +1 -1
- package/lib/module/games/maze-runner/MazeRunnerConstants.js +1 -100
- package/lib/module/games/maze-runner/MazeRunnerConstants.js.map +1 -1
- package/lib/module/games/maze-runner/MazeRunnerService.js +1 -586
- package/lib/module/games/maze-runner/components/EnhancedBallComponent.js +1 -150
- package/lib/module/games/maze-runner/components/EnhancedGameArea.js +1 -370
- package/lib/module/games/maze-runner/components/GameBackground.js +1 -175
- package/lib/module/games/maze-runner/components/ScoreBoard.js +1 -61
- package/lib/module/games/maze-runner/components/SkiaPipeComponent.js +1 -209
- package/lib/module/games/maze-runner/components/StaticGameBackground.js +1 -169
- package/lib/module/games/maze-runner/components/WallComponent.js +1 -91
- package/lib/module/games/maze-runner/components/index.js +1 -8
- package/lib/module/games/popit-fidget/PopitFidget.js +1 -285
- package/lib/module/games/popit-fidget/PopitFidget.js.map +1 -1
- package/lib/module/games/popit-fidget/PopitFidgetConstants.js +1 -113
- package/lib/module/games/popit-fidget/PopitFidgetConstants.js.map +1 -1
- package/lib/module/games/popit-fidget/PopitFidgetService.js +1 -132
- package/lib/module/games/popit-fidget/PopitFidgetStore.js +1 -125
- package/lib/module/games/popit-fidget/components/BubbleComponent.js +1 -198
- package/lib/module/games/popit-fidget/components/FidgetGrid.js +1 -165
- package/lib/module/games/popit-fidget/components/GameBackground.js +1 -177
- package/lib/module/games/popit-fidget/components/ScoreBoard.js +1 -61
- package/lib/module/games/popit-fidget/components/index.js +1 -7
- package/lib/module/games/sliding-numbers/SlidingNumbers.js +1 -159
- package/lib/module/games/sliding-numbers/SlidingNumbers.js.map +1 -1
- package/lib/module/games/sliding-numbers/SlidingNumbersConstants.js +1 -207
- package/lib/module/games/sliding-numbers/SlidingNumbersConstants.js.map +1 -1
- package/lib/module/games/sliding-numbers/SlidingNumbersService.js +1 -248
- package/lib/module/games/sliding-numbers/SlidingNumbersStore.js +1 -274
- package/lib/module/games/sliding-numbers/components/GameBackground.js +1 -259
- package/lib/module/games/sliding-numbers/components/NumbersGrid.js +1 -174
- package/lib/module/games/sliding-numbers/components/NumbersTile.js +1 -116
- package/lib/module/games/sliding-numbers/components/ScoreBoard.js +1 -64
- package/lib/module/games/sliding-numbers/components/index.js +1 -7
- package/lib/module/games/snake/Snake.js +1 -189
- package/lib/module/games/snake/Snake.js.map +1 -1
- package/lib/module/games/snake/SnakeConstants.js +1 -138
- package/lib/module/games/snake/SnakeConstants.js.map +1 -1
- package/lib/module/games/snake/SnakeService.js +1 -148
- package/lib/module/games/snake/SnakeStore.js +1 -182
- package/lib/module/games/snake/components/GameBackground.js +1 -221
- package/lib/module/games/snake/components/GameGrid.js +1 -153
- package/lib/module/games/snake/components/ScoreBoard.js +1 -51
- package/lib/module/games/snake/components/index.js +1 -6
- package/lib/module/games/snake/index.js +1 -6
- package/lib/module/games/space-fighter/SpaceFighter.js +1 -165
- package/lib/module/games/space-fighter/SpaceFighter.js.map +1 -1
- package/lib/module/games/space-fighter/SpaceFighterConstants.js +1 -108
- package/lib/module/games/space-fighter/SpaceFighterConstants.js.map +1 -1
- package/lib/module/games/space-fighter/SpaceFighterService.js +1 -326
- package/lib/module/games/space-fighter/SpaceFighterStore.js +1 -209
- package/lib/module/games/space-fighter/components/AsteroidComponent.js +1 -113
- package/lib/module/games/space-fighter/components/GameArea.js +1 -289
- package/lib/module/games/space-fighter/components/GameBackground.js +1 -239
- package/lib/module/games/space-fighter/components/ScoreBoard.js +1 -136
- package/lib/module/games/space-fighter/components/Spacecraft3D.js +1 -202
- package/lib/module/games/space-fighter/components/SpacecraftPath.js +1 -52
- package/lib/module/games/space-fighter/components/index.js +1 -9
- package/lib/module/games/whack-a-mole/WhackAMole.js +1 -270
- package/lib/module/games/whack-a-mole/WhackAMole.js.map +1 -1
- package/lib/module/games/whack-a-mole/WhackAMoleConstants.js +1 -115
- package/lib/module/games/whack-a-mole/WhackAMoleConstants.js.map +1 -1
- package/lib/module/games/whack-a-mole/WhackAMoleService.js +1 -120
- package/lib/module/games/whack-a-mole/WhackAMoleStore.js +1 -172
- package/lib/module/games/whack-a-mole/components/GameBackground.js +1 -477
- package/lib/module/games/whack-a-mole/components/GameGrid.js +1 -97
- package/lib/module/games/whack-a-mole/components/GameHole.js +1 -196
- package/lib/module/games/whack-a-mole/components/MoleCharacter.js +1 -241
- package/lib/module/games/whack-a-mole/components/ScoreBoard.js +1 -67
- package/lib/module/games/whack-a-mole/components/ScoreBoard.js.map +1 -1
- package/lib/module/games/whack-a-mole/components/index.js +1 -8
- package/lib/module/helpers/AnimationFrame.js +1 -120
- package/lib/module/helpers/AnimationTracker.js +1 -89
- package/lib/module/helpers/ErrorHandler.js +1 -269
- package/lib/module/helpers/GameControlButton.js +1 -219
- package/lib/module/helpers/GameOverModal.js +1 -144
- package/lib/module/helpers/GameOverModal.js.map +1 -1
- package/lib/module/helpers/GameSettingsModal.js +1 -287
- package/lib/module/helpers/ParticleBlast.js +1 -134
- package/lib/module/helpers/ScoreBoardContainer.js +1 -34
- package/lib/module/helpers/index.js +1 -12
- package/lib/module/index.js +1 -22
- package/lib/module/services/GamesConstants.js +1 -178
- package/lib/module/services/GamesService.js +1 -112
- package/lib/module/services/GamesService.js.map +1 -1
- package/lib/module/services/HapticsService.js +1 -77
- package/lib/module/services/SoundsService.js +1 -302
- package/lib/module/services/UtilsService.js +1 -32
- package/lib/typescript/src/games/balloon-blaster/BalloonBlaster.d.ts.map +1 -1
- package/lib/typescript/src/games/balloon-blaster/BalloonBlasterConstants.d.ts +1 -1
- package/lib/typescript/src/games/balloon-blaster/components/ScoreBoard.d.ts.map +1 -1
- package/lib/typescript/src/games/candy-crush/CandyCrushConstants.d.ts +7 -7
- package/lib/typescript/src/games/colors-sort/ColorsSort.d.ts.map +1 -1
- package/lib/typescript/src/games/colors-sort/ColorsSortStore.d.ts.map +1 -1
- package/lib/typescript/src/games/dino-jump/DinoJump.d.ts.map +1 -1
- package/lib/typescript/src/games/dino-jump/components/DinoSprite.d.ts.map +1 -1
- package/lib/typescript/src/games/flappy-bird/FlappyBird.d.ts.map +1 -1
- package/lib/typescript/src/games/flappy-bird/FlappyBirdConstants.d.ts.map +1 -1
- package/lib/typescript/src/games/fruit-merger/FruitMerger.d.ts.map +1 -1
- package/lib/typescript/src/games/fruit-merger/FruitMergerConstants.d.ts.map +1 -1
- package/lib/typescript/src/games/fruit-ninja/FruitNinja.d.ts.map +1 -1
- package/lib/typescript/src/games/fruit-ninja/components/ScoreBoard.d.ts.map +1 -1
- package/lib/typescript/src/games/game-2048/Game2048.d.ts.map +1 -1
- package/lib/typescript/src/games/maze-runner/MazeRunner.d.ts.map +1 -1
- package/lib/typescript/src/games/popit-fidget/PopitFidget.d.ts.map +1 -1
- package/lib/typescript/src/games/sliding-numbers/SlidingNumbers.d.ts.map +1 -1
- package/lib/typescript/src/games/space-fighter/SpaceFighter.d.ts.map +1 -1
- package/lib/typescript/src/games/whack-a-mole/WhackAMole.d.ts.map +1 -1
- package/lib/typescript/src/games/whack-a-mole/WhackAMoleConstants.d.ts +1 -1
- package/lib/typescript/src/games/whack-a-mole/components/ScoreBoard.d.ts.map +1 -1
- package/lib/typescript/src/helpers/GameOverModal.d.ts +3 -0
- package/lib/typescript/src/helpers/GameOverModal.d.ts.map +1 -1
- package/lib/typescript/src/services/GamesConstants.d.ts +7 -7
- package/package.json +2 -2
|
@@ -1,191 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { create } from 'zustand';
|
|
4
|
-
import { subscribeWithSelector } from 'zustand/middleware';
|
|
5
|
-
import { GAME_CONFIG } from "./FruitNinjaService.js";
|
|
6
|
-
import { immerMiddleware } from "../../services/UtilsService.js";
|
|
7
|
-
// Optimized store with selective subscriptions for low-end devices
|
|
8
|
-
export const useFruitNinjaStore = create()(subscribeWithSelector(immerMiddleware((set, get) => ({
|
|
9
|
-
// Initial state
|
|
10
|
-
score: 0,
|
|
11
|
-
timeLeft: 60,
|
|
12
|
-
// Fixed 60 seconds regardless of difficulty
|
|
13
|
-
isPlaying: false,
|
|
14
|
-
gameOver: false,
|
|
15
|
-
combo: 0,
|
|
16
|
-
lives: GAME_CONFIG.MAX_LIVES,
|
|
17
|
-
fruits: [],
|
|
18
|
-
slicePath: [],
|
|
19
|
-
isSlicing: false,
|
|
20
|
-
// Actions
|
|
21
|
-
startGame: _gameDuration => {
|
|
22
|
-
// Always use fixed duration regardless of difficulty or passed duration
|
|
23
|
-
const duration = 60;
|
|
24
|
-
set(draft => {
|
|
25
|
-
draft.score = 0;
|
|
26
|
-
draft.timeLeft = duration;
|
|
27
|
-
draft.isPlaying = true;
|
|
28
|
-
draft.gameOver = false;
|
|
29
|
-
draft.combo = 0;
|
|
30
|
-
draft.lives = GAME_CONFIG.MAX_LIVES;
|
|
31
|
-
draft.fruits = [];
|
|
32
|
-
draft.slicePath = [];
|
|
33
|
-
draft.isSlicing = false;
|
|
34
|
-
});
|
|
35
|
-
},
|
|
36
|
-
stopGame: () => {
|
|
37
|
-
set(draft => {
|
|
38
|
-
draft.score = 0;
|
|
39
|
-
draft.timeLeft = 60; // Fixed 60 seconds
|
|
40
|
-
draft.isPlaying = false;
|
|
41
|
-
draft.gameOver = false;
|
|
42
|
-
draft.combo = 0;
|
|
43
|
-
draft.lives = GAME_CONFIG.MAX_LIVES;
|
|
44
|
-
draft.fruits = [];
|
|
45
|
-
draft.slicePath = [];
|
|
46
|
-
draft.isSlicing = false;
|
|
47
|
-
});
|
|
48
|
-
},
|
|
49
|
-
resetGame: () => {
|
|
50
|
-
set(draft => {
|
|
51
|
-
draft.score = 0;
|
|
52
|
-
draft.timeLeft = 60; // Fixed 60 seconds
|
|
53
|
-
draft.isPlaying = false;
|
|
54
|
-
draft.gameOver = false;
|
|
55
|
-
draft.combo = 0;
|
|
56
|
-
draft.lives = GAME_CONFIG.MAX_LIVES;
|
|
57
|
-
draft.fruits = [];
|
|
58
|
-
draft.slicePath = [];
|
|
59
|
-
draft.isSlicing = false;
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
sliceFruit: fruitId => {
|
|
63
|
-
const {
|
|
64
|
-
fruits,
|
|
65
|
-
isPlaying
|
|
66
|
-
} = get();
|
|
67
|
-
if (!isPlaying) return;
|
|
68
|
-
|
|
69
|
-
// Optimized: Use for-loop instead of find for better performance
|
|
70
|
-
let fruitIndex = -1;
|
|
71
|
-
for (let i = 0; i < fruits.length; i++) {
|
|
72
|
-
if (fruits[i].id === fruitId) {
|
|
73
|
-
fruitIndex = i;
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
if (fruitIndex === -1 || fruits[fruitIndex].isSliced) return;
|
|
78
|
-
|
|
79
|
-
// Simplified scoring: each fruit = 10 points (no combo multipliers)
|
|
80
|
-
const points = 10;
|
|
81
|
-
set(draft => {
|
|
82
|
-
draft.score = draft.score + points;
|
|
83
|
-
// Optimized: Direct array access instead of find
|
|
84
|
-
if (draft.fruits[fruitIndex]) {
|
|
85
|
-
draft.fruits[fruitIndex].isSliced = true;
|
|
86
|
-
draft.fruits[fruitIndex].sliceTime = Date.now();
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
},
|
|
90
|
-
updateScore: points => {
|
|
91
|
-
set(draft => {
|
|
92
|
-
draft.score = draft.score + points;
|
|
93
|
-
});
|
|
94
|
-
},
|
|
95
|
-
decrementTime: () => {
|
|
96
|
-
set(draft => {
|
|
97
|
-
const newTimeLeft = draft.timeLeft - 1;
|
|
98
|
-
if (newTimeLeft <= 0) {
|
|
99
|
-
draft.timeLeft = 0;
|
|
100
|
-
draft.isPlaying = false;
|
|
101
|
-
draft.gameOver = true;
|
|
102
|
-
} else {
|
|
103
|
-
draft.timeLeft = newTimeLeft;
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
},
|
|
107
|
-
addFruit: fruit => {
|
|
108
|
-
set(draft => {
|
|
109
|
-
draft.fruits.push(fruit);
|
|
110
|
-
});
|
|
111
|
-
},
|
|
112
|
-
removeFruit: fruitId => {
|
|
113
|
-
set(draft => {
|
|
114
|
-
draft.fruits = draft.fruits.filter(f => f.id !== fruitId);
|
|
115
|
-
});
|
|
116
|
-
},
|
|
117
|
-
updateFruit: (fruitId, updates) => {
|
|
118
|
-
set(draft => {
|
|
119
|
-
// Optimized: Use for-loop instead of find for better performance
|
|
120
|
-
for (let i = 0; i < draft.fruits.length; i++) {
|
|
121
|
-
if (draft.fruits[i].id === fruitId) {
|
|
122
|
-
Object.assign(draft.fruits[i], updates);
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
},
|
|
128
|
-
setSlicePath: path => {
|
|
129
|
-
set(draft => {
|
|
130
|
-
draft.slicePath = path;
|
|
131
|
-
});
|
|
132
|
-
},
|
|
133
|
-
setIsSlicing: isSlicing => {
|
|
134
|
-
set(draft => {
|
|
135
|
-
draft.isSlicing = isSlicing;
|
|
136
|
-
});
|
|
137
|
-
},
|
|
138
|
-
incrementCombo: () => {
|
|
139
|
-
set(draft => {
|
|
140
|
-
draft.combo = draft.combo + 1;
|
|
141
|
-
});
|
|
142
|
-
},
|
|
143
|
-
resetCombo: () => {
|
|
144
|
-
set(draft => {
|
|
145
|
-
draft.combo = 0;
|
|
146
|
-
});
|
|
147
|
-
},
|
|
148
|
-
loseLife: () => {
|
|
149
|
-
set(draft => {
|
|
150
|
-
const newLives = Math.max(0, draft.lives - 1);
|
|
151
|
-
draft.lives = newLives;
|
|
152
|
-
if (newLives <= 0) {
|
|
153
|
-
draft.isPlaying = false;
|
|
154
|
-
draft.gameOver = true;
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
},
|
|
158
|
-
addLife: () => {
|
|
159
|
-
set(draft => {
|
|
160
|
-
draft.lives = Math.min(draft.lives + 1, GAME_CONFIG.MAX_LIVES); // Cap at max lives
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
}))));
|
|
164
|
-
|
|
165
|
-
// Store reference to game service for cleanup
|
|
166
|
-
let gameServiceInstance = null;
|
|
167
|
-
|
|
168
|
-
// Function to register game service instance
|
|
169
|
-
export const registerGameService = gameService => {
|
|
170
|
-
gameServiceInstance = gameService;
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
// Automatic game cleanup when gameOver becomes true
|
|
174
|
-
// This replaces the cleanup logic that was previously in the FruitNinja component
|
|
175
|
-
useFruitNinjaStore.subscribe(state => state.gameOver, (gameOver, previousGameOver) => {
|
|
176
|
-
if (gameOver && !previousGameOver) {
|
|
177
|
-
// Game just ended, trigger automatic cleanup
|
|
178
|
-
setTimeout(() => {
|
|
179
|
-
// Stop game service to prevent new fruits from spawning
|
|
180
|
-
if (gameServiceInstance) {
|
|
181
|
-
gameServiceInstance.cleanup();
|
|
182
|
-
}
|
|
183
|
-
const state = useFruitNinjaStore.getState();
|
|
184
|
-
// Clear all fruits from the screen
|
|
185
|
-
state.fruits.forEach(fruit => {
|
|
186
|
-
useFruitNinjaStore.getState().removeFruit(fruit.id);
|
|
187
|
-
});
|
|
188
|
-
}, 50); // Small delay to ensure state consistency
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
//# sourceMappingURL=FruitNinjaStore.js.map
|
|
1
|
+
"use strict";import{create}from 'zustand';import{subscribeWithSelector}from 'zustand/middleware';import{GAME_CONFIG}from "./FruitNinjaService.js";import{immerMiddleware}from "../../services/UtilsService.js";export const useFruitNinjaStore = create()(subscribeWithSelector(immerMiddleware((set,get)=>({score:0,timeLeft:120,isPlaying:false,gameOver:false,combo:0,lives:GAME_CONFIG.MAX_LIVES,fruits:[],slicePath:[],isSlicing:false,startGame:_gameDuration =>{const duration = 120;set(draft =>{draft.score = 0;draft.timeLeft = duration;draft.isPlaying = true;draft.gameOver = false;draft.combo = 0;draft.lives = GAME_CONFIG.MAX_LIVES;draft.fruits = [];draft.slicePath = [];draft.isSlicing = false;});},stopGame:()=>{set(draft =>{draft.score = 0;draft.timeLeft = 120;draft.isPlaying = false;draft.gameOver = false;draft.combo = 0;draft.lives = GAME_CONFIG.MAX_LIVES;draft.fruits = [];draft.slicePath = [];draft.isSlicing = false;});},resetGame:()=>{set(draft =>{draft.score = 0;draft.timeLeft = 120;draft.isPlaying = false;draft.gameOver = false;draft.combo = 0;draft.lives = GAME_CONFIG.MAX_LIVES;draft.fruits = [];draft.slicePath = [];draft.isSlicing = false;});},sliceFruit:fruitId =>{const{fruits,isPlaying}= get();if(!isPlaying)return;let fruitIndex = -1;for(let i = 0;i < fruits.length;i++){if(fruits[i].id === fruitId){fruitIndex = i;break;}}if(fruitIndex === -1 || fruits[fruitIndex].isSliced)return;const points = 10;set(draft =>{draft.score = draft.score + points;if(draft.fruits[fruitIndex]){draft.fruits[fruitIndex].isSliced = true;draft.fruits[fruitIndex].sliceTime = Date.now();}});},updateScore:points =>{set(draft =>{draft.score = draft.score + points;});},decrementTime:()=>{set(draft =>{const newTimeLeft = draft.timeLeft - 1;if(newTimeLeft <= 0){draft.timeLeft = 0;draft.isPlaying = false;draft.gameOver = true;}else{draft.timeLeft = newTimeLeft;}});},addFruit:fruit =>{set(draft =>{draft.fruits.push(fruit);});},removeFruit:fruitId =>{set(draft =>{draft.fruits = draft.fruits.filter(f => f.id !== fruitId);});},updateFruit:(fruitId,updates)=>{set(draft =>{for(let i = 0;i < draft.fruits.length;i++){if(draft.fruits[i].id === fruitId){Object.assign(draft.fruits[i],updates);break;}}});},setSlicePath:path =>{set(draft =>{draft.slicePath = path;});},setIsSlicing:isSlicing =>{set(draft =>{draft.isSlicing = isSlicing;});},incrementCombo:()=>{set(draft =>{draft.combo = draft.combo + 1;});},resetCombo:()=>{set(draft =>{draft.combo = 0;});},loseLife:()=>{set(draft =>{const newLives = Math.max(0,draft.lives - 1);draft.lives = newLives;if(newLives <= 0){draft.isPlaying = false;draft.gameOver = true;}});},addLife:()=>{set(draft =>{draft.lives = Math.min(draft.lives + 1,GAME_CONFIG.MAX_LIVES);});}}))));let gameServiceInstance = null;export const registerGameService = gameService =>{gameServiceInstance = gameService;};useFruitNinjaStore.subscribe(state => state.gameOver,(gameOver,previousGameOver)=>{if(gameOver && !previousGameOver){setTimeout(()=>{if(gameServiceInstance){gameServiceInstance.cleanup();}const state = useFruitNinjaStore.getState();state.fruits.forEach(fruit =>{useFruitNinjaStore.getState().removeFruit(fruit.id);});},50);}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["create","subscribeWithSelector","GAME_CONFIG","immerMiddleware","useFruitNinjaStore","set","get","score","timeLeft","isPlaying","gameOver","combo","lives","MAX_LIVES","fruits","slicePath","isSlicing","startGame","_gameDuration","duration","draft","stopGame","resetGame","sliceFruit","fruitId","fruitIndex","i","length","id","isSliced","points","sliceTime","Date","now","updateScore","decrementTime","newTimeLeft","addFruit","fruit","push","removeFruit","filter","f","updateFruit","updates","Object","assign","setSlicePath","path","setIsSlicing","incrementCombo","resetCombo","loseLife","newLives","Math","max","addLife","min","gameServiceInstance","registerGameService","gameService","subscribe","state","previousGameOver","setTimeout","cleanup","getState","forEach"],"sourceRoot":"../../../../src","sources":["games/fruit-ninja/FruitNinjaStore.ts"],"mappings":";;AAAA,SAASA,MAAM,QAAQ,SAAS;AAChC,SAASC,qBAAqB,QAAQ,oBAAoB;AAE1D,SAASC,WAAW,QAAQ,wBAAqB;AACjD,SAASC,eAAe,QAAQ,gCAA6B;AAkC7D;AACA,OAAO,MAAMC,kBAAkB,GAAGJ,MAAM,CAAkB,CAAC,CACzDC,qBAAqB,CACnBE,eAAe,CAAC,CAACE,GAAQ,EAAEC,GAAQ,MAAM;EAC3C;EACAC,KAAK,EAAE,CAAC;EACRC,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"names":["create","subscribeWithSelector","GAME_CONFIG","immerMiddleware","useFruitNinjaStore","set","get","score","timeLeft","isPlaying","gameOver","combo","lives","MAX_LIVES","fruits","slicePath","isSlicing","startGame","_gameDuration","duration","draft","stopGame","resetGame","sliceFruit","fruitId","fruitIndex","i","length","id","isSliced","points","sliceTime","Date","now","updateScore","decrementTime","newTimeLeft","addFruit","fruit","push","removeFruit","filter","f","updateFruit","updates","Object","assign","setSlicePath","path","setIsSlicing","incrementCombo","resetCombo","loseLife","newLives","Math","max","addLife","min","gameServiceInstance","registerGameService","gameService","subscribe","state","previousGameOver","setTimeout","cleanup","getState","forEach"],"sourceRoot":"../../../../src","sources":["games/fruit-ninja/FruitNinjaStore.ts"],"mappings":";;AAAA,SAASA,MAAM,QAAQ,SAAS;AAChC,SAASC,qBAAqB,QAAQ,oBAAoB;AAE1D,SAASC,WAAW,QAAQ,wBAAqB;AACjD,SAASC,eAAe,QAAQ,gCAA6B;AAkC7D;AACA,OAAO,MAAMC,kBAAkB,GAAGJ,MAAM,CAAkB,CAAC,CACzDC,qBAAqB,CACnBE,eAAe,CAAC,CAACE,GAAQ,EAAEC,GAAQ,MAAM;EAC3C;EACAC,KAAK,EAAE,CAAC;EACRC,QAAQ,EAAE,GAAG;EAAE;EACfC,SAAS,EAAE,KAAK;EAChBC,QAAQ,EAAE,KAAK;EACfC,KAAK,EAAE,CAAC;EACRC,KAAK,EAAEV,WAAW,CAACW,SAAS;EAC5BC,MAAM,EAAE,EAAE;EACVC,SAAS,EAAE,EAAE;EACbC,SAAS,EAAE,KAAK;EAEhB;EACAC,SAAS,EAAGC,aAAsB,IAAK;IACrC;IACA,MAAMC,QAAQ,GAAG,GAAG;IACpBd,GAAG,CAAEe,KAAU,IAAK;MAClBA,KAAK,CAACb,KAAK,GAAG,CAAC;MACfa,KAAK,CAACZ,QAAQ,GAAGW,QAAQ;MACzBC,KAAK,CAACX,SAAS,GAAG,IAAI;MACtBW,KAAK,CAACV,QAAQ,GAAG,KAAK;MACtBU,KAAK,CAACT,KAAK,GAAG,CAAC;MACfS,KA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AC/B;MAEA,MAAMH,KAAK,GAAG1D,kBAAkB,CAAC8D,QAAQ,CAAC,CAAC;MAC3C;MACAJ,KAAK,CAAChD,MAAM,CAACqD,OAAO,CAAC7B,KAAK,IAAI;QAC5BlC,kBAAkB,CAAC8D,QAAQ,CAAC,CAAC,CAAC1B,WAAW,CAACF,KAAK,CAACV,EAAE,CAAC;MACrD,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;EACV;AACF,CACF,CAAC","ignoreList":[]}
|
|
@@ -1,99 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import { View, TouchableOpacity, Text, StyleSheet } from 'react-native';
|
|
5
|
-
import { GAME_CONFIG } from "../FruitNinjaService.js";
|
|
6
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
|
-
export const FruitComponent = ({
|
|
8
|
-
fruit,
|
|
9
|
-
onSlice
|
|
10
|
-
}) => {
|
|
11
|
-
const scale = fruit.isSliced ? 0 : 1;
|
|
12
|
-
const opacity = fruit.isSliced ? 0 : 1;
|
|
13
|
-
const style = {
|
|
14
|
-
transform: [{
|
|
15
|
-
translateX: fruit.position.x
|
|
16
|
-
}, {
|
|
17
|
-
translateY: fruit.position.y
|
|
18
|
-
}, {
|
|
19
|
-
rotate: `${fruit.rotation}rad`
|
|
20
|
-
}, {
|
|
21
|
-
scale
|
|
22
|
-
}],
|
|
23
|
-
opacity,
|
|
24
|
-
position: 'absolute',
|
|
25
|
-
width: GAME_CONFIG.FRUIT_SIZE,
|
|
26
|
-
height: GAME_CONFIG.FRUIT_SIZE,
|
|
27
|
-
zIndex: fruit.isBomb ? 10 : 5
|
|
28
|
-
};
|
|
29
|
-
const getBorderColor = () => {
|
|
30
|
-
if (fruit.isBomb) return '#ef4444'; // red-500
|
|
31
|
-
if (fruit.isBonus) return '#fbbf24'; // yellow-400
|
|
32
|
-
if (fruit.isFreeze) return '#60a5fa'; // blue-400
|
|
33
|
-
return '#4ade80'; // green-400
|
|
34
|
-
};
|
|
35
|
-
const getBackgroundColor = () => {
|
|
36
|
-
if (fruit.isBomb) return '#fee2e2'; // red-100
|
|
37
|
-
if (fruit.isBonus) return '#fef3c7'; // yellow-100
|
|
38
|
-
if (fruit.isFreeze) return '#dbeafe'; // blue-100
|
|
39
|
-
return '#dcfce7'; // green-100
|
|
40
|
-
};
|
|
41
|
-
return /*#__PURE__*/_jsx(View, {
|
|
42
|
-
style: style,
|
|
43
|
-
children: /*#__PURE__*/_jsxs(TouchableOpacity, {
|
|
44
|
-
style: [styles.fruitButton, {
|
|
45
|
-
width: GAME_CONFIG.FRUIT_SIZE,
|
|
46
|
-
height: GAME_CONFIG.FRUIT_SIZE,
|
|
47
|
-
borderColor: getBorderColor(),
|
|
48
|
-
backgroundColor: getBackgroundColor()
|
|
49
|
-
}],
|
|
50
|
-
onPress: () => onSlice?.(fruit.id),
|
|
51
|
-
activeOpacity: 0.8,
|
|
52
|
-
children: [/*#__PURE__*/_jsx(Text, {
|
|
53
|
-
style: styles.fruitEmoji,
|
|
54
|
-
children: fruit.type.emoji
|
|
55
|
-
}), (fruit.isBomb || fruit.isBonus || fruit.isFreeze) && /*#__PURE__*/_jsx(View, {
|
|
56
|
-
style: [styles.glowEffect, {
|
|
57
|
-
backgroundColor: fruit.isBomb ? '#ff4757' : fruit.isBonus ? '#ffa502' : '#3742fa',
|
|
58
|
-
shadowColor: fruit.isBomb ? '#ff4757' : fruit.isBonus ? '#ffa502' : '#3742fa',
|
|
59
|
-
shadowOffset: {
|
|
60
|
-
width: 0,
|
|
61
|
-
height: 0
|
|
62
|
-
},
|
|
63
|
-
shadowOpacity: 0.8,
|
|
64
|
-
shadowRadius: 10,
|
|
65
|
-
elevation: 10
|
|
66
|
-
}]
|
|
67
|
-
})]
|
|
68
|
-
})
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
const styles = StyleSheet.create({
|
|
72
|
-
fruitButton: {
|
|
73
|
-
justifyContent: 'center',
|
|
74
|
-
alignItems: 'center',
|
|
75
|
-
borderRadius: 50,
|
|
76
|
-
borderWidth: 2,
|
|
77
|
-
shadowColor: '#000',
|
|
78
|
-
shadowOffset: {
|
|
79
|
-
width: 0,
|
|
80
|
-
height: 4
|
|
81
|
-
},
|
|
82
|
-
shadowOpacity: 0.3,
|
|
83
|
-
shadowRadius: 8,
|
|
84
|
-
elevation: 8
|
|
85
|
-
},
|
|
86
|
-
fruitEmoji: {
|
|
87
|
-
fontSize: 32
|
|
88
|
-
},
|
|
89
|
-
glowEffect: {
|
|
90
|
-
position: 'absolute',
|
|
91
|
-
top: 0,
|
|
92
|
-
left: 0,
|
|
93
|
-
right: 0,
|
|
94
|
-
bottom: 0,
|
|
95
|
-
borderRadius: 50,
|
|
96
|
-
opacity: 0.3
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
//# sourceMappingURL=FruitComponent.js.map
|
|
1
|
+
"use strict";import React from 'react';import{View,TouchableOpacity,Text,StyleSheet}from 'react-native';import{GAME_CONFIG}from "../FruitNinjaService.js";import{jsx as _jsx,jsxs as _jsxs}from "react/jsx-runtime";export const FruitComponent =({fruit,onSlice})=>{const scale = fruit.isSliced ? 0:1;const opacity = fruit.isSliced ? 0:1;const style ={transform:[{translateX:fruit.position.x},{translateY:fruit.position.y},{rotate:`${fruit.rotation}rad`},{scale}],opacity,position:'absolute',width:GAME_CONFIG.FRUIT_SIZE,height:GAME_CONFIG.FRUIT_SIZE,zIndex:fruit.isBomb ? 10:5};const getBorderColor =()=>{if(fruit.isBomb)return '#ef4444';if(fruit.isBonus)return '#fbbf24';if(fruit.isFreeze)return '#60a5fa';return '#4ade80';};const getBackgroundColor =()=>{if(fruit.isBomb)return '#fee2e2';if(fruit.isBonus)return '#fef3c7';if(fruit.isFreeze)return '#dbeafe';return '#dcfce7';};return _jsx(View,{style:style,children:_jsxs(TouchableOpacity,{style:[styles.fruitButton,{width:GAME_CONFIG.FRUIT_SIZE,height:GAME_CONFIG.FRUIT_SIZE,borderColor:getBorderColor(),backgroundColor:getBackgroundColor()}],onPress:()=> onSlice?.(fruit.id),activeOpacity:0.8,children:[_jsx(Text,{style:styles.fruitEmoji,children:fruit.type.emoji}),(fruit.isBomb || fruit.isBonus || fruit.isFreeze)&& _jsx(View,{style:[styles.glowEffect,{backgroundColor:fruit.isBomb ? '#ff4757':fruit.isBonus ? '#ffa502':'#3742fa',shadowColor:fruit.isBomb ? '#ff4757':fruit.isBonus ? '#ffa502':'#3742fa',shadowOffset:{width:0,height:0},shadowOpacity:0.8,shadowRadius:10,elevation:10}]})]})});};const styles = StyleSheet.create({fruitButton:{justifyContent:'center',alignItems:'center',borderRadius:50,borderWidth:2,shadowColor:'#000',shadowOffset:{width:0,height:4},shadowOpacity:0.3,shadowRadius:8,elevation:8},fruitEmoji:{fontSize:32},glowEffect:{position:'absolute',top:0,left:0,right:0,bottom:0,borderRadius:50,opacity:0.3}});
|
|
@@ -1,215 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import React, { useRef, useEffect, useState } from 'react';
|
|
4
|
-
import { View, StyleSheet } from 'react-native';
|
|
5
|
-
import { runOnJS } from 'react-native-reanimated';
|
|
6
|
-
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
|
|
7
|
-
import { useFruitNinjaStore } from "../FruitNinjaStore.js";
|
|
8
|
-
import { GAME_CONFIG } from "../FruitNinjaService.js";
|
|
9
|
-
import { playSound, GAME_SOUNDS } from "../../../services/SoundsService.js";
|
|
10
|
-
import { playHaptic, HapticType } from "../../../services/HapticsService.js";
|
|
11
|
-
import { ParticleBlast, useAnimationTracker } from "../../../helpers/index.js";
|
|
12
|
-
import { FruitComponent } from "./FruitComponent.js";
|
|
13
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
-
export const GameArea = /*#__PURE__*/React.memo(() => {
|
|
15
|
-
// Read state directly from store to reduce main component re-renders
|
|
16
|
-
const fruits = useFruitNinjaStore(state => state.fruits);
|
|
17
|
-
|
|
18
|
-
// Get store actions
|
|
19
|
-
const {
|
|
20
|
-
sliceFruit,
|
|
21
|
-
removeFruit,
|
|
22
|
-
updateFruit,
|
|
23
|
-
resetCombo,
|
|
24
|
-
loseLife,
|
|
25
|
-
addLife
|
|
26
|
-
} = useFruitNinjaStore();
|
|
27
|
-
|
|
28
|
-
// Minimal collision detection - no visual trail needed
|
|
29
|
-
const lastGesturePoint = useRef(null);
|
|
30
|
-
|
|
31
|
-
// Self-contained component - no external settings needed
|
|
32
|
-
|
|
33
|
-
// Animation tracking for fruits using shared utility
|
|
34
|
-
const fruitAnimations = useAnimationTracker();
|
|
35
|
-
|
|
36
|
-
// State for managing active particle blasts
|
|
37
|
-
const [activeBlasts, setActiveBlasts] = useState([]);
|
|
38
|
-
|
|
39
|
-
// Sound and haptic feedback functions (using default enabled state)
|
|
40
|
-
const playSliceSound = () => {
|
|
41
|
-
playSound(GAME_SOUNDS.FRUIT_NINJA.SLICE, true);
|
|
42
|
-
playHaptic(HapticType.LIGHT, true);
|
|
43
|
-
};
|
|
44
|
-
const playBombSound = () => {
|
|
45
|
-
playSound(GAME_SOUNDS.FRUIT_NINJA.BOMB, true);
|
|
46
|
-
playHaptic(HapticType.HEAVY, true);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// Create blast particles using shared ParticleBlast component
|
|
50
|
-
const createBlastParticles = fruit => {
|
|
51
|
-
const blastX = fruit.position.x + GAME_CONFIG.FRUIT_SIZE / 2;
|
|
52
|
-
const blastY = fruit.position.y + GAME_CONFIG.FRUIT_SIZE / 2;
|
|
53
|
-
const blastId = `blast_${Date.now()}_${Math.random()}`;
|
|
54
|
-
setActiveBlasts(prev => [...prev, {
|
|
55
|
-
id: blastId,
|
|
56
|
-
x: blastX,
|
|
57
|
-
y: blastY
|
|
58
|
-
}]);
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
// Handle blast completion (remove from active blasts)
|
|
62
|
-
const handleBlastComplete = blastId => {
|
|
63
|
-
setActiveBlasts(prev => prev.filter(blast => blast.id !== blastId));
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
// Simplified gesture handling - no visual trail, just collision detection
|
|
67
|
-
const handleGestureStart = event => {
|
|
68
|
-
const currentState = useFruitNinjaStore.getState();
|
|
69
|
-
if (!currentState.isPlaying) return;
|
|
70
|
-
lastGesturePoint.current = {
|
|
71
|
-
x: event.x,
|
|
72
|
-
y: event.y
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
// Light haptic feedback on slice start
|
|
76
|
-
playHaptic(HapticType.LIGHT, true);
|
|
77
|
-
};
|
|
78
|
-
const handleGestureUpdate = event => {
|
|
79
|
-
const currentState = useFruitNinjaStore.getState();
|
|
80
|
-
if (!currentState.isPlaying) return;
|
|
81
|
-
const currentPoint = {
|
|
82
|
-
x: event.x,
|
|
83
|
-
y: event.y
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
// Check for fruit collisions with current gesture point
|
|
87
|
-
checkFruitCollisions(currentPoint);
|
|
88
|
-
lastGesturePoint.current = currentPoint;
|
|
89
|
-
};
|
|
90
|
-
const handleGestureEnd = () => {
|
|
91
|
-
const currentState = useFruitNinjaStore.getState();
|
|
92
|
-
if (!currentState.isPlaying) return;
|
|
93
|
-
lastGesturePoint.current = null;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
// Create pan gesture - moved from parent
|
|
97
|
-
const panGesture = Gesture.Pan().onStart(event => {
|
|
98
|
-
runOnJS(handleGestureStart)(event);
|
|
99
|
-
}).onUpdate(event => {
|
|
100
|
-
runOnJS(handleGestureUpdate)(event);
|
|
101
|
-
}).onEnd(() => {
|
|
102
|
-
runOnJS(handleGestureEnd)();
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// Fruit slicing logic - moved from parent
|
|
106
|
-
const handleFruitSlice = fruitId => {
|
|
107
|
-
// Double-check game state to prevent race conditions
|
|
108
|
-
const currentState = useFruitNinjaStore.getState();
|
|
109
|
-
if (!currentState.isPlaying || currentState.gameOver) return;
|
|
110
|
-
const fruit = currentState.fruits.find(f => f.id === fruitId);
|
|
111
|
-
if (!fruit || fruit.isSliced) return;
|
|
112
|
-
|
|
113
|
-
// Handle different fruit types BEFORE marking as sliced
|
|
114
|
-
if (fruit.isBomb) {
|
|
115
|
-
playBombSound();
|
|
116
|
-
loseLife();
|
|
117
|
-
resetCombo();
|
|
118
|
-
// Create blast particles at bomb location
|
|
119
|
-
createBlastParticles(fruit);
|
|
120
|
-
updateFruit(fruitId, {
|
|
121
|
-
isSliced: true
|
|
122
|
-
});
|
|
123
|
-
} else {
|
|
124
|
-
// Handle different fruit types with simplified mechanics
|
|
125
|
-
playSliceSound();
|
|
126
|
-
if (fruit.isBonus) {
|
|
127
|
-
// Star fruit - add a life instead of points
|
|
128
|
-
addLife();
|
|
129
|
-
playSliceSound();
|
|
130
|
-
// Mark star as sliced after processing
|
|
131
|
-
updateFruit(fruitId, {
|
|
132
|
-
isSliced: true
|
|
133
|
-
});
|
|
134
|
-
} else if (fruit.isFreeze) {
|
|
135
|
-
// Freeze fruit - slice and mark (sliceFruit handles marking)
|
|
136
|
-
sliceFruit(fruitId);
|
|
137
|
-
} else {
|
|
138
|
-
// Regular fruit - add 10 points (sliceFruit handles marking)
|
|
139
|
-
sliceFruit(fruitId);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Create blast particles at fruit location
|
|
143
|
-
createBlastParticles(fruit);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Remove fruit after animation
|
|
147
|
-
setTimeout(() => {
|
|
148
|
-
removeFruit(fruitId);
|
|
149
|
-
fruitAnimations.delete(fruitId);
|
|
150
|
-
}, 500);
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
// Optimized collision detection with single point
|
|
154
|
-
const checkFruitCollisions = gesturePoint => {
|
|
155
|
-
const currentFruits = useFruitNinjaStore.getState().fruits;
|
|
156
|
-
currentFruits.forEach(fruit => {
|
|
157
|
-
if (!fruit.isSliced) {
|
|
158
|
-
// Simple distance-based collision detection
|
|
159
|
-
const fruitCenterX = fruit.position.x + GAME_CONFIG.FRUIT_SIZE / 2;
|
|
160
|
-
const fruitCenterY = fruit.position.y + GAME_CONFIG.FRUIT_SIZE / 2;
|
|
161
|
-
const fruitRadius = GAME_CONFIG.FRUIT_SIZE / 2;
|
|
162
|
-
|
|
163
|
-
// Check if gesture point is within fruit radius
|
|
164
|
-
const distance = Math.sqrt(Math.pow(gesturePoint.x - fruitCenterX, 2) + Math.pow(gesturePoint.y - fruitCenterY, 2));
|
|
165
|
-
if (distance <= fruitRadius) {
|
|
166
|
-
handleFruitSlice(fruit.id);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
// Track fruit animations without shared values - moved from parent
|
|
173
|
-
useEffect(() => {
|
|
174
|
-
fruits.forEach(fruit => {
|
|
175
|
-
if (!fruitAnimations.has(fruit.id)) {
|
|
176
|
-
fruitAnimations.initialize(fruit.id);
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
}, [fruits, fruitAnimations]);
|
|
180
|
-
return /*#__PURE__*/_jsx(GestureDetector, {
|
|
181
|
-
gesture: panGesture,
|
|
182
|
-
children: /*#__PURE__*/_jsxs(View, {
|
|
183
|
-
style: styles.gameArea,
|
|
184
|
-
children: [fruits.map(fruit => {
|
|
185
|
-
const animation = fruitAnimations.get(fruit.id);
|
|
186
|
-
return /*#__PURE__*/_jsx(FruitComponent, {
|
|
187
|
-
fruit: fruit,
|
|
188
|
-
animation: animation,
|
|
189
|
-
onSlice: handleFruitSlice
|
|
190
|
-
}, fruit.id);
|
|
191
|
-
}), activeBlasts.map(blast => /*#__PURE__*/_jsx(ParticleBlast, {
|
|
192
|
-
x: blast.x,
|
|
193
|
-
y: blast.y,
|
|
194
|
-
particleCount: 8,
|
|
195
|
-
duration: 1000,
|
|
196
|
-
onComplete: () => handleBlastComplete(blast.id)
|
|
197
|
-
}, blast.id))]
|
|
198
|
-
})
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
const styles = StyleSheet.create({
|
|
202
|
-
gameArea: {
|
|
203
|
-
flex: 1,
|
|
204
|
-
position: 'relative',
|
|
205
|
-
overflow: 'hidden'
|
|
206
|
-
},
|
|
207
|
-
backgroundGradient: {
|
|
208
|
-
position: 'absolute',
|
|
209
|
-
top: 0,
|
|
210
|
-
left: 0,
|
|
211
|
-
right: 0,
|
|
212
|
-
bottom: 0
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
//# sourceMappingURL=GameArea.js.map
|
|
1
|
+
"use strict";import React,{useRef,useEffect,useState}from 'react';import{View,StyleSheet}from 'react-native';import{runOnJS}from 'react-native-reanimated';import{Gesture,GestureDetector}from 'react-native-gesture-handler';import{useFruitNinjaStore}from "../FruitNinjaStore.js";import{GAME_CONFIG}from "../FruitNinjaService.js";import{playSound,GAME_SOUNDS}from "../../../services/SoundsService.js";import{playHaptic,HapticType}from "../../../services/HapticsService.js";import{ParticleBlast,useAnimationTracker}from "../../../helpers/index.js";import{FruitComponent}from "./FruitComponent.js";import{jsx as _jsx,jsxs as _jsxs}from "react/jsx-runtime";export const GameArea = React.memo(()=>{const fruits = useFruitNinjaStore(state => state.fruits);const{sliceFruit,removeFruit,updateFruit,resetCombo,loseLife,addLife}= useFruitNinjaStore();const lastGesturePoint = useRef(null);const fruitAnimations = useAnimationTracker();const [activeBlasts,setActiveBlasts] = useState([]);const playSliceSound =()=>{playSound(GAME_SOUNDS.FRUIT_NINJA.SLICE,true);playHaptic(HapticType.LIGHT,true);};const playBombSound =()=>{playSound(GAME_SOUNDS.FRUIT_NINJA.BOMB,true);playHaptic(HapticType.HEAVY,true);};const createBlastParticles = fruit =>{const blastX = fruit.position.x + GAME_CONFIG.FRUIT_SIZE / 2;const blastY = fruit.position.y + GAME_CONFIG.FRUIT_SIZE / 2;const blastId = `blast_${Date.now()}_${Math.random()}`;setActiveBlasts(prev => [...prev,{id:blastId,x:blastX,y:blastY}]);};const handleBlastComplete = blastId =>{setActiveBlasts(prev => prev.filter(blast => blast.id !== blastId));};const handleGestureStart = event =>{const currentState = useFruitNinjaStore.getState();if(!currentState.isPlaying)return;lastGesturePoint.current ={x:event.x,y:event.y};playHaptic(HapticType.LIGHT,true);};const handleGestureUpdate = event =>{const currentState = useFruitNinjaStore.getState();if(!currentState.isPlaying)return;const currentPoint ={x:event.x,y:event.y};checkFruitCollisions(currentPoint);lastGesturePoint.current = currentPoint;};const handleGestureEnd =()=>{const currentState = useFruitNinjaStore.getState();if(!currentState.isPlaying)return;lastGesturePoint.current = null;};const panGesture = Gesture.Pan().onStart(event =>{runOnJS(handleGestureStart)(event);}).onUpdate(event =>{runOnJS(handleGestureUpdate)(event);}).onEnd(()=>{runOnJS(handleGestureEnd)();});const handleFruitSlice = fruitId =>{const currentState = useFruitNinjaStore.getState();if(!currentState.isPlaying || currentState.gameOver)return;const fruit = currentState.fruits.find(f => f.id === fruitId);if(!fruit || fruit.isSliced)return;if(fruit.isBomb){playBombSound();loseLife();resetCombo();createBlastParticles(fruit);updateFruit(fruitId,{isSliced:true});}else{playSliceSound();if(fruit.isBonus){addLife();playSliceSound();updateFruit(fruitId,{isSliced:true});}else if(fruit.isFreeze){sliceFruit(fruitId);}else{sliceFruit(fruitId);}createBlastParticles(fruit);}setTimeout(()=>{removeFruit(fruitId);fruitAnimations.delete(fruitId);},500);};const checkFruitCollisions = gesturePoint =>{const currentFruits = useFruitNinjaStore.getState().fruits;currentFruits.forEach(fruit =>{if(!fruit.isSliced){const fruitCenterX = fruit.position.x + GAME_CONFIG.FRUIT_SIZE / 2;const fruitCenterY = fruit.position.y + GAME_CONFIG.FRUIT_SIZE / 2;const fruitRadius = GAME_CONFIG.FRUIT_SIZE / 2;const distance = Math.sqrt(Math.pow(gesturePoint.x - fruitCenterX,2)+ Math.pow(gesturePoint.y - fruitCenterY,2));if(distance <= fruitRadius){handleFruitSlice(fruit.id);}}});};useEffect(()=>{fruits.forEach(fruit =>{if(!fruitAnimations.has(fruit.id)){fruitAnimations.initialize(fruit.id);}});},[fruits,fruitAnimations]);return _jsx(GestureDetector,{gesture:panGesture,children:_jsxs(View,{style:styles.gameArea,children:[fruits.map(fruit =>{const animation = fruitAnimations.get(fruit.id);return _jsx(FruitComponent,{fruit:fruit,animation:animation,onSlice:handleFruitSlice},fruit.id);}),activeBlasts.map(blast => _jsx(ParticleBlast,{x:blast.x,y:blast.y,particleCount:8,duration:1000,onComplete:()=> handleBlastComplete(blast.id)},blast.id))]})});});const styles = StyleSheet.create({gameArea:{flex:1,position:'relative',overflow:'hidden'},backgroundGradient:{position:'absolute',top:0,left:0,right:0,bottom:0}});
|