# Asteroids 2.01: Making the Asteroids Move

With a taste of success under my belt, I started remaking the Asteroids game using ActionSctipt 2.0 and class structure.

``` class Asteroid extends MovieClip { // velocity value for the Asteroid's x- and y- movement private var xv:Number; private var yv:Number; // rotation of the Asteroid, so it looks like it drifts // in outer space private var r:Number; // this is the constructor function, which initializes // each Asteroid instance. It must be a public function // or it won't be able to be accessed by the Flash movie. private function Asteroid () { // shorten up some Math functions var mr = Math.random; var mf = Math.floor; // set the velocity for the Asteroid xv = mf( mr() * 6 ) - 3; yv = mf( mr() * 6 ) - 3; // set the Asteroid's original rotation. r = mf( mr() * 360 ) - 180; _rotation = r; } // Each Asteroid will now encapsulates, or // determintes its own movement. This will // improve performance over the original // game, where one onEnterFrame on the _root // controlled everything. private function onEnterFrame():Void { // This series of if statements simply guides the placement // of an asteroid as it floats near the borders of the movie. if ( _x < = 10 ) { _x += 390; } if ( _x >= 390 ) { _x -= 390; } if ( _y < = 10 ) { _y += 140; } if ( _y >= 140 ) { _y -= 140; } // Keep the Asteroid moving per its velocity _x += xv; _y += yv; // Keep the Asteroid rotating on its axis, as if it were floating // in space. _rotation += r / 60; } } ```