Flash Games
 FAQ   Search   Memberlist   Usergroups   Register  Profile   Log in to check your private messages   Log in 


anyone have a code that makes an object move in 8 directions



 

Post new topic   Reply to topic  
   DEVPPL Forum Index -> Flash Forum
View previous topic :: View next topic  
Author Message
Solar42693



Joined: 11 Jul 2006
Posts: 35

PostPosted: Thu Jul 13, 2006 12:32 am    Post subject: anyone have a code that makes an object move in 8 directions Reply with quote

i've tried 3 or 4 but i couldn't get any to work right

thanks
Back to top
View user's profile Send private message
Samuel Rounce
100+ Club


Joined: 30 Oct 2005
Posts: 116
Location: London, UK

PostPosted: Sat Jul 15, 2006 2:13 am    Post subject: Re: anyone have a code that makes an object move in 8 directions Reply with quote

Explain it better and I may be able to help you, I normally can as long as I know what you're talking about.
Back to top
View user's profile Send private message AIM Address MSN Messenger
Solar42693



Joined: 11 Jul 2006
Posts: 35

PostPosted: Sat Jul 15, 2006 4:48 pm    Post subject: Re: anyone have a code that makes an object move in 8 directions Reply with quote

Explained Better: Do you have an actionscript code i can apply to a movieclip to make it rotate, face, and move in 8 directions by using the arrow keys, up to go forward in the direction your facing, right to rotate to the right, left to rotate to the left, and down to go backwards from the direction your facing. Like a spaceship or something.
Back to top
View user's profile Send private message
Solar42693



Joined: 11 Jul 2006
Posts: 35

PostPosted: Sat Jul 15, 2006 4:51 pm    Post subject: Re: anyone have a code that makes an object move in 8 directions Reply with quote

For example, the spaceship in this game http://addictinggames.com/asteroidsduel.html
Back to top
View user's profile Send private message
Samuel Rounce
100+ Club


Joined: 30 Oct 2005
Posts: 116
Location: London, UK

PostPosted: Sat Jul 15, 2006 6:48 pm    Post subject: Re: anyone have a code that makes an object move in 8 directions Reply with quote

Although I'd rather write a post walking you through how to do this, I've never tried flash game programming so I'm not too sure myself but a quick google around got me:

http://www.adobe.com/devnet/flash/articles/asteroids.html

That should contain what you were after.

I don't mean any offence here but you seem pretty new to flash and actionscript, I recommend getting a book or doing beginner tutorials for the basics rather than just copying and pasting code and not fully knowing what all of it does.
Back to top
View user's profile Send private message AIM Address MSN Messenger
Solar42693



Joined: 11 Jul 2006
Posts: 35

PostPosted: Sun Jul 16, 2006 1:17 am    Post subject: Re: anyone have a code that makes an object move in 8 directions Reply with quote

Thanks for the site, and about the beginner tutorials thing, I've done most of those. It's moving on to the intermediate tutorials that's the problem lol.
Back to top
View user's profile Send private message
Solar42693



Joined: 11 Jul 2006
Posts: 35

PostPosted: Sun Jul 16, 2006 6:36 pm    Post subject: Re: anyone have a code that makes an object move in 8 directions Reply with quote

After cutting down the code from that website here's the code for anyone else that wants it. Just create a movieclip and give it an instance name of ship.
Code:

function makeShip (){
   
   ship.angle = 0;    
   ship.xv = 0;       
   ship.x = 0;       
   ship.y = 0;       
   ship.yv = 0;       
   ship.xa = 0;       
   ship.ya = 0;       
   ship.v = 0;       
   ship.visc = 0.02;    
   ship.drag = 0;       
   
   
   mp = Math.PI, mpow = Math.pow, msr = Math.sqrt;
   
   ship.onEnterFrame = function() {
      
      if (Key.isDown(Key.RIGHT)) {
         this.torque = 5;
      } else if (Key.isDown(Key.LEFT)) {
         this.torque = -5;
      } else {
         this.torque = 0;
      }

      this.rtorque = 0.5*this.AngVelocity;
      this.AngAcceleration = this.torque-this.rtorque;
      this.AngVelocity += this.AngAcceleration;
      this.angle += this.AngVelocity;

      if (this.angle<0) {
         this.angle += 360;
      }
      if (this.angle>360) {
         this.angle -= 360;
      }

      this.v = msr(mpow(this.xv, 2)+mpow(this.yv, 2));
      this.drag = this.visc*this.v;

      
      if (Key.isDown(Key.UP)) {
         this.force = 1;
      } else {
         this.force = 0;
      }
      this.xa = ((this.drag*this.xv)*-1)+(this.force*Math.sin(mp/180*this.angle));
      this.ya = ((this.drag*this.yv)*-1)-(this.force*Math.cos(mp/180*this.angle));
      this.xv += this.xa;
      this.yv += this.ya;
      this._y += this.yv;
      this._x += this.xv;
      this._rotation = this.angle;

   };
}

function Game() {
   
   doo = new makeShip();
   
}

foo=new Game();



Apply this to the actionscript on the keyframe, not on the actual mc.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    DEVPPL Forum Index -> Flash Forum All times are GMT + 1 Hour
Page 1 of 1

 
 
Welcome to DEVPPL.com
You are not logged in, which means that you can't post in the forums.
Click here to Register

If you are a current member here on DEVPPL, please login below:

User: Pass:
Log me on automatically each visit:

 


Powered by phpBB © 2001, 2005 phpBB Group - Modified by DEVPPL

Flash Games - Sitemap