Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 01-18-2011, 03:44 PM   #1
Zflash8
Registered User
 
Join Date: Dec 2010
Posts: 8
Default [AS2] How to do Slope Detection

Hey guys,I want to make a slope detection in my game but i am not good at actionscripts!!!!....The instance name of my character is char.The code that contains in my character is:


onClipEvent (load) {
var speed:Number = 15;
fight = false;
}
onClipEvent (enterFrame) {
if (fight == false) {
if (Key.isDown(65) && fight != true) {
this._x -= speed;
//walk left
this._xscale = -100;
this.gotoAndStop(2);
} else if (Key.isDown(68) && fight != true) {
this._x += speed;
//walk right
this._xscale = 100;
this.gotoAndStop(2);
} else if (Key.isDown(83) && fight != true) {
this.gotoAndStop(8);
//crouch
} else {
this.gotoAndStop(1);
}
}
if (Key.isDown(74)) {
// otherwise if J is pressed
this.gotoAndStop(3);
//punch
fight = true;
}
if (Key.isDown(75)) {
// otherwise if K is pressed
this.gotoAndStop(9);
//headpunch
fight = true;
}
if (Key.isDown(76)) {
// otherwise if L is pressed
this.gotoAndStop(7);
//kick
fight = true;
}
if (Key.isDown(85)) {
// otherwise if U is pressed
this.gotoAndStop(4);
//headbutt
fight = true;
}
if (this._currentframe == 1) {
fight = false;
}
}
onClipEvent (load) {
var ground:MovieClip = _root.ground;
var grav:Number = 0;
var gravity:Number = 2;
var maxJump:Number = -20;
var touchingGround:Boolean = false;
}
onClipEvent (enterFrame) {
_y += grav;
grav += gravity;
while (ground.hitTest(_x, _y, true)) {
_y -= gravity;
grav = 0;
}
if (ground.hitTest(_x, _y+5, true)) {
touchingGround = true;
} else {
touchingGround = false;
}
if (Key.isDown(87) && touchingGround) {
grav = maxJump;
this.gotoAndStop(5);
//jump
}
if (ground.hitTest(_x+(_width/2), _y-(_height/2), true)) {
_x -= speed;
}
if (ground.hitTest(_x-(_width/2), _y-(_height/2), true)) {
_x += speed;
}
if (ground.hitTest(_x, _y-(height), true)) {
grav = 3;
}
}

So please,if you guys know how to do it....Please post replies!!!!......
Zflash8 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 10:30 PM.

///
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.