Drivable Car
Description: This car moves forwards, backwards, turns, and has angling wheels.
Author: John Bezanis
Added: January 28th 2007
Version: Flash 8
The car is drivable on the press of the direction keys. The car moves forward, backwards, turns, and has moving front wheels.
- //www.swfspot.com
- //movement speed of the car
- var speed=7;
- //Compute pi/180. The value is used twice for each frame, so storing it as a variable saves CPU
- var piOver180=Math.PI/180;
- onEnterFrame=function(){
- //If the left or right keys are down, rotate the wheels
- if(Key.isDown(Key.LEFT)){
- car.leftwheel._rotation=Math.min(24,Math.max(-24,car.leftwheel._rotation-5));
- car.rightwheel._rotation=Math.min(24,Math.max(-24,car.rightwheel._rotation-5));
- }
- if(Key.isDown(Key.RIGHT)){
- car.leftwheel._rotation=Math.min(24,Math.max(-24,car.leftwheel._rotation+4));
- car.rightwheel._rotation=Math.min(24,Math.max(-24,car.rightwheel._rotation+4));
- }
- //check if the up or down keys are pressed
- if(Key.isDown(Key.UP)||Key.isDown(Key.DOWN)){
- //if the up key is down, the car moves forward
- if(Key.isDown(Key.UP)){
- carDirection=1;
- //otherwise move the car backwards
- }else{carDirection=-1;}
- //default turning to false
- turning=0;
- //if the left or right keys are pressed, set turning to true and rotate the car
- if(Key.isDown(Key.LEFT)){
- turning=1;
- car._rotation-=5*carDirection;
- }
- else if(Key.isDown(Key.RIGHT)){
- turning=1;
- car._rotation+=5*carDirection;
- }
- //if the car isn't turning, reset the rotation of the tires
- if(!turning){
- car.leftwheel._rotation=0;
- car.rightwheel._rotation=0;
- }
- //move the car. The y coordinate plane is flipped in flash, so we use - instead of +
- car._x+=Math.sin(car._rotation*piOver180)*speed*carDirection;
- car._y-=Math.cos(car._rotation*piOver180)*(speed)*carDirection;
- }
- }
Download Source File
Comments
Good tut, but you could add physics, like friction, drag, etc. This would cause the car to behave more realistically. It would coast, slide, and other good stuff.
June 2nd 2007 11:06AM - Egan
can utell how thr car was made
October 11th 2007 10:10PM - altaf
Even a little simple physics would be awsome
October 30th 2008 12:10AM - Axl
I am happy to find many useful information in the post, thanks.
December 6th 2009 02:12AM - seo
Really nice post,thanks for sharing.
December 7th 2009 10:12AM - condo
I have bookmarked your site. Thanks for sharing
December 13th 2009 08:12AM - dental
If could add physics, like friction, drag, etc. This would cause the car to behave more realistically. It would coast, slide, and other good stuff.
December 17th 2009 02:12AM - Dating Advice
i like
January 4th 2010 01:01AM - Evening Gowns
Thank you for sharing the source file. Much appreciated. Cheers.
January 5th 2010 06:01PM - racing car games
The blog is really informative and i like to share it with my friends we can easily learn more about web designing through this post thanks for post
January 15th 2010 08:01PM - evening dresses
Great sharing dude :)
January 20th 2010 05:01AM - Car parts
Special thank for good post.
February 5th 2010 08:02AM - โหลดเพลงà
Thank
February 6th 2010 12:02AM - โหลดเพลงm
Special thank for good post.
February 10th 2010 03:02AM - โหลดเพลงà
Special thank for good post.
February 10th 2010 08:02AM - โหลดเพลงà
Hi all. Experience is a good teacher, but she send in terrific bills. Help me! Could you help me find sites on the: High quality brochure printing. I found only this - <a href="http://www.honbu.fi/Members/BrochurePrinting">brochure printing costs</a>. Brochure printing, acronyms are plated the uncertainty to leave and buy a version of destiny which holds the southeastern consortium of hell attack. Brochure printing, this carefully crowds a brochure of character and banking to vegan which would clearly still have malicious unbulletted or true separations that can move fluid. Thank :confused: Jalen from Central.
February 12th 2010 12:02PM - Jalen
Add a Comment





