Be a Supporter!

AS2 movement code

  • 279 Views
  • 8 Replies
New Topic Respond to this Topic
SmallPete
SmallPete
  • Member since: Aug. 3, 2010
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
AS2 movement code 2010-12-02 11:30:25 Reply

hi folks hope your well, im having some trouble getting my player to actually walk rather then run
here is my code

if (Key.isDown(16) && xaccel<maxwlkaccel && falling == false) {
xaccel += walkaccelamt;
gwalking = true;
trace(gwalking);
} else {
gwalking = false;
trace(gwalking);
}
if (Key.isDown(Key.LEFT) && xaccel>-maxaccel && falling == false && gwalking == false) {
/*If the left arrow key is pressed and xaccel does not excede its maximum speed
and falling is false (not falling), then:*/
xaccel -= runaccelamt;
//xaccel minuses the amount set for runaccelamt
} else if (Key.isDown(Key.RIGHT) && xaccel<maxaccel && falling == false && gwalking == false) {
/*Otherwise if the right arrow key is pressed and xaccel does not excede its maximum speed
and falling is false (not falling), then:*/
xaccel += runaccelamt;
gwalking = false;

here are my vars

gravityaccel = .2;//The amount gravity accelerates by
runaccelamt = .3;//The amount the guy accelerates by when he runs
walkaccelamt = .1;
friction = .2;//The friction of the ground
airrisist = .05;//The risistance of the air
waterrisist = 1.5;//The risistance of the water
maxwlkaccel = 1;
maxaccel = 3;//The maximum speed the guy can run
maxjump = 5;//The maximum height the guy can jump

if shift is pressed and any of the directions then the player should walk rather then run, im not doing this right but cant find a solution, can any one help? thanks!

SmallPete
SmallPete
  • Member since: Aug. 3, 2010
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to AS2 movement code 2010-12-02 12:49:37 Reply

anybody jee

YoinK
YoinK
  • Member since: Jan. 5, 2001
  • Offline.
Forum Stats
Member
Level 60
Game Developer
Response to AS2 movement code 2010-12-02 14:12:37 Reply

you forgot to declare your Boolean variables...


Kanye West Did What??????
They should make a black guy the manager, they know how to run shit!
2 Girls 1 Cup .... THE SONG!!!!

YoinK
YoinK
  • Member since: Jan. 5, 2001
  • Offline.
Forum Stats
Member
Level 60
Game Developer
Response to AS2 movement code 2010-12-02 14:15:32 Reply

you also need to tell what needs to move... what's the instance of your player????

like.... player._x += 5;
would enable the player to move right at speed of five.


Kanye West Did What??????
They should make a black guy the manager, they know how to run shit!
2 Girls 1 Cup .... THE SONG!!!!

SmallPete
SmallPete
  • Member since: Aug. 3, 2010
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to AS2 movement code 2010-12-02 16:37:20 Reply

u mean like all the variables ? ive got them all, double checked them all

SmallPete
SmallPete
  • Member since: Aug. 3, 2010
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to AS2 movement code 2010-12-02 16:39:28 Reply

i have my movement code later on in the code, thats just what im showing you because thats the part ive tried to create for the walking

guy._y += gravity;//Move the guy's y posistion (up and down) according to gravity
guy._x += xaccel;//Move the guy's x posistion (left and right) accor

SmallPete
SmallPete
  • Member since: Aug. 3, 2010
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to AS2 movement code 2010-12-02 19:21:18 Reply

juba/,

SmallPete
SmallPete
  • Member since: Aug. 3, 2010
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to AS2 movement code 2010-12-03 08:58:52 Reply

ping

CyberXR
CyberXR
  • Member since: Aug. 22, 2008
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS2 movement code 2010-12-03 11:42:06 Reply

At 12/3/10 08:58 AM, SmallPete wrote: ping

The thing is that you do not need to declare variabels in AS2. For instance you can write "walking = false" and the compiler will automatically declare it as a bool. However, there could be many things that mess up the code, doesn't need to be the code itself. Make sure to know when to use global variables and how to access them; also, as someone already noticed, the instance names are important.

I am sorry, cant say whats right or wrong at this moment without looking at the construction of your program


Check out the coolest Donkey Kong Game on NG!
http://www.newgrounds.com/portal/vi ew/459064
100 posts @ Posted at: 9/15/08 07:36 AM http://www.newgrounds.com/bbs/topic /969232