Skip to content

Commit 542831e

Browse files
author
sarthakpranesh
committed
changes
- handling network error while login - added different frames for the bird (bird actually flaps now :>)
1 parent 6c46813 commit 542831e

File tree

6 files changed

+30
-5
lines changed

6 files changed

+30
-5
lines changed

assets/bird2.png

425 Bytes
Loading

assets/bird3.png

426 Bytes
Loading

src/components/Bird.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
/* eslint-disable react-native/no-inline-styles */
22
import React, {Component} from 'react';
33
import {Image} from 'react-native';
4-
import birdImage from '../../assets/bird.png';
4+
import birdImage1 from '../../assets/bird.png';
5+
import birdImage2 from '../../assets/bird2.png';
6+
import birdImage3 from '../../assets/bird3.png';
57

68
import Constants from '../Constant.js';
79

@@ -13,9 +15,22 @@ export default class Bird extends Component {
1315
this.height = Constants.BIRD_HEIGHT;
1416
}
1517

18+
birdFrameSelector = () => {
19+
if (this.props.pose === 0) {
20+
return birdImage1;
21+
} else if (this.props.pose === 1) {
22+
return birdImage2;
23+
} else if (this.props.pose === 2) {
24+
return birdImage3;
25+
} else {
26+
return birdImage1;
27+
}
28+
};
29+
1630
render() {
1731
const x = this.props.position[0] - this.width / 2;
1832
const y = this.props.position[1] - this.height / 2;
33+
1934
return (
2035
<Image
2136
style={{
@@ -26,7 +41,7 @@ export default class Bird extends Component {
2641
height: this.height,
2742
}}
2843
resizeMode="contain"
29-
source={birdImage}
44+
source={this.birdFrameSelector()}
3045
/>
3146
);
3247
}

src/components/Physics.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Constants from '../Constant';
33
let pause = false;
44
let birdJump = 0;
55
let gravity = 0;
6+
let prevTime = 0;
67
let scored = false;
78

89
export const stopGame = () => {
@@ -26,7 +27,7 @@ export const randomBetween = () => {
2627
return Math.floor(Math.random() * (max - min + 1) + min);
2728
};
2829

29-
export const GameControl = (entities, {touches, dispatch}) => {
30+
export const GameControl = (entities, {time, touches, dispatch}) => {
3031
if (!pause) {
3132
Object.keys(entities).forEach(key => {
3233
const bird = entities['1'];
@@ -77,8 +78,12 @@ export const GameControl = (entities, {touches, dispatch}) => {
7778
body.position[0] -= 1;
7879
return;
7980
} else {
80-
// if bird, apply gravity
81+
// if bird, apply gravity and change pose
8182
body.position[1] += gravity - birdJump;
83+
if (time.current - prevTime >= 500) {
84+
prevTime = time.current;
85+
body.pose = (body.pose + 1) % 3;
86+
}
8287
if (birdJump > 0) {
8388
birdJump--;
8489
}

src/screens/Play.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export default class Play extends PureComponent {
9696
];
9797

9898
return {
99-
1: {position: bird, renderer: <Bird />, name: 'bird'},
99+
1: {position: bird, renderer: <Bird />, name: 'bird', pose: 0},
100100
2: {position: floor1, renderer: <Floor />, name: 'floor'},
101101
3: {position: floor2, renderer: <Floor />, name: 'floor'},
102102
4: {position: pipe1, renderer: <Pipe />, name: 'pipe'},

src/screens/UserStarting.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ export default class UserStarting extends Component {
4747
'Please install Google Play Services!',
4848
ToastAndroid.SHORT,
4949
);
50+
} else if (error.message === 'NETWORK_ERROR') {
51+
ToastAndroid.show(
52+
'We are having Network issues :<',
53+
ToastAndroid.SHORT,
54+
);
5055
} else {
5156
console.log(error.message);
5257
}

0 commit comments

Comments
 (0)