alpha
Login
or
Join now
andri.dk
/
silly-experiment1
Star
0
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
[READ-ONLY] Mirror of https://github.com/andrioid/silly-experiment1. Workshop tasks turned into a silly poop game. That's how mature I am.
Star
0
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Overview
Issues
Pulls
Pipelines
so its a working game now
author
Andri Oskarsson
date
8 years ago
(May 16, 2018, 5:14 PM +0200)
commit
e48987f3
e48987f39cef63989d924e15d69d4bac742b9360
parent
61814917
618149178ee3139a27b115ed36165ef9ddbb1e5d
+45
-23
3 changed files
Expand all
Collapse all
Unified
Split
App.js
Blob.js
app.json
+40
-16
App.js
View file
Reviewed
···
1
1
import React from "react";
2
2
-
import { StyleSheet, Text, View, Animated, Easing } from "react-native";
2
2
+
import { StyleSheet, Text, View, Animated, Easing, Button } from "react-native";
3
3
import { Flag } from "./Flag";
4
4
import { FrenchBox } from "./FrenchBox";
5
5
import { Blob } from "./Blob";
···
8
8
anim = new Animated.Value(0);
9
9
10
10
state = {
11
11
-
blobs: [{ id: 1 }, { id: 2 }],
12
12
-
counter: 0
11
11
+
blobs: [{ id: 1 }, { id: 2 }, { id: 3 }],
12
12
+
counter: 0,
13
13
+
score: 0,
14
14
+
baseSpeed: 1,
15
15
+
running: true
13
16
};
14
17
15
18
addBlob = () => {
···
27
30
28
31
handleDead = id => {
29
32
this.addBlob();
30
30
-
// delete the dead one, add two more
33
33
+
// delete the dead one, add one more and increase speed
31
34
const idx = this.state.blobs.findIndex(v => v.id === id);
32
35
if (idx !== -1) {
33
36
// delete the old one from array
34
37
this.setState(state => {
35
38
state.blobs.splice(idx, 1); // I'm not happy with this
36
39
return {
37
37
-
...state
40
40
+
score: state.score + 1,
41
41
+
baseSpeed: state.baseSpeed + 0.1,
42
42
+
blobs: state.blobs
38
43
};
39
44
});
40
45
}
41
46
};
42
47
43
48
handleGameOver = () => {
44
44
-
alert("Game over");
49
49
+
this.setState({ running: false, baseSpeed: 1 });
45
50
};
46
51
47
52
render() {
48
53
return (
49
54
<View style={styles.container}>
50
50
-
{this.state.blobs.map(b => (
51
51
-
<Blob
52
52
-
key={b.id}
53
53
-
onDead={() => this.handleDead(b.id)}
54
54
-
onGameOver={this.handleGameOver}
55
55
-
/>
56
56
-
))}
55
55
+
{this.state.running ? (
56
56
+
<View style={{ flex: 1, backgroundColor: "#ffffff" }}>
57
57
+
{this.state.blobs.map(b => (
58
58
+
<Blob
59
59
+
key={b.id}
60
60
+
onDead={() => this.handleDead(b.id)}
61
61
+
baseSpeed={this.state.baseSpeed}
62
62
+
onGameOver={this.handleGameOver}
63
63
+
/>
64
64
+
))}
65
65
+
</View>
66
66
+
) : (
67
67
+
<View
68
68
+
style={{ flex: 1, justifyContent: "center", alignItems: "center" }}
69
69
+
>
70
70
+
<Text style={{ fontSize: 20 }}>Game Over</Text>
71
71
+
<Text>Your score: {this.state.score}</Text>
72
72
+
<Button
73
73
+
title="Restart"
74
74
+
onPress={() => {
75
75
+
this.setState({ running: true, score: 0 });
76
76
+
}}
77
77
+
/>
78
78
+
</View>
79
79
+
)}
80
80
+
<View>
81
81
+
<Text style={{ fontSize: 24 }}>{this.state.score}</Text>
82
82
+
</View>
57
83
</View>
58
84
);
59
85
}
···
62
88
const styles = StyleSheet.create({
63
89
container: {
64
90
flex: 1,
65
65
-
backgroundColor: "#d3d3d3",
66
66
-
alignItems: "center",
67
67
-
justifyContent: "space-around"
91
91
+
backgroundColor: "#d3d3d3"
68
92
}
69
93
});
+1
-1
Blob.js
View file
Reviewed
···
36
36
const initialPosition = Animated.timing(this.anim, {
37
37
toValue: 1,
38
38
easing: Easing.linear,
39
39
-
duration: 8000,
39
39
+
duration: 8000 / this.props.baseSpeed,
40
40
useNativeDriver: true
41
41
}).start(({ finished }) => {
42
42
if (finished) {
+4
-6
app.json
View file
Reviewed
···
1
1
{
2
2
"expo": {
3
3
-
"name": "day1-1",
4
4
-
"description": "This project is really great.",
5
5
-
"slug": "day1-1",
3
3
+
"name": "Poo Falls",
4
4
+
"description": "Some silly game I made",
5
5
+
"slug": "poo-falls",
6
6
"privacy": "public",
7
7
"sdkVersion": "27.0.0",
8
8
"platforms": ["ios", "android"],
···
17
17
"updates": {
18
18
"fallbackToCacheTimeout": 0
19
19
},
20
20
-
"assetBundlePatterns": [
21
21
-
"**/*"
22
22
-
],
20
20
+
"assetBundlePatterns": ["**/*"],
23
21
"ios": {
24
22
"supportsTablet": true
25
23
}