JavaScript and AJAX For Dummies by Andy Harris
Author:Andy Harris
Language: eng
Format: epub, pdf
Publisher: Wiley
Published: 2010-03-08T16:00:00+00:00
I chose a simple but effective technique. I temporarily took out the checkbounds() call and just took a look at the output to see what the values of x and y were. I looked to see how large x should be before the sprite wraps and wrote the value down on paper. Likewise, I found largest and smallest values for y.
When I knew these values, I simply placed them in constants. I don’t really care that the maximum value for x is 365. I just want to know that when I’m messing around with x I don’t want it to go past the MAX_X value.
If the size of my playing surface changes, I can just change the constants and everything will work out fine.
If you’re interested, here are the other techniques you can use when a sprite is about to leave the visual area:
Bounce: The object bounces off the wall. This is done by inverting the dx or dy value (depending on whether it’s a vertical or horizontal wall).
Stop: The object simply stops moving when it hits the wall. Set dx and dy to 0 to achieve this effect.
Continue: The object keeps moving even though it is out of sight. This is sometimes used for air-traffic control simulations (where visualizing the location is part of the game) or orbital simulations (where presumably the object will return).
Combinations: Sometimes you’ll see combinations like the civilization games that simulate a cylindrical map by stopping on the top and bottom and scrolling on the sides.
Reading Input from the Keyboard
You can use JavaScript to read directly from the keyboard. Reading from the keyboard can be useful in a number of situations, but it’s especially handy in animation and simple gaming applications.
Figure 8-2 shows a program with another moving ball.
Figure 8-2: You can move the ball with the arrow keys.
Download
JavaScript and AJAX For Dummies by Andy Harris.pdf
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Ada | Ajax |
Assembly Language Programming | Borland Delphi |
C & C++ | C# |
CSS | Compiler Design |
Compilers | DHTML |
Debugging | Delphi |
Fortran | Java |
Lisp | Perl |
Prolog | Python |
RPG | Ruby |
Swift | Visual Basic |
XHTML | XML |
XSL |
Hello! Python by Anthony Briggs(9865)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9755)
The Mikado Method by Ola Ellnestam Daniel Brolund(9745)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8256)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7743)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7739)
Grails in Action by Glen Smith Peter Ledbrook(7665)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7514)
Windows APT Warfare by Sheng-Hao Ma(6495)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6376)
Layered Design for Ruby on Rails Applications by Vladimir Dementyev(6241)
Blueprints Visual Scripting for Unreal Engine 5 - Third Edition by Marcos Romero & Brenden Sewell(6111)
Kotlin in Action by Dmitry Jemerov(5017)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4295)
Functional Programming in JavaScript by Mantyla Dan(4016)
Solidity Programming Essentials by Ritesh Modi(3836)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3611)
Unity 3D Game Development by Anthony Davis & Travis Baptiste & Russell Craig & Ryan Stunkel(3561)
The Ultimate iOS Interview Playbook by Avi Tsadok(3529)
