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

Commit e38809e

Browse files
committed
its a start
0 parents  commit e38809e

29 files changed

+617
-0
lines changed

.babelrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"presets": ["es2015", "react", "stage-0"],
3+
"plugins": ["transform-flow-strip-types"]
4+
}

.eslintignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/demo/**
2+
/dist/**
3+
/interfaces/**
4+
/lib/**
5+
/node_modules/**
6+
/public/**
7+
/umd/**

.eslintrc

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"extends": "formidable/configurations/es6-react"
2+
"parser": "babel-eslint"
3+
"env":
4+
"browser": true
5+
"rules":
6+
"no-magic-numbers": 0
7+
"no-invalid-this": 0
8+
"react/sort-comp": 0
9+
"comma-dangle": [2, "always-multiline"]
10+
"jsx-quotes": [2, "prefer-double"]
11+
"quotes": [2, "single",{"allowTemplateLiterals": true}]

.flowconfig

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[libs]
2+
interfaces
3+
4+
[ignore]
5+
.*/dist/.*
6+
.*/lib/.*
7+
.*/umd/.*
8+
.*/demo/.*
9+
.*/node_modules/flow-bin/.*
10+
11+
[include]
12+
src
13+
14+
[options]
15+
esproposal.class_static_fields=enable
16+
esproposal.class_instance_fields=enable

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
npm-debug.log
3+
lib
4+
umd

.npmignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
src
2+
dist

LICENSE.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2013
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

demo/character.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React, { Component, PropTypes } from 'react';
2+
3+
import {
4+
Sprite,
5+
} from '../src';
6+
7+
export default class Character extends Component {
8+
static propTypes = {
9+
state: PropTypes.number,
10+
};
11+
render() {
12+
return (
13+
<Sprite
14+
animating
15+
src="assets/character-sprite.png"
16+
scale={4}
17+
state={this.props.state}
18+
states={[9, 9, 0]}
19+
/>
20+
);
21+
}
22+
}

demo/demo.js

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React, { Component } from 'react';
2+
3+
import {
4+
Game,
5+
Keys,
6+
} from '../src';
7+
8+
import Character from './character';
9+
10+
import './index.css';
11+
12+
export default class Demo extends Component {
13+
14+
handleInput = (e) => {
15+
switch (e.keyCode) {
16+
case '37':
17+
// left
18+
break;
19+
case '39':
20+
// right
21+
break;
22+
default:
23+
break;
24+
}
25+
};
26+
27+
constructor(props) {
28+
super(props);
29+
this.state = {
30+
character: 0,
31+
};
32+
this.handleClick = this.handleClick.bind(this);
33+
}
34+
35+
handleClick() {
36+
const state = this.state.character === 2 ? 0 : this.state.character + 1;
37+
this.setState({
38+
character: state,
39+
});
40+
}
41+
42+
render() {
43+
return (
44+
<Game>
45+
<Keys onInput={this.handleInput} />
46+
<Character state={this.state.character}/>
47+
{this.state.character}
48+
<button style={{ marginTop: 200 }}onClick={this.handleClick} type="button">Toggle</button>
49+
</Game>
50+
);
51+
}
52+
53+
}

demo/index.css

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
html, body, #root {
2+
height: 100%;
3+
width: 100%;
4+
margin: 0;
5+
padding: 0;
6+
}

demo/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import Demo from './demo';
4+
5+
ReactDOM.render(
6+
<Demo />,
7+
document.getElementById('root')
8+
);

package.json

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"name": "react-game-kit",
3+
"version": "0.0.1",
4+
"description": "Make games with react",
5+
"main": "lib",
6+
"files": [
7+
"lib",
8+
"umd"
9+
],
10+
"scripts": {
11+
"start": "webpack-dev-server --inline --port 3000 --config webpack.config.dev.js --content-base public/",
12+
"build": "babel src -d lib --copy-files",
13+
"clean": "rimraf dist",
14+
"clean-umd": "rimraf umd",
15+
"dist": "npm run clean && webpack && cp -a public/. dist/",
16+
"lint": "eslint src demo --fix",
17+
"flow-check": "flow check",
18+
"flow": "flow",
19+
"umd": "npm run clean-umd && webpack --config webpack.config.umd.js"
20+
},
21+
"author": "Ken Wheeler",
22+
"license": "MIT",
23+
"repository": "https://github.com/FormidableLabs/react-music",
24+
"dependencies": {
25+
"mobx": "^2.5.0",
26+
"mobx-react": "^3.5.5"
27+
},
28+
"peerDependencies": {
29+
"react": "^15.2.1",
30+
"react-dom": "^15.2.1"
31+
},
32+
"devDependencies": {
33+
"babel-cli": "^6.10.1",
34+
"babel-core": "^6.10.4",
35+
"babel-eslint": "^6.1.2",
36+
"babel-loader": "^6.2.4",
37+
"babel-plugin-transform-flow-strip-types": "^6.14.0",
38+
"babel-preset-es2015": "^6.9.0",
39+
"babel-preset-react": "^6.11.1",
40+
"babel-preset-stage-0": "^6.5.0",
41+
"css-loader": "^0.23.1",
42+
"eslint": "^3.3.1",
43+
"eslint-config-formidable": "^1.0.1",
44+
"eslint-plugin-filenames": "^1.1.0",
45+
"eslint-plugin-import": "^1.14.0",
46+
"eslint-plugin-jsx-a11y": "^2.1.0",
47+
"eslint-plugin-react": "^6.1.2",
48+
"flow-bin": "^0.31.1",
49+
"json-loader": "^0.5.4",
50+
"postcss-loader": "^0.10.1",
51+
"react": "^15.2.1",
52+
"react-dom": "^15.2.1",
53+
"rimraf": "^2.5.4",
54+
"style-loader": "^0.13.1",
55+
"webpack": "^1.13.1",
56+
"webpack-dev-server": "^1.15.0"
57+
}
58+
}

public/assets/character-sprite.png

8.11 KB
Loading

public/index.css

Whitespace-only changes.

public/index.html

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>React Game Kit</title>
5+
<link rel="stylesheet" type="text/css" href="index.css">
6+
</head>
7+
<body>
8+
<div id='root'></div>
9+
<script src="bundle.js"></script>
10+
</body>
11+
</html>

src/components/body.js

Whitespace-only changes.

src/components/canvas-sprite.js

Whitespace-only changes.

src/components/game.js

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import React, { Component, PropTypes } from 'react';
2+
3+
import GameLoop from '../utils/game-loop';
4+
5+
export default class Game extends Component {
6+
7+
static propTypes = {
8+
children: PropTypes.any,
9+
stageHeight: PropTypes.number,
10+
stageWidth: PropTypes.number,
11+
style: PropTypes.object,
12+
};
13+
14+
static defaultProps = {
15+
stageWidth: 1024,
16+
stageHeight: 768,
17+
};
18+
19+
static childContextTypes = {
20+
loop: PropTypes.object,
21+
scale: PropTypes.number,
22+
};
23+
24+
constructor(props) {
25+
super(props);
26+
this.container = null;
27+
this.loop = new GameLoop();
28+
}
29+
30+
componentDidMount() {
31+
this.loop.start();
32+
}
33+
34+
componentWillUnmount() {
35+
this.loop.stop();
36+
}
37+
38+
getChildContext() {
39+
const { container } = this;
40+
const { stageWidth, stageHeight } = this.props;
41+
42+
if (!container) {
43+
return {
44+
scale: 0,
45+
loop: this.loop,
46+
};
47+
}
48+
49+
const xScale = container.offsetWidth / stageWidth;
50+
const yScale = container.offsetHeight / stageHeight;
51+
52+
return {
53+
scale: Math.max(xScale, yScale),
54+
loop: this.loop,
55+
};
56+
}
57+
58+
render() {
59+
const defaultStyles = {
60+
height: '100%',
61+
width: '100%',
62+
};
63+
const styles = { ...defaultStyles, ...this.props.style };
64+
return (
65+
<div style={styles} ref={(c) => { this.container = c; }}>
66+
{this.props.children}
67+
</div>
68+
);
69+
}
70+
71+
}

src/components/keys.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React, { Component, PropTypes } from 'react';
2+
3+
export default class Keys extends Component {
4+
5+
static propTypes = {
6+
onInput: PropTypes.func,
7+
};
8+
9+
static defaultProps = {
10+
onInput: () => {},
11+
};
12+
13+
handleKeyPress = (e) => {
14+
this.props.onInput.call(null, e);
15+
}
16+
17+
constructor(props) {
18+
super(props);
19+
}
20+
21+
componentDidMount() {
22+
window.addEventListener('keydown', this.handleKeyPress);
23+
}
24+
25+
componentWillUnmount() {
26+
window.removeEventListener('keydown', this.handleKeyPress);
27+
}
28+
29+
render() {
30+
return null;
31+
}
32+
33+
}

0 commit comments

Comments
 (0)