react-native-games 1.0.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 +80 -368
- 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,90 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { Dimensions } from 'react-native';
|
|
4
|
-
const {
|
|
5
|
-
width,
|
|
6
|
-
height
|
|
7
|
-
} = Dimensions.get('window');
|
|
8
|
-
export const FLAPPY_BIRD_GAME_CONFIG = {
|
|
9
|
-
BIRD_SIZE: 40,
|
|
10
|
-
BIRD_START_X: width * 0.2,
|
|
11
|
-
BIRD_START_Y: height * 0.4,
|
|
12
|
-
GRAVITY: 0.25,
|
|
13
|
-
JUMP_VELOCITY: -6.5,
|
|
14
|
-
MAX_FALL_SPEED: 7,
|
|
15
|
-
VELOCITY_DAMPING: 0.98,
|
|
16
|
-
PIPE_WIDTH: 60,
|
|
17
|
-
PIPE_GAP: 200,
|
|
18
|
-
PIPE_SPEED_EASY: 1.5,
|
|
19
|
-
PIPE_SPEED_MEDIUM: 2.5,
|
|
20
|
-
PIPE_SPEED_HARD: 3.5,
|
|
21
|
-
PIPE_SPAWN_INTERVAL: 2800,
|
|
22
|
-
MIN_PIPE_HEIGHT: 100,
|
|
23
|
-
MAX_PIPE_HEIGHT: height * 0.6,
|
|
24
|
-
GROUND_HEIGHT: 80,
|
|
25
|
-
GAME_WIDTH: width,
|
|
26
|
-
GAME_HEIGHT: height
|
|
27
|
-
};
|
|
28
|
-
export const FLAPPY_BIRD_COLORS = {
|
|
29
|
-
SKY_START: '#87CEEB',
|
|
30
|
-
SKY_END: '#E0F6FF',
|
|
31
|
-
GROUND: '#DEB887',
|
|
32
|
-
GROUND_DARK: '#8B7355',
|
|
33
|
-
PIPE_GREEN: '#5CB85C',
|
|
34
|
-
PIPE_DARK: '#4A934A',
|
|
35
|
-
BIRD_YELLOW: '#FFD700',
|
|
36
|
-
BIRD_ORANGE: '#FF8C00',
|
|
37
|
-
SCORE_TEXT: '#FFFFFF',
|
|
38
|
-
BUTTON_PRIMARY: '#5CB85C',
|
|
39
|
-
BUTTON_SECONDARY: '#4A934A',
|
|
40
|
-
GAME_OVER_BG: 'rgba(74, 147, 74, 0.95)',
|
|
41
|
-
SCORE_BACKGROUND: 'rgba(92, 184, 92, 0.4)',
|
|
42
|
-
SCORE_BORDER: 'rgba(92, 184, 92, 0.8)'
|
|
43
|
-
};
|
|
44
|
-
export const FLAPPY_BIRD_THEME = {
|
|
45
|
-
backgroundColor: '#87CEEB',
|
|
46
|
-
headerBackgroundColor: '#5CB85C',
|
|
47
|
-
headerTextColor: '#FFFFFF',
|
|
48
|
-
sectionBackgroundColor: 'rgba(255, 255, 255, 0.95)',
|
|
49
|
-
sectionTitleColor: '#2C3E50',
|
|
50
|
-
buttonSelectedColor: '#5CB85C',
|
|
51
|
-
buttonUnselectedColor: '#E8E8E8',
|
|
52
|
-
buttonSelectedTextColor: '#FFFFFF',
|
|
53
|
-
buttonUnselectedTextColor: '#7F8C8D',
|
|
54
|
-
switchTrackColorFalse: '#D1D5DB',
|
|
55
|
-
switchTrackColorTrue: '#5CB85C',
|
|
56
|
-
switchThumbColor: '#FFFFFF',
|
|
57
|
-
infoTextColor: '#7F8C8D'
|
|
58
|
-
};
|
|
59
|
-
export const FLAPPY_BIRD_DIFFICULTY_DESCRIPTIONS = {
|
|
60
|
-
easy: {
|
|
61
|
-
title: 'Easy Mode',
|
|
62
|
-
description: 'Perfect for beginners! Slower pipes and more time to react.',
|
|
63
|
-
features: ['Slower pipe speed', 'Easier timing', 'Great for learning']
|
|
64
|
-
},
|
|
65
|
-
medium: {
|
|
66
|
-
title: 'Medium Mode',
|
|
67
|
-
description: 'Balanced challenge for casual players.',
|
|
68
|
-
features: ['Moderate pipe speed', 'Standard difficulty', 'Good practice']
|
|
69
|
-
},
|
|
70
|
-
hard: {
|
|
71
|
-
title: 'Hard Mode',
|
|
72
|
-
description: 'Fast-paced action for experienced players!',
|
|
73
|
-
features: ['Fast pipe speed', 'Quick reflexes needed', 'Maximum challenge']
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
export const DIFFICULTY_CONFIG = {
|
|
77
|
-
easy: {
|
|
78
|
-
pipeSpeed: FLAPPY_BIRD_GAME_CONFIG.PIPE_SPEED_EASY,
|
|
79
|
-
pipeGap: 250
|
|
80
|
-
},
|
|
81
|
-
medium: {
|
|
82
|
-
pipeSpeed: FLAPPY_BIRD_GAME_CONFIG.PIPE_SPEED_MEDIUM,
|
|
83
|
-
pipeGap: 220
|
|
84
|
-
},
|
|
85
|
-
hard: {
|
|
86
|
-
pipeSpeed: FLAPPY_BIRD_GAME_CONFIG.PIPE_SPEED_HARD,
|
|
87
|
-
pipeGap: 200
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
//# sourceMappingURL=FlappyBirdConstants.js.map
|
|
1
|
+
"use strict";import{Dimensions}from 'react-native';const{width,height}= Dimensions.get('window');export const FLAPPY_BIRD_GAME_CONFIG ={BIRD_SIZE:40,BIRD_START_X:width * 0.2,BIRD_START_Y:height * 0.4,GRAVITY:0.25,JUMP_VELOCITY:-4.5,MAX_FALL_SPEED:7,VELOCITY_DAMPING:0.98,PIPE_WIDTH:60,PIPE_GAP:200,PIPE_SPEED_EASY:1.5,PIPE_SPEED_MEDIUM:2.5,PIPE_SPEED_HARD:3.5,PIPE_SPAWN_INTERVAL:2800,MIN_PIPE_HEIGHT:100,MAX_PIPE_HEIGHT:height * 0.6,GROUND_HEIGHT:80,GAME_WIDTH:width,GAME_HEIGHT:height};export const FLAPPY_BIRD_COLORS ={SKY_START:'#87CEEB',SKY_END:'#E0F6FF',GROUND:'#DEB887',GROUND_DARK:'#8B7355',PIPE_GREEN:'#5CB85C',PIPE_DARK:'#4A934A',BIRD_YELLOW:'#FFD700',BIRD_ORANGE:'#FF8C00',SCORE_TEXT:'#FFFFFF',BUTTON_PRIMARY:'#5CB85C',BUTTON_SECONDARY:'#4A934A',GAME_OVER_BG:'rgba(74,147,74,0.95)',SCORE_BACKGROUND:'rgba(92,184,92,0.4)',SCORE_BORDER:'rgba(92,184,92,0.8)'};export const FLAPPY_BIRD_THEME ={backgroundColor:'rgba(0,0,0,0.7)',headerBackgroundColor:'#5CB85C',headerTextColor:'#ffffff',sectionBackgroundColor:'rgba(92,184,92,0.15)',sectionTitleColor:'#5CB85C',buttonSelectedColor:'#5CB85C',buttonUnselectedColor:'rgba(255,255,255,0.2)',buttonSelectedTextColor:'#ffffff',buttonUnselectedTextColor:'rgba(255,255,255,0.7)',switchTrackColorFalse:'rgba(92,184,92,0.3)',switchTrackColorTrue:'#5CB85C',switchThumbColor:'#ffffff',infoTextColor:'rgba(255,255,255,0.9)'};export const FLAPPY_BIRD_DIFFICULTY_DESCRIPTIONS ={easy:{title:'Easy Mode',description:'Perfect for beginners! Slower pipes and more time to react.',features:['Slower pipe speed','Easier timing','Great for learning']},medium:{title:'Medium Mode',description:'Balanced challenge for casual players.',features:['Moderate pipe speed','Standard difficulty','Good practice']},hard:{title:'Hard Mode',description:'Fast-paced action for experienced players!',features:['Fast pipe speed','Quick reflexes needed','Maximum challenge']}};export const DIFFICULTY_CONFIG ={easy:{pipeSpeed:FLAPPY_BIRD_GAME_CONFIG.PIPE_SPEED_EASY,pipeGap:250},medium:{pipeSpeed:FLAPPY_BIRD_GAME_CONFIG.PIPE_SPEED_MEDIUM,pipeGap:220},hard:{pipeSpeed:FLAPPY_BIRD_GAME_CONFIG.PIPE_SPEED_HARD,pipeGap:200}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Dimensions","width","height","get","FLAPPY_BIRD_GAME_CONFIG","BIRD_SIZE","BIRD_START_X","BIRD_START_Y","GRAVITY","JUMP_VELOCITY","MAX_FALL_SPEED","VELOCITY_DAMPING","PIPE_WIDTH","PIPE_GAP","PIPE_SPEED_EASY","PIPE_SPEED_MEDIUM","PIPE_SPEED_HARD","PIPE_SPAWN_INTERVAL","MIN_PIPE_HEIGHT","MAX_PIPE_HEIGHT","GROUND_HEIGHT","GAME_WIDTH","GAME_HEIGHT","FLAPPY_BIRD_COLORS","SKY_START","SKY_END","GROUND","GROUND_DARK","PIPE_GREEN","PIPE_DARK","BIRD_YELLOW","BIRD_ORANGE","SCORE_TEXT","BUTTON_PRIMARY","BUTTON_SECONDARY","GAME_OVER_BG","SCORE_BACKGROUND","SCORE_BORDER","FLAPPY_BIRD_THEME","backgroundColor","headerBackgroundColor","headerTextColor","sectionBackgroundColor","sectionTitleColor","buttonSelectedColor","buttonUnselectedColor","buttonSelectedTextColor","buttonUnselectedTextColor","switchTrackColorFalse","switchTrackColorTrue","switchThumbColor","infoTextColor","FLAPPY_BIRD_DIFFICULTY_DESCRIPTIONS","easy","title","description","features","medium","hard","DIFFICULTY_CONFIG","pipeSpeed","pipeGap"],"sourceRoot":"../../../../src","sources":["games/flappy-bird/FlappyBirdConstants.ts"],"mappings":";;AAAA,SAASA,UAAU,QAAQ,cAAc;AAEzC,MAAM;EAAEC,KAAK;EAAEC;AAAO,CAAC,GAAGF,UAAU,CAACG,GAAG,CAAC,QAAQ,CAAC;AAElD,OAAO,MAAMC,uBAAuB,GAAG;EACrCC,SAAS,EAAE,EAAE;EACbC,YAAY,EAAEL,KAAK,GAAG,GAAG;EACzBM,YAAY,EAAEL,MAAM,GAAG,GAAG;EAC1BM,OAAO,EAAE,IAAI;EACbC,aAAa,EAAE,CAAC,GAAG;EACnBC,cAAc,EAAE,CAAC;EACjBC,gBAAgB,EAAE,IAAI;EACtBC,UAAU,EAAE,EAAE;EACdC,QAAQ,EAAE,GAAG;EACbC,eAAe,EAAE,GAAG;EACpBC,iBAAiB,EAAE,GAAG;EACtBC,eAAe,EAAE,GAAG;EACpBC,mBAAmB,EAAE,IAAI;EACzBC,eAAe,EAAE,GAAG;EACpBC,eAAe,EAAEjB,MAAM,GAAG,GAAG;EAC7BkB,aAAa,EAAE,EAAE;EACjBC,UAAU,EAAEpB,KAAK;EACjBqB,WAAW,EAAEpB;AACf,CAAC;AAED,OAAO,MAAMqB,kBAAkB,GAAG;EAChCC,SAAS,EAAE,SAAS;EACpBC,OAAO,EAAE,SAAS;EAClBC,MAAM,EAAE,SAAS;EACjBC,WAAW,EAAE,SAAS;EACtBC,UAAU,EAAE,SAAS;EACrBC,SAAS,EAAE,SAAS;EACpBC,WAAW,EAAE,SAAS;EACtBC,WAAW,EAAE,SAAS;EACtBC,UAAU,EAAE,SAAS;EACrBC,cAAc,EAAE,SAAS;EACzBC,gBAAgB,EAAE,SAAS;EAC3BC,YAAY,EAAE,yBAAyB;EACvCC,gBAAgB,EAAE,wBAAwB;EAC1CC,YAAY,EAAE;AAChB,CAAC;
|
|
1
|
+
{"version":3,"names":["Dimensions","width","height","get","FLAPPY_BIRD_GAME_CONFIG","BIRD_SIZE","BIRD_START_X","BIRD_START_Y","GRAVITY","JUMP_VELOCITY","MAX_FALL_SPEED","VELOCITY_DAMPING","PIPE_WIDTH","PIPE_GAP","PIPE_SPEED_EASY","PIPE_SPEED_MEDIUM","PIPE_SPEED_HARD","PIPE_SPAWN_INTERVAL","MIN_PIPE_HEIGHT","MAX_PIPE_HEIGHT","GROUND_HEIGHT","GAME_WIDTH","GAME_HEIGHT","FLAPPY_BIRD_COLORS","SKY_START","SKY_END","GROUND","GROUND_DARK","PIPE_GREEN","PIPE_DARK","BIRD_YELLOW","BIRD_ORANGE","SCORE_TEXT","BUTTON_PRIMARY","BUTTON_SECONDARY","GAME_OVER_BG","SCORE_BACKGROUND","SCORE_BORDER","FLAPPY_BIRD_THEME","backgroundColor","headerBackgroundColor","headerTextColor","sectionBackgroundColor","sectionTitleColor","buttonSelectedColor","buttonUnselectedColor","buttonSelectedTextColor","buttonUnselectedTextColor","switchTrackColorFalse","switchTrackColorTrue","switchThumbColor","infoTextColor","FLAPPY_BIRD_DIFFICULTY_DESCRIPTIONS","easy","title","description","features","medium","hard","DIFFICULTY_CONFIG","pipeSpeed","pipeGap"],"sourceRoot":"../../../../src","sources":["games/flappy-bird/FlappyBirdConstants.ts"],"mappings":";;AAAA,SAASA,UAAU,QAAQ,cAAc;AAEzC,MAAM;EAAEC,KAAK;EAAEC;AAAO,CAAC,GAAGF,UAAU,CAACG,GAAG,CAAC,QAAQ,CAAC;AAElD,OAAO,MAAMC,uBAAuB,GAAG;EACrCC,SAAS,EAAE,EAAE;EACbC,YAAY,EAAEL,KAAK,GAAG,GAAG;EACzBM,YAAY,EAAEL,MAAM,GAAG,GAAG;EAC1BM,OAAO,EAAE,IAAI;EACbC,aAAa,EAAE,CAAC,GAAG;EACnBC,cAAc,EAAE,CAAC;EACjBC,gBAAgB,EAAE,IAAI;EACtBC,UAAU,EAAE,EAAE;EACdC,QAAQ,EAAE,GAAG;EACbC,eAAe,EAAE,GAAG;EACpBC,iBAAiB,EAAE,GAAG;EACtBC,eAAe,EAAE,GAAG;EACpBC,mBAAmB,EAAE,IAAI;EACzBC,eAAe,EAAE,GAAG;EACpBC,eAAe,EAAEjB,MAAM,GAAG,GAAG;EAC7BkB,aAAa,EAAE,EAAE;EACjBC,UAAU,EAAEpB,KAAK;EACjBqB,WAAW,EAAEpB;AACf,CAAC;AAED,OAAO,MAAMqB,kBAAkB,GAAG;EAChCC,SAAS,EAAE,SAAS;EACpBC,OAAO,EAAE,SAAS;EAClBC,MAAM,EAAE,SAAS;EACjBC,WAAW,EAAE,SAAS;EACtBC,UAAU,EAAE,SAAS;EACrBC,SAAS,EAAE,SAAS;EACpBC,WAAW,EAAE,SAAS;EACtBC,WAAW,EAAE,SAAS;EACtBC,UAAU,EAAE,SAAS;EACrBC,cAAc,EAAE,SAAS;EACzBC,gBAAgB,EAAE,SAAS;EAC3BC,YAAY,EAAE,yBAAyB;EACvCC,gBAAgB,EAAE,wBAAwB;EAC1CC,YAAY,EAAE;AAChB,CAAC;;AAED;AACA,OAAO,MAAMC,iBAAiB,GAAG;EAC/BC,eAAe,EAAE,oBAAoB;EAAE;EACvCC,qBAAqB,EAAE,SAAS;EAAE;EAClCC,eAAe,EAAE,SAAS;EAC1BC,sBAAsB,EAAE,yBAAyB;EAAE;EACnDC,iBAAiB,EAAE,SAAS;EAAE;EAC9BC,mBAAmB,EAAE,SAAS;EAAE;EAChCC,qBAAqB,EAAE,0BAA0B;EACjDC,uBAAuB,EAAE,SAAS;EAClCC,yBAAyB,EAAE,0BAA0B;EAAE;EACvDC,qBAAqB,EAAE,wBAAwB;EAC/CC,oBAAoB,EAAE,SAAS;EAAE;EACjCC,gBAAgB,EAAE,SAAS;EAC3BC,aAAa,EAAE,0BAA0B,CAAE;AAC7C,CAAC;AAED,OAAO,MAAMC,mCAAmC,GAAG;EACjDC,IAAI,EAAE;IACJC,KAAK,EAAE,WAAW;IAClBC,WAAW,EAAE,6DAA6D;IAC1EC,QAAQ,EAAE,CAAC,mBAAmB,EAAE,eAAe,EAAE,oBAAoB;EACvE,CAAC;EACDC,MAAM,EAAE;IACNH,KAAK,EAAE,aAAa;IACpBC,WAAW,EAAE,wCAAwC;IACrDC,QAAQ,EAAE,CAAC,qBAAqB,EAAE,qBAAqB,EAAE,eAAe;EAC1E,CAAC;EACDE,IAAI,EAAE;IACJJ,KAAK,EAAE,WAAW;IAClBC,WAAW,EAAE,4CAA4C;IACzDC,QAAQ,EAAE,CAAC,iBAAiB,EAAE,uBAAuB,EAAE,mBAAmB;EAC5E;AACF,CAAC;AAED,OAAO,MAAMG,iBAAiB,GAAG;EAC/BN,IAAI,EAAE;IACJO,SAAS,EAAExD,uBAAuB,CAACU,eAAe;IAClD+C,OAAO,EAAE;EACX,CAAC;EACDJ,MAAM,EAAE;IACNG,SAAS,EAAExD,uBAAuB,CAACW,iBAAiB;IACpD8C,OAAO,EAAE;EACX,CAAC;EACDH,IAAI,EAAE;IACJE,SAAS,EAAExD,uBAAuB,CAACY,eAAe;IAClD6C,OAAO,EAAE;EACX;AACF,CAAC","ignoreList":[]}
|
|
@@ -1,300 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { create } from 'zustand';
|
|
4
|
-
import { subscribeWithSelector } from 'zustand/middleware';
|
|
5
|
-
import { immerMiddleware } from "../../services/UtilsService.js";
|
|
6
|
-
import { FLAPPY_BIRD_GAME_CONFIG, DIFFICULTY_CONFIG } from "./FlappyBirdConstants.js";
|
|
7
|
-
const BASE_BRICK_WALL_HEIGHT = 150; // Base wall height (both top and bottom)
|
|
8
|
-
|
|
9
|
-
const generateRandomPipeHeight = (offset = 0) => {
|
|
10
|
-
const {
|
|
11
|
-
MIN_PIPE_HEIGHT,
|
|
12
|
-
GAME_HEIGHT
|
|
13
|
-
} = FLAPPY_BIRD_GAME_CONFIG;
|
|
14
|
-
const topWallHeight = BASE_BRICK_WALL_HEIGHT + offset;
|
|
15
|
-
const bottomWallHeight = offset > 0 ? 150 : 250; // Dynamic bottom wall height
|
|
16
|
-
// Calculate playable height accounting for increased top wall and dynamic bottom wall
|
|
17
|
-
// Bottom wall is at screen bottom, so no GROUND_HEIGHT subtraction needed
|
|
18
|
-
const playableHeight = GAME_HEIGHT - topWallHeight - bottomWallHeight;
|
|
19
|
-
const minHeight = topWallHeight + MIN_PIPE_HEIGHT;
|
|
20
|
-
const maxHeight = topWallHeight + playableHeight * 0.6;
|
|
21
|
-
return minHeight + Math.random() * (maxHeight - minHeight);
|
|
22
|
-
};
|
|
23
|
-
export const useFlappyBirdStore = create()(subscribeWithSelector(immerMiddleware((set, get) => ({
|
|
24
|
-
isPlaying: false,
|
|
25
|
-
isGameOver: false,
|
|
26
|
-
score: 0,
|
|
27
|
-
survivalTime: 0,
|
|
28
|
-
birdY: FLAPPY_BIRD_GAME_CONFIG.BIRD_START_Y,
|
|
29
|
-
birdVelocity: 0,
|
|
30
|
-
pipes: [],
|
|
31
|
-
collisionBlasts: [],
|
|
32
|
-
gameLoopInterval: null,
|
|
33
|
-
pipeSpawnInterval: null,
|
|
34
|
-
timerInterval: null,
|
|
35
|
-
initializeGame: () => {
|
|
36
|
-
set(state => {
|
|
37
|
-
state.isPlaying = false;
|
|
38
|
-
state.isGameOver = false;
|
|
39
|
-
state.score = 0;
|
|
40
|
-
state.survivalTime = 0;
|
|
41
|
-
state.birdY = FLAPPY_BIRD_GAME_CONFIG.BIRD_START_Y;
|
|
42
|
-
state.birdVelocity = 0;
|
|
43
|
-
state.pipes = [];
|
|
44
|
-
state.collisionBlasts = [];
|
|
45
|
-
});
|
|
46
|
-
},
|
|
47
|
-
startGame: settings => {
|
|
48
|
-
const state = get();
|
|
49
|
-
if (state.gameLoopInterval) clearInterval(state.gameLoopInterval);
|
|
50
|
-
if (state.pipeSpawnInterval) clearInterval(state.pipeSpawnInterval);
|
|
51
|
-
if (state.timerInterval) clearInterval(state.timerInterval);
|
|
52
|
-
set(state => {
|
|
53
|
-
state.isPlaying = true;
|
|
54
|
-
state.isGameOver = false;
|
|
55
|
-
state.birdY = FLAPPY_BIRD_GAME_CONFIG.BIRD_START_Y;
|
|
56
|
-
state.birdVelocity = 0;
|
|
57
|
-
state.pipes = [];
|
|
58
|
-
state.score = 0;
|
|
59
|
-
state.survivalTime = 0;
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
// Start game loop (60fps)
|
|
63
|
-
const gameLoop = setInterval(() => {
|
|
64
|
-
get().updatePhysics(settings);
|
|
65
|
-
}, 1000 / 60);
|
|
66
|
-
|
|
67
|
-
// Start pipe spawning
|
|
68
|
-
const pipeSpawn = setInterval(() => {
|
|
69
|
-
get().spawnPipe(settings);
|
|
70
|
-
}, FLAPPY_BIRD_GAME_CONFIG.PIPE_SPAWN_INTERVAL);
|
|
71
|
-
|
|
72
|
-
// Start survival timer (1 second intervals)
|
|
73
|
-
const timer = setInterval(() => {
|
|
74
|
-
set(state => {
|
|
75
|
-
state.survivalTime += 1;
|
|
76
|
-
});
|
|
77
|
-
}, 1000);
|
|
78
|
-
set(state => {
|
|
79
|
-
state.gameLoopInterval = gameLoop;
|
|
80
|
-
state.pipeSpawnInterval = pipeSpawn;
|
|
81
|
-
state.timerInterval = timer;
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
// Spawn first pipe immediately
|
|
85
|
-
setTimeout(() => get().spawnPipe(settings), 500);
|
|
86
|
-
},
|
|
87
|
-
stopGame: () => {
|
|
88
|
-
const state = get();
|
|
89
|
-
if (state.gameLoopInterval) clearInterval(state.gameLoopInterval);
|
|
90
|
-
if (state.pipeSpawnInterval) clearInterval(state.pipeSpawnInterval);
|
|
91
|
-
if (state.timerInterval) clearInterval(state.timerInterval);
|
|
92
|
-
|
|
93
|
-
// Reset the game instead of showing game over modal
|
|
94
|
-
state.initializeGame();
|
|
95
|
-
},
|
|
96
|
-
resetGame: () => {
|
|
97
|
-
const state = get();
|
|
98
|
-
if (state.gameLoopInterval) clearInterval(state.gameLoopInterval);
|
|
99
|
-
if (state.pipeSpawnInterval) clearInterval(state.pipeSpawnInterval);
|
|
100
|
-
if (state.timerInterval) clearInterval(state.timerInterval);
|
|
101
|
-
set(state => {
|
|
102
|
-
state.isPlaying = false;
|
|
103
|
-
state.isGameOver = false;
|
|
104
|
-
state.score = 0;
|
|
105
|
-
state.survivalTime = 0;
|
|
106
|
-
state.birdY = FLAPPY_BIRD_GAME_CONFIG.BIRD_START_Y;
|
|
107
|
-
state.birdVelocity = 0;
|
|
108
|
-
state.pipes = [];
|
|
109
|
-
state.collisionBlasts = [];
|
|
110
|
-
state.gameLoopInterval = null;
|
|
111
|
-
state.pipeSpawnInterval = null;
|
|
112
|
-
state.timerInterval = null;
|
|
113
|
-
});
|
|
114
|
-
},
|
|
115
|
-
jump: () => {
|
|
116
|
-
const state = get();
|
|
117
|
-
if (!state.isPlaying || state.isGameOver) return;
|
|
118
|
-
set(state => {
|
|
119
|
-
state.birdVelocity = FLAPPY_BIRD_GAME_CONFIG.JUMP_VELOCITY;
|
|
120
|
-
});
|
|
121
|
-
},
|
|
122
|
-
updatePhysics: settings => {
|
|
123
|
-
const state = get();
|
|
124
|
-
if (!state.isPlaying || state.isGameOver) return;
|
|
125
|
-
const config = DIFFICULTY_CONFIG[settings.difficulty];
|
|
126
|
-
const {
|
|
127
|
-
GAME_HEIGHT,
|
|
128
|
-
GRAVITY,
|
|
129
|
-
BIRD_SIZE,
|
|
130
|
-
MAX_FALL_SPEED,
|
|
131
|
-
VELOCITY_DAMPING
|
|
132
|
-
} = FLAPPY_BIRD_GAME_CONFIG;
|
|
133
|
-
const offset = settings.offset ?? 0;
|
|
134
|
-
const topWallHeight = BASE_BRICK_WALL_HEIGHT + offset;
|
|
135
|
-
const bottomWallHeight = offset > 0 ? 150 : 250; // Dynamic bottom wall height
|
|
136
|
-
const bottomWallTop = GAME_HEIGHT - bottomWallHeight; // Bottom wall at screen bottom
|
|
137
|
-
|
|
138
|
-
let topWallCollision = false;
|
|
139
|
-
let bottomWallCollision = false;
|
|
140
|
-
set(draftState => {
|
|
141
|
-
// Update bird physics with damping for smoother movement
|
|
142
|
-
draftState.birdVelocity += GRAVITY;
|
|
143
|
-
draftState.birdVelocity *= VELOCITY_DAMPING;
|
|
144
|
-
|
|
145
|
-
// Cap maximum fall speed for more control
|
|
146
|
-
if (draftState.birdVelocity > MAX_FALL_SPEED) {
|
|
147
|
-
draftState.birdVelocity = MAX_FALL_SPEED;
|
|
148
|
-
}
|
|
149
|
-
draftState.birdY += draftState.birdVelocity;
|
|
150
|
-
|
|
151
|
-
// Update pipes
|
|
152
|
-
for (let i = draftState.pipes.length - 1; i >= 0; i--) {
|
|
153
|
-
const pipe = draftState.pipes[i];
|
|
154
|
-
if (!pipe) continue;
|
|
155
|
-
pipe.x -= config.pipeSpeed;
|
|
156
|
-
|
|
157
|
-
// Check if bird passed pipe
|
|
158
|
-
if (!pipe.passed && pipe.x + FLAPPY_BIRD_GAME_CONFIG.PIPE_WIDTH < FLAPPY_BIRD_GAME_CONFIG.BIRD_START_X) {
|
|
159
|
-
pipe.passed = true;
|
|
160
|
-
draftState.score += 1;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// Remove off-screen pipes
|
|
164
|
-
if (pipe.x + FLAPPY_BIRD_GAME_CONFIG.PIPE_WIDTH < 0) {
|
|
165
|
-
draftState.pipes.splice(i, 1);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// Check boundaries - top wall adjusted by offset
|
|
170
|
-
// Top brick wall collision (with offset)
|
|
171
|
-
if (draftState.birdY < topWallHeight) {
|
|
172
|
-
draftState.birdY = topWallHeight;
|
|
173
|
-
draftState.birdVelocity = 0;
|
|
174
|
-
draftState.isGameOver = true;
|
|
175
|
-
draftState.isPlaying = false;
|
|
176
|
-
topWallCollision = true;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// Bottom wall collision (150px wall at ground)
|
|
180
|
-
if (draftState.birdY + BIRD_SIZE > bottomWallTop) {
|
|
181
|
-
draftState.birdY = bottomWallTop - BIRD_SIZE;
|
|
182
|
-
draftState.isGameOver = true;
|
|
183
|
-
draftState.isPlaying = false;
|
|
184
|
-
bottomWallCollision = true;
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
// Add collision blasts after state update
|
|
189
|
-
if (topWallCollision) {
|
|
190
|
-
const blastX = FLAPPY_BIRD_GAME_CONFIG.BIRD_START_X + BIRD_SIZE / 2;
|
|
191
|
-
const blastY = topWallHeight + BIRD_SIZE / 2;
|
|
192
|
-
get().addCollisionBlast(blastX, blastY);
|
|
193
|
-
// Clear intervals but don't reset game (modal will show)
|
|
194
|
-
const state = get();
|
|
195
|
-
if (state.gameLoopInterval) clearInterval(state.gameLoopInterval);
|
|
196
|
-
if (state.pipeSpawnInterval) clearInterval(state.pipeSpawnInterval);
|
|
197
|
-
if (state.timerInterval) clearInterval(state.timerInterval);
|
|
198
|
-
}
|
|
199
|
-
if (bottomWallCollision) {
|
|
200
|
-
const blastX = FLAPPY_BIRD_GAME_CONFIG.BIRD_START_X + BIRD_SIZE / 2;
|
|
201
|
-
const blastY = bottomWallTop - BIRD_SIZE / 2;
|
|
202
|
-
get().addCollisionBlast(blastX, blastY);
|
|
203
|
-
// Clear intervals but don't reset game (modal will show)
|
|
204
|
-
const state = get();
|
|
205
|
-
if (state.gameLoopInterval) clearInterval(state.gameLoopInterval);
|
|
206
|
-
if (state.pipeSpawnInterval) clearInterval(state.pipeSpawnInterval);
|
|
207
|
-
if (state.timerInterval) clearInterval(state.timerInterval);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// Check collision with pipes
|
|
211
|
-
if (get().checkCollision()) {
|
|
212
|
-
// Clear intervals but don't reset game (modal will show)
|
|
213
|
-
const state = get();
|
|
214
|
-
if (state.gameLoopInterval) clearInterval(state.gameLoopInterval);
|
|
215
|
-
if (state.pipeSpawnInterval) clearInterval(state.pipeSpawnInterval);
|
|
216
|
-
if (state.timerInterval) clearInterval(state.timerInterval);
|
|
217
|
-
}
|
|
218
|
-
},
|
|
219
|
-
spawnPipe: settings => {
|
|
220
|
-
const state = get();
|
|
221
|
-
if (!state.isPlaying || state.isGameOver) return;
|
|
222
|
-
const config = DIFFICULTY_CONFIG[settings.difficulty];
|
|
223
|
-
const offset = settings.offset ?? 0;
|
|
224
|
-
const topHeight = generateRandomPipeHeight(offset);
|
|
225
|
-
const bottomY = topHeight + config.pipeGap;
|
|
226
|
-
const pipe = {
|
|
227
|
-
id: `pipe-${Date.now()}-${Math.random()}`,
|
|
228
|
-
x: FLAPPY_BIRD_GAME_CONFIG.GAME_WIDTH,
|
|
229
|
-
topHeight,
|
|
230
|
-
bottomY,
|
|
231
|
-
passed: false
|
|
232
|
-
};
|
|
233
|
-
set(state => {
|
|
234
|
-
state.pipes.push(pipe);
|
|
235
|
-
});
|
|
236
|
-
},
|
|
237
|
-
checkCollision: () => {
|
|
238
|
-
const state = get();
|
|
239
|
-
const {
|
|
240
|
-
BIRD_START_X,
|
|
241
|
-
BIRD_SIZE,
|
|
242
|
-
PIPE_WIDTH
|
|
243
|
-
} = FLAPPY_BIRD_GAME_CONFIG;
|
|
244
|
-
const birdLeft = BIRD_START_X;
|
|
245
|
-
const birdRight = BIRD_START_X + BIRD_SIZE;
|
|
246
|
-
const birdTop = state.birdY;
|
|
247
|
-
const birdBottom = state.birdY + BIRD_SIZE;
|
|
248
|
-
const birdCenterX = BIRD_START_X + BIRD_SIZE / 2;
|
|
249
|
-
const birdCenterY = state.birdY + BIRD_SIZE / 2;
|
|
250
|
-
for (const pipe of state.pipes) {
|
|
251
|
-
const pipeLeft = pipe.x;
|
|
252
|
-
const pipeRight = pipe.x + PIPE_WIDTH;
|
|
253
|
-
|
|
254
|
-
// Check if bird is in pipe's horizontal range
|
|
255
|
-
if (birdRight > pipeLeft && birdLeft < pipeRight) {
|
|
256
|
-
// Check collision with top pipe
|
|
257
|
-
if (birdTop < pipe.topHeight) {
|
|
258
|
-
get().addCollisionBlast(birdCenterX, birdCenterY);
|
|
259
|
-
set(state => {
|
|
260
|
-
state.isGameOver = true;
|
|
261
|
-
state.isPlaying = false;
|
|
262
|
-
});
|
|
263
|
-
return true;
|
|
264
|
-
}
|
|
265
|
-
// Check collision with bottom pipe
|
|
266
|
-
if (birdBottom > pipe.bottomY) {
|
|
267
|
-
get().addCollisionBlast(birdCenterX, birdCenterY);
|
|
268
|
-
set(state => {
|
|
269
|
-
state.isGameOver = true;
|
|
270
|
-
state.isPlaying = false;
|
|
271
|
-
});
|
|
272
|
-
return true;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
return false;
|
|
277
|
-
},
|
|
278
|
-
addCollisionBlast: (x, y) => {
|
|
279
|
-
set(state => {
|
|
280
|
-
state.collisionBlasts.push({
|
|
281
|
-
id: `blast-${Date.now()}-${Math.random()}`,
|
|
282
|
-
x,
|
|
283
|
-
y
|
|
284
|
-
});
|
|
285
|
-
});
|
|
286
|
-
},
|
|
287
|
-
removeCollisionBlast: id => {
|
|
288
|
-
set(state => {
|
|
289
|
-
state.collisionBlasts = state.collisionBlasts.filter(blast => blast.id !== id);
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
}))));
|
|
293
|
-
export const useIsPlaying = () => useFlappyBirdStore(state => state.isPlaying);
|
|
294
|
-
export const useIsGameOver = () => useFlappyBirdStore(state => state.isGameOver);
|
|
295
|
-
export const useScore = () => useFlappyBirdStore(state => state.score);
|
|
296
|
-
export const useSurvivalTime = () => useFlappyBirdStore(state => state.survivalTime);
|
|
297
|
-
export const useBirdY = () => useFlappyBirdStore(state => state.birdY);
|
|
298
|
-
export const usePipes = () => useFlappyBirdStore(state => state.pipes);
|
|
299
|
-
export const useCollisionBlasts = () => useFlappyBirdStore(state => state.collisionBlasts);
|
|
300
|
-
//# sourceMappingURL=FlappyBirdStore.js.map
|
|
1
|
+
"use strict";import{create}from 'zustand';import{subscribeWithSelector}from 'zustand/middleware';import{immerMiddleware}from "../../services/UtilsService.js";import{FLAPPY_BIRD_GAME_CONFIG,DIFFICULTY_CONFIG}from "./FlappyBirdConstants.js";const BASE_BRICK_WALL_HEIGHT = 150;const generateRandomPipeHeight =(offset = 0)=>{const{MIN_PIPE_HEIGHT,GAME_HEIGHT}= FLAPPY_BIRD_GAME_CONFIG;const topWallHeight = BASE_BRICK_WALL_HEIGHT + offset;const bottomWallHeight = offset > 0 ? 150:250;const playableHeight = GAME_HEIGHT - topWallHeight - bottomWallHeight;const minHeight = topWallHeight + MIN_PIPE_HEIGHT;const maxHeight = topWallHeight + playableHeight * 0.6;return minHeight + Math.random()*(maxHeight - minHeight);};export const useFlappyBirdStore = create()(subscribeWithSelector(immerMiddleware((set,get)=>({isPlaying:false,isGameOver:false,score:0,survivalTime:0,birdY:FLAPPY_BIRD_GAME_CONFIG.BIRD_START_Y,birdVelocity:0,pipes:[],collisionBlasts:[],gameLoopInterval:null,pipeSpawnInterval:null,timerInterval:null,initializeGame:()=>{set(state =>{state.isPlaying = false;state.isGameOver = false;state.score = 0;state.survivalTime = 0;state.birdY = FLAPPY_BIRD_GAME_CONFIG.BIRD_START_Y;state.birdVelocity = 0;state.pipes = [];state.collisionBlasts = [];});},startGame:settings =>{const state = get();if(state.gameLoopInterval)clearInterval(state.gameLoopInterval);if(state.pipeSpawnInterval)clearInterval(state.pipeSpawnInterval);if(state.timerInterval)clearInterval(state.timerInterval);set(state =>{state.isPlaying = true;state.isGameOver = false;state.birdY = FLAPPY_BIRD_GAME_CONFIG.BIRD_START_Y;state.birdVelocity = 0;state.pipes = [];state.score = 0;state.survivalTime = 0;});const gameLoop = setInterval(()=>{get().updatePhysics(settings);},1000 / 60);const pipeSpawn = setInterval(()=>{get().spawnPipe(settings);},FLAPPY_BIRD_GAME_CONFIG.PIPE_SPAWN_INTERVAL);const timer = setInterval(()=>{set(state =>{state.survivalTime += 1;});},1000);set(state =>{state.gameLoopInterval = gameLoop;state.pipeSpawnInterval = pipeSpawn;state.timerInterval = timer;});setTimeout(()=> get().spawnPipe(settings),500);},stopGame:()=>{const state = get();if(state.gameLoopInterval)clearInterval(state.gameLoopInterval);if(state.pipeSpawnInterval)clearInterval(state.pipeSpawnInterval);if(state.timerInterval)clearInterval(state.timerInterval);state.initializeGame();},resetGame:()=>{const state = get();if(state.gameLoopInterval)clearInterval(state.gameLoopInterval);if(state.pipeSpawnInterval)clearInterval(state.pipeSpawnInterval);if(state.timerInterval)clearInterval(state.timerInterval);set(state =>{state.isPlaying = false;state.isGameOver = false;state.score = 0;state.survivalTime = 0;state.birdY = FLAPPY_BIRD_GAME_CONFIG.BIRD_START_Y;state.birdVelocity = 0;state.pipes = [];state.collisionBlasts = [];state.gameLoopInterval = null;state.pipeSpawnInterval = null;state.timerInterval = null;});},jump:()=>{const state = get();if(!state.isPlaying || state.isGameOver)return;set(state =>{state.birdVelocity = FLAPPY_BIRD_GAME_CONFIG.JUMP_VELOCITY;});},updatePhysics:settings =>{const state = get();if(!state.isPlaying || state.isGameOver)return;const config = DIFFICULTY_CONFIG[settings.difficulty];const{GAME_HEIGHT,GRAVITY,BIRD_SIZE,MAX_FALL_SPEED,VELOCITY_DAMPING}= FLAPPY_BIRD_GAME_CONFIG;const offset = settings.offset ?? 0;const topWallHeight = BASE_BRICK_WALL_HEIGHT + offset;const bottomWallHeight = offset > 0 ? 150:250;const bottomWallTop = GAME_HEIGHT - bottomWallHeight;let topWallCollision = false;let bottomWallCollision = false;set(draftState =>{draftState.birdVelocity += GRAVITY;draftState.birdVelocity *= VELOCITY_DAMPING;if(draftState.birdVelocity > MAX_FALL_SPEED){draftState.birdVelocity = MAX_FALL_SPEED;}draftState.birdY += draftState.birdVelocity;for(let i = draftState.pipes.length - 1;i >= 0;i--){const pipe = draftState.pipes[i];if(!pipe)continue;pipe.x -= config.pipeSpeed;if(!pipe.passed && pipe.x + FLAPPY_BIRD_GAME_CONFIG.PIPE_WIDTH < FLAPPY_BIRD_GAME_CONFIG.BIRD_START_X){pipe.passed = true;draftState.score += 1;}if(pipe.x + FLAPPY_BIRD_GAME_CONFIG.PIPE_WIDTH < 0){draftState.pipes.splice(i,1);}}if(draftState.birdY < topWallHeight){draftState.birdY = topWallHeight;draftState.birdVelocity = 0;draftState.isGameOver = true;draftState.isPlaying = false;topWallCollision = true;}if(draftState.birdY + BIRD_SIZE > bottomWallTop){draftState.birdY = bottomWallTop - BIRD_SIZE;draftState.isGameOver = true;draftState.isPlaying = false;bottomWallCollision = true;}});if(topWallCollision){const blastX = FLAPPY_BIRD_GAME_CONFIG.BIRD_START_X + BIRD_SIZE / 2;const blastY = topWallHeight + BIRD_SIZE / 2;get().addCollisionBlast(blastX,blastY);const state = get();if(state.gameLoopInterval)clearInterval(state.gameLoopInterval);if(state.pipeSpawnInterval)clearInterval(state.pipeSpawnInterval);if(state.timerInterval)clearInterval(state.timerInterval);}if(bottomWallCollision){const blastX = FLAPPY_BIRD_GAME_CONFIG.BIRD_START_X + BIRD_SIZE / 2;const blastY = bottomWallTop - BIRD_SIZE / 2;get().addCollisionBlast(blastX,blastY);const state = get();if(state.gameLoopInterval)clearInterval(state.gameLoopInterval);if(state.pipeSpawnInterval)clearInterval(state.pipeSpawnInterval);if(state.timerInterval)clearInterval(state.timerInterval);}if(get().checkCollision()){const state = get();if(state.gameLoopInterval)clearInterval(state.gameLoopInterval);if(state.pipeSpawnInterval)clearInterval(state.pipeSpawnInterval);if(state.timerInterval)clearInterval(state.timerInterval);}},spawnPipe:settings =>{const state = get();if(!state.isPlaying || state.isGameOver)return;const config = DIFFICULTY_CONFIG[settings.difficulty];const offset = settings.offset ?? 0;const topHeight = generateRandomPipeHeight(offset);const bottomY = topHeight + config.pipeGap;const pipe ={id:`pipe-${Date.now()}-${Math.random()}`,x:FLAPPY_BIRD_GAME_CONFIG.GAME_WIDTH,topHeight,bottomY,passed:false};set(state =>{state.pipes.push(pipe);});},checkCollision:()=>{const state = get();const{BIRD_START_X,BIRD_SIZE,PIPE_WIDTH}= FLAPPY_BIRD_GAME_CONFIG;const birdLeft = BIRD_START_X;const birdRight = BIRD_START_X + BIRD_SIZE;const birdTop = state.birdY;const birdBottom = state.birdY + BIRD_SIZE;const birdCenterX = BIRD_START_X + BIRD_SIZE / 2;const birdCenterY = state.birdY + BIRD_SIZE / 2;for(const pipe of state.pipes){const pipeLeft = pipe.x;const pipeRight = pipe.x + PIPE_WIDTH;if(birdRight > pipeLeft && birdLeft < pipeRight){if(birdTop < pipe.topHeight){get().addCollisionBlast(birdCenterX,birdCenterY);set(state =>{state.isGameOver = true;state.isPlaying = false;});return true;}if(birdBottom > pipe.bottomY){get().addCollisionBlast(birdCenterX,birdCenterY);set(state =>{state.isGameOver = true;state.isPlaying = false;});return true;}}}return false;},addCollisionBlast:(x,y)=>{set(state =>{state.collisionBlasts.push({id:`blast-${Date.now()}-${Math.random()}`,x,y});});},removeCollisionBlast:id =>{set(state =>{state.collisionBlasts = state.collisionBlasts.filter(blast => blast.id !== id);});}}))));export const useIsPlaying =()=> useFlappyBirdStore(state => state.isPlaying);export const useIsGameOver =()=> useFlappyBirdStore(state => state.isGameOver);export const useScore =()=> useFlappyBirdStore(state => state.score);export const useSurvivalTime =()=> useFlappyBirdStore(state => state.survivalTime);export const useBirdY =()=> useFlappyBirdStore(state => state.birdY);export const usePipes =()=> useFlappyBirdStore(state => state.pipes);export const useCollisionBlasts =()=> useFlappyBirdStore(state => state.collisionBlasts);
|
|
@@ -1,87 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import Animated, { useAnimatedStyle, interpolate, Extrapolate } from 'react-native-reanimated';
|
|
5
|
-
import { Canvas, Circle, Group } from '@shopify/react-native-skia';
|
|
6
|
-
import { FLAPPY_BIRD_GAME_CONFIG, FLAPPY_BIRD_COLORS } from "../FlappyBirdConstants.js";
|
|
7
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
8
|
-
const {
|
|
9
|
-
BIRD_SIZE
|
|
10
|
-
} = FLAPPY_BIRD_GAME_CONFIG;
|
|
11
|
-
|
|
12
|
-
// Define styles outside component to prevent re-creation
|
|
13
|
-
const birdContainerStyle = {
|
|
14
|
-
position: 'absolute',
|
|
15
|
-
width: BIRD_SIZE,
|
|
16
|
-
height: BIRD_SIZE
|
|
17
|
-
};
|
|
18
|
-
const canvasStyle = {
|
|
19
|
-
width: BIRD_SIZE,
|
|
20
|
-
height: BIRD_SIZE
|
|
21
|
-
};
|
|
22
|
-
export const Bird = /*#__PURE__*/React.memo(({
|
|
23
|
-
birdY,
|
|
24
|
-
velocity
|
|
25
|
-
}) => {
|
|
26
|
-
const {
|
|
27
|
-
BIRD_START_X
|
|
28
|
-
} = FLAPPY_BIRD_GAME_CONFIG;
|
|
29
|
-
|
|
30
|
-
// Use derived value instead of useEffect (PERFORMANCE OPTIMIZATION)
|
|
31
|
-
const animatedStyle = useAnimatedStyle(() => {
|
|
32
|
-
'worklet';
|
|
33
|
-
|
|
34
|
-
const targetRotation = interpolate(velocity, [-15, 15], [-30, 90], Extrapolate.CLAMP);
|
|
35
|
-
return {
|
|
36
|
-
transform: [{
|
|
37
|
-
translateX: BIRD_START_X
|
|
38
|
-
}, {
|
|
39
|
-
translateY: birdY
|
|
40
|
-
}, {
|
|
41
|
-
rotate: `${targetRotation}deg`
|
|
42
|
-
}]
|
|
43
|
-
};
|
|
44
|
-
}, [birdY, velocity]);
|
|
45
|
-
return /*#__PURE__*/_jsx(Animated.View, {
|
|
46
|
-
style: [birdContainerStyle, animatedStyle],
|
|
47
|
-
children: /*#__PURE__*/_jsx(Canvas, {
|
|
48
|
-
style: canvasStyle,
|
|
49
|
-
children: /*#__PURE__*/_jsxs(Group, {
|
|
50
|
-
children: [/*#__PURE__*/_jsx(Circle, {
|
|
51
|
-
cx: BIRD_SIZE / 2,
|
|
52
|
-
cy: BIRD_SIZE / 2,
|
|
53
|
-
r: BIRD_SIZE / 2,
|
|
54
|
-
color: FLAPPY_BIRD_COLORS.BIRD_YELLOW
|
|
55
|
-
}), /*#__PURE__*/_jsx(Circle, {
|
|
56
|
-
cx: BIRD_SIZE / 2,
|
|
57
|
-
cy: BIRD_SIZE / 2 + 5,
|
|
58
|
-
r: BIRD_SIZE / 3,
|
|
59
|
-
color: FLAPPY_BIRD_COLORS.BIRD_ORANGE
|
|
60
|
-
}), /*#__PURE__*/_jsx(Circle, {
|
|
61
|
-
cx: BIRD_SIZE / 2 + 8,
|
|
62
|
-
cy: BIRD_SIZE / 2 - 5,
|
|
63
|
-
r: 4,
|
|
64
|
-
color: "#FFFFFF"
|
|
65
|
-
}), /*#__PURE__*/_jsx(Circle, {
|
|
66
|
-
cx: BIRD_SIZE / 2 + 8,
|
|
67
|
-
cy: BIRD_SIZE / 2 - 5,
|
|
68
|
-
r: 2,
|
|
69
|
-
color: "#000000"
|
|
70
|
-
}), /*#__PURE__*/_jsx(Circle, {
|
|
71
|
-
cx: BIRD_SIZE / 2 + 15,
|
|
72
|
-
cy: BIRD_SIZE / 2,
|
|
73
|
-
r: 5,
|
|
74
|
-
color: "#FF8C00"
|
|
75
|
-
}), /*#__PURE__*/_jsx(Circle, {
|
|
76
|
-
cx: BIRD_SIZE / 2 - 5,
|
|
77
|
-
cy: BIRD_SIZE / 2 + 5,
|
|
78
|
-
r: 10,
|
|
79
|
-
color: FLAPPY_BIRD_COLORS.BIRD_ORANGE,
|
|
80
|
-
opacity: 0.8
|
|
81
|
-
})]
|
|
82
|
-
})
|
|
83
|
-
})
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
Bird.displayName = 'Bird';
|
|
87
|
-
//# sourceMappingURL=Bird.js.map
|
|
1
|
+
"use strict";import React from 'react';import Animated,{useAnimatedStyle,interpolate,Extrapolate}from 'react-native-reanimated';import{Canvas,Circle,Group}from '@shopify/react-native-skia';import{FLAPPY_BIRD_GAME_CONFIG,FLAPPY_BIRD_COLORS}from "../FlappyBirdConstants.js";import{jsx as _jsx,jsxs as _jsxs}from "react/jsx-runtime";const{BIRD_SIZE}= FLAPPY_BIRD_GAME_CONFIG;const birdContainerStyle ={position:'absolute',width:BIRD_SIZE,height:BIRD_SIZE};const canvasStyle ={width:BIRD_SIZE,height:BIRD_SIZE};export const Bird = React.memo(({birdY,velocity})=>{const{BIRD_START_X}= FLAPPY_BIRD_GAME_CONFIG;const animatedStyle = useAnimatedStyle(()=>{'worklet';const targetRotation = interpolate(velocity,[-15,15],[-30,90],Extrapolate.CLAMP);return{transform:[{translateX:BIRD_START_X},{translateY:birdY},{rotate:`${targetRotation}deg`}]};},[birdY,velocity]);return _jsx(Animated.View,{style:[birdContainerStyle,animatedStyle],children:_jsx(Canvas,{style:canvasStyle,children:_jsxs(Group,{children:[_jsx(Circle,{cx:BIRD_SIZE / 2,cy:BIRD_SIZE / 2,r:BIRD_SIZE / 2,color:FLAPPY_BIRD_COLORS.BIRD_YELLOW}),_jsx(Circle,{cx:BIRD_SIZE / 2,cy:BIRD_SIZE / 2 + 5,r:BIRD_SIZE / 3,color:FLAPPY_BIRD_COLORS.BIRD_ORANGE}),_jsx(Circle,{cx:BIRD_SIZE / 2 + 8,cy:BIRD_SIZE / 2 - 5,r:4,color:"#FFFFFF"}),_jsx(Circle,{cx:BIRD_SIZE / 2 + 8,cy:BIRD_SIZE / 2 - 5,r:2,color:"#000000"}),_jsx(Circle,{cx:BIRD_SIZE / 2 + 15,cy:BIRD_SIZE / 2,r:5,color:"#FF8C00"}),_jsx(Circle,{cx:BIRD_SIZE / 2 - 5,cy:BIRD_SIZE / 2 + 5,r:10,color:FLAPPY_BIRD_COLORS.BIRD_ORANGE,opacity:0.8})]})})});});Bird.displayName = 'Bird';
|
|
@@ -1,87 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import React, { useCallback, useEffect, useRef } from 'react';
|
|
4
|
-
import { View, StyleSheet, TouchableOpacity } from 'react-native';
|
|
5
|
-
import { GestureHandlerRootView } from 'react-native-gesture-handler';
|
|
6
|
-
import { usePipes, useFlappyBirdStore, useCollisionBlasts } from "../FlappyBirdStore.js";
|
|
7
|
-
import { Bird } from "./Bird.js";
|
|
8
|
-
import { Pipes } from "./Pipes.js";
|
|
9
|
-
import { ParticleBlast } from "../../../helpers/index.js";
|
|
10
|
-
import { playSound, GAME_SOUNDS } from "../../../services/SoundsService.js";
|
|
11
|
-
import { playHaptic, HapticType } from "../../../services/HapticsService.js";
|
|
12
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
-
// Constant particle colors - defined outside component to prevent re-creation
|
|
14
|
-
const PARTICLE_COLORS = ['#FFD700', '#FF8C00', '#FF6B6B', '#FF4757', '#FFA500', '#FF6347'];
|
|
15
|
-
export const GameArea = /*#__PURE__*/React.memo(({
|
|
16
|
-
settings
|
|
17
|
-
}) => {
|
|
18
|
-
const birdY = useFlappyBirdStore(state => state.birdY);
|
|
19
|
-
const birdVelocity = useFlappyBirdStore(state => state.birdVelocity);
|
|
20
|
-
const isPlaying = useFlappyBirdStore(state => state.isPlaying);
|
|
21
|
-
const score = useFlappyBirdStore(state => state.score);
|
|
22
|
-
const pipes = usePipes();
|
|
23
|
-
const collisionBlasts = useCollisionBlasts();
|
|
24
|
-
|
|
25
|
-
// Stable references - don't change on re-renders
|
|
26
|
-
const jump = useFlappyBirdStore(state => state.jump);
|
|
27
|
-
const removeCollisionBlast = useFlappyBirdStore(state => state.removeCollisionBlast);
|
|
28
|
-
const prevScoreRef = useRef(0);
|
|
29
|
-
|
|
30
|
-
// Play sound when score increases (bird passes through pipe)
|
|
31
|
-
useEffect(() => {
|
|
32
|
-
if (score > prevScoreRef.current && isPlaying) {
|
|
33
|
-
playSound(GAME_SOUNDS.FLAPPY_BIRD.SCORE, settings.enableSounds);
|
|
34
|
-
playHaptic(HapticType.LIGHT, settings.enableHaptics);
|
|
35
|
-
}
|
|
36
|
-
prevScoreRef.current = score;
|
|
37
|
-
}, [score, isPlaying, settings.enableSounds, settings.enableHaptics]);
|
|
38
|
-
const handleTap = useCallback(() => {
|
|
39
|
-
if (!isPlaying) return;
|
|
40
|
-
jump();
|
|
41
|
-
playSound(GAME_SOUNDS.FLAPPY_BIRD.FLAP, settings.enableSounds);
|
|
42
|
-
playHaptic(HapticType.LIGHT, settings.enableHaptics);
|
|
43
|
-
}, [isPlaying, jump, settings.enableSounds, settings.enableHaptics]);
|
|
44
|
-
|
|
45
|
-
// Memoize particle blast callback to prevent re-creating on every render
|
|
46
|
-
const handleBlastComplete = useCallback(id => {
|
|
47
|
-
removeCollisionBlast(id);
|
|
48
|
-
}, [removeCollisionBlast]);
|
|
49
|
-
return /*#__PURE__*/_jsx(View, {
|
|
50
|
-
style: styles.container,
|
|
51
|
-
children: /*#__PURE__*/_jsx(GestureHandlerRootView, {
|
|
52
|
-
children: /*#__PURE__*/_jsx(TouchableOpacity, {
|
|
53
|
-
style: styles.container,
|
|
54
|
-
activeOpacity: 1,
|
|
55
|
-
onPress: handleTap,
|
|
56
|
-
children: /*#__PURE__*/_jsxs(View, {
|
|
57
|
-
style: styles.gameContainer,
|
|
58
|
-
children: [/*#__PURE__*/_jsx(Pipes, {
|
|
59
|
-
pipes: pipes,
|
|
60
|
-
offset: settings.offset ?? 0
|
|
61
|
-
}), /*#__PURE__*/_jsx(Bird, {
|
|
62
|
-
birdY: birdY,
|
|
63
|
-
velocity: birdVelocity
|
|
64
|
-
}), collisionBlasts.map(blast => /*#__PURE__*/_jsx(ParticleBlast, {
|
|
65
|
-
x: blast.x,
|
|
66
|
-
y: blast.y,
|
|
67
|
-
particleCount: 12,
|
|
68
|
-
colors: PARTICLE_COLORS,
|
|
69
|
-
duration: 800,
|
|
70
|
-
onComplete: () => handleBlastComplete(blast.id)
|
|
71
|
-
}, blast.id))]
|
|
72
|
-
})
|
|
73
|
-
})
|
|
74
|
-
})
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
const styles = StyleSheet.create({
|
|
78
|
-
container: {
|
|
79
|
-
flex: 1
|
|
80
|
-
},
|
|
81
|
-
gameContainer: {
|
|
82
|
-
flex: 1,
|
|
83
|
-
position: 'relative'
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
GameArea.displayName = 'GameArea';
|
|
87
|
-
//# sourceMappingURL=GameArea.js.map
|
|
1
|
+
"use strict";import React,{useCallback,useEffect,useRef}from 'react';import{View,StyleSheet,TouchableOpacity}from 'react-native';import{GestureHandlerRootView}from 'react-native-gesture-handler';import{usePipes,useFlappyBirdStore,useCollisionBlasts}from "../FlappyBirdStore.js";import{Bird}from "./Bird.js";import{Pipes}from "./Pipes.js";import{ParticleBlast}from "../../../helpers/index.js";import{playSound,GAME_SOUNDS}from "../../../services/SoundsService.js";import{playHaptic,HapticType}from "../../../services/HapticsService.js";import{jsx as _jsx,jsxs as _jsxs}from "react/jsx-runtime";const PARTICLE_COLORS = ['#FFD700','#FF8C00','#FF6B6B','#FF4757','#FFA500','#FF6347'];export const GameArea = React.memo(({settings})=>{const birdY = useFlappyBirdStore(state => state.birdY);const birdVelocity = useFlappyBirdStore(state => state.birdVelocity);const isPlaying = useFlappyBirdStore(state => state.isPlaying);const score = useFlappyBirdStore(state => state.score);const pipes = usePipes();const collisionBlasts = useCollisionBlasts();const jump = useFlappyBirdStore(state => state.jump);const removeCollisionBlast = useFlappyBirdStore(state => state.removeCollisionBlast);const prevScoreRef = useRef(0);useEffect(()=>{if(score > prevScoreRef.current && isPlaying){playSound(GAME_SOUNDS.FLAPPY_BIRD.SCORE,settings.enableSounds);playHaptic(HapticType.LIGHT,settings.enableHaptics);}prevScoreRef.current = score;},[score,isPlaying,settings.enableSounds,settings.enableHaptics]);const handleTap = useCallback(()=>{if(!isPlaying)return;jump();playSound(GAME_SOUNDS.FLAPPY_BIRD.FLAP,settings.enableSounds);playHaptic(HapticType.LIGHT,settings.enableHaptics);},[isPlaying,jump,settings.enableSounds,settings.enableHaptics]);const handleBlastComplete = useCallback(id =>{removeCollisionBlast(id);},[removeCollisionBlast]);return _jsx(View,{style:styles.container,children:_jsx(GestureHandlerRootView,{children:_jsx(TouchableOpacity,{style:styles.container,activeOpacity:1,onPress:handleTap,children:_jsxs(View,{style:styles.gameContainer,children:[_jsx(Pipes,{pipes:pipes,offset:settings.offset ?? 0}),_jsx(Bird,{birdY:birdY,velocity:birdVelocity}),collisionBlasts.map(blast => _jsx(ParticleBlast,{x:blast.x,y:blast.y,particleCount:12,colors:PARTICLE_COLORS,duration:800,onComplete:()=> handleBlastComplete(blast.id)},blast.id))]})})})});});const styles = StyleSheet.create({container:{flex:1},gameContainer:{flex:1,position:'relative'}});GameArea.displayName = 'GameArea';
|