PDA

View Full Version : [AS2] How to do Slope Detection


Zflash8
01-18-2011, 03:44 PM
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!!!!......