Let me preface this question by saying that I'd like to avoid using javascript to solve this problem. If possible (it may not be) I'd like to keep all of this "logic" in CSS.
I am creating a board game (Khet) for fun in javascript. The board pieces can have multiple states, such as:
- Color (which player owns the piece)
- What type of piece it is (pyramid, sphinx, blank tile, etc)
- What direction the piece is facing (pieces may be rotated as well as moved)
- If the piece is reflecting a laser
- If the piece is damaged by a laser
That being said, I have one sprite.png
file containing all of the possible combinations for every piece and I would like to be able to use CSS classes to move the pieces through their states.
For example, imagine the red player has a pyramid piece on the board and it is facing northeast. This piece would have the classes .red
, .pyramid
, and .northeast
. If the piece is struck by a laser and reflects it, all I would have to do is add a .laser
class to the piece and CSS background-position
classes would kick in and change the piece to have the proper image.
This leads to a few questions:
- Is this even possible to do in pure CSS?
- How would you arrange the images in
sprite.png
such that thesebackground-position
classes would work? - What would the classes look like (this probably depends on #2)?
- Do I need to break the image apart? Like placing all red pieces in one
sprite_red.png
and blue insprite_blue.png
?
I've put this on the back burner while I work on some of the other portions of the game. Any help would be appreciated!