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,134 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import React, { useEffect, useRef } from 'react';
|
|
4
|
-
import { View, StyleSheet } from 'react-native';
|
|
5
|
-
import { GestureHandlerRootView } from 'react-native-gesture-handler';
|
|
6
|
-
import { useFruitNinjaStore, registerGameService } from "./FruitNinjaStore.js";
|
|
7
|
-
import { createFruitNinjaService, getDifficultySpawnInterval } from "./FruitNinjaService.js";
|
|
8
|
-
import { ScoreBoard, GameArea, GameBackground } from "./components/index.js";
|
|
9
|
-
import { GameControlButton, GameOverModal, useAnimationTrackers, useGameErrorHandler, GameErrorType } from "../../helpers/index.js";
|
|
10
|
-
import { GameSettingsModal } from "../../helpers/index.js";
|
|
11
|
-
import { GAME_IDS, DEFAULT_GAME_SETTINGS } from "../../services/UtilsService.js";
|
|
12
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
-
export const FruitNinja = ({
|
|
14
|
-
settings,
|
|
15
|
-
onSettingsChange
|
|
16
|
-
}) => {
|
|
17
|
-
// Read UI-critical state independently to minimize re-renders
|
|
18
|
-
const isPlaying = useFruitNinjaStore(state => state.isPlaying);
|
|
19
|
-
const gameOver = useFruitNinjaStore(state => state.gameOver);
|
|
20
|
-
const score = useFruitNinjaStore(state => state.score);
|
|
21
|
-
|
|
22
|
-
// Get store actions independently (these don't cause re-renders)
|
|
23
|
-
const startGame = useFruitNinjaStore(state => state.startGame);
|
|
24
|
-
const stopGame = useFruitNinjaStore(state => state.stopGame);
|
|
25
|
-
const resetGame = useFruitNinjaStore(state => state.resetGame);
|
|
26
|
-
const decrementTime = useFruitNinjaStore(state => state.decrementTime);
|
|
27
|
-
const addFruit = useFruitNinjaStore(state => state.addFruit);
|
|
28
|
-
const removeFruit = useFruitNinjaStore(state => state.removeFruit);
|
|
29
|
-
const updateFruit = useFruitNinjaStore(state => state.updateFruit);
|
|
30
|
-
|
|
31
|
-
// Use shared animation tracking utility
|
|
32
|
-
const {
|
|
33
|
-
fruitAnimations,
|
|
34
|
-
particleAnimations
|
|
35
|
-
} = useAnimationTrackers(['fruitAnimations', 'particleAnimations']);
|
|
36
|
-
|
|
37
|
-
// Error handling for the game
|
|
38
|
-
const {
|
|
39
|
-
wrapFunction,
|
|
40
|
-
safeExecute
|
|
41
|
-
} = useGameErrorHandler(GAME_IDS.FRUIT_NINJA);
|
|
42
|
-
|
|
43
|
-
// Game service for main game control only with error handling
|
|
44
|
-
const gameService = useRef(safeExecute(() => createFruitNinjaService(fruitAnimations, particleAnimations), createFruitNinjaService(fruitAnimations, particleAnimations),
|
|
45
|
-
// Fallback to direct creation
|
|
46
|
-
GameErrorType.INITIALIZATION_ERROR)).current;
|
|
47
|
-
|
|
48
|
-
// Register game service with store for automatic cleanup
|
|
49
|
-
useEffect(() => {
|
|
50
|
-
registerGameService(gameService);
|
|
51
|
-
return () => {
|
|
52
|
-
handleResetGame();
|
|
53
|
-
};
|
|
54
|
-
}, [gameService]);
|
|
55
|
-
|
|
56
|
-
// Game control functions with error handling
|
|
57
|
-
const handleStartGame = wrapFunction(() => {
|
|
58
|
-
startGame(); // Store uses fixed 60s duration internally
|
|
59
|
-
if (gameService) {
|
|
60
|
-
gameService.resetAnimations();
|
|
61
|
-
gameService.startGameTimer(decrementTime);
|
|
62
|
-
gameService.startFruitSpawning(spawnFruit, getDifficultySpawnInterval(settings?.difficulty || 'medium'));
|
|
63
|
-
gameService.startPhysicsLoop(updateFruit, removeFruit, () => useFruitNinjaStore.getState().fruits);
|
|
64
|
-
}
|
|
65
|
-
}, GameErrorType.INITIALIZATION_ERROR);
|
|
66
|
-
const handleStopGame = wrapFunction(() => {
|
|
67
|
-
stopGame();
|
|
68
|
-
if (gameService) {
|
|
69
|
-
gameService.cleanup();
|
|
70
|
-
gameService.resetAnimations();
|
|
71
|
-
}
|
|
72
|
-
}, GameErrorType.UNKNOWN_ERROR);
|
|
73
|
-
const handleResetGame = wrapFunction(() => {
|
|
74
|
-
if (gameService) {
|
|
75
|
-
gameService.cleanup();
|
|
76
|
-
}
|
|
77
|
-
resetGame();
|
|
78
|
-
if (gameService) {
|
|
79
|
-
gameService.resetAnimations();
|
|
80
|
-
}
|
|
81
|
-
}, GameErrorType.UNKNOWN_ERROR);
|
|
82
|
-
|
|
83
|
-
// Fruit spawning
|
|
84
|
-
const spawnFruit = fruit => {
|
|
85
|
-
addFruit(fruit);
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
// Get offset from settings
|
|
89
|
-
const offset = settings?.offset ?? 0;
|
|
90
|
-
return /*#__PURE__*/_jsx(View, {
|
|
91
|
-
style: styles.container,
|
|
92
|
-
children: /*#__PURE__*/_jsx(GestureHandlerRootView, {
|
|
93
|
-
children: /*#__PURE__*/_jsxs(GameBackground, {
|
|
94
|
-
offset: offset,
|
|
95
|
-
children: [/*#__PURE__*/_jsx(GameArea, {}), /*#__PURE__*/_jsx(ScoreBoard, {
|
|
96
|
-
offset: offset
|
|
97
|
-
}), /*#__PURE__*/_jsx(GameControlButton, {
|
|
98
|
-
isPlaying: isPlaying,
|
|
99
|
-
gameOver: gameOver,
|
|
100
|
-
onStartGame: handleStartGame,
|
|
101
|
-
onStopGame: handleStopGame,
|
|
102
|
-
startButtonText: "START SLICING",
|
|
103
|
-
stopButtonText: "STOP GAME",
|
|
104
|
-
startButtonSubtext: "Slice fruits to score!",
|
|
105
|
-
stopButtonSubtext: "End current game",
|
|
106
|
-
startButtonColor: "#10b981",
|
|
107
|
-
stopButtonColor: "#dc2626",
|
|
108
|
-
startButtonBorderColor: "#34d399",
|
|
109
|
-
stopButtonBorderColor: "#f87171"
|
|
110
|
-
}), /*#__PURE__*/_jsx(GameOverModal, {
|
|
111
|
-
isVisible: gameOver,
|
|
112
|
-
score: score,
|
|
113
|
-
onPlayAgain: handleResetGame,
|
|
114
|
-
buttonText: "Slice Again!",
|
|
115
|
-
primaryColor: "rgba(34, 139, 34, 0.8)" // Green theme for Fruit Ninja
|
|
116
|
-
,
|
|
117
|
-
borderColor: "rgba(34, 139, 34, 0.9)",
|
|
118
|
-
buttonColor: "#10b981",
|
|
119
|
-
buttonBorderColor: "#34d399"
|
|
120
|
-
}), /*#__PURE__*/_jsx(GameSettingsModal, {
|
|
121
|
-
gameId: GAME_IDS.FRUIT_NINJA,
|
|
122
|
-
settings: settings || DEFAULT_GAME_SETTINGS,
|
|
123
|
-
onSettingsChange: onSettingsChange
|
|
124
|
-
})]
|
|
125
|
-
})
|
|
126
|
-
})
|
|
127
|
-
});
|
|
128
|
-
};
|
|
129
|
-
const styles = StyleSheet.create({
|
|
130
|
-
container: {
|
|
131
|
-
flex: 1
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
//# sourceMappingURL=FruitNinja.js.map
|
|
1
|
+
"use strict";import React,{useEffect,useRef}from 'react';import{View,StyleSheet}from 'react-native';import{GestureHandlerRootView}from 'react-native-gesture-handler';import{useFruitNinjaStore,registerGameService}from "./FruitNinjaStore.js";import{createFruitNinjaService,getDifficultySpawnInterval}from "./FruitNinjaService.js";import{ScoreBoard,GameArea,GameBackground}from "./components/index.js";import{GameControlButton,GameOverModal,useAnimationTrackers,useGameErrorHandler,GameErrorType}from "../../helpers/index.js";import{GameSettingsModal}from "../../helpers/index.js";import{GAME_IDS,DEFAULT_GAME_SETTINGS}from "../../services/UtilsService.js";import{jsx as _jsx,jsxs as _jsxs}from "react/jsx-runtime";export const FruitNinja =({settings,onSettingsChange})=>{const isPlaying = useFruitNinjaStore(state => state.isPlaying);const gameOver = useFruitNinjaStore(state => state.gameOver);const score = useFruitNinjaStore(state => state.score);const startGame = useFruitNinjaStore(state => state.startGame);const stopGame = useFruitNinjaStore(state => state.stopGame);const resetGame = useFruitNinjaStore(state => state.resetGame);const decrementTime = useFruitNinjaStore(state => state.decrementTime);const addFruit = useFruitNinjaStore(state => state.addFruit);const removeFruit = useFruitNinjaStore(state => state.removeFruit);const updateFruit = useFruitNinjaStore(state => state.updateFruit);const{fruitAnimations,particleAnimations}= useAnimationTrackers(['fruitAnimations','particleAnimations']);const{wrapFunction,safeExecute}= useGameErrorHandler(GAME_IDS.FRUIT_NINJA);const gameService = useRef(safeExecute(()=> createFruitNinjaService(fruitAnimations,particleAnimations),createFruitNinjaService(fruitAnimations,particleAnimations),GameErrorType.INITIALIZATION_ERROR)).current;useEffect(()=>{registerGameService(gameService);return()=>{handleResetGame();};},[gameService]);const handleStartGame = wrapFunction(()=>{startGame();if(gameService){gameService.resetAnimations();gameService.startGameTimer(decrementTime);gameService.startFruitSpawning(spawnFruit,getDifficultySpawnInterval(settings?.difficulty || 'medium'));gameService.startPhysicsLoop(updateFruit,removeFruit,()=> useFruitNinjaStore.getState().fruits);}},GameErrorType.INITIALIZATION_ERROR);const handleStopGame = wrapFunction(()=>{stopGame();if(gameService){gameService.cleanup();gameService.resetAnimations();}},GameErrorType.UNKNOWN_ERROR);const handleResetGame = wrapFunction(()=>{if(gameService){gameService.cleanup();}resetGame();if(gameService){gameService.resetAnimations();}},GameErrorType.UNKNOWN_ERROR);const spawnFruit = fruit =>{addFruit(fruit);};const offset = settings?.offset ?? 0;return _jsx(View,{style:styles.container,children:_jsx(GestureHandlerRootView,{children:_jsxs(GameBackground,{offset:offset,children:[_jsx(GameArea,{}),_jsx(ScoreBoard,{offset:offset}),_jsx(GameControlButton,{isPlaying:isPlaying,gameOver:gameOver,onStartGame:handleStartGame,onStopGame:handleStopGame,startButtonText:"START SLICING",stopButtonText:"STOP GAME",startButtonSubtext:"Slice fruits to score!",stopButtonSubtext:"End current game",startButtonColor:"#10b981",stopButtonColor:"#dc2626",startButtonBorderColor:"#34d399",stopButtonBorderColor:"#f87171"}),_jsx(GameOverModal,{isVisible:gameOver,score:score,onPlayAgain:handleResetGame,buttonText:"Slice Again!",primaryColor:"rgba(16,185,129,0.5)",borderColor:"rgba(16,185,129,0.5)",buttonColor:"#ffffff",buttonBorderColor:"#ffffff",buttonTextColor:"#10b981"}),_jsx(GameSettingsModal,{gameId:GAME_IDS.FRUIT_NINJA,settings:settings || DEFAULT_GAME_SETTINGS,onSettingsChange:onSettingsChange})]})})});};const styles = StyleSheet.create({container:{flex:1}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useEffect","useRef","View","StyleSheet","GestureHandlerRootView","useFruitNinjaStore","registerGameService","createFruitNinjaService","getDifficultySpawnInterval","ScoreBoard","GameArea","GameBackground","GameControlButton","GameOverModal","useAnimationTrackers","useGameErrorHandler","GameErrorType","GameSettingsModal","GAME_IDS","DEFAULT_GAME_SETTINGS","jsx","_jsx","jsxs","_jsxs","FruitNinja","settings","onSettingsChange","isPlaying","state","gameOver","score","startGame","stopGame","resetGame","decrementTime","addFruit","removeFruit","updateFruit","fruitAnimations","particleAnimations","wrapFunction","safeExecute","FRUIT_NINJA","gameService","INITIALIZATION_ERROR","current","handleResetGame","handleStartGame","resetAnimations","startGameTimer","startFruitSpawning","spawnFruit","difficulty","startPhysicsLoop","getState","fruits","handleStopGame","cleanup","UNKNOWN_ERROR","fruit","offset","style","styles","container","children","onStartGame","onStopGame","startButtonText","stopButtonText","startButtonSubtext","stopButtonSubtext","startButtonColor","stopButtonColor","startButtonBorderColor","stopButtonBorderColor","isVisible","onPlayAgain","buttonText","primaryColor","borderColor","buttonColor","buttonBorderColor","gameId","create","flex"],"sourceRoot":"../../../../src","sources":["games/fruit-ninja/FruitNinja.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,SAAS,EAAEC,MAAM,QAAQ,OAAO;AAChD,SAASC,IAAI,EAAEC,UAAU,QAAQ,cAAc;AAC/C,SAASC,sBAAsB,QAAQ,8BAA8B;AACrE,SAASC,kBAAkB,EAAEC,mBAAmB,QAAQ,sBAAmB;AAC3E,SAASC,uBAAuB,EAAEC,0BAA0B,QAAQ,wBAAqB;AACzF,SAASC,UAAU,EAAEC,QAAQ,EAAEC,cAAc,QAAQ,uBAAc;AACnE,SAASC,iBAAiB,EAAEC,aAAa,EAAEC,oBAAoB,EAAEC,mBAAmB,EAAEC,aAAa,QAAQ,wBAAe;AAC1H,SAASC,iBAAiB,QAAQ,wBAAe;AACjD,SAASC,QAAQ,EAAkBC,qBAAqB,QAAQ,gCAA6B;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAE9F,OAAO,MAAMC,UAA+B,GAAGA,CAAC;EAC9CC,QAAQ;EACRC;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QAAQ,CAACwB,KAAK,CAAC;EACjB,CAAC;;EAED;EACA,MAAMC,MAAM,GAAGnC,QAAQ,EAAEmC,MAAM,IAAI,CAAC;EAEpC,oBACEvC,IAAA,CAACnB,IAAI;IAAC2D,KAAK,EAAEC,MAAM,CAACC,SAAU;IAAAC,QAAA,eAC5B3C,IAAA,CAACjB,sBAAsB;MAAA4D,QAAA,eACrBzC,KAAA,CAACZ,cAAc;QAACiD,MAAM,EAAEA,MAAO;QAAAI,QAAA,gBAE/B3C,IAAA,CAACX,QAAQ,IAAE,CAAC,eAGZW,IAAA,CAACZ,UAAU;UAACmD,MAAM,EAAEA;QAAO,CAAE,CAAC,eAG9BvC,IAAA,CAACT,iBAAiB;UAChBe,SAAS,EAAEA,SAAU;UACrBE,QAAQ,EAAEA,QAAS;UACnBoC,WAAW,EAAElB,eAAgB;UAC7BmB,UAAU,EAAEV,cAAe;UAC3BW,eAAe,EAAC,eAAe;UAC/BC,cAAc,EAAC,WAAW;UAC1BC,kBAAkB,EAAC,wBAAwB;UAC3CC,iBAAiB,EAAC,kBAAkB;UACpCC,gBAAgB,EAAC,SAAS;UAC1BC,eAAe,EAAC,SAAS;UACzBC,sBAAsB,EAAC,SAAS;UAChCC,qBAAqB,EAAC;QAAS,CAChC,CAAC,eAEFrD,IAAA,CAACR,aAAa;UACZ8D,SAAS,EAAE9C,QAAS;UACpBC,KAAK,EAAEA,KAAM;UACb8C,WAAW,EAAE9B,eAAgB;UAC7B+B,UAAU,EAAC,cAAc;UACzBC,YAAY,EAAC,
|
|
1
|
+
{"version":3,"names":["React","useEffect","useRef","View","StyleSheet","GestureHandlerRootView","useFruitNinjaStore","registerGameService","createFruitNinjaService","getDifficultySpawnInterval","ScoreBoard","GameArea","GameBackground","GameControlButton","GameOverModal","useAnimationTrackers","useGameErrorHandler","GameErrorType","GameSettingsModal","GAME_IDS","DEFAULT_GAME_SETTINGS","jsx","_jsx","jsxs","_jsxs","FruitNinja","settings","onSettingsChange","isPlaying","state","gameOver","score","startGame","stopGame","resetGame","decrementTime","addFruit","removeFruit","updateFruit","fruitAnimations","particleAnimations","wrapFunction","safeExecute","FRUIT_NINJA","gameService","INITIALIZATION_ERROR","current","handleResetGame","handleStartGame","resetAnimations","startGameTimer","startFruitSpawning","spawnFruit","difficulty","startPhysicsLoop","getState","fruits","handleStopGame","cleanup","UNKNOWN_ERROR","fruit","offset","style","styles","container","children","onStartGame","onStopGame","startButtonText","stopButtonText","startButtonSubtext","stopButtonSubtext","startButtonColor","stopButtonColor","startButtonBorderColor","stopButtonBorderColor","isVisible","onPlayAgain","buttonText","primaryColor","borderColor","buttonColor","buttonBorderColor","buttonTextColor","gameId","create","flex"],"sourceRoot":"../../../../src","sources":["games/fruit-ninja/FruitNinja.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,SAAS,EAAEC,MAAM,QAAQ,OAAO;AAChD,SAASC,IAAI,EAAEC,UAAU,QAAQ,cAAc;AAC/C,SAASC,sBAAsB,QAAQ,8BAA8B;AACrE,SAASC,kBAAkB,EAAEC,mBAAmB,QAAQ,sBAAmB;AAC3E,SAASC,uBAAuB,EAAEC,0BAA0B,QAAQ,wBAAqB;AACzF,SAASC,UAAU,EAAEC,QAAQ,EAAEC,cAAc,QAAQ,uBAAc;AACnE,SAASC,iBAAiB,EAAEC,aAAa,EAAEC,oBAAoB,EAAEC,mBAAmB,EAAEC,aAAa,QAAQ,wBAAe;AAC1H,SAASC,iBAAiB,QAAQ,wBAAe;AACjD,SAASC,QAAQ,EAAkBC,qBAAqB,QAAQ,gCAA6B;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAE9F,OAAO,MAAMC,UAA+B,GAAGA,CAAC;EAC9CC,QAAQ;EACRC;AACF,CAAC,KAAK;EACJ;EACA,MAAMC,SAAS,GAAGtB,kBAAkB,CAACuB,KAAK,IAAIA,KAAK,CAACD,SAAS,CAAC;EAC9D,MAAME,QAAQ,GAAGxB,kBAAkB,CAACuB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3D,UAAU,CAACiF,MAAM,CAAC;EAC/BrB,SAAS,EAAE;IACTsB,IAAI,EAAE;EACR;AACF,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,148 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// Fruit Ninja Game Constants
|
|
4
|
-
export const FRUIT_NINJA_GAME_CONFIG = {
|
|
5
|
-
GAME_DURATION: 60,
|
|
6
|
-
// seconds
|
|
7
|
-
MAX_LIVES: 3,
|
|
8
|
-
FRUIT_SPAWN_INTERVAL: 1500,
|
|
9
|
-
// ms - even slower spawning for better gameplay
|
|
10
|
-
FRUIT_FALL_SPEED: 2,
|
|
11
|
-
// pixels per frame
|
|
12
|
-
GRAVITY: 0.12,
|
|
13
|
-
// acceleration - further reduced for even slower movement
|
|
14
|
-
INITIAL_VELOCITY_Y: -10,
|
|
15
|
-
// upward velocity - further reduced for slower, more manageable arc
|
|
16
|
-
INITIAL_VELOCITY_X_RANGE: 1.5,
|
|
17
|
-
// horizontal velocity range - further reduced for slower horizontal movement
|
|
18
|
-
FRUIT_SIZE: 60,
|
|
19
|
-
SLICE_TRAIL_LENGTH: 10,
|
|
20
|
-
SLICE_TRAIL_WIDTH: 8,
|
|
21
|
-
COMBO_TIMEOUT: 2000,
|
|
22
|
-
// ms
|
|
23
|
-
PARTICLE_COUNT: 6,
|
|
24
|
-
PARTICLE_LIFETIME: 1000 // ms
|
|
25
|
-
};
|
|
26
|
-
export const FRUIT_NINJA_ANIMATION_CONFIG = {
|
|
27
|
-
FRUIT_SPRING: {
|
|
28
|
-
damping: 15,
|
|
29
|
-
stiffness: 200
|
|
30
|
-
},
|
|
31
|
-
SLICE_SPRING: {
|
|
32
|
-
damping: 20,
|
|
33
|
-
stiffness: 300
|
|
34
|
-
},
|
|
35
|
-
PARTICLE_SPRING: {
|
|
36
|
-
damping: 25,
|
|
37
|
-
stiffness: 400
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
export const FRUIT_NINJA_COLORS = {
|
|
41
|
-
BACKGROUND: '#87CEEB',
|
|
42
|
-
// Sky blue
|
|
43
|
-
SCORE_BOARD: '#4169E1',
|
|
44
|
-
SLICE_TRAIL: '#FFD700',
|
|
45
|
-
PARTICLE_COLORS: ['#FF6B6B', '#4ECDC4', '#45B7D1', '#96CEB4', '#FFEAA7', '#DDA0DD'],
|
|
46
|
-
PARTICLE_GLOW: 'rgba(255,255,255,0.9)',
|
|
47
|
-
COMBO_TEXT: '#FF4757',
|
|
48
|
-
LIVES_COLOR: '#FF6B6B',
|
|
49
|
-
SCORE: '#FFFFFF',
|
|
50
|
-
UI: '#FF6347',
|
|
51
|
-
BUTTON_ACTIVE: '#FF7F50',
|
|
52
|
-
BUTTON_INACTIVE: '#FFA07A',
|
|
53
|
-
TEXT_PRIMARY: '#FFFFFF',
|
|
54
|
-
TEXT_SECONDARY: '#F0F8FF',
|
|
55
|
-
WHITE: '#FFFFFF',
|
|
56
|
-
START_BUTTON: '#4CAF50',
|
|
57
|
-
GAME_OVER_OVERLAY: 'rgba(0, 0, 0, 0.85)'
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
// Fruit types and their properties
|
|
61
|
-
export const FRUIT_TYPES = [{
|
|
62
|
-
emoji: '🍎',
|
|
63
|
-
points: 10,
|
|
64
|
-
name: 'apple'
|
|
65
|
-
}, {
|
|
66
|
-
emoji: '🍊',
|
|
67
|
-
points: 10,
|
|
68
|
-
name: 'orange'
|
|
69
|
-
}, {
|
|
70
|
-
emoji: '🍌',
|
|
71
|
-
points: 15,
|
|
72
|
-
name: 'banana'
|
|
73
|
-
}, {
|
|
74
|
-
emoji: '🍇',
|
|
75
|
-
points: 20,
|
|
76
|
-
name: 'grapes'
|
|
77
|
-
}, {
|
|
78
|
-
emoji: '🥝',
|
|
79
|
-
points: 25,
|
|
80
|
-
name: 'kiwi'
|
|
81
|
-
}, {
|
|
82
|
-
emoji: '🍓',
|
|
83
|
-
points: 15,
|
|
84
|
-
name: 'strawberry'
|
|
85
|
-
}, {
|
|
86
|
-
emoji: '🥭',
|
|
87
|
-
points: 30,
|
|
88
|
-
name: 'mango'
|
|
89
|
-
}, {
|
|
90
|
-
emoji: '🍑',
|
|
91
|
-
points: 25,
|
|
92
|
-
name: 'cherry'
|
|
93
|
-
}, {
|
|
94
|
-
emoji: '🍒',
|
|
95
|
-
points: 35,
|
|
96
|
-
name: 'cherries'
|
|
97
|
-
}, {
|
|
98
|
-
emoji: '🥥',
|
|
99
|
-
points: 40,
|
|
100
|
-
name: 'coconut'
|
|
101
|
-
}];
|
|
102
|
-
export const FRUIT_SPECIAL_ITEMS = [{
|
|
103
|
-
emoji: '💣',
|
|
104
|
-
points: -50,
|
|
105
|
-
name: 'bomb',
|
|
106
|
-
isBomb: true
|
|
107
|
-
}, {
|
|
108
|
-
emoji: '⭐',
|
|
109
|
-
points: 50,
|
|
110
|
-
name: 'star',
|
|
111
|
-
isBonus: true
|
|
112
|
-
}, {
|
|
113
|
-
emoji: '❄️',
|
|
114
|
-
points: 0,
|
|
115
|
-
name: 'freeze',
|
|
116
|
-
isFreeze: true
|
|
117
|
-
}];
|
|
118
|
-
|
|
119
|
-
// Fruit Ninja Game Theme - Matches scoreboard forest green
|
|
120
|
-
export const FRUIT_NINJA_THEME = {
|
|
121
|
-
backgroundColor: '#87CEEB',
|
|
122
|
-
// Sky blue background
|
|
123
|
-
headerBackgroundColor: 'rgba(34, 139, 34, 0.9)',
|
|
124
|
-
// Forest green header to match scoreboard
|
|
125
|
-
headerTextColor: '#ffffff',
|
|
126
|
-
sectionBackgroundColor: 'rgba(34, 139, 34, 0.3)',
|
|
127
|
-
// Match scoreboard transparency
|
|
128
|
-
sectionTitleColor: '#ffffff',
|
|
129
|
-
// White text on green sections
|
|
130
|
-
buttonSelectedColor: '#166534',
|
|
131
|
-
// Darker green for better contrast
|
|
132
|
-
buttonUnselectedColor: 'rgba(255, 255, 255, 0.3)',
|
|
133
|
-
buttonSelectedTextColor: '#ffffff',
|
|
134
|
-
buttonUnselectedTextColor: '#1f2937',
|
|
135
|
-
switchTrackColorFalse: 'rgba(34, 139, 34, 0.5)',
|
|
136
|
-
switchTrackColorTrue: '#166534',
|
|
137
|
-
// Darker green for better contrast
|
|
138
|
-
switchThumbColor: '#ffffff',
|
|
139
|
-
infoTextColor: '#1f2937' // Dark text for readability
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
// Fruit Ninja Difficulty Descriptions
|
|
143
|
-
export const FRUIT_NINJA_DIFFICULTY_DESCRIPTIONS = {
|
|
144
|
-
easy: 'Fruits spawn slower, more forgiving',
|
|
145
|
-
medium: 'Balanced gameplay and fruit speed',
|
|
146
|
-
hard: 'Fast fruits, quick reflexes needed!'
|
|
147
|
-
};
|
|
148
|
-
//# sourceMappingURL=FruitNinjaConstants.js.map
|
|
1
|
+
"use strict";export const FRUIT_NINJA_GAME_CONFIG ={GAME_DURATION:60,MAX_LIVES:3,FRUIT_SPAWN_INTERVAL:1500,FRUIT_FALL_SPEED:2,GRAVITY:0.12,INITIAL_VELOCITY_Y:-10,INITIAL_VELOCITY_X_RANGE:1.5,FRUIT_SIZE:60,SLICE_TRAIL_LENGTH:10,SLICE_TRAIL_WIDTH:8,COMBO_TIMEOUT:2000,PARTICLE_COUNT:6,PARTICLE_LIFETIME:1000};export const FRUIT_NINJA_ANIMATION_CONFIG ={FRUIT_SPRING:{damping:15,stiffness:200},SLICE_SPRING:{damping:20,stiffness:300},PARTICLE_SPRING:{damping:25,stiffness:400}};export const FRUIT_NINJA_COLORS ={BACKGROUND:'#87CEEB',SCORE_BOARD:'#4169E1',SLICE_TRAIL:'#FFD700',PARTICLE_COLORS:['#FF6B6B','#4ECDC4','#45B7D1','#96CEB4','#FFEAA7','#DDA0DD'],PARTICLE_GLOW:'rgba(255,255,255,0.9)',COMBO_TEXT:'#FF4757',LIVES_COLOR:'#FF6B6B',SCORE:'#FFFFFF',UI:'#FF6347',BUTTON_ACTIVE:'#FF7F50',BUTTON_INACTIVE:'#FFA07A',TEXT_PRIMARY:'#FFFFFF',TEXT_SECONDARY:'#F0F8FF',WHITE:'#FFFFFF',START_BUTTON:'#4CAF50',GAME_OVER_OVERLAY:'rgba(0,0,0,0.85)'};export const FRUIT_TYPES = [{emoji:'🍎',points:10,name:'apple'},{emoji:'🍊',points:10,name:'orange'},{emoji:'🍌',points:15,name:'banana'},{emoji:'🍇',points:20,name:'grapes'},{emoji:'🥝',points:25,name:'kiwi'},{emoji:'🍓',points:15,name:'strawberry'},{emoji:'🥭',points:30,name:'mango'},{emoji:'🍑',points:25,name:'cherry'},{emoji:'🍒',points:35,name:'cherries'},{emoji:'🥥',points:40,name:'coconut'}];export const FRUIT_SPECIAL_ITEMS = [{emoji:'💣',points:-50,name:'bomb',isBomb:true},{emoji:'⭐',points:50,name:'star',isBonus:true},{emoji:'❄️',points:0,name:'freeze',isFreeze:true}];export const FRUIT_NINJA_THEME ={backgroundColor:'rgba(0,0,0,0.7)',headerBackgroundColor:'#10b981',headerTextColor:'#ffffff',sectionBackgroundColor:'rgba(16,185,129,0.15)',sectionTitleColor:'#10b981',buttonSelectedColor:'#10b981',buttonUnselectedColor:'rgba(255,255,255,0.2)',buttonSelectedTextColor:'#ffffff',buttonUnselectedTextColor:'rgba(255,255,255,0.7)',switchTrackColorFalse:'rgba(16,185,129,0.3)',switchTrackColorTrue:'#10b981',switchThumbColor:'#ffffff',infoTextColor:'rgba(255,255,255,0.9)'};export const FRUIT_NINJA_DIFFICULTY_DESCRIPTIONS ={easy:'Fruits spawn slower,more forgiving',medium:'Balanced gameplay and fruit speed',hard:'Fast fruits,quick reflexes needed!'};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["FRUIT_NINJA_GAME_CONFIG","GAME_DURATION","MAX_LIVES","FRUIT_SPAWN_INTERVAL","FRUIT_FALL_SPEED","GRAVITY","INITIAL_VELOCITY_Y","INITIAL_VELOCITY_X_RANGE","FRUIT_SIZE","SLICE_TRAIL_LENGTH","SLICE_TRAIL_WIDTH","COMBO_TIMEOUT","PARTICLE_COUNT","PARTICLE_LIFETIME","FRUIT_NINJA_ANIMATION_CONFIG","FRUIT_SPRING","damping","stiffness","SLICE_SPRING","PARTICLE_SPRING","FRUIT_NINJA_COLORS","BACKGROUND","SCORE_BOARD","SLICE_TRAIL","PARTICLE_COLORS","PARTICLE_GLOW","COMBO_TEXT","LIVES_COLOR","SCORE","UI","BUTTON_ACTIVE","BUTTON_INACTIVE","TEXT_PRIMARY","TEXT_SECONDARY","WHITE","START_BUTTON","GAME_OVER_OVERLAY","FRUIT_TYPES","emoji","points","name","FRUIT_SPECIAL_ITEMS","isBomb","isBonus","isFreeze","FRUIT_NINJA_THEME","backgroundColor","headerBackgroundColor","headerTextColor","sectionBackgroundColor","sectionTitleColor","buttonSelectedColor","buttonUnselectedColor","buttonSelectedTextColor","buttonUnselectedTextColor","switchTrackColorFalse","switchTrackColorTrue","switchThumbColor","infoTextColor","FRUIT_NINJA_DIFFICULTY_DESCRIPTIONS","easy","medium","hard"],"sourceRoot":"../../../../src","sources":["games/fruit-ninja/FruitNinjaConstants.ts"],"mappings":";;AAEA;AACA,OAAO,MAAMA,uBAAuB,GAAG;EACrCC,aAAa,EAAE,EAAE;EAAE;EACnBC,SAAS,EAAE,CAAC;EACZC,oBAAoB,EAAE,IAAI;EAAE;EAC5BC,gBAAgB,EAAE,CAAC;EAAE;EACrBC,OAAO,EAAE,IAAI;EAAE;EACfC,kBAAkB,EAAE,CAAC,EAAE;EAAE;EACzBC,wBAAwB,EAAE,GAAG;EAAE;EAC/BC,UAAU,EAAE,EAAE;EACdC,kBAAkB,EAAE,EAAE;EACtBC,iBAAiB,EAAE,CAAC;EACpBC,aAAa,EAAE,IAAI;EAAE;EACrBC,cAAc,EAAE,CAAC;EACjBC,iBAAiB,EAAE,IAAI,CAAC;AAC1B,CAAU;AAEV,OAAO,MAAMC,4BAA4B,GAAG;EAC1CC,YAAY,EAAE;IACZC,OAAO,EAAE,EAAE;IACXC,SAAS,EAAE;EAC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I,EAAE;AAAa,CAAC,EAC/C;EAAEF,KAAK,EAAE,IAAI;EAAEC,MAAM,EAAE,EAAE;EAAEC,IAAI,EAAE;AAAQ,CAAC,EAC1C;EAAEF,KAAK,EAAE,IAAI;EAAEC,MAAM,EAAE,EAAE;EAAEC,IAAI,EAAE;AAAS,CAAC,EAC3C;EAAEF,KAAK,EAAE,IAAI;EAAEC,MAAM,EAAE,EAAE;EAAEC,IAAI,EAAE;AAAW,CAAC,EAC7C;EAAEF,KAAK,EAAE,IAAI;EAAEC,MAAM,EAAE,EAAE;EAAEC,IAAI,EAAE;AAAU,CAAC,CACpC;AAEV,OAAO,MAAMC,mBAAmB,GAAG,CACjC;EAAEH,KAAK,EAAE,IAAI;EAAEC,MAAM,EAAE,CAAC,EAAE;EAAEC,IAAI,EAAE,MAAM;EAAEE,MAAM,EAAE;AAAK,CAAC,EACxD;EAAEJ,KAAK,EAAE,GAAG;EAAEC,MAAM,EAAE,EAAE;EAAEC,IAAI,EAAE,MAAM;EAAEG,OAAO,EAAE;AAAK,CAAC,EACvD;EAAEL,KAAK,EAAE,IAAI;EAAEC,MAAM,EAAE,CAAC;EAAEC,IAAI,EAAE,QAAQ;EAAEI,QAAQ,EAAE;AAAK,CAAC,CAClD;;AAEV;AACA,OAAO,MAAMC,iBAAoC,GAAG;EAClDC,eAAe,EAAE,
|
|
1
|
+
{"version":3,"names":["FRUIT_NINJA_GAME_CONFIG","GAME_DURATION","MAX_LIVES","FRUIT_SPAWN_INTERVAL","FRUIT_FALL_SPEED","GRAVITY","INITIAL_VELOCITY_Y","INITIAL_VELOCITY_X_RANGE","FRUIT_SIZE","SLICE_TRAIL_LENGTH","SLICE_TRAIL_WIDTH","COMBO_TIMEOUT","PARTICLE_COUNT","PARTICLE_LIFETIME","FRUIT_NINJA_ANIMATION_CONFIG","FRUIT_SPRING","damping","stiffness","SLICE_SPRING","PARTICLE_SPRING","FRUIT_NINJA_COLORS","BACKGROUND","SCORE_BOARD","SLICE_TRAIL","PARTICLE_COLORS","PARTICLE_GLOW","COMBO_TEXT","LIVES_COLOR","SCORE","UI","BUTTON_ACTIVE","BUTTON_INACTIVE","TEXT_PRIMARY","TEXT_SECONDARY","WHITE","START_BUTTON","GAME_OVER_OVERLAY","FRUIT_TYPES","emoji","points","name","FRUIT_SPECIAL_ITEMS","isBomb","isBonus","isFreeze","FRUIT_NINJA_THEME","backgroundColor","headerBackgroundColor","headerTextColor","sectionBackgroundColor","sectionTitleColor","buttonSelectedColor","buttonUnselectedColor","buttonSelectedTextColor","buttonUnselectedTextColor","switchTrackColorFalse","switchTrackColorTrue","switchThumbColor","infoTextColor","FRUIT_NINJA_DIFFICULTY_DESCRIPTIONS","easy","medium","hard"],"sourceRoot":"../../../../src","sources":["games/fruit-ninja/FruitNinjaConstants.ts"],"mappings":";;AAEA;AACA,OAAO,MAAMA,uBAAuB,GAAG;EACrCC,aAAa,EAAE,EAAE;EAAE;EACnBC,SAAS,EAAE,CAAC;EACZC,oBAAoB,EAAE,IAAI;EAAE;EAC5BC,gBAAgB,EAAE,CAAC;EAAE;EACrBC,OAAO,EAAE,IAAI;EAAE;EACfC,kBAAkB,EAAE,CAAC,EAAE;EAAE;EACzBC,wBAAwB,EAAE,GAAG;EAAE;EAC/BC,UAAU,EAAE,EAAE;EACdC,kBAAkB,EAAE,EAAE;EACtBC,iBAAiB,EAAE,CAAC;EACpBC,aAAa,EAAE,IAAI;EAAE;EACrBC,cAAc,EAAE,CAAC;EACjBC,iBAAiB,EAAE,IAAI,CAAC;AAC1B,CAAU;AAEV,OAAO,MAAMC,4BAA4B,GAAG;EAC1CC,YAAY,EAAE;IACZC,OAAO,EAAE,EAAE;IACXC,SAAS,EAAE;EACb,CAAC;EACDC,YAAY,EAAE;IACZF,OAAO,EAAE,EAAE;IACXC,SAAS,EAAE;EACb,CAAC;EACDE,eAAe,EAAE;IACfH,OAAO,EAAE,EAAE;IACXC,SAAS,EAAE;EACb;AACF,CAAU;AAEV,OAAO,MAAMG,kBAAkB,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
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { Dimensions } from 'react-native';
|
|
4
|
-
import { FRUIT_NINJA_GAME_CONFIG as GAME_CONFIG, FRUIT_NINJA_ANIMATION_CONFIG as ANIMATION_CONFIG, FRUIT_NINJA_COLORS as COLORS, FRUIT_TYPES, FRUIT_SPECIAL_ITEMS as SPECIAL_ITEMS } from "./FruitNinjaConstants.js";
|
|
5
|
-
const {
|
|
6
|
-
width,
|
|
7
|
-
height
|
|
8
|
-
} = Dimensions.get('window');
|
|
9
|
-
|
|
10
|
-
// Constants now imported from FruitNinjaConstants.ts
|
|
11
|
-
// Re-export for backward compatibility
|
|
12
|
-
export { GAME_CONFIG, ANIMATION_CONFIG, COLORS, FRUIT_TYPES, SPECIAL_ITEMS };
|
|
13
|
-
|
|
14
|
-
// Types
|
|
15
|
-
|
|
16
|
-
// Define game-specific types and constants locally
|
|
17
|
-
|
|
18
|
-
export const DEFAULT_FRUIT_NINJA_SETTINGS = {
|
|
19
|
-
gameDuration: 60,
|
|
20
|
-
// Fixed 60 seconds for all games
|
|
21
|
-
difficulty: 'medium',
|
|
22
|
-
soundEnabled: true,
|
|
23
|
-
hapticEnabled: true
|
|
24
|
-
};
|
|
25
|
-
export const getDifficultySpawnInterval = difficulty => {
|
|
26
|
-
const intervals = {
|
|
27
|
-
easy: 2000,
|
|
28
|
-
medium: 1500,
|
|
29
|
-
hard: 1000
|
|
30
|
-
};
|
|
31
|
-
return intervals[difficulty];
|
|
32
|
-
};
|
|
33
|
-
export class FruitNinjaService {
|
|
34
|
-
gameTimerRef = null;
|
|
35
|
-
fruitSpawnRef = null;
|
|
36
|
-
animationRef = null;
|
|
37
|
-
comboTimeoutRef = null;
|
|
38
|
-
particles = [];
|
|
39
|
-
constructor(fruitAnimations, particleAnimations) {
|
|
40
|
-
this.fruitAnimations = fruitAnimations;
|
|
41
|
-
this.particleAnimations = particleAnimations;
|
|
42
|
-
}
|
|
43
|
-
startGameTimer(onTick) {
|
|
44
|
-
this.clearGameTimer();
|
|
45
|
-
this.gameTimerRef = setInterval(onTick, 1000);
|
|
46
|
-
}
|
|
47
|
-
startFruitSpawning(spawnFruit, customSpawnInterval) {
|
|
48
|
-
this.clearFruitSpawn();
|
|
49
|
-
const spawnInterval = customSpawnInterval || GAME_CONFIG.FRUIT_SPAWN_INTERVAL;
|
|
50
|
-
const spawnLoop = () => {
|
|
51
|
-
const fruit = this.createRandomFruit();
|
|
52
|
-
spawnFruit(fruit);
|
|
53
|
-
|
|
54
|
-
// Randomly vary spawn timing
|
|
55
|
-
const nextSpawnTime = spawnInterval + (Math.random() - 0.5) * 400;
|
|
56
|
-
this.fruitSpawnRef = setTimeout(spawnLoop, Math.max(300, nextSpawnTime));
|
|
57
|
-
};
|
|
58
|
-
this.fruitSpawnRef = setTimeout(spawnLoop, 1000);
|
|
59
|
-
}
|
|
60
|
-
startPhysicsLoop(updateFruit, removeFruit, getFruits) {
|
|
61
|
-
const updateLoop = () => {
|
|
62
|
-
const fruits = getFruits();
|
|
63
|
-
fruits.forEach(fruit => {
|
|
64
|
-
if (fruit.isSliced) return;
|
|
65
|
-
|
|
66
|
-
// Apply gravity
|
|
67
|
-
const newVelocityY = fruit.velocity.y + GAME_CONFIG.GRAVITY;
|
|
68
|
-
|
|
69
|
-
// Update position
|
|
70
|
-
let newX = fruit.position.x + fruit.velocity.x;
|
|
71
|
-
const newY = fruit.position.y + newVelocityY;
|
|
72
|
-
|
|
73
|
-
// Update rotation
|
|
74
|
-
const newRotation = fruit.rotation + fruit.rotationSpeed;
|
|
75
|
-
|
|
76
|
-
// Remove fruits that fall off screen (bottom only)
|
|
77
|
-
if (newY > height + 100) {
|
|
78
|
-
// Fruit fell off screen without being sliced
|
|
79
|
-
removeFruit(fruit.id);
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Prevent fruits from going too high off screen (top boundary)
|
|
84
|
-
// Handle wall bouncing properly
|
|
85
|
-
let newVelocityX = fruit.velocity.x;
|
|
86
|
-
if (newY < -50) {
|
|
87
|
-
// If fruit goes too high, start bringing it back down
|
|
88
|
-
const adjustedVelocityY = Math.max(newVelocityY, 0.5); // Ensure downward movement
|
|
89
|
-
updateFruit(fruit.id, {
|
|
90
|
-
position: {
|
|
91
|
-
x: newX,
|
|
92
|
-
y: -50
|
|
93
|
-
},
|
|
94
|
-
velocity: {
|
|
95
|
-
x: newVelocityX,
|
|
96
|
-
y: adjustedVelocityY
|
|
97
|
-
},
|
|
98
|
-
rotation: newRotation
|
|
99
|
-
});
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Left wall bounce
|
|
104
|
-
if (newX <= 0) {
|
|
105
|
-
newX = 0;
|
|
106
|
-
newVelocityX = Math.abs(newVelocityX) * 0.8; // Bounce right with damping
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Right wall bounce
|
|
110
|
-
if (newX >= width - GAME_CONFIG.FRUIT_SIZE) {
|
|
111
|
-
newX = width - GAME_CONFIG.FRUIT_SIZE;
|
|
112
|
-
newVelocityX = -Math.abs(newVelocityX) * 0.8; // Bounce left with damping
|
|
113
|
-
}
|
|
114
|
-
updateFruit(fruit.id, {
|
|
115
|
-
position: {
|
|
116
|
-
x: newX,
|
|
117
|
-
y: newY
|
|
118
|
-
},
|
|
119
|
-
velocity: {
|
|
120
|
-
x: newVelocityX,
|
|
121
|
-
y: newVelocityY
|
|
122
|
-
},
|
|
123
|
-
rotation: newRotation
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
// Update particles
|
|
128
|
-
this.updateParticles();
|
|
129
|
-
this.animationRef = requestAnimationFrame(updateLoop);
|
|
130
|
-
};
|
|
131
|
-
this.animationRef = requestAnimationFrame(updateLoop);
|
|
132
|
-
}
|
|
133
|
-
createRandomFruit() {
|
|
134
|
-
const isSpecial = Math.random() < 0.5;
|
|
135
|
-
const type = isSpecial ? SPECIAL_ITEMS[Math.floor(Math.random() * SPECIAL_ITEMS.length)] : FRUIT_TYPES[Math.floor(Math.random() * FRUIT_TYPES.length)];
|
|
136
|
-
if (!type) {
|
|
137
|
-
// Fallback to default fruit type if undefined
|
|
138
|
-
const defaultType = FRUIT_TYPES[0];
|
|
139
|
-
const spawnX = Math.random() * (width - GAME_CONFIG.FRUIT_SIZE);
|
|
140
|
-
const spawnY = height - 50; // Spawn slightly above bottom for higher trajectory
|
|
141
|
-
const velocityX = (Math.random() - 0.5) * GAME_CONFIG.INITIAL_VELOCITY_X_RANGE;
|
|
142
|
-
const velocityY = GAME_CONFIG.INITIAL_VELOCITY_Y - 3; // Stronger upward velocity for higher arc
|
|
143
|
-
|
|
144
|
-
return {
|
|
145
|
-
id: `fruit_${Date.now()}_${Math.random()}`,
|
|
146
|
-
type: defaultType,
|
|
147
|
-
position: {
|
|
148
|
-
x: spawnX,
|
|
149
|
-
y: spawnY
|
|
150
|
-
},
|
|
151
|
-
velocity: {
|
|
152
|
-
x: velocityX,
|
|
153
|
-
y: velocityY
|
|
154
|
-
},
|
|
155
|
-
rotation: 0,
|
|
156
|
-
rotationSpeed: (Math.random() - 0.5) * 0.2,
|
|
157
|
-
isSliced: false,
|
|
158
|
-
spawnTime: Date.now(),
|
|
159
|
-
isBomb: Boolean(defaultType.isBomb),
|
|
160
|
-
isBonus: Boolean(defaultType.isBonus),
|
|
161
|
-
isFreeze: Boolean(defaultType.isFreeze)
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// Random spawn position (slightly above bottom for higher trajectory)
|
|
166
|
-
const spawnX = Math.random() * (width - GAME_CONFIG.FRUIT_SIZE);
|
|
167
|
-
const spawnY = height - 50; // Spawn slightly above bottom for higher arc
|
|
168
|
-
|
|
169
|
-
// Random initial velocity with stronger upward force for higher trajectory
|
|
170
|
-
const velocityX = (Math.random() - 0.5) * GAME_CONFIG.INITIAL_VELOCITY_X_RANGE;
|
|
171
|
-
const velocityY = GAME_CONFIG.INITIAL_VELOCITY_Y - 3 + (Math.random() - 0.5) * 2; // Stronger upward velocity for higher arc
|
|
172
|
-
|
|
173
|
-
return {
|
|
174
|
-
id: `fruit_${Date.now()}_${Math.random()}`,
|
|
175
|
-
type,
|
|
176
|
-
position: {
|
|
177
|
-
x: spawnX,
|
|
178
|
-
y: spawnY
|
|
179
|
-
},
|
|
180
|
-
velocity: {
|
|
181
|
-
x: velocityX,
|
|
182
|
-
y: velocityY
|
|
183
|
-
},
|
|
184
|
-
rotation: 0,
|
|
185
|
-
rotationSpeed: (Math.random() - 0.5) * 0.2,
|
|
186
|
-
isSliced: false,
|
|
187
|
-
spawnTime: Date.now(),
|
|
188
|
-
isBomb: Boolean(type.isBomb),
|
|
189
|
-
isBonus: Boolean(type.isBonus),
|
|
190
|
-
isFreeze: Boolean(type.isFreeze)
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
createSliceParticles(fruit) {
|
|
194
|
-
const particles = [];
|
|
195
|
-
for (let i = 0; i < GAME_CONFIG.PARTICLE_COUNT; i++) {
|
|
196
|
-
const angle = i / GAME_CONFIG.PARTICLE_COUNT * Math.PI * 2;
|
|
197
|
-
const speed = 3 + Math.random() * 4;
|
|
198
|
-
particles.push({
|
|
199
|
-
id: `particle_${fruit.id}_${Date.now()}_${Math.random()}_${i}`,
|
|
200
|
-
position: {
|
|
201
|
-
...fruit.position
|
|
202
|
-
},
|
|
203
|
-
velocity: {
|
|
204
|
-
x: Math.cos(angle) * speed,
|
|
205
|
-
y: Math.sin(angle) * speed - 2
|
|
206
|
-
},
|
|
207
|
-
color: COLORS.PARTICLE_COLORS[Math.floor(Math.random() * COLORS.PARTICLE_COLORS.length)] || '#ff6b6b',
|
|
208
|
-
size: 4 + Math.random() * 6,
|
|
209
|
-
lifetime: 0,
|
|
210
|
-
maxLifetime: GAME_CONFIG.PARTICLE_LIFETIME
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
this.particles.push(...particles);
|
|
214
|
-
return particles;
|
|
215
|
-
}
|
|
216
|
-
updateParticles() {
|
|
217
|
-
this.particles = this.particles.filter(particle => {
|
|
218
|
-
particle.lifetime += 16; // Assume 60fps
|
|
219
|
-
|
|
220
|
-
if (particle.lifetime >= particle.maxLifetime) {
|
|
221
|
-
return false;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// Update particle physics
|
|
225
|
-
particle.position.x += particle.velocity.x;
|
|
226
|
-
particle.position.y += particle.velocity.y;
|
|
227
|
-
particle.velocity.y += 0.1; // Gravity
|
|
228
|
-
|
|
229
|
-
return true;
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
getParticles() {
|
|
233
|
-
return this.particles;
|
|
234
|
-
}
|
|
235
|
-
checkFruitSlice(fruit, slicePath) {
|
|
236
|
-
if (fruit.isSliced || slicePath.length < 2) return false;
|
|
237
|
-
const fruitCenter = {
|
|
238
|
-
x: fruit.position.x + GAME_CONFIG.FRUIT_SIZE / 2,
|
|
239
|
-
y: fruit.position.y + GAME_CONFIG.FRUIT_SIZE / 2
|
|
240
|
-
};
|
|
241
|
-
const fruitRadius = GAME_CONFIG.FRUIT_SIZE / 2;
|
|
242
|
-
|
|
243
|
-
// Check if slice path intersects with fruit
|
|
244
|
-
for (let i = 0; i < slicePath.length - 1; i++) {
|
|
245
|
-
const p1 = slicePath[i];
|
|
246
|
-
const p2 = slicePath[i + 1];
|
|
247
|
-
if (!p1 || !p2) continue;
|
|
248
|
-
const distance = this.distanceFromPointToLine(fruitCenter, p1, p2);
|
|
249
|
-
if (distance <= fruitRadius) {
|
|
250
|
-
return true;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
return false;
|
|
254
|
-
}
|
|
255
|
-
distanceFromPointToLine(point, lineStart, lineEnd) {
|
|
256
|
-
const A = point.x - lineStart.x;
|
|
257
|
-
const B = point.y - lineStart.y;
|
|
258
|
-
const C = lineEnd.x - lineStart.x;
|
|
259
|
-
const D = lineEnd.y - lineStart.y;
|
|
260
|
-
const dot = A * C + B * D;
|
|
261
|
-
const lenSq = C * C + D * D;
|
|
262
|
-
if (lenSq === 0) return Math.sqrt(A * A + B * B);
|
|
263
|
-
let param = dot / lenSq;
|
|
264
|
-
param = Math.max(0, Math.min(1, param));
|
|
265
|
-
const xx = lineStart.x + param * C;
|
|
266
|
-
const yy = lineStart.y + param * D;
|
|
267
|
-
const dx = point.x - xx;
|
|
268
|
-
const dy = point.y - yy;
|
|
269
|
-
return Math.sqrt(dx * dx + dy * dy);
|
|
270
|
-
}
|
|
271
|
-
resetAnimations() {
|
|
272
|
-
this.fruitAnimations.clear();
|
|
273
|
-
this.particleAnimations.clear();
|
|
274
|
-
this.particles = [];
|
|
275
|
-
}
|
|
276
|
-
cleanup() {
|
|
277
|
-
this.clearGameTimer();
|
|
278
|
-
this.clearFruitSpawn();
|
|
279
|
-
this.clearAnimationLoop();
|
|
280
|
-
this.clearComboTimeout();
|
|
281
|
-
this.particles = [];
|
|
282
|
-
}
|
|
283
|
-
clearGameTimer() {
|
|
284
|
-
if (this.gameTimerRef) {
|
|
285
|
-
clearInterval(this.gameTimerRef);
|
|
286
|
-
this.gameTimerRef = null;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
clearFruitSpawn() {
|
|
290
|
-
if (this.fruitSpawnRef) {
|
|
291
|
-
clearTimeout(this.fruitSpawnRef);
|
|
292
|
-
this.fruitSpawnRef = null;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
clearAnimationLoop() {
|
|
296
|
-
if (this.animationRef) {
|
|
297
|
-
cancelAnimationFrame(this.animationRef);
|
|
298
|
-
this.animationRef = null;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
clearComboTimeout() {
|
|
302
|
-
if (this.comboTimeoutRef) {
|
|
303
|
-
clearTimeout(this.comboTimeoutRef);
|
|
304
|
-
this.comboTimeoutRef = null;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
export const createFruitNinjaService = (fruitAnimations, particleAnimations) => {
|
|
309
|
-
return new FruitNinjaService(fruitAnimations, particleAnimations);
|
|
310
|
-
};
|
|
311
|
-
//# sourceMappingURL=FruitNinjaService.js.map
|
|
1
|
+
"use strict";import{Dimensions}from 'react-native';import{FRUIT_NINJA_GAME_CONFIG as GAME_CONFIG,FRUIT_NINJA_ANIMATION_CONFIG as ANIMATION_CONFIG,FRUIT_NINJA_COLORS as COLORS,FRUIT_TYPES,FRUIT_SPECIAL_ITEMS as SPECIAL_ITEMS}from "./FruitNinjaConstants.js";const{width,height}= Dimensions.get('window');export{GAME_CONFIG,ANIMATION_CONFIG,COLORS,FRUIT_TYPES,SPECIAL_ITEMS};export const DEFAULT_FRUIT_NINJA_SETTINGS ={gameDuration:60,difficulty:'medium',soundEnabled:true,hapticEnabled:true};export const getDifficultySpawnInterval = difficulty =>{const intervals ={easy:2000,medium:1500,hard:1000};return intervals[difficulty];};export class FruitNinjaService{gameTimerRef = null;fruitSpawnRef = null;animationRef = null;comboTimeoutRef = null;particles = [];constructor(fruitAnimations,particleAnimations){this.fruitAnimations = fruitAnimations;this.particleAnimations = particleAnimations;}startGameTimer(onTick){this.clearGameTimer();this.gameTimerRef = setInterval(onTick,1000);}startFruitSpawning(spawnFruit,customSpawnInterval){this.clearFruitSpawn();const spawnInterval = customSpawnInterval || GAME_CONFIG.FRUIT_SPAWN_INTERVAL;const spawnLoop =()=>{const fruit = this.createRandomFruit();spawnFruit(fruit);const nextSpawnTime = spawnInterval +(Math.random()- 0.5)* 400;this.fruitSpawnRef = setTimeout(spawnLoop,Math.max(300,nextSpawnTime));};this.fruitSpawnRef = setTimeout(spawnLoop,1000);}startPhysicsLoop(updateFruit,removeFruit,getFruits){const updateLoop =()=>{const fruits = getFruits();fruits.forEach(fruit =>{if(fruit.isSliced)return;const newVelocityY = fruit.velocity.y + GAME_CONFIG.GRAVITY;let newX = fruit.position.x + fruit.velocity.x;const newY = fruit.position.y + newVelocityY;const newRotation = fruit.rotation + fruit.rotationSpeed;if(newY > height + 100){removeFruit(fruit.id);return;}let newVelocityX = fruit.velocity.x;if(newY < -50){const adjustedVelocityY = Math.max(newVelocityY,0.5);updateFruit(fruit.id,{position:{x:newX,y:-50},velocity:{x:newVelocityX,y:adjustedVelocityY},rotation:newRotation});return;}if(newX <= 0){newX = 0;newVelocityX = Math.abs(newVelocityX)* 0.8;}if(newX >= width - GAME_CONFIG.FRUIT_SIZE){newX = width - GAME_CONFIG.FRUIT_SIZE;newVelocityX = -Math.abs(newVelocityX)* 0.8;}updateFruit(fruit.id,{position:{x:newX,y:newY},velocity:{x:newVelocityX,y:newVelocityY},rotation:newRotation});});this.updateParticles();this.animationRef = requestAnimationFrame(updateLoop);};this.animationRef = requestAnimationFrame(updateLoop);}createRandomFruit(){const isSpecial = Math.random()< 0.5;const type = isSpecial ? SPECIAL_ITEMS[Math.floor(Math.random()* SPECIAL_ITEMS.length)]:FRUIT_TYPES[Math.floor(Math.random()* FRUIT_TYPES.length)];if(!type){const defaultType = FRUIT_TYPES[0];const spawnX = Math.random()*(width - GAME_CONFIG.FRUIT_SIZE);const spawnY = height - 50;const velocityX =(Math.random()- 0.5)* GAME_CONFIG.INITIAL_VELOCITY_X_RANGE;const velocityY = GAME_CONFIG.INITIAL_VELOCITY_Y - 3;return{id:`fruit_${Date.now()}_${Math.random()}`,type:defaultType,position:{x:spawnX,y:spawnY},velocity:{x:velocityX,y:velocityY},rotation:0,rotationSpeed:(Math.random()- 0.5)* 0.2,isSliced:false,spawnTime:Date.now(),isBomb:Boolean(defaultType.isBomb),isBonus:Boolean(defaultType.isBonus),isFreeze:Boolean(defaultType.isFreeze)};}const spawnX = Math.random()*(width - GAME_CONFIG.FRUIT_SIZE);const spawnY = height - 50;const velocityX =(Math.random()- 0.5)* GAME_CONFIG.INITIAL_VELOCITY_X_RANGE;const velocityY = GAME_CONFIG.INITIAL_VELOCITY_Y - 3 +(Math.random()- 0.5)* 2;return{id:`fruit_${Date.now()}_${Math.random()}`,type,position:{x:spawnX,y:spawnY},velocity:{x:velocityX,y:velocityY},rotation:0,rotationSpeed:(Math.random()- 0.5)* 0.2,isSliced:false,spawnTime:Date.now(),isBomb:Boolean(type.isBomb),isBonus:Boolean(type.isBonus),isFreeze:Boolean(type.isFreeze)};}createSliceParticles(fruit){const particles = [];for(let i = 0;i < GAME_CONFIG.PARTICLE_COUNT;i++){const angle = i / GAME_CONFIG.PARTICLE_COUNT * Math.PI * 2;const speed = 3 + Math.random()* 4;particles.push({id:`particle_${fruit.id}_${Date.now()}_${Math.random()}_${i}`,position:{...fruit.position},velocity:{x:Math.cos(angle)* speed,y:Math.sin(angle)* speed - 2},color:COLORS.PARTICLE_COLORS[Math.floor(Math.random()* COLORS.PARTICLE_COLORS.length)] || '#ff6b6b',size:4 + Math.random()* 6,lifetime:0,maxLifetime:GAME_CONFIG.PARTICLE_LIFETIME});}this.particles.push(...particles);return particles;}updateParticles(){this.particles = this.particles.filter(particle =>{particle.lifetime += 16;if(particle.lifetime >= particle.maxLifetime){return false;}particle.position.x += particle.velocity.x;particle.position.y += particle.velocity.y;particle.velocity.y += 0.1;return true;});}getParticles(){return this.particles;}checkFruitSlice(fruit,slicePath){if(fruit.isSliced || slicePath.length < 2)return false;const fruitCenter ={x:fruit.position.x + GAME_CONFIG.FRUIT_SIZE / 2,y:fruit.position.y + GAME_CONFIG.FRUIT_SIZE / 2};const fruitRadius = GAME_CONFIG.FRUIT_SIZE / 2;for(let i = 0;i < slicePath.length - 1;i++){const p1 = slicePath[i];const p2 = slicePath[i + 1];if(!p1 || !p2)continue;const distance = this.distanceFromPointToLine(fruitCenter,p1,p2);if(distance <= fruitRadius){return true;}}return false;}distanceFromPointToLine(point,lineStart,lineEnd){const A = point.x - lineStart.x;const B = point.y - lineStart.y;const C = lineEnd.x - lineStart.x;const D = lineEnd.y - lineStart.y;const dot = A * C + B * D;const lenSq = C * C + D * D;if(lenSq === 0)return Math.sqrt(A * A + B * B);let param = dot / lenSq;param = Math.max(0,Math.min(1,param));const xx = lineStart.x + param * C;const yy = lineStart.y + param * D;const dx = point.x - xx;const dy = point.y - yy;return Math.sqrt(dx * dx + dy * dy);}resetAnimations(){this.fruitAnimations.clear();this.particleAnimations.clear();this.particles = [];}cleanup(){this.clearGameTimer();this.clearFruitSpawn();this.clearAnimationLoop();this.clearComboTimeout();this.particles = [];}clearGameTimer(){if(this.gameTimerRef){clearInterval(this.gameTimerRef);this.gameTimerRef = null;}}clearFruitSpawn(){if(this.fruitSpawnRef){clearTimeout(this.fruitSpawnRef);this.fruitSpawnRef = null;}}clearAnimationLoop(){if(this.animationRef){cancelAnimationFrame(this.animationRef);this.animationRef = null;}}clearComboTimeout(){if(this.comboTimeoutRef){clearTimeout(this.comboTimeoutRef);this.comboTimeoutRef = null;}}}export const createFruitNinjaService =(fruitAnimations,particleAnimations)=>{return new FruitNinjaService(fruitAnimations,particleAnimations);};
|