forked from AdaGold/litter-patrol
-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathGameItem.js
62 lines (52 loc) · 1.54 KB
/
GameItem.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import React, { Component } from 'react';
import '../App.css';
import ItemIcons from '../ItemIcons.js';
import PropTypes from 'prop-types';
class GameItem extends Component {
clickCallback = (e) => {
console.log("An item was clicked!");
console.log(this.props.index);
this.props.onClickCallback(this.props.index);
}
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
let icon;
let className = "game-item";
switch(this.props.type) {
case 'litter':
icon = ItemIcons.litter;
break;
case 'rock':
icon = ItemIcons.rock;
break;
case 'bush':
icon = ItemIcons.bush;
break;
case 'flower':
icon = ItemIcons.flower;
break;
default:
icon = ItemIcons.mushroom;
};
if (this.props.type === "litter" && this.props.wasSpotted) {
className = "game-item spotted-litter"
} else if (this.props.wasSpotted) {
className = "game-item spotted-nature";
}
return (
<div className={className} style={itemStyle} onClick={this.clickCallback}>
<img src={icon} alt="Item" className="icon-item" />
</div>
);
}
}
GameItem.propTypes = {
height: PropTypes.number.isRequired,
layer: PropTypes.number.isRequired,
type: PropTypes.string,
}
export default GameItem;