// code.main
//
//
var dist = 4;
//
function updateGuy() {
// called upon key event
// move the ship based on key just pressed
//
switch (Key.getCode()) {
case Key.UP : //we 0 alpha the other char states anjust show the active one
guy._alpha = 0;
guyup._alpha = 100;
guyleft._alpha = 0;
guydown._alpha = 0;
guyup._x = guy._x; //gives correct horiz position
if (guyup._y > 310){ //sets up boundaries
guyup._y -= dist; //moves
}
else {guyup._y = guyup._y;} //doesnt move
guydown._y = guyup._y; //haveto pass current value for other functions
break;
case Key.DOWN :
guy._alpha = 0;
guyup._alpha = 0;
guyleft._alpha = 0;
guydown._alpha = 100;
guydown._x = guy._x;
if (guydown._y <410){
guydown._y += dist;
}
else {guydown._y = guydown._y;}
guyup._y = guydown._y;
break;
case Key.LEFT :
guy._alpha = 0;
guyup._alpha = 0;
guyleft._alpha = 100;
guydown._alpha = 0;
// guyup._x = guy._x; //
guyleft._y = guyup._y;
if (guyleft._x <= 3) { //hit left screen boundary
guyleft._x = guyleft._x;
}
else {guyleft._x -= dist;} //move left
guy._x = guyleft._x; //save x position
break;
case Key.RIGHT :
guy._alpha = 100;
guyup._alpha = 0;
guyleft._alpha = 0;
guydown._alpha = 0;
guy._y = guyup._y; //keep y constant
guy._x += dist; //move right
if (guy._x >= Stage.width) { //hit right border
guy._x = 1; //reset x, so starts at left of next screen
gotoAndPlay(5);
}
guyleft._x = guy._x; //pass on the x value
break;
}
}
|
|