Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 1a44203

Browse files
committed
slide start
1 parent d3ae11b commit 1a44203

File tree

11 files changed

+60
-30
lines changed

11 files changed

+60
-30
lines changed

demo/game/character.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ export default class Character extends Component {
4343
{ x: 0, y: 0 },
4444
{ x: 0, y: -0.15 },
4545
);
46-
Matter.Body.set(body, 'friction', 0);
46+
Matter.Body.set(body, 'friction', 0.0001);
4747
};
4848

4949
punch = () => {
5050
this.isPunching = true;
5151
this.setState({
5252
characterState: 4,
53-
loop: false,
53+
repeat: false,
5454
});
5555
}
5656

57-
enterBuilding = (body) => {
57+
getDoorIndex = (body) => {
5858
let doorIndex = null;
5959

6060
const doorPositions = [...Array(6).keys()].map((a) => {
@@ -67,6 +67,12 @@ export default class Character extends Component {
6767
}
6868
});
6969

70+
return doorIndex;
71+
}
72+
73+
enterBuilding = (body) => {
74+
const doorIndex = this.getDoorIndex(body);
75+
7076
if (doorIndex !== null) {
7177
this.setState({
7278
characterState: 3,
@@ -76,15 +82,10 @@ export default class Character extends Component {
7682
}
7783
};
7884

79-
checkKeys = () => {
85+
checkKeys = (shouldMoveStageLeft, shouldMoveStageRight) => {
8086
const { keys, store } = this.props;
8187
const { body } = this.body;
8288

83-
const midPoint = Math.abs(store.stageX) + 448;
84-
85-
const shouldMoveStageLeft = body.position.x < midPoint && store.stageX < 0;
86-
const shouldMoveStageRight = body.position.x > midPoint && store.stageX > -2048;
87-
8889
let characterState = 2;
8990

9091
if (keys.isDown(65) || gamepad.button(0, 'b')) {
@@ -105,21 +106,19 @@ export default class Character extends Component {
105106
}
106107

107108
this.move(body, -5);
108-
109109
characterState = 1;
110110
} else if (keys.isDown(keys.RIGHT) || gamepad.button(0, 'button 15')) {
111111
if (shouldMoveStageRight) {
112112
store.setStageX(store.stageX - 5);
113113
}
114114

115115
this.move(body, 5);
116-
117116
characterState = 0;
118117
}
119118

120119
this.setState({
121120
characterState,
122-
loop: characterState < 2,
121+
repeat: characterState < 2,
123122
});
124123
}
125124

@@ -132,15 +131,17 @@ export default class Character extends Component {
132131
const shouldMoveStageLeft = body.position.x < midPoint && store.stageX < 0;
133132
const shouldMoveStageRight = body.position.x > midPoint && store.stageX > -2048;
134133

135-
if (body.velocity.y === 0 || body.velocity.y < -100) {
134+
const velY = parseFloat(body.velocity.y.toFixed(10));
135+
136+
if (velY === 0) {
136137
this.isJumping = false;
137-
Matter.Body.set(body, 'friction', 1);
138+
Matter.Body.set(body, 'friction', 0.9999);
138139
}
139140

140141
if (!this.isJumping && !this.isPunching && !this.isLeaving) {
141142
gamepad.update();
142143

143-
this.checkKeys();
144+
this.checkKeys(shouldMoveStageLeft, shouldMoveStageRight);
144145

145146
store.setCharacterPosition(body.position);
146147
} else {
@@ -206,13 +207,12 @@ export default class Character extends Component {
206207
ref={(b) => { this.body = b; }}
207208
>
208209
<Sprite
209-
animating
210-
loop={this.state.loop}
210+
repeat={this.state.repeat}
211211
onPlayStateChanged={this.handlePlayStateChanged}
212212
src="assets/character-sprite.png"
213213
scale={this.context.scale * 2}
214214
state={this.state.characterState}
215-
states={[9, 9, 0, 4, 5]}
215+
steps={[9, 9, 0, 4, 5]}
216216
/>
217217
</Body>
218218
</div>

demo/game/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export default class Game extends Component {
8585
this.keyListener.RIGHT,
8686
this.keyListener.UP,
8787
this.keyListener.SPACE,
88+
65,
8889
]);
8990
}
9091

demo/slides/basics.js

Whitespace-only changes.

demo/slides/index.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React, { Component, PropTypes } from 'react';
22
import Gamepad from 'html5-gamepad';
33

4+
import Slide from './slide';
5+
46
const gamepad = new Gamepad();
57

68
export default class Slides extends Component {
@@ -29,6 +31,7 @@ export default class Slides extends Component {
2931
}
3032

3133
componentDidMount() {
34+
window.addEventListener('keyup', this.handleKeyPress);
3235
window.addEventListener('keypress', this.handleKeyPress);
3336
this.animationFrame = requestAnimationFrame(this.startUpdate);
3437
}
@@ -38,10 +41,20 @@ export default class Slides extends Component {
3841
cancelAnimationFrame(this.animationFrame);
3942
}
4043

44+
getWrapperStyles() {
45+
return {
46+
height: '100%',
47+
width: '100%',
48+
display: 'flex',
49+
alignItems: 'stretch',
50+
justifyContent: 'center',
51+
};
52+
}
53+
4154
render() {
4255
return (
43-
<div>
44-
<p>Ayy whatup</p>
56+
<div style={this.getWrapperStyles()}>
57+
<Slide>test</Slide>
4558
</div>
4659
);
4760
}

demo/slides/loop.js

Whitespace-only changes.

demo/slides/physics.js

Whitespace-only changes.

demo/slides/scaling.js

Whitespace-only changes.

demo/slides/slide.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from 'react';
2+
3+
const slideStyles = {
4+
display: 'flex',
5+
flex: '1 1 0',
6+
alignItems: 'center',
7+
justifyContent: 'center',
8+
maxWidth: '166vh',
9+
background: 'red',
10+
};
11+
12+
const Slide = (props) => (
13+
<div style={slideStyles}>
14+
{props.children}
15+
</div>
16+
);
17+
18+
export default Slide;

demo/slides/sprites.js

Whitespace-only changes.

demo/slides/tilemaps.js

Whitespace-only changes.

0 commit comments

Comments
 (0)