Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Joncom

I want to modify the way in which a player moves over one-way tiles (you know, the collision tiles in Weltmeister with arrows on them).

Currently I use the following function to see if my player is allowed to move immediately left/right/up/down:

var canMove = function(player)
    // returns true if no collision will occur
    // in the direction the player faces
    {
	var vx = 0;
	var vy = 0;
	switch(player.facing)
	{
	    case 'left':
		vx = -1;
		break;
	    case 'right':
		vx = 1;
		break;
	    case 'up':
		vy = -1;
		break;
	    case 'down':
		vy = 1;
		break;
	}
	// check map collisions
	var res = ig.game.collisionMap.trace( player.pos.x, player.pos.y, vx, vy, player.size.x, player.size.y );
	if(res.collision.x || res.collision.y) return false;
	
	return true; // no collisions
    };

The above works great, but it doesn't tell me if I can move because I'm passing through a regular walkable tile, or a special one-way tile. I'd very much like to know when I'm passing or about to pass through a one way tile.

Thanks.

1 decade ago by Joncom

Thanks to quidmonkey for helping me find a solution:

var canJump = function(player)
    // returns true if faced tile is jumpable
    // otherwise false
    {
	var vx = 0;
	var vy = 0;
	var want = -1; // to match weltmeister one-way collision tiles
	var c = ig.game.collisionMap;
	var tilesize = ig.game.collisionMap.tilesize;
	switch(player.facing)
	{
	    case 'left':
		vx = -tilesize;
		want = 45;
		break;
	    case 'right':
		vx = tilesize;
		want = 34;
		break;
	    case 'up':
		vy = -tilesize;
		want = 12;
		break;
	    case 'down':
		vy = tilesize;
		want = 23;
		break;
	}
	var pX = player.pos.x + vx;
	var pY = player.pos.y + vy;
	if(c.getTile(pX,pY) == want) return true; // can jump
	return false; // no jumpable tiles found
    };
Page 1 of 1
« first « previous next › last »