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,182 +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 { SnakeService } from "./SnakeService.js";
|
|
7
|
-
import { SNAKE_GAME_CONFIG, SNAKE_SOUNDS } from "./SnakeConstants.js";
|
|
8
|
-
import { playSound } from "../../services/SoundsService.js";
|
|
9
|
-
import { playHaptic, HapticType } from "../../services/HapticsService.js";
|
|
10
|
-
const gameService = new SnakeService();
|
|
11
|
-
export const useSnakeStore = create()(subscribeWithSelector(immerMiddleware((set, get) => ({
|
|
12
|
-
// Initial state
|
|
13
|
-
snake: gameService.initializeSnake(),
|
|
14
|
-
food: null,
|
|
15
|
-
direction: 'RIGHT',
|
|
16
|
-
nextDirection: 'RIGHT',
|
|
17
|
-
score: 0,
|
|
18
|
-
isPlaying: false,
|
|
19
|
-
isGameOver: false,
|
|
20
|
-
isPaused: false,
|
|
21
|
-
difficulty: 'easy',
|
|
22
|
-
enableSounds: true,
|
|
23
|
-
enableHaptics: true,
|
|
24
|
-
moveTimer: null,
|
|
25
|
-
startGame: () => {
|
|
26
|
-
const state = get();
|
|
27
|
-
|
|
28
|
-
// Clear any existing timers
|
|
29
|
-
if (state.moveTimer) clearInterval(state.moveTimer);
|
|
30
|
-
|
|
31
|
-
// Generate initial food
|
|
32
|
-
const initialFood = gameService.generateFood(state.snake, false);
|
|
33
|
-
|
|
34
|
-
// Start game loop
|
|
35
|
-
const gameSpeed = SNAKE_GAME_CONFIG.GAME_SPEED[state.difficulty];
|
|
36
|
-
const moveTimer = setInterval(() => {
|
|
37
|
-
const currentState = get();
|
|
38
|
-
if (currentState.isPlaying && !currentState.isPaused) {
|
|
39
|
-
currentState.gameLoop();
|
|
40
|
-
}
|
|
41
|
-
}, gameSpeed);
|
|
42
|
-
set(state => {
|
|
43
|
-
state.isPlaying = true;
|
|
44
|
-
state.isPaused = false;
|
|
45
|
-
state.food = initialFood;
|
|
46
|
-
state.moveTimer = moveTimer;
|
|
47
|
-
});
|
|
48
|
-
},
|
|
49
|
-
stopGame: () => {
|
|
50
|
-
const state = get();
|
|
51
|
-
if (state.moveTimer) clearInterval(state.moveTimer);
|
|
52
|
-
playSound(SNAKE_SOUNDS.LOSE, state.enableSounds);
|
|
53
|
-
playHaptic(HapticType.MEDIUM, state.enableHaptics);
|
|
54
|
-
|
|
55
|
-
// Reset the game instead of showing game over modal
|
|
56
|
-
state.initializeGame(state.difficulty);
|
|
57
|
-
},
|
|
58
|
-
pauseGame: () => {
|
|
59
|
-
set(state => {
|
|
60
|
-
state.isPaused = true;
|
|
61
|
-
});
|
|
62
|
-
},
|
|
63
|
-
resumeGame: () => {
|
|
64
|
-
set(state => {
|
|
65
|
-
state.isPaused = false;
|
|
66
|
-
});
|
|
67
|
-
},
|
|
68
|
-
resetGame: () => {
|
|
69
|
-
const state = get();
|
|
70
|
-
state.initializeGame(state.difficulty);
|
|
71
|
-
},
|
|
72
|
-
initializeGame: (difficulty = 'easy') => {
|
|
73
|
-
const state = get();
|
|
74
|
-
if (state.moveTimer) clearInterval(state.moveTimer);
|
|
75
|
-
gameService.resetIdCounter();
|
|
76
|
-
const newSnake = gameService.initializeSnake();
|
|
77
|
-
set(state => {
|
|
78
|
-
state.snake = newSnake;
|
|
79
|
-
state.food = null;
|
|
80
|
-
state.direction = 'RIGHT';
|
|
81
|
-
state.nextDirection = 'RIGHT';
|
|
82
|
-
state.score = 0;
|
|
83
|
-
state.isPlaying = false;
|
|
84
|
-
state.isGameOver = false;
|
|
85
|
-
state.isPaused = false;
|
|
86
|
-
state.difficulty = difficulty;
|
|
87
|
-
state.moveTimer = null;
|
|
88
|
-
});
|
|
89
|
-
},
|
|
90
|
-
changeDirection: newDirection => {
|
|
91
|
-
const state = get();
|
|
92
|
-
if (!state.isPlaying || state.isPaused) return;
|
|
93
|
-
|
|
94
|
-
// Check if direction change is valid (can't reverse)
|
|
95
|
-
if (gameService.isValidDirectionChange(state.direction, newDirection)) {
|
|
96
|
-
set(state => {
|
|
97
|
-
state.nextDirection = newDirection;
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
gameLoop: () => {
|
|
102
|
-
const state = get();
|
|
103
|
-
if (!state.isPlaying || state.isPaused || state.isGameOver) return;
|
|
104
|
-
set(draft => {
|
|
105
|
-
// Update direction
|
|
106
|
-
draft.direction = draft.nextDirection;
|
|
107
|
-
|
|
108
|
-
// Move snake
|
|
109
|
-
const newSnake = gameService.moveSnake(draft.snake, draft.direction);
|
|
110
|
-
const head = newSnake[0];
|
|
111
|
-
if (!head) return;
|
|
112
|
-
|
|
113
|
-
// Check wall collision
|
|
114
|
-
if (gameService.checkWallCollision(head)) {
|
|
115
|
-
draft.isGameOver = true;
|
|
116
|
-
draft.isPlaying = false;
|
|
117
|
-
if (draft.moveTimer) {
|
|
118
|
-
clearInterval(draft.moveTimer);
|
|
119
|
-
draft.moveTimer = null;
|
|
120
|
-
}
|
|
121
|
-
playSound(SNAKE_SOUNDS.COLLISION, draft.enableSounds);
|
|
122
|
-
playHaptic(HapticType.HEAVY, draft.enableHaptics);
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// Check self collision
|
|
127
|
-
if (gameService.checkSelfCollision(newSnake)) {
|
|
128
|
-
draft.isGameOver = true;
|
|
129
|
-
draft.isPlaying = false;
|
|
130
|
-
if (draft.moveTimer) {
|
|
131
|
-
clearInterval(draft.moveTimer);
|
|
132
|
-
draft.moveTimer = null;
|
|
133
|
-
}
|
|
134
|
-
playSound(SNAKE_SOUNDS.COLLISION, draft.enableSounds);
|
|
135
|
-
playHaptic(HapticType.HEAVY, draft.enableHaptics);
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Check food collision
|
|
140
|
-
if (draft.food && gameService.checkFoodCollision(head, draft.food)) {
|
|
141
|
-
// Grow snake
|
|
142
|
-
const grownSnake = gameService.growSnake(newSnake);
|
|
143
|
-
draft.snake = grownSnake;
|
|
144
|
-
|
|
145
|
-
// Update score with difficulty multiplier
|
|
146
|
-
const points = gameService.calculateScore(draft.food.isSpecial, draft.difficulty);
|
|
147
|
-
draft.score += points;
|
|
148
|
-
|
|
149
|
-
// Play sound
|
|
150
|
-
const sound = draft.food.isSpecial ? SNAKE_SOUNDS.SPECIAL : SNAKE_SOUNDS.EAT;
|
|
151
|
-
playSound(sound, draft.enableSounds);
|
|
152
|
-
playHaptic(draft.food.isSpecial ? HapticType.HEAVY : HapticType.MEDIUM, draft.enableHaptics);
|
|
153
|
-
|
|
154
|
-
// Generate new food
|
|
155
|
-
const isSpecial = Math.random() < SNAKE_GAME_CONFIG.SPECIAL_FOOD_CHANCE;
|
|
156
|
-
draft.food = gameService.generateFood(grownSnake, isSpecial);
|
|
157
|
-
} else {
|
|
158
|
-
draft.snake = newSnake;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// Check if special food expired
|
|
162
|
-
if (draft.food && gameService.isSpecialFoodExpired(draft.food)) {
|
|
163
|
-
draft.food = gameService.generateFood(draft.snake, false);
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
},
|
|
167
|
-
updateSettings: (enableSounds, enableHaptics) => {
|
|
168
|
-
set(state => {
|
|
169
|
-
state.enableSounds = enableSounds;
|
|
170
|
-
state.enableHaptics = enableHaptics;
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
}))));
|
|
174
|
-
|
|
175
|
-
// Selector hooks for optimal re-renders
|
|
176
|
-
export const useSnake = () => useSnakeStore(state => state.snake);
|
|
177
|
-
export const useFood = () => useSnakeStore(state => state.food);
|
|
178
|
-
export const useScore = () => useSnakeStore(state => state.score);
|
|
179
|
-
export const useIsPlaying = () => useSnakeStore(state => state.isPlaying);
|
|
180
|
-
export const useIsGameOver = () => useSnakeStore(state => state.isGameOver);
|
|
181
|
-
export const useIsPaused = () => useSnakeStore(state => state.isPaused);
|
|
182
|
-
//# sourceMappingURL=SnakeStore.js.map
|
|
1
|
+
"use strict";import{create}from 'zustand';import{subscribeWithSelector}from 'zustand/middleware';import{immerMiddleware}from "../../services/UtilsService.js";import{SnakeService}from "./SnakeService.js";import{SNAKE_GAME_CONFIG,SNAKE_SOUNDS}from "./SnakeConstants.js";import{playSound}from "../../services/SoundsService.js";import{playHaptic,HapticType}from "../../services/HapticsService.js";const gameService = new SnakeService();export const useSnakeStore = create()(subscribeWithSelector(immerMiddleware((set,get)=>({snake:gameService.initializeSnake(),food:null,direction:'RIGHT',nextDirection:'RIGHT',score:0,isPlaying:false,isGameOver:false,isPaused:false,difficulty:'easy',enableSounds:true,enableHaptics:true,moveTimer:null,startGame:()=>{const state = get();if(state.moveTimer)clearInterval(state.moveTimer);const initialFood = gameService.generateFood(state.snake,false);const gameSpeed = SNAKE_GAME_CONFIG.GAME_SPEED[state.difficulty];const moveTimer = setInterval(()=>{const currentState = get();if(currentState.isPlaying && !currentState.isPaused){currentState.gameLoop();}},gameSpeed);set(state =>{state.isPlaying = true;state.isPaused = false;state.food = initialFood;state.moveTimer = moveTimer;});},stopGame:()=>{const state = get();if(state.moveTimer)clearInterval(state.moveTimer);playSound(SNAKE_SOUNDS.LOSE,state.enableSounds);playHaptic(HapticType.MEDIUM,state.enableHaptics);state.initializeGame(state.difficulty);},pauseGame:()=>{set(state =>{state.isPaused = true;});},resumeGame:()=>{set(state =>{state.isPaused = false;});},resetGame:()=>{const state = get();state.initializeGame(state.difficulty);},initializeGame:(difficulty = 'easy')=>{const state = get();if(state.moveTimer)clearInterval(state.moveTimer);gameService.resetIdCounter();const newSnake = gameService.initializeSnake();set(state =>{state.snake = newSnake;state.food = null;state.direction = 'RIGHT';state.nextDirection = 'RIGHT';state.score = 0;state.isPlaying = false;state.isGameOver = false;state.isPaused = false;state.difficulty = difficulty;state.moveTimer = null;});},changeDirection:newDirection =>{const state = get();if(!state.isPlaying || state.isPaused)return;if(gameService.isValidDirectionChange(state.direction,newDirection)){set(state =>{state.nextDirection = newDirection;});}},gameLoop:()=>{const state = get();if(!state.isPlaying || state.isPaused || state.isGameOver)return;set(draft =>{draft.direction = draft.nextDirection;const newSnake = gameService.moveSnake(draft.snake,draft.direction);const head = newSnake[0];if(!head)return;if(gameService.checkWallCollision(head)){draft.isGameOver = true;draft.isPlaying = false;if(draft.moveTimer){clearInterval(draft.moveTimer);draft.moveTimer = null;}playSound(SNAKE_SOUNDS.COLLISION,draft.enableSounds);playHaptic(HapticType.HEAVY,draft.enableHaptics);return;}if(gameService.checkSelfCollision(newSnake)){draft.isGameOver = true;draft.isPlaying = false;if(draft.moveTimer){clearInterval(draft.moveTimer);draft.moveTimer = null;}playSound(SNAKE_SOUNDS.COLLISION,draft.enableSounds);playHaptic(HapticType.HEAVY,draft.enableHaptics);return;}if(draft.food && gameService.checkFoodCollision(head,draft.food)){const grownSnake = gameService.growSnake(newSnake);draft.snake = grownSnake;const points = gameService.calculateScore(draft.food.isSpecial,draft.difficulty);draft.score += points;const sound = draft.food.isSpecial ? SNAKE_SOUNDS.SPECIAL:SNAKE_SOUNDS.EAT;playSound(sound,draft.enableSounds);playHaptic(draft.food.isSpecial ? HapticType.HEAVY:HapticType.MEDIUM,draft.enableHaptics);const isSpecial = Math.random()< SNAKE_GAME_CONFIG.SPECIAL_FOOD_CHANCE;draft.food = gameService.generateFood(grownSnake,isSpecial);}else{draft.snake = newSnake;}if(draft.food && gameService.isSpecialFoodExpired(draft.food)){draft.food = gameService.generateFood(draft.snake,false);}});},updateSettings:(enableSounds,enableHaptics)=>{set(state =>{state.enableSounds = enableSounds;state.enableHaptics = enableHaptics;});}}))));export const useSnake =()=> useSnakeStore(state => state.snake);export const useFood =()=> useSnakeStore(state => state.food);export const useScore =()=> useSnakeStore(state => state.score);export const useIsPlaying =()=> useSnakeStore(state => state.isPlaying);export const useIsGameOver =()=> useSnakeStore(state => state.isGameOver);export const useIsPaused =()=> useSnakeStore(state => state.isPaused);
|
|
@@ -1,221 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import { Canvas, Rect, LinearGradient, vec, Circle, RoundedRect } from '@shopify/react-native-skia';
|
|
5
|
-
import { Dimensions, View } from 'react-native';
|
|
6
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
|
-
const {
|
|
8
|
-
width,
|
|
9
|
-
height
|
|
10
|
-
} = Dimensions.get('window');
|
|
11
|
-
|
|
12
|
-
// Snake-themed vibrant neon colors
|
|
13
|
-
const SNAKE_NEON_COLORS = ['#00ff88',
|
|
14
|
-
// Neon green (primary)
|
|
15
|
-
'#00ffaa',
|
|
16
|
-
// Bright mint
|
|
17
|
-
'#00cc6a',
|
|
18
|
-
// Medium green
|
|
19
|
-
'#00dd77',
|
|
20
|
-
// Lime green
|
|
21
|
-
'#00ff99',
|
|
22
|
-
// Light green
|
|
23
|
-
'#00ee77',
|
|
24
|
-
// Bright green
|
|
25
|
-
'#00bb55',
|
|
26
|
-
// Forest green
|
|
27
|
-
'#00aa44' // Deep green
|
|
28
|
-
];
|
|
29
|
-
export const GameBackground = /*#__PURE__*/React.memo(({
|
|
30
|
-
children
|
|
31
|
-
}) => {
|
|
32
|
-
// Generate static floating snake-themed elements
|
|
33
|
-
const generateFloatingElements = React.useMemo(() => {
|
|
34
|
-
const elements = [];
|
|
35
|
-
const elementCount = 20;
|
|
36
|
-
for (let i = 0; i < elementCount; i++) {
|
|
37
|
-
const baseX = width / elementCount * i;
|
|
38
|
-
const baseY = height / elementCount * i;
|
|
39
|
-
|
|
40
|
-
// Add random offset for natural look
|
|
41
|
-
const x = baseX + Math.sin(i * 0.5) * 60 + Math.random() * 80;
|
|
42
|
-
const y = baseY + Math.cos(i * 0.7) * 70 + Math.random() * 100;
|
|
43
|
-
const size = 15 + Math.random() * 25;
|
|
44
|
-
const colorIndex = i % SNAKE_NEON_COLORS.length;
|
|
45
|
-
const opacity = 0.15 + Math.sin(i) * 0.1;
|
|
46
|
-
const elementX = Math.max(size / 2, Math.min(width - size, x));
|
|
47
|
-
const elementY = Math.max(size / 2, Math.min(height - size, y));
|
|
48
|
-
|
|
49
|
-
// Create different shapes for variety
|
|
50
|
-
if (i % 3 === 0) {
|
|
51
|
-
// Circular elements (like snake segments)
|
|
52
|
-
elements.push(/*#__PURE__*/_jsx(Circle, {
|
|
53
|
-
cx: elementX + size / 2,
|
|
54
|
-
cy: elementY + size / 2,
|
|
55
|
-
r: size / 2,
|
|
56
|
-
color: `${SNAKE_NEON_COLORS[colorIndex]}${Math.floor(opacity * 255).toString(16).padStart(2, '0')}`
|
|
57
|
-
}, `circle-${i}`));
|
|
58
|
-
} else {
|
|
59
|
-
// Rounded rectangles (like snake body parts)
|
|
60
|
-
elements.push(/*#__PURE__*/_jsx(RoundedRect, {
|
|
61
|
-
x: elementX,
|
|
62
|
-
y: elementY,
|
|
63
|
-
width: size,
|
|
64
|
-
height: size,
|
|
65
|
-
r: size * 0.3,
|
|
66
|
-
color: `${SNAKE_NEON_COLORS[colorIndex]}${Math.floor(opacity * 255).toString(16).padStart(2, '0')}`
|
|
67
|
-
}, `rect-${i}`));
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return elements;
|
|
71
|
-
}, []);
|
|
72
|
-
return /*#__PURE__*/_jsxs(View, {
|
|
73
|
-
style: {
|
|
74
|
-
flex: 1
|
|
75
|
-
},
|
|
76
|
-
children: [/*#__PURE__*/_jsxs(Canvas, {
|
|
77
|
-
style: {
|
|
78
|
-
position: 'absolute',
|
|
79
|
-
top: 0,
|
|
80
|
-
left: 0,
|
|
81
|
-
right: 0,
|
|
82
|
-
bottom: 0,
|
|
83
|
-
width,
|
|
84
|
-
height
|
|
85
|
-
},
|
|
86
|
-
children: [/*#__PURE__*/_jsx(Rect, {
|
|
87
|
-
x: 0,
|
|
88
|
-
y: 0,
|
|
89
|
-
width: width,
|
|
90
|
-
height: height,
|
|
91
|
-
children: /*#__PURE__*/_jsx(LinearGradient, {
|
|
92
|
-
start: vec(0, 0),
|
|
93
|
-
end: vec(width, height),
|
|
94
|
-
colors: ['#1a1a2e',
|
|
95
|
-
// Dark base
|
|
96
|
-
'#252541',
|
|
97
|
-
// Purple-blue
|
|
98
|
-
'#1e3a3a',
|
|
99
|
-
// Dark teal
|
|
100
|
-
'#1a2e1a',
|
|
101
|
-
// Dark green
|
|
102
|
-
'#1a1a2e' // Back to dark
|
|
103
|
-
]
|
|
104
|
-
})
|
|
105
|
-
}), /*#__PURE__*/_jsx(Rect, {
|
|
106
|
-
x: 0,
|
|
107
|
-
y: 0,
|
|
108
|
-
width: width,
|
|
109
|
-
height: height,
|
|
110
|
-
children: /*#__PURE__*/_jsx(LinearGradient, {
|
|
111
|
-
start: vec(0, 0),
|
|
112
|
-
end: vec(width / 2, height / 2),
|
|
113
|
-
colors: [`${SNAKE_NEON_COLORS[0]}15`,
|
|
114
|
-
// Neon green
|
|
115
|
-
'transparent', `${SNAKE_NEON_COLORS[1]}10`,
|
|
116
|
-
// Bright mint
|
|
117
|
-
'transparent', `${SNAKE_NEON_COLORS[4]}15`,
|
|
118
|
-
// Light green
|
|
119
|
-
'transparent']
|
|
120
|
-
})
|
|
121
|
-
}), /*#__PURE__*/_jsx(Rect, {
|
|
122
|
-
x: 0,
|
|
123
|
-
y: 0,
|
|
124
|
-
width: width,
|
|
125
|
-
height: height,
|
|
126
|
-
children: /*#__PURE__*/_jsx(LinearGradient, {
|
|
127
|
-
start: vec(width, 0),
|
|
128
|
-
end: vec(0, height),
|
|
129
|
-
colors: [`${SNAKE_NEON_COLORS[2]}12`,
|
|
130
|
-
// Medium green
|
|
131
|
-
'transparent', `${SNAKE_NEON_COLORS[5]}10`,
|
|
132
|
-
// Bright green
|
|
133
|
-
'transparent', `${SNAKE_NEON_COLORS[3]}12`,
|
|
134
|
-
// Lime green
|
|
135
|
-
'transparent']
|
|
136
|
-
})
|
|
137
|
-
}), generateFloatingElements, /*#__PURE__*/_jsx(Circle, {
|
|
138
|
-
cx: width * 0.12,
|
|
139
|
-
cy: height * 0.15,
|
|
140
|
-
r: 35,
|
|
141
|
-
color: `${SNAKE_NEON_COLORS[0]}30`
|
|
142
|
-
}), /*#__PURE__*/_jsx(RoundedRect, {
|
|
143
|
-
x: width * 0.82,
|
|
144
|
-
y: height * 0.78,
|
|
145
|
-
width: 45,
|
|
146
|
-
height: 45,
|
|
147
|
-
r: 12,
|
|
148
|
-
color: `${SNAKE_NEON_COLORS[1]}35`
|
|
149
|
-
}), /*#__PURE__*/_jsx(Circle, {
|
|
150
|
-
cx: width * 0.85,
|
|
151
|
-
cy: height * 0.2,
|
|
152
|
-
r: 28,
|
|
153
|
-
color: `${SNAKE_NEON_COLORS[2]}30`
|
|
154
|
-
}), /*#__PURE__*/_jsx(RoundedRect, {
|
|
155
|
-
x: width * 0.08,
|
|
156
|
-
y: height * 0.75,
|
|
157
|
-
width: 50,
|
|
158
|
-
height: 50,
|
|
159
|
-
r: 15,
|
|
160
|
-
color: `${SNAKE_NEON_COLORS[3]}35`
|
|
161
|
-
}), /*#__PURE__*/_jsx(Circle, {
|
|
162
|
-
cx: width * 0.5,
|
|
163
|
-
cy: height * 0.1,
|
|
164
|
-
r: 25,
|
|
165
|
-
color: `${SNAKE_NEON_COLORS[4]}28`
|
|
166
|
-
}), /*#__PURE__*/_jsx(RoundedRect, {
|
|
167
|
-
x: width * 0.1,
|
|
168
|
-
y: height * 0.45,
|
|
169
|
-
width: 40,
|
|
170
|
-
height: 40,
|
|
171
|
-
r: 10,
|
|
172
|
-
color: `${SNAKE_NEON_COLORS[5]}32`
|
|
173
|
-
}), /*#__PURE__*/_jsx(Circle, {
|
|
174
|
-
cx: width * 0.88,
|
|
175
|
-
cy: height * 0.55,
|
|
176
|
-
r: 30,
|
|
177
|
-
color: `${SNAKE_NEON_COLORS[6]}30`
|
|
178
|
-
}), /*#__PURE__*/_jsx(RoundedRect, {
|
|
179
|
-
x: width * 0.55,
|
|
180
|
-
y: height * 0.85,
|
|
181
|
-
width: 35,
|
|
182
|
-
height: 35,
|
|
183
|
-
r: 8,
|
|
184
|
-
color: `${SNAKE_NEON_COLORS[7]}33`
|
|
185
|
-
}), /*#__PURE__*/_jsx(Circle, {
|
|
186
|
-
cx: width * 0.3,
|
|
187
|
-
cy: height * 0.3,
|
|
188
|
-
r: 20,
|
|
189
|
-
color: `${SNAKE_NEON_COLORS[0]}25`
|
|
190
|
-
}), /*#__PURE__*/_jsx(Circle, {
|
|
191
|
-
cx: width * 0.7,
|
|
192
|
-
cy: height * 0.4,
|
|
193
|
-
r: 24,
|
|
194
|
-
color: `${SNAKE_NEON_COLORS[1]}28`
|
|
195
|
-
}), /*#__PURE__*/_jsx(Circle, {
|
|
196
|
-
cx: width * 0.4,
|
|
197
|
-
cy: height * 0.65,
|
|
198
|
-
r: 18,
|
|
199
|
-
color: `${SNAKE_NEON_COLORS[2]}26`
|
|
200
|
-
}), Array.from({
|
|
201
|
-
length: Math.floor(width / 70)
|
|
202
|
-
}, (_, i) => /*#__PURE__*/_jsx(Rect, {
|
|
203
|
-
x: i * 70,
|
|
204
|
-
y: 0,
|
|
205
|
-
width: 1,
|
|
206
|
-
height: height,
|
|
207
|
-
color: "rgba(0, 255, 136, 0.04)"
|
|
208
|
-
}, `grid-v-${i}`)), Array.from({
|
|
209
|
-
length: Math.floor(height / 70)
|
|
210
|
-
}, (_, i) => /*#__PURE__*/_jsx(Rect, {
|
|
211
|
-
x: 0,
|
|
212
|
-
y: i * 70,
|
|
213
|
-
width: width,
|
|
214
|
-
height: 1,
|
|
215
|
-
color: "rgba(0, 255, 136, 0.04)"
|
|
216
|
-
}, `grid-h-${i}`))]
|
|
217
|
-
}), children]
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
GameBackground.displayName = 'GameBackground';
|
|
221
|
-
//# sourceMappingURL=GameBackground.js.map
|
|
1
|
+
"use strict";import React from 'react';import{Canvas,Rect,LinearGradient,vec,Circle,RoundedRect}from '@shopify/react-native-skia';import{Dimensions,View}from 'react-native';import{jsx as _jsx,jsxs as _jsxs}from "react/jsx-runtime";const{width,height}= Dimensions.get('window');const SNAKE_NEON_COLORS = ['#00ff88','#00ffaa','#00cc6a','#00dd77','#00ff99','#00ee77','#00bb55','#00aa44' ];export const GameBackground = React.memo(({children})=>{const generateFloatingElements = React.useMemo(()=>{const elements = [];const elementCount = 20;for(let i = 0;i < elementCount;i++){const baseX = width / elementCount * i;const baseY = height / elementCount * i;const x = baseX + Math.sin(i * 0.5)* 60 + Math.random()* 80;const y = baseY + Math.cos(i * 0.7)* 70 + Math.random()* 100;const size = 15 + Math.random()* 25;const colorIndex = i % SNAKE_NEON_COLORS.length;const opacity = 0.15 + Math.sin(i)* 0.1;const elementX = Math.max(size / 2,Math.min(width - size,x));const elementY = Math.max(size / 2,Math.min(height - size,y));if(i % 3 === 0){elements.push(_jsx(Circle,{cx:elementX + size / 2,cy:elementY + size / 2,r:size / 2,color:`${SNAKE_NEON_COLORS[colorIndex]}${Math.floor(opacity * 255).toString(16).padStart(2,'0')}`},`circle-${i}`));}else{elements.push(_jsx(RoundedRect,{x:elementX,y:elementY,width:size,height:size,r:size * 0.3,color:`${SNAKE_NEON_COLORS[colorIndex]}${Math.floor(opacity * 255).toString(16).padStart(2,'0')}`},`rect-${i}`));}}return elements;},[]);return _jsxs(View,{style:{flex:1},children:[_jsxs(Canvas,{style:{position:'absolute',top:0,left:0,right:0,bottom:0,width,height},children:[_jsx(Rect,{x:0,y:0,width:width,height:height,children:_jsx(LinearGradient,{start:vec(0,0),end:vec(width,height),colors:['#1a1a2e','#252541','#1e3a3a','#1a2e1a','#1a1a2e' ]})}),_jsx(Rect,{x:0,y:0,width:width,height:height,children:_jsx(LinearGradient,{start:vec(0,0),end:vec(width / 2,height / 2),colors:[`${SNAKE_NEON_COLORS[0]}15`,'transparent',`${SNAKE_NEON_COLORS[1]}10`,'transparent',`${SNAKE_NEON_COLORS[4]}15`,'transparent']})}),_jsx(Rect,{x:0,y:0,width:width,height:height,children:_jsx(LinearGradient,{start:vec(width,0),end:vec(0,height),colors:[`${SNAKE_NEON_COLORS[2]}12`,'transparent',`${SNAKE_NEON_COLORS[5]}10`,'transparent',`${SNAKE_NEON_COLORS[3]}12`,'transparent']})}),generateFloatingElements,_jsx(Circle,{cx:width * 0.12,cy:height * 0.15,r:35,color:`${SNAKE_NEON_COLORS[0]}30`}),_jsx(RoundedRect,{x:width * 0.82,y:height * 0.78,width:45,height:45,r:12,color:`${SNAKE_NEON_COLORS[1]}35`}),_jsx(Circle,{cx:width * 0.85,cy:height * 0.2,r:28,color:`${SNAKE_NEON_COLORS[2]}30`}),_jsx(RoundedRect,{x:width * 0.08,y:height * 0.75,width:50,height:50,r:15,color:`${SNAKE_NEON_COLORS[3]}35`}),_jsx(Circle,{cx:width * 0.5,cy:height * 0.1,r:25,color:`${SNAKE_NEON_COLORS[4]}28`}),_jsx(RoundedRect,{x:width * 0.1,y:height * 0.45,width:40,height:40,r:10,color:`${SNAKE_NEON_COLORS[5]}32`}),_jsx(Circle,{cx:width * 0.88,cy:height * 0.55,r:30,color:`${SNAKE_NEON_COLORS[6]}30`}),_jsx(RoundedRect,{x:width * 0.55,y:height * 0.85,width:35,height:35,r:8,color:`${SNAKE_NEON_COLORS[7]}33`}),_jsx(Circle,{cx:width * 0.3,cy:height * 0.3,r:20,color:`${SNAKE_NEON_COLORS[0]}25`}),_jsx(Circle,{cx:width * 0.7,cy:height * 0.4,r:24,color:`${SNAKE_NEON_COLORS[1]}28`}),_jsx(Circle,{cx:width * 0.4,cy:height * 0.65,r:18,color:`${SNAKE_NEON_COLORS[2]}26`}),Array.from({length:Math.floor(width / 70)},(_,i)=> _jsx(Rect,{x:i * 70,y:0,width:1,height:height,color:"rgba(0,255,136,0.04)"},`grid-v-${i}`)),Array.from({length:Math.floor(height / 70)},(_,i)=> _jsx(Rect,{x:0,y:i * 70,width:width,height:1,color:"rgba(0,255,136,0.04)"},`grid-h-${i}`))]}),children]});});GameBackground.displayName = 'GameBackground';
|
|
@@ -1,153 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import { View, StyleSheet } from 'react-native';
|
|
5
|
-
import { Canvas, RoundedRect, Circle, Group, Shadow } from '@shopify/react-native-skia';
|
|
6
|
-
import { useSnake, useFood } from "../SnakeStore.js";
|
|
7
|
-
import { SNAKE_GAME_CONFIG, SNAKE_COLORS } from "../SnakeConstants.js";
|
|
8
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
9
|
-
export const GameGrid = /*#__PURE__*/React.memo(() => {
|
|
10
|
-
const snake = useSnake();
|
|
11
|
-
const food = useFood();
|
|
12
|
-
const cellSize = SNAKE_GAME_CONFIG.CELL_SIZE;
|
|
13
|
-
const gridSize = SNAKE_GAME_CONFIG.GRID_SIZE;
|
|
14
|
-
const canvasSize = cellSize * gridSize;
|
|
15
|
-
|
|
16
|
-
// Memoized grid lines
|
|
17
|
-
const gridLines = React.useMemo(() => {
|
|
18
|
-
const lines = [];
|
|
19
|
-
for (let i = 0; i <= gridSize; i++) {
|
|
20
|
-
lines.push(i);
|
|
21
|
-
}
|
|
22
|
-
return lines;
|
|
23
|
-
}, [gridSize]);
|
|
24
|
-
return /*#__PURE__*/_jsx(View, {
|
|
25
|
-
style: styles.container,
|
|
26
|
-
children: /*#__PURE__*/_jsx(View, {
|
|
27
|
-
style: [styles.gridContainer, {
|
|
28
|
-
width: canvasSize,
|
|
29
|
-
height: canvasSize
|
|
30
|
-
}],
|
|
31
|
-
children: /*#__PURE__*/_jsx(Canvas, {
|
|
32
|
-
style: {
|
|
33
|
-
width: canvasSize,
|
|
34
|
-
height: canvasSize
|
|
35
|
-
},
|
|
36
|
-
children: /*#__PURE__*/_jsxs(Group, {
|
|
37
|
-
children: [/*#__PURE__*/_jsx(RoundedRect, {
|
|
38
|
-
x: 0,
|
|
39
|
-
y: 0,
|
|
40
|
-
width: canvasSize,
|
|
41
|
-
height: canvasSize,
|
|
42
|
-
r: 15,
|
|
43
|
-
color: SNAKE_COLORS.BACKGROUND,
|
|
44
|
-
children: /*#__PURE__*/_jsx(Shadow, {
|
|
45
|
-
dx: 0,
|
|
46
|
-
dy: 4,
|
|
47
|
-
blur: 8,
|
|
48
|
-
color: "rgba(0, 0, 0, 0.3)"
|
|
49
|
-
})
|
|
50
|
-
}), gridLines.map(i => {
|
|
51
|
-
// Adjust last line position to be visible
|
|
52
|
-
const xPos = i === gridSize ? canvasSize - 2 : i * cellSize;
|
|
53
|
-
return /*#__PURE__*/_jsx(RoundedRect, {
|
|
54
|
-
x: xPos,
|
|
55
|
-
y: 0,
|
|
56
|
-
width: i === 0 || i === gridSize ? 2 : 1,
|
|
57
|
-
height: canvasSize,
|
|
58
|
-
r: 0,
|
|
59
|
-
color: SNAKE_COLORS.GRID_LINE
|
|
60
|
-
}, `v-${i}`);
|
|
61
|
-
}), gridLines.map(i => {
|
|
62
|
-
// Adjust last line position to be visible
|
|
63
|
-
const yPos = i === gridSize ? canvasSize - 2 : i * cellSize;
|
|
64
|
-
return /*#__PURE__*/_jsx(RoundedRect, {
|
|
65
|
-
x: 0,
|
|
66
|
-
y: yPos,
|
|
67
|
-
width: canvasSize,
|
|
68
|
-
height: i === 0 || i === gridSize ? 2 : 1,
|
|
69
|
-
r: 0,
|
|
70
|
-
color: SNAKE_COLORS.GRID_LINE
|
|
71
|
-
}, `h-${i}`);
|
|
72
|
-
}), food && /*#__PURE__*/_jsxs(Group, {
|
|
73
|
-
children: [/*#__PURE__*/_jsx(Circle, {
|
|
74
|
-
cx: food.x * cellSize + cellSize / 2,
|
|
75
|
-
cy: food.y * cellSize + cellSize / 2,
|
|
76
|
-
r: cellSize * 0.6,
|
|
77
|
-
color: food.isSpecial ? 'rgba(255, 165, 2, 0.3)' : SNAKE_COLORS.FOOD_GLOW
|
|
78
|
-
}), /*#__PURE__*/_jsx(Circle, {
|
|
79
|
-
cx: food.x * cellSize + cellSize / 2,
|
|
80
|
-
cy: food.y * cellSize + cellSize / 2,
|
|
81
|
-
r: cellSize * 0.4,
|
|
82
|
-
color: food.isSpecial ? SNAKE_COLORS.FOOD_SPECIAL : SNAKE_COLORS.FOOD_NORMAL,
|
|
83
|
-
children: /*#__PURE__*/_jsx(Shadow, {
|
|
84
|
-
dx: 0,
|
|
85
|
-
dy: 2,
|
|
86
|
-
blur: 4,
|
|
87
|
-
color: "rgba(0, 0, 0, 0.4)"
|
|
88
|
-
})
|
|
89
|
-
}), /*#__PURE__*/_jsx(Circle, {
|
|
90
|
-
cx: food.x * cellSize + cellSize / 2 - cellSize * 0.1,
|
|
91
|
-
cy: food.y * cellSize + cellSize / 2 - cellSize * 0.1,
|
|
92
|
-
r: cellSize * 0.15,
|
|
93
|
-
color: "rgba(255, 255, 255, 0.6)"
|
|
94
|
-
})]
|
|
95
|
-
}), snake.map((segment, index) => {
|
|
96
|
-
const isHead = index === 0;
|
|
97
|
-
const isTail = index === snake.length - 1;
|
|
98
|
-
|
|
99
|
-
// Calculate color based on position
|
|
100
|
-
const segmentColor = isHead ? SNAKE_COLORS.SNAKE_HEAD : isTail ? SNAKE_COLORS.SNAKE_TAIL : SNAKE_COLORS.SNAKE_BODY;
|
|
101
|
-
return /*#__PURE__*/_jsxs(Group, {
|
|
102
|
-
children: [/*#__PURE__*/_jsx(RoundedRect, {
|
|
103
|
-
x: segment.x * cellSize + 2,
|
|
104
|
-
y: segment.y * cellSize + 2,
|
|
105
|
-
width: cellSize - 4,
|
|
106
|
-
height: cellSize - 4,
|
|
107
|
-
r: isHead ? 8 : 6,
|
|
108
|
-
color: segmentColor,
|
|
109
|
-
children: /*#__PURE__*/_jsx(Shadow, {
|
|
110
|
-
dx: 0,
|
|
111
|
-
dy: 2,
|
|
112
|
-
blur: 4,
|
|
113
|
-
color: "rgba(0, 0, 0, 0.3)"
|
|
114
|
-
})
|
|
115
|
-
}), /*#__PURE__*/_jsx(RoundedRect, {
|
|
116
|
-
x: segment.x * cellSize + cellSize * 0.2,
|
|
117
|
-
y: segment.y * cellSize + cellSize * 0.2,
|
|
118
|
-
width: cellSize * 0.3,
|
|
119
|
-
height: cellSize * 0.3,
|
|
120
|
-
r: 4,
|
|
121
|
-
color: "rgba(255, 255, 255, 0.3)"
|
|
122
|
-
}), isHead && /*#__PURE__*/_jsxs(_Fragment, {
|
|
123
|
-
children: [/*#__PURE__*/_jsx(Circle, {
|
|
124
|
-
cx: segment.x * cellSize + cellSize * 0.35,
|
|
125
|
-
cy: segment.y * cellSize + cellSize * 0.4,
|
|
126
|
-
r: cellSize * 0.08,
|
|
127
|
-
color: "#000000"
|
|
128
|
-
}), /*#__PURE__*/_jsx(Circle, {
|
|
129
|
-
cx: segment.x * cellSize + cellSize * 0.65,
|
|
130
|
-
cy: segment.y * cellSize + cellSize * 0.4,
|
|
131
|
-
r: cellSize * 0.08,
|
|
132
|
-
color: "#000000"
|
|
133
|
-
})]
|
|
134
|
-
})]
|
|
135
|
-
}, segment.id);
|
|
136
|
-
})]
|
|
137
|
-
})
|
|
138
|
-
})
|
|
139
|
-
})
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
GameGrid.displayName = 'GameGrid';
|
|
143
|
-
const styles = StyleSheet.create({
|
|
144
|
-
container: {
|
|
145
|
-
flex: 1,
|
|
146
|
-
justifyContent: 'center',
|
|
147
|
-
alignItems: 'center'
|
|
148
|
-
},
|
|
149
|
-
gridContainer: {
|
|
150
|
-
// Shadow removed for Android compatibility
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
//# sourceMappingURL=GameGrid.js.map
|
|
1
|
+
"use strict";import React from 'react';import{View,StyleSheet}from 'react-native';import{Canvas,RoundedRect,Circle,Group,Shadow}from '@shopify/react-native-skia';import{useSnake,useFood}from "../SnakeStore.js";import{SNAKE_GAME_CONFIG,SNAKE_COLORS}from "../SnakeConstants.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from "react/jsx-runtime";export const GameGrid = React.memo(()=>{const snake = useSnake();const food = useFood();const cellSize = SNAKE_GAME_CONFIG.CELL_SIZE;const gridSize = SNAKE_GAME_CONFIG.GRID_SIZE;const canvasSize = cellSize * gridSize;const gridLines = React.useMemo(()=>{const lines = [];for(let i = 0;i <= gridSize;i++){lines.push(i);}return lines;},[gridSize]);return _jsx(View,{style:styles.container,children:_jsx(View,{style:[styles.gridContainer,{width:canvasSize,height:canvasSize}],children:_jsx(Canvas,{style:{width:canvasSize,height:canvasSize},children:_jsxs(Group,{children:[_jsx(RoundedRect,{x:0,y:0,width:canvasSize,height:canvasSize,r:15,color:SNAKE_COLORS.BACKGROUND,children:_jsx(Shadow,{dx:0,dy:4,blur:8,color:"rgba(0,0,0,0.3)"})}),gridLines.map(i =>{const xPos = i === gridSize ? canvasSize - 2:i * cellSize;return _jsx(RoundedRect,{x:xPos,y:0,width:i === 0 || i === gridSize ? 2:1,height:canvasSize,r:0,color:SNAKE_COLORS.GRID_LINE},`v-${i}`);}),gridLines.map(i =>{const yPos = i === gridSize ? canvasSize - 2:i * cellSize;return _jsx(RoundedRect,{x:0,y:yPos,width:canvasSize,height:i === 0 || i === gridSize ? 2:1,r:0,color:SNAKE_COLORS.GRID_LINE},`h-${i}`);}),food && _jsxs(Group,{children:[_jsx(Circle,{cx:food.x * cellSize + cellSize / 2,cy:food.y * cellSize + cellSize / 2,r:cellSize * 0.6,color:food.isSpecial ? 'rgba(255,165,2,0.3)':SNAKE_COLORS.FOOD_GLOW}),_jsx(Circle,{cx:food.x * cellSize + cellSize / 2,cy:food.y * cellSize + cellSize / 2,r:cellSize * 0.4,color:food.isSpecial ? SNAKE_COLORS.FOOD_SPECIAL:SNAKE_COLORS.FOOD_NORMAL,children:_jsx(Shadow,{dx:0,dy:2,blur:4,color:"rgba(0,0,0,0.4)"})}),_jsx(Circle,{cx:food.x * cellSize + cellSize / 2 - cellSize * 0.1,cy:food.y * cellSize + cellSize / 2 - cellSize * 0.1,r:cellSize * 0.15,color:"rgba(255,255,255,0.6)"})]}),snake.map((segment,index)=>{const isHead = index === 0;const isTail = index === snake.length - 1;const segmentColor = isHead ? SNAKE_COLORS.SNAKE_HEAD:isTail ? SNAKE_COLORS.SNAKE_TAIL:SNAKE_COLORS.SNAKE_BODY;return _jsxs(Group,{children:[_jsx(RoundedRect,{x:segment.x * cellSize + 2,y:segment.y * cellSize + 2,width:cellSize - 4,height:cellSize - 4,r:isHead ? 8:6,color:segmentColor,children:_jsx(Shadow,{dx:0,dy:2,blur:4,color:"rgba(0,0,0,0.3)"})}),_jsx(RoundedRect,{x:segment.x * cellSize + cellSize * 0.2,y:segment.y * cellSize + cellSize * 0.2,width:cellSize * 0.3,height:cellSize * 0.3,r:4,color:"rgba(255,255,255,0.3)"}),isHead && _jsxs(_Fragment,{children:[_jsx(Circle,{cx:segment.x * cellSize + cellSize * 0.35,cy:segment.y * cellSize + cellSize * 0.4,r:cellSize * 0.08,color:"#000000"}),_jsx(Circle,{cx:segment.x * cellSize + cellSize * 0.65,cy:segment.y * cellSize + cellSize * 0.4,r:cellSize * 0.08,color:"#000000"})]})]},segment.id);})]})})})});});GameGrid.displayName = 'GameGrid';const styles = StyleSheet.create({container:{flex:1,justifyContent:'center',alignItems:'center'},gridContainer:{}});
|
|
@@ -1,51 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import { View, Text, StyleSheet } from 'react-native';
|
|
5
|
-
import { useScore } from "../SnakeStore.js";
|
|
6
|
-
import { SNAKE_COLORS } from "../SnakeConstants.js";
|
|
7
|
-
import { ScoreBoardContainer } from "../../../helpers/index.js";
|
|
8
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
9
|
-
export const ScoreBoard = /*#__PURE__*/React.memo(({
|
|
10
|
-
offset = 0
|
|
11
|
-
}) => {
|
|
12
|
-
const score = useScore();
|
|
13
|
-
return /*#__PURE__*/_jsx(ScoreBoardContainer, {
|
|
14
|
-
offset: offset,
|
|
15
|
-
backgroundColor: SNAKE_COLORS.SCORE_BACKGROUND,
|
|
16
|
-
borderColor: SNAKE_COLORS.SCORE_BACKGROUND,
|
|
17
|
-
children: /*#__PURE__*/_jsx(View, {
|
|
18
|
-
style: styles.scoreContainer,
|
|
19
|
-
children: /*#__PURE__*/_jsxs(View, {
|
|
20
|
-
style: styles.scoreItem,
|
|
21
|
-
children: [/*#__PURE__*/_jsx(Text, {
|
|
22
|
-
style: styles.label,
|
|
23
|
-
children: "Score"
|
|
24
|
-
}), /*#__PURE__*/_jsx(Text, {
|
|
25
|
-
style: styles.value,
|
|
26
|
-
children: score
|
|
27
|
-
})]
|
|
28
|
-
})
|
|
29
|
-
})
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
ScoreBoard.displayName = 'ScoreBoard';
|
|
33
|
-
const styles = StyleSheet.create({
|
|
34
|
-
scoreContainer: {
|
|
35
|
-
alignItems: 'center'
|
|
36
|
-
},
|
|
37
|
-
scoreItem: {
|
|
38
|
-
alignItems: 'center'
|
|
39
|
-
},
|
|
40
|
-
label: {
|
|
41
|
-
fontSize: 18,
|
|
42
|
-
color: 'rgba(255, 255, 255, 0.7)',
|
|
43
|
-
marginBottom: 4
|
|
44
|
-
},
|
|
45
|
-
value: {
|
|
46
|
-
fontSize: 34,
|
|
47
|
-
color: SNAKE_COLORS.SCORE_TEXT,
|
|
48
|
-
fontWeight: 'bold'
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
//# sourceMappingURL=ScoreBoard.js.map
|
|
1
|
+
"use strict";import React from 'react';import{View,Text,StyleSheet}from 'react-native';import{useScore}from "../SnakeStore.js";import{SNAKE_COLORS}from "../SnakeConstants.js";import{ScoreBoardContainer}from "../../../helpers/index.js";import{jsx as _jsx,jsxs as _jsxs}from "react/jsx-runtime";export const ScoreBoard = React.memo(({offset = 0})=>{const score = useScore();return _jsx(ScoreBoardContainer,{offset:offset,backgroundColor:SNAKE_COLORS.SCORE_BACKGROUND,borderColor:SNAKE_COLORS.SCORE_BACKGROUND,children:_jsx(View,{style:styles.scoreContainer,children:_jsxs(View,{style:styles.scoreItem,children:[_jsx(Text,{style:styles.label,children:"Score"}),_jsx(Text,{style:styles.value,children:score})]})})});});ScoreBoard.displayName = 'ScoreBoard';const styles = StyleSheet.create({scoreContainer:{alignItems:'center'},scoreItem:{alignItems:'center'},label:{fontSize:16,color:'rgba(255,255,255,0.7)',marginBottom:4},value:{fontSize:25,color:SNAKE_COLORS.SCORE_TEXT,fontWeight:'bold'}});
|
|
@@ -1,6 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
export { GameBackground } from "./GameBackground.js";
|
|
4
|
-
export { GameGrid } from "./GameGrid.js";
|
|
5
|
-
export { ScoreBoard } from "./ScoreBoard.js";
|
|
6
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
"use strict";export{GameBackground}from "./GameBackground.js";export{GameGrid}from "./GameGrid.js";export{ScoreBoard}from "./ScoreBoard.js";
|
|
@@ -1,6 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
export { Snake } from "./Snake.js";
|
|
4
|
-
export { useSnakeStore } from "./SnakeStore.js";
|
|
5
|
-
export * from "./SnakeConstants.js";
|
|
6
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
"use strict";export{Snake}from "./Snake.js";export{useSnakeStore}from "./SnakeStore.js";export * from "./SnakeConstants.js";
|