Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 07-28-2004, 07:23 AM   #1
kristof88
Registered User
 
Join Date: Jul 2004
Posts: 8
Default [AS1] Platform game help

Well, I've got this code here for my character. It's instance name is 'circle', though the character itself is animated, that's just to keep it simple.
PHP Code:
onClipEvent (load) {
     
fall false;
     
_name "circle";
     
jump 0;
     
speed 6;
     
jumpheight 11;
     
maxfall = -54;
}
onClipEvent (enterFrame) {
     
xmin getBounds(_root).xMin;
     
xmax getBounds(_root).xMax;
     
ymin getBounds(_root).yMin;
     
ymax getBounds(_root).yMax;
     if (
Key.isDown(Key.SPACE) && fall == false && jump == undefined) {
          
fall true;
          
jump jumpheight;
     }
     if (
jump<>undefined) {
          if (
jump>maxfall) {
               
jump--;
          }
          
_y -= jump;
     }
}
onClipEvent (enterFrame) {
     if (
Key.isDown(Key.LEFT)) {
          
_x -= speed;
          if(
_xscale==100){_xscale=-100;}
     }
     if (
Key.isDown(Key.RIGHT)) {
          
_x += speed;
          if(
_xscale==-100){_xscale=100;}
     }

Now, this makes the character land on a platform and turn around fine, though my characters movie clip is one frame long, and therefore animated within itself(you know, when you double click). And the character keeps walking no matter what button you press(or don't press). So I need a code to make the character stop walking when no buttons are pressed.
Thanks.

PS. The platform code I have is this:
PHP Code:
onClipEvent (load) {
     
activated false;
     
down false;
}
onClipEvent (enterFrame) {
     
_root.report.text Math.round(_root.circle.yMax)+" "+Math.round(yMin);
     
xmin getBounds(_root).xMin;
     
xmax getBounds(_root).xMax;
     
ymin getBounds(_root).yMin;
     
ymax getBounds(_root).yMax;
     if (
_root.circle.xMax>xMin && _root.circle.xMin<xMax && _root.circle.yMax<yMin) {
          if (
_root.circle.yMax-_root.circle.jump*2>yMin) {
               
_root.circle._y ymin-_root.circle._height/2;
               
_root.circle.jump undefined;
               
_root.circle.fall false;
               
activated true;
          }
     }
     if (
Math.round(_root.circle.yMax)>Math.round(yMin)) {
          if (
hitTest(_root.circle) && _root.circle.xmax<xmin) {
               
_root.circle._x -= _root.circle.speed;
          }
          if (
hitTest(_root.circle) && _root.circle.xmin>xmax) {
               
_root.circle._x += _root.circle.speed;
          }
          if (
hitTest(_root.circle) && _root.circle.ymin>ymax && _root.circle.jump>-1) {
               
_root.circle.jump = -1*(_root.circle.jump);
          }
     }
     if (
activated == true && not hitTest(_root.circle) && _root.circle.jump == undefined) {
          
_root.circle.jump 0;
          
activated false;
     }
     if (
hitTest(_root.circle) && _root.circle.ymax>ymin && _root.circle.jump<>undefined && _root.circle._y<_y) {
          
_root.circle._y ymin-_root.circle._height/2;
          
_root.circle.jump undefined;
          
_root.circle.fall false;
          
activated true;
     }
     if (
_root.circle.ymax-_root.circle.jump>ymin && _root.circle.xMin<xMax && _root.circle.xMax>xMin && _root.circle.jump<>undefined && _root.circle._y<_y) {
          
_root.circle._y ymin-_root.circle._height/2;
          
_root.circle.jump undefined;
          
_root.circle.fall false;
          
activated true;
     }

Maybe that can help......

Last edited by CyanBlue; 08-03-2004 at 04:47 PM. Reason: PHP tag is applied
kristof88 is offline   Reply With Quote
Old 07-28-2004, 06:16 PM   #2
kristof88
Registered User
 
Join Date: Jul 2004
Posts: 8
Default

Anyone? C'mon, SOMEONE must know.
kristof88 is offline   Reply With Quote
Old 07-28-2004, 06:36 PM   #3
speedlemon
Registered User
 
speedlemon's Avatar
 
Join Date: Jun 2004
Location: U.S.A.
Posts: 108
Default

try using code tags.
it makes it a little easier to read.
speedlemon is offline   Reply With Quote
Old 07-28-2004, 06:41 PM   #4
speedlemon
Registered User
 
speedlemon's Avatar
 
Join Date: Jun 2004
Location: U.S.A.
Posts: 108
Default

PHP Code:
onClipEvent(keyUp){
     
gotoAndStop(1//or where ever your standing still frame(s) is/are

should do the trick

Last edited by speedlemon; 07-28-2004 at 06:42 PM. Reason: add code tags.
speedlemon is offline   Reply With Quote
Old 07-29-2004, 07:15 AM   #5
kristof88
Registered User
 
Join Date: Jul 2004
Posts: 8
Default

Thanks, though it should gotoandstop on the first frame of the movie clip...how do you do that?
kristof88 is offline   Reply With Quote
Old 07-29-2004, 09:09 AM   #6
Crismo
Senior Member
 
Crismo's Avatar
 
Join Date: Jul 2003
Location: Norway
Posts: 296
Send a message via ICQ to Crismo Send a message via Skype™ to Crismo
Default

What you should do is to insert a stop command in the first frame of your character.
Then in the characters enter frame event handler you would test for the key down.
If the key is down you tell the character to go to the next frame and stop.
Else you don't do anything (and it stays in place).
Remember that you need to test for the last frame of the character animation so that you can circle back to the first frame.

Ideally you should have the animation connected to the speed of the character and not the key (it kind of depends on the game physics, but I noticed a speed variable in your code).

The following is code from a game I made that uses this approach.

ActionScript Code:
// Updating runners visiual aperanc. if (!(runner_mc._currentframe == RUN_END) && speed > MIN_SPEED) {     runner_mc.nextFrame(); } else if ((runner_mc._currentframe == RUN_END) && speed >MIN_SPEED) {     runner_mc.gotoAndStop(RUN_START); }

Last edited by Crismo; 07-29-2004 at 09:11 AM.
Crismo is offline   Reply With Quote
Old 07-29-2004, 03:59 PM   #7
speedlemon
Registered User
 
speedlemon's Avatar
 
Join Date: Jun 2004
Location: U.S.A.
Posts: 108
Default

Quote:
Originally Posted by kristof88
Thanks, though it should gotoandstop on the first frame of the movie clip...how do you do that?
as far as i know it should anyways, but if it isnt -
_root.movieclipnamegoeshere.gotoAndStop(1)
speedlemon is offline   Reply With Quote
Old 07-29-2004, 05:00 PM   #8
kristof88
Registered User
 
Join Date: Jul 2004
Posts: 8
Default

PHP Code:
onClipEvent (load) {
fall false;
_name "circle";
jump 0;
speed 6;
jumpheight 11;
maxfall = -54;
}
onClipEvent (enterFrame) {
xmin getBounds(_root).xMin;
xmax getBounds(_root).xMax;
ymin getBounds(_root).yMin;
ymax getBounds(_root).yMax;
if (
Key.isDown(Key.SPACE) && fall == false && jump == undefined) {
fall true;
jump jumpheight;
}
if (
jump<>undefined) {
if (
jump>maxfall) {
jump--;
}
_y -= jump;


}
}
onClipEvent (enterFrame) {
if (
Key.isDown(Key.LEFT)) {
_x -= speed;
if(
_xscale==100){_xscale=-100;}
_root.circle.gotoAndPlay(2)
}
if (
Key.isDown(Key.RIGHT)) {
_x += speed;
if(
_xscale==-100){_xscale=100;}
_root.circle.gotoAndPlay(2)
}

That's the code I have now, and a stop command in the first frame of the MC. The problem now is that the MC only plays when you lift the button, and then it only loops once....I've got an idea on how to fix that, though, I just have to put a Gotoandplay the second frame of the MC at the last frame of that MC. Anyways, how can I make the walking animation play while the button is pressed?
kristof88 is offline   Reply With Quote
Old 07-31-2004, 09:30 AM   #9
kristof88
Registered User
 
Join Date: Jul 2004
Posts: 8
Default

Anyone?
kristof88 is offline   Reply With Quote
Old 08-03-2004, 04:32 PM   #10
kristof88
Registered User
 
Join Date: Jul 2004
Posts: 8
Default

Come on, someone has to know.....
kristof88 is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:49 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.