Created
May 30, 2019 08:34
-
-
Save Olbergx/6de0f1f41fee7b6d4a3cd8ca23d022a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import flash.events.KeyboardEvent; | |
import flash.display.MovieClip; | |
import flash.events.MouseEvent; | |
var up,down,left,right = 0; | |
stage.addEventListener(MouseEvent.MOUSE_MOVE, moveMouse) | |
function moveMouse(event:MouseEvent):void { | |
Mouse.hide(); | |
mc1.x = mouseX; | |
mc1.y = mouseY; | |
event.updateAfterEvent(); | |
} | |
stage.addEventListener(KeyboardEvent.KEY_DOWN, fun); | |
function fun (e:KeyboardEvent):void | |
{ | |
if (e.keyCode == Keyboard.LEFT || e.keyCode == 65) { | |
mc.x -=5; | |
mc.rotation =0; | |
// trace(mc.x); | |
left = 1; | |
} | |
if (e.keyCode == Keyboard.RIGHT || e.keyCode == 68) { | |
mc.x +=5; | |
mc.rotation =180; | |
// trace(mc.x); | |
right = 1; | |
} | |
if (e.keyCode == Keyboard.DOWN || e.keyCode == 83) { | |
mc.y +=5; | |
mc.rotation =270; | |
// trace(mc.y); | |
down = 1; | |
} | |
if (e.keyCode == Keyboard.UP || e.keyCode == 87) { | |
mc.y -=5; | |
mc.rotation =90; | |
// trace(mc.y); | |
up = 1; | |
} | |
} | |
//---------------------------------- | |
// запрет на передвижение, если пчелка возле краёв экрана | |
if (mc.y <=mc.height/2) | |
{ | |
up = 0; | |
mc.y +=5; | |
} | |
if (mc.y >= stage.stageHeight-mc.height/2) | |
{ | |
down = 0; | |
mc.y -=5; | |
} | |
if (mc.x <= mc.width/2) | |
{ | |
left = 0; | |
mc.x+=5; | |
} | |
if (mc.x >= stage.stageWidth-mc.width/2) | |
{ | |
right = 0; | |
mc.x-=5; | |
} | |
//------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment