Hey guys, I have been posting for a while on my game that I am currently working on. We have figured out the gravity, thanks to sacrificial lamb :D, but there are so many other problems I have not been able to figure out for the past 2 weeks. So for now, I am just making a post with ALL of my problems in some hope that you guys could help me out.
I can attach the Fla tommorow if needed.
Here is the code to the side movements and jumping:
onClipEvent (enterFrame) {
fall += 2;
//How can I have the camera follow him up and down when he falls to a lower platform?
if (walking) {
if (Key.isDown(Key.LEFT)) {
xspeed = -speed;
this._xscale = -100;
this.gotoAndStop("run");
_root._x += speed;
} else if (Key.isDown(Key.RIGHT)) {
xspeed = speed;
this._xscale = 100;
this.gotoAndStop("run");
_root._x -= speed;
} else {
xspeed = 0;
this.gotoAndStop("idle");
walking = false;
}
}
for (i=1; i<=platforms; i++) {
ground = _root["g"+i];
if (ground.hitTest(this._x, this._y+1, true)) {
fall = 0;
walking = true;
//jumping
//How can I have the camera follow him when he jumps side to side as well?
if (Key.isDown(Key.SPACE) && fall<1 && jumping == false) {
if (Key.isDown(Key.LEFT)) {
this.gotoAndStop("jump_run");
_root._x += speed;
} else if (Key.isDown(Key.RIGHT)) {
_root._x -= speed;
this.gotoAndStop("jump_run");
} else {
this.gotoAndStop("jump");
}
fall = -20;
walking = false;
}
} else if (ground.hitTest(this._x, this._y+fall, true)) {
while (ground.hitTest(this._x, this._y+fall, true)) {
fall--;
}
walking = true;
jumping = false;
}
}
this._y += fall;
this._x += xspeed;
-
The first problem, is how I can have the camera follow him when he falls to a lower platform. As you can see I have the camera (_root) change when he moves side to side, how can I have this done when he jumps to a higher platform or falls to a lower one?
-
The second problem is in the jumping, when the character moves side to side as previously stated, the _root follows him by changing its _x. But when he jumps side to side the _root remains still. How can I have the root move side to side just like how he runs side to side as well?
Here is the code to the regular attack:
//regular attack
//Why does this not work correctly?
if (Key.isDown(65) && !this.fight) {
this.fight = true;
this.gotoAndStop("attack");
}
this.fight = false;
- My problem here, is that when A is pressed, he will go to the frame inside of him named “attack”, on this frame is a movieclip of his attack punch, which is also how the running is done. But the problem is when you press A he will only go to the first frame of the attack motion and will not play the entire punch, I have no idea how to fix this…
Here is the code to the gun:
//gun shooting
bulletlayer = _root.createEmptyMovieClip("bulletlayer", 99);
bulletcount = 0;
gunshoot = function (type, x, y, dx) {
var nm = "bull"+bulletcount;
bulletlayer.attachMovie(type, nm, bulletcount);
bulletlayer[nm]._x = x;
bulletlayer[nm]._y = y;
bulletlayer[nm].dx = dx;
bulletlayer[nm].onEnterFrame = function() {
//why does this not apply and move the bullet?
this._x += this.dx;
if (this._x<=-10) {
this.removeMovieClip();
}
};
bulletcount++;
bulletcount %= 10;
};
if (this.hitTest(_root.gun)) {
gun = true;
//why does the gun not remove itself?
_root.gun.removeMovieClip();
}
if (Key.isDown(83) && gun == true) {
walking = false;
this.gotoAndStop("char_gun");
gunshoot("bullet", this._x, this._y, 10);
}
-
This gun has been giving me lots of issues, in the first part of the code, where the x and y positions are declared in the function, work fine. But the bulletlayer[nm].onEnterFrame function will not work, The bullet simply appears at his feet for as long as you have the button pressed down. How can I fix this as well? :h:
-
My last problem in the gun coding, is when the character hits the root.gun, it will not remove itself, I am at a loss as to how to fix this.
Finally, the last bit of code:
//crouching
//How can I have it so if you are running and then crouch, he will not slide? (same with shooting)
if (Key.isDown(Key.DOWN)) {
this.gotoAndStop("crouch");
walking = false;
}
- The crouch, when he crouches everything goes to plan, but If I am running before I hit the down key, he will go into a crouch position and just slide, I don’t know how to fix this either…
Well this was a lot, I’m sorry if it is too much, but I have been trying to troubleshoot the problems for about 2 weeks now to no avail. I hope some of you A.S. gods out there can figure this stuff out, and It will be much appreciated.