Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sockets - Carla #29

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,21 @@ class App extends Component {
};

// Uncomment this to spawn a single test item
//const testItem = this.spawnItem(Date.now());
//this.state.items.push(testItem);
// const testItem = this.spawnItem(Date.now());
// this.state.items.push(testItem);

// Uncomment this to automatically spawn new items
this.enableSpawner();

console.log(this.state);

}

onItemClicked = () => {
// Fill this in!

onItemClicked = (itemType) => {
if(itemType === 'litter') {
this.setState({points: this.state.points + 1})
}
}

render() {
Expand All @@ -49,11 +53,13 @@ class App extends Component {
height={item.height} // Height - used for a CSS style to position on the screen
layer={100 + i} // Layer - used for a CSS style to show items on-top of bg
key={item.id} // Key - to help React with performance

// Additional props (event callbacks, etc.) can be passed here
itemType={item.type}
onItemClickedCallback={this.onItemClicked}
/>;
});



return (
<div className="game">
<section className="hud">
Expand Down
26 changes: 23 additions & 3 deletions src/components/GameItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,43 @@ import '../App.css';
import ItemIcons from '../ItemIcons.js';
import PropTypes from 'prop-types';


class GameItem extends Component {
propTypes = {
constructor(props){
super(props)
this.state = {
spotted: false
}
}

static propTypes = {
height: PropTypes.number.isRequired,
layer: PropTypes.number.isRequired,
}

onItemClick = () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's confusing to have these named so similarly. Could you give it a different name that is easier to differentiate?

this.setState({'spotted': true})

this.props.onItemClickedCallback(this.props.itemType)
}

render() {
const itemStyle = {
bottom: `${this.props.height}px`, // use props.height to offset from the bottom of screen
zIndex: this.props.layer, // use props.layer to set z-index, so we display ontop of background
};

// Update this to select the correct icon for each item
const icon = ItemIcons.rock;
const icon = ItemIcons[this.props.itemType];

let targetStyle = ''

if(this.state.spotted) {
targetStyle = (this.props.itemType === 'litter') ? 'spotted-litter' : 'spotted-nature'
}

return (
<div className="game-item" style={itemStyle}>
<div onClick={this.onItemClick} className={`game-item ${targetStyle}`} style={itemStyle}>
<img src={icon} alt="Item" className="icon-item"></img>
</div>
);
Expand Down