-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
88 lines (82 loc) · 2.3 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import React, {useMemo} from 'react';
import {
Dimensions,
PixelRatio,
StyleSheet,
TouchableNativeFeedback,
View,
} from 'react-native';
import {Background} from './Background';
import {Canvas} from '@shopify/react-native-skia';
import {GRASS_SIDE, Terrain} from './Terrain';
import {useGameState, game_update, PressHandler} from './GameState';
import {useFrameCallback} from 'react-native-reanimated';
import {side, y_sleep} from './Fox';
import {FoxComponent} from './FoxComponent';
import {
ENEMY_FRAMES,
ENEMY_HEIGHT,
ENEMY_WIDTH,
EnemyComponent,
} from './EnemyComponent';
import {LivesCount} from './LivesCount';
import {GameOverLabel} from './GameOverLabel';
import {StartTapLabel} from './StartTapLabel';
import {
START_FRAMES,
START_SIDE,
StartFlagComponent,
} from './StartFlagComponent';
import {CountLabel} from './CountLabel';
const {width, height} = Dimensions.get('window');
const pd = PixelRatio.get();
export function App() {
const terrain_size = GRASS_SIDE;
const gs = useGameState({
width: width / pd,
height: height / pd,
terrain_size,
velocity: 0.2 / pd,
pd,
fox_x: side,
fox_y: height / pd - terrain_size - side,
fox_state: y_sleep,
enemy_height: ENEMY_HEIGHT,
enemy_width: ENEMY_WIDTH,
enemy_frames: ENEMY_FRAMES,
initial_lives: 3,
start_frames: START_FRAMES,
start_side: START_SIDE,
});
useFrameCallback(info => {
// @ts-ignore
gs.modify(gs => {
'worklet';
return game_update(gs, info);
});
}, true);
const pressHandler = useMemo(() => new PressHandler(gs), [gs]);
return (
<TouchableNativeFeedback onPress={pressHandler.onPress}>
<View style={styles.container}>
<Canvas style={StyleSheet.absoluteFill}>
<Background width={width} height={height} />
<LivesCount game_state={gs} pd={pd} />
<EnemyComponent game_state={gs} pd={pd} />
<Terrain width={width} pd={pd} game_state={gs} />
<StartFlagComponent game_state={gs} pd={pd} />
<FoxComponent game_state={gs} pd={pd} />
</Canvas>
<GameOverLabel gs={gs} />
<StartTapLabel gs={gs} />
<CountLabel gs={gs} />
</View>
</TouchableNativeFeedback>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
});
export default App;