Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Space Invaders Type Game

Status
Not open for further replies.

N64MARIO64

Technical User
Nov 17, 2002
11
US
I'm working on a space invaders type game and I'm working on learning Action Script. If someone can help and tell me the code to make the ship move up and down. The target name is 'ship' Thanks -mario
 
These scripts should be put in the 'ship' movie clip. I believe they are all correct but since I haven't been able to check them, write back if there's a problem.


// THIS SCRIPT ASSUMES YOU WANT THE SHIP TO MOVE WHILE THE UP AND DOWN BUTTONS ARE BEING HELD.


onClipEvent (load)
speed = 2
// The higher you set the variable speed, the faster the ship will move.
}

onClipEvent (enterFrame)
if (Key.isDown(Key.UP) && !Key.isDown(Key.DOWN)
setProperty("_root.ship", _y, ("_root.ship", _y) - speed);
}

if (Key.isDown(Key.DOWN) && !Key.isDown(Key.UP)
setProperty("_root.ship", _y, ("_root.ship", _y) + speed);
}
}


// THIS SCRIPT ASSUMES YOU WANT THE SHIP TO MOVE EACH TIME THE UP AND DOWN BUTTONS ARE PRESSED.


onClipEvent (load)
speed = 2
// The higher you set the variable speed, the faster the ship will move.
}

onClipEvent (keyDown) {
if (Key.getCode(Key.DOWN))
setProperty("_root.ship", _y, ("_root.ship", _y) + speed);
}
if (Key.getCode(Key.UP))
setProperty("_root.ship", _y, ("_root.ship", _y) - speed);
}
}



// THIS SCRIPT ASSUMES YOU WANT THE SHIP TO MOVE WITH THE MOUSE.


onClipEvent (enterFrame)
setProperty("_root.ship", _y, _ymouse);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top