Skip to content

Commit

Permalink
Asteroid stub.
Browse files Browse the repository at this point in the history
  • Loading branch information
freiksenet committed May 15, 2014
1 parent 52c307e commit 1f749f2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/Asteroid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/** @jsx React.DOM */

var React = require('react');
var ReactKinetic = require('react-kinetic');
var Circle = ReactKinetic.Circle;

var Asteroid = React.createClass({
getDefaultProps: function () {
return {
radius: 20,
velocity: [5, 5]
};
},

render: function () {
return (
<Circle x={this.props.x}
y={this.props.y}
radius={this.props.radius}
stroke="white"
strokeWidth="2" />
);
}
});

module.exports = Asteroid;
14 changes: 13 additions & 1 deletion src/Asteroids.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var InputHandler = require('./InputHandler');
var ResourceLoader = require('./ResourceLoader');

var Ship = require('./Ship');
var Asteroid = require('./Asteroid');

var Stage = ReactKinetic.Stage;
var Layer = ReactKinetic.Layer;
Expand All @@ -32,7 +33,10 @@ var Game = React.createClass({
playerRot: 0,
playerRotVel: 0,
playerRotAcc: 0,
currentTick: 0
currentTick: 0,
asteroids: [{
pos: [50, 50]
}]
};
},

Expand Down Expand Up @@ -133,6 +137,13 @@ var Game = React.createClass({

render: function () {
var planeSprite = this.props.resourceLoader.getResource('planeSprite');
var asteroids = this.state.asteroids.map(function (asteroid, i) {
return (
<Asteroid key={i}
x={asteroid.pos[0]}
y={asteroid.pos[1]} />
);
});
return (
<Layer>
<Ship x={this.state.playerPos[0]}
Expand All @@ -141,6 +152,7 @@ var Game = React.createClass({
rotVel={this.state.playerRotVel}
velX={this.state.playerVelX}
image={planeSprite}/>
{asteroids}
</Layer>
);
}
Expand Down

0 comments on commit 1f749f2

Please sign in to comment.