|
|
#02 - Illusion Of Movement
irt.org | Games | Techniques | #02 - Illusion Of Movement Games are distributed under the WebGames License By: Keith Drakard
IntroductionSome games can do with a little graphical spicing-up, and since it's often achievable without loading any more images, then it's quite easy to add the illusion of movement into your game. Like the previous article, I've compiled some example functions to demonstrate the principles involved, some of which I've used in JavaScript games. These should give you a good starting point to adapt to your own games. Example 1 - Connect Four CountersIf you've ever played Connect Four, you'll know that a distinctive part of the game is seeing the counters actually drop down the columns in the board. When re-creating the game for the computer, I had to make sure that this feature was included. The function below is called when a player has chosen a column to drop their counter down. It drops the counter down a space and calls itself repeatedly, until the counter can drop no further.
You can see this function in action in the Connect Four game. Example 2 - Dice RollingAs an alternative to images moving across a board, you may want to display multiple images in one location - so here's an example using a series of dice to create an illusion of rolling:
You can see this function in action in this Dice Rolling example. Example 3 - Multiple MovementHere's an example which moves two pieces at once, bouncing them around a small checkerboard. It would also be possible to calculate the movement of each piece independently, but for the sake of simplicity I've presented them together:
You can see this function in action in this Multiple Movement example. SummaryIn the first two functions, movement was created by repeatedly calling one function with a slightly different value each time. In the third function, the basic principle stayed the same but the calculation of the positions was done with global variables to avoid complications. In any case, the function would remove the previous image (unless the new image would overwrite the same location), adjust the position of the image and re-display the image in the new position. Finally, the setTimeout() command is used to call the same function again - "recursively". A small delay between calls was used to prevent the images appearing as a blur. Games are distributed under the WebGames License |
-- div -->
|