Actionscript Code:
onClipEvent (load) {
var ground:MovieClip = _root.ground;
var grav:Number = 0;
var gravity:Number = 2;
var speed:Number = 5;
var maxJump:Number = -18;
var scale:Number = _xscale;
var touchingGround:Boolean = false;
var dead=false;
this.gotoAndStop(3);
mySound = new Sound(this);
mySound.attachSound("player_jump.wav",isStreaming);
}
onClipEvent (enterFrame) {
_y += grav;
grav += gravity;
while (ground.hitTest(_x, _y - 1.8, true)) {
_y -= gravity;
grav = 0;
}
if (ground.hitTest(_x, _y + 5, true)) {
touchingGround = true;
} else {
touchingGround = false;
}
if (Key.isDown(Key.RIGHT)) {
_x += speed;
_xscale = scale;
isLeft=false;
isRight=true;
if (ground.hitTest(_x, _y + 2, true)) {
this.gotoAndStop(2);
} else {
this.gotoAndStop(3);
}
} else if (Key.isDown(Key.LEFT)) {
_x -= speed;
_xscale = -scale;
isLeft=true;
isRight=false;
if (ground.hitTest(_x, _y + 2, true)) {
this.gotoAndStop(2);
} else {
this.gotoAndStop(3);
}
} else {
if (_root.ground.hitTest(_x, _y + 2, true)) {
this.gotoAndStop(1);
}
}
if (Key.isDown(Key.UP) && touchingGround) {
grav = maxJump;
mySound.start();
this.gotoAndStop(3);
}
if (ground.hitTest(_x + (_width / 2.5), _y - (_height / 2), true)) {
_x -= speed;
}
if (ground.hitTest(_x - (_width / 2.5), _y - (_height / 2), true)) {
_x += speed;
}
if (ground.hitTest(_x, _y - (_height), true)) {
grav = 3;
}
}
onClipEvent(enterFrame){
if (_root.next_frame.hitTest(_x+1, _y, true)) {
_parent.nextFrame()
}
}
onClipEvent (enterFrame) {
if (_root.health.text<=0) {
health.text -= 5;
_root._x = 0;
maxJump=0;
_root.player.speed = 0;
this.gotoAndStop(4);
delete mySound
}
}
Actionscript Code:
onClipEvent (load) {
var speed:Number = 4;
var ground:MovieClip = _root.ground;
var grav:Number = 0;
var gravity:Number = 2;
var moveDir:String = "right";
var player_attack:MovieClip = _root.player.attack_point;
mySound = new Sound(this);
mySound.attachSound("killed_sound.wav",isStreaming);
}
onClipEvent (enterFrame) {
_y += grav;
grav += gravity;
while (ground.hitTest(_x, _y - 1.8, true) && !killed) {
_y -= gravity;
grav = 0;
}
//Movement
if (moveDir == "left") {
this._x -= speed;
} else {
this._x += speed;
}
//Check if your hitting "ground" but coming from the left
if (_root.ground.hitTest(_x - (_width / 2), _y - (_height / 2), true) || _root.ground.hitTest(_x - (_width / 2), _y - ((_height / 6) * 4), true)) {
if (moveDir == "left") {
moveDir = "right";
} else {
moveDir = "left";
}
}
//Check if your hitting "ground" but coming from the right
if (_root.ground.hitTest(_x + (_width / 2), _y - (_height / 2), true) || _root.ground.hitTest(_x + (_width / 2), _y - ((_height / 6) * 4), true)) {
if (moveDir == "left") {
moveDir = "right";
} else {
moveDir = "left";
}
}
if (_root.player.hitTest(_x + (_width / 2), _y - (_height / 2), true) || _root.player.hitTest(_x + (_width / 2), _y - ((_height / 6) * 4), true)) {
trace("player should of died");
}
if (_root.player.hitTest(_x - (_width / 2), _y - (_height / 2), true) || _root.player.hitTest(_x - (_width / 2), _y - ((_height / 6) * 4), true)) {
trace("player should of died");
}
if (this._parent.player.attack_point.hitTest(this) && !killed) {
_root.player.grav = _root.player.maxJump;
trace(_root.player.grav);
this.gotoAndStop(7);
speed = 0;
mySound.start();
_root.score.text++;
killed = true;
}
}