Advertisement
Guest User

Ped. Run

a guest
Feb 19th, 2014
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package
  2. {
  3.     import flash.display.Bitmap;
  4.     import flash.display.Graphics;
  5.     import flash.display.Sprite;
  6.     import flash.events.Event;
  7.     import flash.events.KeyboardEvent;
  8.     import flash.text.TextField;
  9.     import flash.text.TextFieldAutoSize;
  10.     import flash.text.TextFormat;
  11.     import flash.ui.Keyboard;
  12.     import flash.utils.*;
  13.    
  14.     /**
  15.      * ...
  16.      * @author DogeGames Studios
  17.      */
  18.    
  19.     public class Main extends Sprite
  20.     {
  21.         public var inair:int = 1;
  22.         [Embed(source = 'img/char.png')]
  23.         var charClass:Class;
  24.         var char:Bitmap = new charClass();
  25.         [Embed(source = 'img/rock.png')]
  26.         var rockClass:Class;
  27.         var rock:Bitmap = new rockClass();
  28.         public function Main():void
  29.         {
  30.            
  31.             if (stage) init();
  32.             else addEventListener(Event.ADDED_TO_STAGE, init);
  33.             stage.addEventListener(KeyboardEvent.KEY_DOWN, detectKey);
  34.             stage.addEventListener(Event.ENTER_FRAME, moveRock);
  35.         }
  36.        
  37.         private function init(e:Event = null):void
  38.         {
  39.             addChild(rock);
  40.             removeEventListener(Event.ADDED_TO_STAGE, init);
  41.             // entry point
  42.             var text:TextField = new TextField();
  43.             text.text = "Pedestrian Run";
  44.             char.x = 50;
  45.             char.y = 482;
  46.             rock.x = 850;
  47.             rock.y = 520;
  48.             var format:TextFormat = new TextFormat();
  49.             format.size = 24;
  50.             format.font = "Comic Sans MS";
  51.             text.setTextFormat(format);
  52.             text.autoSize = TextFieldAutoSize.LEFT;
  53.             addChild(text);
  54.             addChild(char);
  55.             drawLine();
  56.         }
  57.        
  58.         function detectKey(event:KeyboardEvent):void {
  59.             var key:uint = event.keyCode;
  60.             var step:uint = 5;
  61.            
  62.             switch (key) {
  63.                 case Keyboard.SPACE :
  64.                     spacePressed();
  65.             }
  66.         }
  67.        
  68.         public function spacePressed():void {
  69.             char.y = char.y - 50;
  70.             inair = 0;
  71.             setTimeout(down, 500);
  72.         }
  73.        
  74.         function down():void {
  75.             inair = 1;
  76.             char.y = 482;
  77.         }
  78.        
  79.         function drawLine():void {
  80.             var g:Graphics = graphics;
  81.            
  82.             g.lineStyle(5, 0, 100);
  83.             g.moveTo(0, 550);
  84.             g.lineTo(850, 550);
  85.         }
  86.        
  87.         private var speed:Number = 15;
  88.        
  89.         function moveRock(event:Event):void {
  90.             rock.x -= speed;
  91.             if (rock.x == 0) {
  92.                 stage.removeEventListener(Event.ENTER_FRAME, moveRock);
  93.                 rock.x = 850;
  94.                 rock.y = 520;
  95.                 stage.addEventListener(Event.ENTER_FRAME, moveRock);
  96.             }
  97.         }
  98.        
  99.     }
  100.    
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement