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 farman

Medallion is the puzzle game I'm currently developing.

The core game mechanic revolves around flipping the character to his opposite position over the line of symmetry.

Right now I am grabbing the width and height of the screen and calculating the player's distance from the line of symmetry, throwing it into an Absolute Value algorithm, and tossing him on the other side of the line. This is done in code like this.

if (this.pos.y > this.mapSizeX) {
			this.shadowY = this.mapSizeX - this.distanceFromMiddleX - 16;
		} else {
			this.shadowY = this.mapSizeX + this.distanceFromMiddleX - 16;
		}
		
		//fip vars
		this.mapSizeY = (ig.game.collisionMap.width * 16) / 2;
		this.mapSizeX = (ig.game.collisionMap.height * 16) / 2;
		this.distanceFromMiddleY = Math.abs(this.mapSizeY - this.pos.x);
		this.distanceFromMiddleX = Math.abs(this.mapSizeX - this.pos.y);
		
		//flip change Y
		if (ig.input.released('Y') && this.vel.x === 0 && this.vel.y === 0 &&             ig.game.canFlipY === true) {			
			var shadowMan = ig.game.getEntitiesByType(EntityShadowMan)[0];
			if (shadowMan.checkToSeeIfYouCan()) {
				ig.game.spawnEntity(EntityMothMarker, this.pos.x, this.pos.y - 7);
				ig.game.shadowJump.play();
				this.pos.x = this.shadowX;				
			} else if (!shadowMan.checkToSeeIfYouCan()) {
				ig.game.youCannotDoThat.play();
			}
			
		}

This works fine when I keep the levels the size of the game screen. Each tile is 16px and the screen is 24x16 tiles.

The problem is that I am planning on making levels later in the game where the map is bigger and the screen pans. I&039;ve searched through our documentation for Impact and I can't find a solution. I need to eliminate my dependence on #ig.game.collisionMap.width and height.

Also the documentation lists pos.x and pos.y as "The entity's position in the game world."

Is (0,0) the top left corner of the map or the camera screen? Is there anyway to access the coordinates based on their location within the camera screen?

Thank you,
Tom
Farman.Farout

1 decade ago by drhayes

I'm not clear on your problem. Right now your code is translating the player across a line of symmetry for the map and you want it to only work on the screen?

If you really do just need to re-position the player based on where they are in the screen then you need to convert your entity&039;s #pos to its position on the screen, figure out its new position on the screen, then map that back to the entity&039;s #pos.

Check out the documentation for ig.system.realWidth/realHeight which I think will help you a lot. Also screen.x and screen.y which hands you back the viewport into the game world.

Also, check out the map.tilesize docs the tilesize property to get rid of your hard-coded 16).

1 decade ago by farman

Yes that is the problem. Thank you I will have a look at these resources.
Page 1 of 1
« first « previous next › last »