[AC2] Platform game engine code help

I’m trying to make a mario-styled platform game, with Pac-Man as the main character (don’t ask me why, I just felt like doing something outrageously random for a change). I started out by using the platformer tutorial here on Kirupa, but I just couldn’t deal with the quirks that engine code had. I decided to build my own code based slightly on the same idea to make it work the way I wanted.

So the specific things I want to see :

  • Jump height depending on how long you hold down the jump key (UP arrow)
  • Sideways movement slows down or speeds up depending on the left/right keypresses (got this working already)
  • Proper hittesting so the character doesn’t glitch when you try to jump
  • Proper gravity

Right now the stage has two main pieces. The terrain, which has a few walls, a platform you can jump onto and walk under, a big pit you can jump over, all of which is pretty basic shapes, mostly rectangular. The other part is the character, just a circle which opens/closes it’s mouth like Pac-Man.

Here’s the code on my character movieclip :

onClipEvent (load) {
	jump = 0;
	speed = 0;
	maxmove = 10;
	maxjump = 20;
}

onClipEvent (enterFrame) {

	if(Key.isDown(Key.LEFT)){
		if(speed > -maxmove){
			speed--;
		}
		this._xscale = -100;
		lastkey = "left";
	}
	if(!Key.isDown(Key.LEFT)){
		if(speed < 0){
			speed += 0.5;
		}
	}
	if(Key.isDown(Key.RIGHT)){
		if(speed < maxmove){
			speed++;
		}
		this._xscale = 100;
		lastkey = "right";
	} 
	if(!Key.isDown(Key.RIGHT)){
		if(speed > 0){
			speed -= 0.5;
		}
	}
	if(Key.isDown(Key.UP)){
		if(jump < 10){
			jump = 10;
		} else {
			if(jump < maxjump){
				jump++;
			}
		}
		jumping = true;
	}
	if(!Key.isDown(Key.UP)){
		if(jump > 0){
			jump -= 2;
		}
	}
	if (!_root.terrain.hitTest(this._x-20, this._y, true) && lastkey == "left"){
		_root.terrain._x -= speed;
	}
	if (_root.terrain.hitTest(this._x-20, this._y, true) && lastkey == "left"){
		speed = 0;
	}
	if (_root.terrain.hitTest(this._x-20, this._y, true) && lastkey == "right"){
		speed = 2;
	}
																   
	if (!_root.terrain.hitTest(this._x+20, this._y, true) && lastkey == "right"){
		_root.terrain._x -= speed;
	}
	if (_root.terrain.hitTest(this._x+20, this._y, true) && lastkey == "right"){
		speed = 0;
	}
	if (_root.terrain.hitTest(this._x+20, this._y, true) && lastkey == "left"){
		speed = -2;
	}
	
	if (!_root.terrain.hitTest(this._x, this._y+22, true))  {
		this._y += 10;
	} 
	if (_root.terrain.hitTest(this._x, this._y-22, true))  {
		this._y += 10;
		jumping = false;
		jump = 0;
	}
	if(jumping){
		this._y -= jump;
	}
}

I’ll also attach the .fla I have so far.

I hope I can get some help :slight_smile: