Do you like my tutorials?

Then consider supporting me on Ko-fi

Talking about Platform game game, Actionscript 2, Flash and Game development.

As said in New tile based platform engine – part 11 – slopes part a, the game needed a fix for the jump from/on slope bug.

In part b the bug becomes a glitch… now you can jump from/on the slope but sometimes there is a “rebounce” glitch.

It’s very easy to determine why it’s happening and fix it… I am just leaving the explication for next time because I just got my computer repaired and need to do a lot of things.

I just wanted to answer a question about senseless slopes and N game mechanics.

There is a lot of difference between my tile based engine and a raycasting one.

Maybe I’ll cover it in next future.

Meanwhile, you are invited to take a look at the source code and fix the glitch at line 338

walkable_tiles = Array(0, 5, 6, 7, 10, 11);
tile_size = 20;
ground_acceleration = 1;
ground_friction = 0.8;
air_acceleration = 0.5;
air_friction = 0.7;
ice_acceleration = 0.15;
ice_friction = 0.95;
treadmill_speed = 2;
max_speed = 3;
xspeed = 0;
yspeed = 0;
falling = false;
jumping = false;
on_slope = false;
gravity = 0.5;
jump_speed = 6;
climbing = false;
climb_speed = 0.8;
level = new Array();
enemy = new Array();
coin = new Array();
key = new Array();
level[0] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
level[1] = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1];
level[2] = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 1, 0, 0, 0, 0, 1];
level[3] = [1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 1];
level[4] = [1, 0, 1, 2, 2, 1, 0, 4, 4, 8, 3, 3, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 1];
level[5] = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 6, 0, 0, 0, 0, 0, 1];
level[6] = [1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 1, 0, 0, 0, 0, 0, 1];
level[7] = [1, 1, 1, 0, 0, 1, 0, 0, 0, 10, 1, 11, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 1];
level[8] = [1, 1, 1, 1, 0, 9, 0, 0, 10, 1, 1, 1, 11, 0, 7, 0, 0, 6, 0, 0, 0, 0, 7, 0, 1];
level[9] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 1, 4, 4, 1, 8, 1, 8, 1];
player = [10, 6];
enemy[0] = [10, 3, -2];
enemy[1] = [3, 3, -2];
coin[0] = [2, 2];
coin[1] = [23, 4];
key[0] = [1, 5, 5, 8];
function create_level(l) {
	_root.createEmptyMovieClip("level_container",1);
	level_height = l.length;
	level_width = l[0].length;
	for (y=0; ymax_speed) {
		xspeed = max_speed;
	}
	if (xspeed0 and !on_slope) {
		if ((bottom_right != 0 and bottom_right != 6 and bottom_right != 10 and bottom_right != 11) or (bottom_left != 0 and bottom_left != 6 and bottom_left != 10 and bottom_left != 11)) {
			// not a cloud...
			if (bottom_right != 5 and bottom_left != 5) {
				// a trampoline
				if ((bottom_right == 7 or bottom_left == 7) and (Math.abs(yspeed)>1)) {
					yspeed = yspeed*-1;
					jumping = true;
					falling = true;
				} else {
					y_pos = bottom*tile_size-9;
					yspeed = 0;
					falling = false;
					jumping = false;
				}
			} else {
				//cloud
				if (prev_bottom0) {
		if (!is_walkable(top_right) or !is_walkable(bottom_right)) {
			x_pos = right*tile_size-6;
			xspeed = 0;
		}
	}
	prev_bottom = bottom;
}
function get_edges() {
	// right edge
	right = Math.floor((x_pos+5)/tile_size);
	// left edge   
	left = Math.floor((x_pos-6)/tile_size);
	// bottom edge
	bottom = Math.floor((y_pos+8)/tile_size);
	// top edge
	top = Math.floor((y_pos-9)/tile_size);
	// adjacent tiles
	top_right = level[top][right];
	top_left = level[top][left];
	bottom_left = level[bottom][left];
	bottom_right = level[bottom][right];
}
function place_player() {
	level_container.hero.removeMovieClip();
	x_pos = player[0]*tile_size+tile_size/2;
	y_pos = player[1]*tile_size+tile_size/2+1;
	level_container.attachMovie("hero","hero",_root.level_container.getNextHighestDepth(),{_x:x_pos, _y:y_pos});
}
function is_walkable(tile) {
	walkable = false;
	if (!on_slope) {
		for (x=0; xMath.floor(y_pos/tile_size)*tile_size-9+x_offset) {
				// rebounce fix here
			}
		}
	}
	// could NOT be an else  
	if (!jumping and !falling) {
		if (level[y_slope_detector+1][x_slope_detector] == 10 or level[y_slope_detector+1][x_slope_detector] == 11) {
			y_pos = (y_slope_detector+1)*tile_size+tile_size/2+1;
			y_slope_detector += 1;
		}
		if (level[y_slope_detector][x_slope_detector] == 10 or level[y_slope_detector][x_slope_detector] == 11) {
			if (level[y_slope_detector][x_slope_detector] == 10) {
				x_offset = tile_size-x_pos%tile_size;
			}
			// could be an "else"...               
			if (level[y_slope_detector][x_slope_detector] == 11) {
				x_offset = x_pos%tile_size;
			}
			y_pos = Math.floor(y_pos/tile_size)*tile_size-9+x_offset;
			on_slope = true;
		}
	}
	if (!jumping and !falling and !on_slope and over != "ladder") {
		y_pos = (y_slope_detector)*tile_size+tile_size/2+1;
	}
}

Enjoy the result

Download the source code and have fun

Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.