Application Android et IOS pour l'amicale des élèves https://play.google.com/store/apps/details?id=fr.amicaleinsat.application
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GameBrackground.tsx 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import React from 'react';
  2. import { StyleSheet, View } from 'react-native';
  3. import * as Animatable from 'react-native-animatable';
  4. import { useTheme } from 'react-native-paper';
  5. import GridManager from '../logic/GridManager';
  6. import Piece from '../logic/Piece';
  7. import GridComponent from './GridComponent';
  8. const styles = StyleSheet.create({
  9. pieceContainer: {
  10. position: 'absolute',
  11. width: '100%',
  12. height: '100%',
  13. },
  14. pieceBackground: {
  15. position: 'absolute',
  16. },
  17. });
  18. export default function GameBackground() {
  19. const theme = useTheme();
  20. const gridManager = new GridManager(4, 4, theme);
  21. const gridList = [];
  22. for (let i = 0; i < 18; i += 1) {
  23. gridList.push(gridManager.getEmptyGrid(4, 4));
  24. const piece = new Piece(theme);
  25. piece.toGrid(gridList[i], true);
  26. }
  27. return (
  28. <View style={styles.pieceContainer}>
  29. {gridList.map((item, index) => {
  30. const size = 10 + Math.floor(Math.random() * 30);
  31. const top = Math.floor(Math.random() * 100);
  32. const rot = Math.floor(Math.random() * 360);
  33. const left = (index % 6) * 20;
  34. const animDelay = size * 20;
  35. const animDuration = 2 * (2000 - size * 30);
  36. return (
  37. <Animatable.View
  38. useNativeDriver={true}
  39. animation={'fadeInDownBig'}
  40. delay={animDelay}
  41. duration={animDuration}
  42. key={`piece${index.toString()}`}
  43. style={{
  44. width: `${size}%`,
  45. top: `${top}%`,
  46. left: `${left}%`,
  47. ...styles.pieceBackground,
  48. }}
  49. >
  50. <GridComponent
  51. width={4}
  52. height={4}
  53. grid={item}
  54. style={{
  55. transform: [{ rotateZ: `${rot}deg` }],
  56. }}
  57. />
  58. </Animatable.View>
  59. );
  60. })}
  61. </View>
  62. );
  63. }