nathandemick.com

Progressive enhancement

Weekend progress

Obviously, getting from displaying a keyboard-controlled object to a more "game-like" state is pretty easy. Here I've loaded an external PNG (that represents a spaceship of some kind) and attached it to a "ship" class instance. The left/right arrow keys control the object's internal "rotation" value, and pressing the up arrow key moves the ship. The direction is determined by trigonometry functions; the movement vector along the x-axis is cos(ship.rotation) and the y-axis movement vector is sin(ship.rotation). (For example, if our ship is pointing straight up (90°), cos(90)=0 and sin(90)=1, so it'll move straight up.)

· 0 comments


Comments