Web Hosting Tomcat, Java, JSP, Servlets, J2EE, PHP, MySQL

Cheap web hosting provider

15
Nov

} } public static void initiateClass (Applet app)

Collision Handling Listing 12-6 shows the bouncing box with collision handling. To conserve space, only the changes to Listing 12-1 are shown. The complete source code can be found on the CD-ROM. Listing 12-6 The bouncing box, with collision handling class BouncingBox extends fMovingObject{ .. .. public boolean interestedOfCollisionWith (fObject obj){ //– i’m interested in collisions with static boxes if(obj instanceof StaticBox) return true; //– none of the objects I know, let the base class decide return super.interestedOfCollisionWith (obj); } protected boolean handleCollisionWith (fObject obj,double dt){ //– if it is one of my “interest” objects if(obj instanceof StaticBox){ //– retrieve the position and velocity of the box fPoint3d dp=getdPosition(); dp.y=-dp.y; //– make sure gravity does it’s share dp.y-=BouncingBoxWorld.gravity*dt; //– set the new velocity setdPosition(dp); //– event has been handled, get more events return true; } //– if I don’t know what this object is then it //– means that a super class is interested. //– let it take care of it return super.handleCollisionWith(obj,dt); } .. .. } The interestedOfCollisionWith() Method Collision detection is an expensive operation. In order to optimize the core, one has to be very selective about which collisions objects should be interested in. Say that an object of type LargeTruck

Hint: This post is supported by Gama hrvatski web hosting services

Comments are closed.

Home | About Us | Compare Plans | Standard Hosting | Business Hosting | Java Tomcat Hosting | Support | FAQ | Order Now!

Powered by Omnicus java hosting services. All rights reserved.
Entries (RSS) and Comments (RSS).