forked from vergnet/application-amicale
Improved game start screen
This commit is contained in:
parent
0ed3122dcf
commit
4f911ce32d
3 changed files with 119 additions and 8 deletions
|
@ -363,6 +363,9 @@
|
||||||
},
|
},
|
||||||
"game": {
|
"game": {
|
||||||
"title": "Game",
|
"title": "Game",
|
||||||
|
"welcomeTitle": "Welcome !",
|
||||||
|
"welcomeMessage": "Stuck on the toilet? The teacher is late?\nThis game is for you!\n\nTry to get the best score and beat your friends.",
|
||||||
|
"play": "Play!",
|
||||||
"score": "Score : %{score}",
|
"score": "Score : %{score}",
|
||||||
"time": "Time :",
|
"time": "Time :",
|
||||||
"level": "Level :",
|
"level": "Level :",
|
||||||
|
|
|
@ -361,7 +361,10 @@
|
||||||
"homeButtonSubtitle": "Contacte le développeur de l'appli"
|
"homeButtonSubtitle": "Contacte le développeur de l'appli"
|
||||||
},
|
},
|
||||||
"game": {
|
"game": {
|
||||||
"title": "Le Jeu trop ouf",
|
"title": "Jeu trop ouf",
|
||||||
|
"welcomeTitle": "Bienvenue !",
|
||||||
|
"welcomeMessage": "Coincé sur les WC ? Le prof est pas là ?\nCe jeu est fait pour toi !\n\nEssaie d'avoir le meilleur score et de battre tes amis.",
|
||||||
|
"play": "Jouer !",
|
||||||
"score": "Score : %{score}",
|
"score": "Score : %{score}",
|
||||||
"time": "Temps :",
|
"time": "Temps :",
|
||||||
"level": "Niveau :",
|
"level": "Niveau :",
|
||||||
|
|
|
@ -3,12 +3,17 @@
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import {StackNavigationProp} from "@react-navigation/stack";
|
import {StackNavigationProp} from "@react-navigation/stack";
|
||||||
import type {CustomTheme} from "../../../managers/ThemeManager";
|
import type {CustomTheme} from "../../../managers/ThemeManager";
|
||||||
import {Button, Headline, withTheme} from "react-native-paper";
|
import {Button, Card, Divider, Headline, Paragraph, withTheme} from "react-native-paper";
|
||||||
import {View} from "react-native";
|
import {View} from "react-native";
|
||||||
import i18n from "i18n-js";
|
import i18n from "i18n-js";
|
||||||
import Mascot, {MASCOT_STYLE} from "../../../components/Mascot/Mascot";
|
import Mascot, {MASCOT_STYLE} from "../../../components/Mascot/Mascot";
|
||||||
import MascotPopup from "../../../components/Mascot/MascotPopup";
|
import MascotPopup from "../../../components/Mascot/MascotPopup";
|
||||||
import AsyncStorageManager from "../../../managers/AsyncStorageManager";
|
import AsyncStorageManager from "../../../managers/AsyncStorageManager";
|
||||||
|
import type {Grid} from "../components/GridComponent";
|
||||||
|
import GridComponent from "../components/GridComponent";
|
||||||
|
import GridManager from "../logic/GridManager";
|
||||||
|
import Piece from "../logic/Piece";
|
||||||
|
import * as Animatable from "react-native-animatable";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
navigation: StackNavigationProp,
|
navigation: StackNavigationProp,
|
||||||
|
@ -21,10 +26,17 @@ type State = {
|
||||||
|
|
||||||
class GameStartScreen extends React.Component<Props, State> {
|
class GameStartScreen extends React.Component<Props, State> {
|
||||||
|
|
||||||
|
gridManager: GridManager;
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
mascotDialogVisible: AsyncStorageManager.getInstance().preferences.gameStartShowBanner.current === "1",
|
mascotDialogVisible: AsyncStorageManager.getInstance().preferences.gameStartShowBanner.current === "1",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constructor(props: Props) {
|
||||||
|
super(props);
|
||||||
|
this.gridManager = new GridManager(4, 4, props.theme);
|
||||||
|
}
|
||||||
|
|
||||||
hideMascotDialog = () => {
|
hideMascotDialog = () => {
|
||||||
AsyncStorageManager.getInstance().savePref(
|
AsyncStorageManager.getInstance().savePref(
|
||||||
AsyncStorageManager.getInstance().preferences.gameStartShowBanner.key,
|
AsyncStorageManager.getInstance().preferences.gameStartShowBanner.key,
|
||||||
|
@ -33,20 +45,113 @@ class GameStartScreen extends React.Component<Props, State> {
|
||||||
this.setState({mascotDialogVisible: false})
|
this.setState({mascotDialogVisible: false})
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
getPiecesBackground() {
|
||||||
|
let gridList = [];
|
||||||
|
for (let i = 0; i < 18; i++) {
|
||||||
|
gridList.push(this.gridManager.getEmptyGrid(4, 4));
|
||||||
|
const piece = new Piece(this.props.theme);
|
||||||
|
piece.toGrid(gridList[i], true);
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<View style={{flex: 1}}>
|
<View style={{
|
||||||
<Mascot emotion={MASCOT_STYLE.NORMAL} style={{
|
position: "absolute",
|
||||||
width: "50%",
|
width: "100%",
|
||||||
|
height: "100%",
|
||||||
|
}}>
|
||||||
|
{gridList.map((item: Grid, index: number) => {
|
||||||
|
const size = 10 + Math.floor(Math.random() * 30);
|
||||||
|
const top = Math.floor(Math.random() * 100);
|
||||||
|
const rot = Math.floor(Math.random() * 360);
|
||||||
|
const left = (index % 6) * 20;
|
||||||
|
const animDelay = size * 20;
|
||||||
|
const animDuration = 2 * (2000 - (size * 30));
|
||||||
|
return (
|
||||||
|
<Animatable.View
|
||||||
|
animation={"fadeInDownBig"}
|
||||||
|
delay={animDelay}
|
||||||
|
duration={animDuration}
|
||||||
|
key={index.toString()}
|
||||||
|
style={{
|
||||||
|
width: size + "%",
|
||||||
|
position: "absolute",
|
||||||
|
top: top + "%",
|
||||||
|
left: left + "%",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<View style={{
|
||||||
|
transform: [{rotateZ: rot + "deg"}],
|
||||||
|
}}>
|
||||||
|
<GridComponent
|
||||||
|
width={4}
|
||||||
|
height={4}
|
||||||
|
grid={item}
|
||||||
|
style={{
|
||||||
|
marginRight: 5,
|
||||||
|
marginLeft: 5,
|
||||||
|
marginBottom: 5,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
</Animatable.View>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</View>
|
||||||
|
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
getWelcomeText() {
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<Mascot emotion={MASCOT_STYLE.COOL} style={{
|
||||||
|
width: "40%",
|
||||||
marginLeft: "auto",
|
marginLeft: "auto",
|
||||||
marginRight: "auto",
|
marginRight: "auto",
|
||||||
}}/>
|
}}/>
|
||||||
<Headline style={{textAlign: "center"}}>Coucou</Headline>
|
<Card style={{
|
||||||
|
marginLeft: 10,
|
||||||
|
marginRight: 10,
|
||||||
|
}}>
|
||||||
|
<Card.Content>
|
||||||
|
<Headline
|
||||||
|
style={{
|
||||||
|
textAlign: "center",
|
||||||
|
color: this.props.theme.colors.primary
|
||||||
|
}}>
|
||||||
|
{i18n.t("screens.game.welcomeTitle")}
|
||||||
|
</Headline>
|
||||||
|
<Divider/>
|
||||||
|
<Paragraph
|
||||||
|
style={{
|
||||||
|
textAlign: "center",
|
||||||
|
marginTop: 10,
|
||||||
|
}}>
|
||||||
|
{i18n.t("screens.game.welcomeMessage")}
|
||||||
|
</Paragraph>
|
||||||
|
</Card.Content>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<View style={{flex: 1}}>
|
||||||
|
{this.getPiecesBackground()}
|
||||||
|
{this.getWelcomeText()}
|
||||||
<Button
|
<Button
|
||||||
|
icon={"play"}
|
||||||
mode={"contained"}
|
mode={"contained"}
|
||||||
onPress={() => this.props.navigation.navigate("game-main")}
|
onPress={() => this.props.navigation.navigate("game-main")}
|
||||||
|
style={{
|
||||||
|
marginLeft: "auto",
|
||||||
|
marginRight: "auto",
|
||||||
|
marginTop: 10,
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
PLAY
|
{i18n.t("screens.game.play")}
|
||||||
</Button>
|
</Button>
|
||||||
<MascotPopup
|
<MascotPopup
|
||||||
visible={this.state.mascotDialogVisible}
|
visible={this.state.mascotDialogVisible}
|
||||||
|
|
Loading…
Reference in a new issue