Platformer/ Side-Scroller Issues

Ok, I’ve been working on this game for months now…well, just started working on it after months…Most things are working…

I am having problems with the collisions section dealing with the screen still moving slightly off track when I hit a wall.

My enemy doesn’t seem to fall, kinda floats (doesn’t start ON platform). Enemy doesn’t jump up to platform when reaching a wall.

Both characters get wider the moment they start walking.

…and anything else you notice wrong with the coding…here it is


stop();
_global.attack = false;

var g:Number = .3;
var f:Number = .5;
miscar._x = 120;
miscar.vx = 0;
miscar.vy = 0;
miscar.power = 5;
miscar.jump = -10;
miscar.jumping = false;
miscar.health = 50;
enemy.vx = 0;
enemy.vy = 0;
enemy.power = .5;
enemy.jump = -10;
enemy.jumping = false;
//for (i=1;i<=10;i++){
//_root["wall"+i]._visible=false
//_root["platform"+i]._visible=false
//}
this.onEnterFrame = function() {
	brain(enemy,miscar);
	miscar.vx *= f;
	miscar.vy += g;
	miscar._y += miscar.vy;
	healthbar.gotoAndStop(miscar.health);
	if (miscar.health<=0) {
		cleanup();
	}
	if (miscar._x>=(Stage.width/2)-10 && miscar._x<=(Stage.width/2)+10) {
		for (i=1; i<=10; i++) {
			_root["wall"+i]._x -= miscar.vx;
			_root["platform"+i]._x -= miscar.vx;
		}
		stage1._x -= miscar.vx;
		enemy._x -= miscar.vx;
	} else {
		miscar._x += miscar.vx;
	}
	updater(enemy);
	if (_global.attack == false) {
		if (duck == false) {
			if (miscar.jumping == false) {
				if (Key.isDown(Key.LEFT) && !_root.ground.hitTest(miscar._x-(miscar._width/2)-3, miscar._y, true)) {
					miscar._xscale = -100;
					miscar.vx -= miscar.power;
					miscar.gotoAndStop("walk");
				} else if (Key.isDown(Key.RIGHT) && !_root.ground.hitTest(miscar._x+(miscar._width/2)+3, miscar._y, true)) {
					miscar.vx += miscar.power;
					miscar._xscale = 100;
					miscar.gotoAndStop("walk");
				} else {
					miscar.gotoAndStop("stand");

				}
			}
			if (miscar.jumping == true) {
				if (Key.isDown(Key.LEFT) && !_root.ground.hitTest(miscar._x-(miscar._width/2)-3, miscar._y, true)) {
					miscar._xscale = -100;
					miscar.vx -= miscar.power;
				} else if (Key.isDown(Key.RIGHT) && !_root.ground.hitTest(miscar._x+(miscar._width/2)+3, miscar._y, true)) {
					miscar.vx += miscar.power;
					miscar._xscale = 100;
				}
				miscar.gotoAndStop("jump");
			}
			if (duck == true) {
				if (Key.isDown(Key.LEFT) && !_root.ground.hitTest(miscar._x-(miscar._width/2)-3, miscar._y, true)) {
					miscar._xscale = -100;

				} else if (Key.isDown(Key.RIGHT) && !_root.ground.hitTest(miscar._x+(miscar._width/2)+3, miscar._y, true)) {
					miscar._xscale = 100;
				}
			}
		}
	}
	if (Key.isDown(Key.SPACE) && !miscar.jumping) {
		miscar.vy += miscar.jump;
		miscar._y += miscar.jump;
		miscar.jumping = true;
		miscar.gotoAndStop("jump");

	}
	if (Key.isDown(Key.DOWN) && !miscar.jumping) {
		duck = miscar.gotoAndStop("duck");
		duck = true;
		f = 0;
		if (duck == false) {
			f = .5;
		}
	} else {
		duck = false;
	}
	if (Key.isDown(Key.SHIFT) && !miscar.jumping) {
		_global.attack = miscar.gotoAndStop("attack");
		_global.attack = true;
		if (_global.attack == true) {
			f = 0;
		}
	} else {
		_global.attack == false;
		f = .5;
	}
	collisions(miscar);
	collisions(enemy);
};
function updater() {
	ob.vx *= f;
	ob.vy += g;
	ob._x += ob.vx;
	ob._y += ob.vy;
}
function collisions(ob) {
	for (i=1; i<=10; i++) {
		while (_root["platform"+i].hitTest(ob._x, ob._y-(ob._height/2), true)) {
			ob._y --;
			ob.vy = 0;
		}
		while (_root["platform"+i].hitTest(ob._x+(ob._width)/3, ob._y+(ob._height/18), true) || _root.ground.hitTest(ob._x-(ob._width)/3, ob._y+(ob._height/2), true)) {
			ob._y -= .1;
			ob.vy = 0;
			ob.jumping = false;
		}
		while (_root["platform"+i].hitTest(ob._x+(ob._width/2), ob._y-(ob._height/2), true) || _root.ground.hitTest(ob._x+(ob._width/2), ob._y+(ob._height/3), true)) {
			ob._x -= .1;
			ob.vx = 0;
		}
		while (_root["platform"+i].hitTest(ob._x-(ob._width/2), ob._y-(ob._height/2), true) || _root.ground.hitTest(ob._x-(ob._width/2), ob._y+(ob._height)/3, true)) {
			ob._x += .1;
			ob.vx = 0;
		}
		while (_root["wall"+i].hitTest(ob._x, ob._y-(ob._height/2), true)) {
			ob._y += .9;
			ob.vy = 0;
		}
		while (_root["wall"+i].hitTest(ob._x+(ob._width)/3, ob._y+(ob._height/18), true) || _root.ground.hitTest(ob._x-(ob._width)/3, ob._y+(ob._height/2), true)) {
			ob._y -= .9;
			ob.vy = 0;
			ob.jumping = false;
		}
		while (_root["wall"+i].hitTest(ob._x+(ob._width/2), ob._y-(ob._height/2), true) || _root.ground.hitTest(ob._x+(ob._width/2), ob._y+(ob._height/3), true)) {
			ob._x -= .9;
			ob.vx = 0;
		}
		//while (_root["wall"+i].hitTest(ob._x-(ob._width/2), ob._y-(ob._height/2), true) || _root.ground.hitTest(ob._x-(ob._width/2), ob._y+(ob._height)/3, true)) {
			//ob._x += .9;
			//ob.vx = 0;
		//}
	}
}
function brain(ob, tr) {
	if (ob._x<tr._x-40) {
		enemy._x++;
		enemy._xscale = -100;
		ob.vx -= ob.power;
		enemy.gotoAndStop("walk");
	} else if (ob._x>tr._x+40) {
		enemy._x--;
		enemy._xscale = 100;
		ob.vx += ob.power;
		enemy.gotoAndStop("walk");
	} else if (ob.hitTest(tr._y)-100) {
		enemy.gotoAndStop("attack");
		if (_root.enemy.attack.weapon.hitTest(tr)) {
			tr.health--;
		}
	}
	if (ob._y<tr._y && !ob.jumping && _root.ground.hitTest(ob._x+(ob._width/2), ob._y, true) || _root.ground.hitTest(ob._x-(ob._width/2), ob._y, true)) {

		ob.vy += ob.jump;
		ob._y += ob.jump;
		ob.jumping = true;
	}
}

function cleanup() {
	delete this.onEnterFrame;
	gotoAndStop(2);
}