flash on 2010-2-10

by hacker_j0htd766
♥0 | Line 57 | Modified 2010-02-10 20:55:32 | MIT License
play

ActionScript3 source code

/**
 * Copyright hacker_j0htd766 ( http://wonderfl.net/user/hacker_j0htd766 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/6B9V
 */

package {
    import flash.display.Sprite;
    import flash.events.Event;
    
    public class AnimationExample extends Sprite {
        
        private var _car:Car;
        
        public function AnimationExample(){
        	
        	_car = new Car(0xd00000);
        	_car.putGas(60);
        	_car.y = 200;
        	addChild(_car);
        	
        	addEventListener(Event.ENTER_FRAME, moveCar);
        }
        
        private function moveCar(e:Event):void{
        	_car.move();
        }
    }
}

  
import flash.display.Sprite;

class Car extends Sprite{
	
	private var _gas:int = 0;
	
	public function Car(_fillColor:uint){
		_draw(_fillColor);
	}
	
	
	public function putGas(_amount:int):void{
		if(_amount < 0){
			return;
		}
	
		_gas += _amount;
	}
	
	public function move():void{
		if(_gas > 10){
			x += 5;
		}else{
			x += _gas/2;
		}
		
		_gas--;
		if (_gas <0){
			_gas =0;
		}
	}
private function _draw(_fillColor:uint):void{
	graphics.beginFill(0x333333);        
	graphics.drawCircle(10, 20, 5);        
	graphics.drawCircle(45, 20, 5);        
	graphics.endFill();
	
	graphics.beginFill(_fillColor);
	graphics.moveTo(0,10);
	graphics.lineTo(15,0);
	graphics.lineTo(30,0);
	graphics.lineTo(40,10);
	graphics.lineTo(50,10);
	graphics.lineTo(55,15);
	graphics.lineTo(55,20);
	graphics.lineTo(0,20);
	graphics.endFill();
	}
}