Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //variables
- var allDown:Boolean=false
- if(rightDown=true && leftDown==true){
- allDown=true
- }
- var allUp:Boolean=true
- if(rightDown=false && leftDown==false){
- allUp=true
- }
- var rightDown:Boolean=false
- var leftDown:Boolean=false
- var playerXSpeed:int=0
- var playerYSpeed:int=0
- var maxPositiveSpeed:int=10
- var maxNegativeSpeed:int=maxPositiveSpeed-maxPositiveSpeed*2
- //event listeners
- stage.addEventListener(Event.ENTER_FRAME, updateGame);
- addEventListener(KeyboardEvent.KEY_DOWN, keyHandler);
- addEventListener(KeyboardEvent.KEY_UP, keyHandler);
- //functions
- function updateGame(event){
- movePlayer();
- updateSpeed();
- }
- function movePlayer(){
- player.x+=playerXSpeed
- }
- function updateSpeed(){
- if(rightDown==true && playerXSpeed>maxPositiveSpeed){
- playerXSpeed+=1
- }
- if(leftDown==true && playerXSpeed>maxNegativeSpeed){
- playerXSpeed-=1
- }
- if(allUp==true && playerXSpeed<0){
- playerXSpeed-=1
- }
- if(allUp==true && playerXSpeed>0){
- playerXSpeed+=1
- }
- }
- function keyHandler(event){
- if(event.keyCode==68 || event.keyCode==39){
- if(rightDown==true){
- rightDown=false
- }
- else{
- rightDown=true
- }
- }
- if(event.keyCode==65 || event.keyCode==37){
- if(leftDown==true){
- leftDown=false
- }
- else{
- leftDown=true
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement