<commit_before>
var Player = function()
{
	Actor.call(this);
	
	this.transform.position.set(-50, 0, 0);
	
	this.maxMovementSpeed = 100;
	this.acceleration = 512;
	this.ignoreSpeedMultAbove = 0.15;
	
	// create mesh
	this.geometry = bmacSdk.GEO.makeSpriteGeo(24,32);
	this.mesh = bmacSdk.GEO.makeSpriteMesh(Player.texture, this.geometry);
	this.transform.add(this.mesh);
	this.mesh.position.set(0, 0, -50);
	
	this.controlHelperDom = document.getElementById("interactionMessage");
	
	bmacSdk.GEO.setTilesheetGeometry(this.geometry, 0, 1, 24, 4);
}

Player.texture = bmacSdk.GEO.loadPixelTexture("media/player.png");

// stores functions to call to check control states
Player.controls =
{
	left: function()
	{
		return GameEngine.keyboard.keyDown(bmacSdk.KEYBOARD.LEFT)
			|| bmacSdk.INPUT.gamepadButtonPressed(bmacSdk.INPUT.FIRST_PLAYER, bmacSdk.INPUT.GB_DPAD_LEFT);
	},
	right: function()
	{
		return GameEngine.keyboard.keyDown(bmacSdk.KEYBOARD.RIGHT)
			|| bmacSdk.INPUT.gamepadButtonPressed(bmacSdk.INPUT.FIRST_PLAYER, bmacSdk.INPUT.GB_DPAD_RIGHT);
	},
	up: function()
	{
		return GameEngine.keyboard.keyDown(bmacSdk.KEYBOARD.UP)
			|| bmacSdk.INPUT.gamepadButtonPressed(bmacSdk.INPUT.FIRST_PLAYER, bmacSdk.INPUT.GB_DPAD_UP);
	},
	down: function()
	{
		return GameEngine.keyboard.keyDown(bmacSdk.KEYBOARD.DOWN)
			|| bmacSdk.INPUT.gamepadButtonPressed(bmacSdk.INPUT.FIRST_PLAYER, bmacSdk.INPUT.GB_DPAD_DOWN);
	},
	machete: function()
	{
		return GameEngine.keyboard.keyDown("z")
			|| bmacSdk.INPUT.gamepadButtonDown(bmacSdk.INPUT.FIRST_PLAYER, bmacSdk.INPUT.GB_A);
	},
	interact: function()
	{
		return GameEngine.keyboard.keyPressed("x")
			|| bmacSdk.INPUT.gamepadButtonPressed(bmacSdk.INPUT.FIRST_PLAYER, bmacSdk.INPUT.GB_B);
	},
}

Player.prototype = Object.create(Actor.prototype);

Player.prototype.update = function()
{
	//DEBUG CHEAT
	if (GameEngine.keyboard.keyPressed("p"))
	{
		sampleGame.tileManager.peek();
	}
	
	// take input and set desired movement
	if (Player.controls.left())
	{
		this.desiredMovement.x--;
	}
	if (Player.controls.right())
	{
		this.desiredMovement.x++;
	}
	if (Player.controls.up())
	{
		this.desiredMovement.y--;
	}
	if (Player.controls.down())
	{
		this.desiredMovement.y++;
	}
	if (Player.controls.machete())
	{
		this.swingMachete();
	}
	
	// display a UI helper for the player to interact with things
	var tileX = sampleGame.tileManager.worldToTileX(this.transform.position.x);
	var tileY = sampleGame.tileManager.worldToTileY(this.transform.position.y);
	var currentTile = sampleGame.tileManager.getTile(tileX, tileY);
	var interactionMessage = "";
	if (currentTile)
	{
		var resource = terainKey[currentTile.terrainType].resource;
		if (resource !== undefined && currentTile.growthLevel < growthMax)
		{
			if (sampleGame.villagerManager.hasResourceFlagAt(tileX, tileY))
			{
				//TODO: resource name string
				interactionMessage = "(X): Unflag " + resource;
				
				if (Player.controls.interact())
				{
					sampleGame.villagerManager.unflagResourceAt(tileX, tileY);
				}<commit_msg>fixed an error when walking off map right edge<commit_after>
var Player = function()
{
	Actor.call(this);
	
	this.transform.position.set(-50, 0, 0);
	
	this.maxMovementSpeed = 100;
	this.acceleration = 512;
	this.ignoreSpeedMultAbove = 0.15;
	
	// create mesh
	this.geometry = bmacSdk.GEO.makeSpriteGeo(24,32);
	this.mesh = bmacSdk.GEO.makeSpriteMesh(Player.texture, this.geometry);
	this.transform.add(this.mesh);
	this.mesh.position.set(0, 0, -50);
	
	this.controlHelperDom = document.getElementById("interactionMessage");
	
	bmacSdk.GEO.setTilesheetGeometry(this.geometry, 0, 1, 24, 4);
}

Player.texture = bmacSdk.GEO.loadPixelTexture("media/player.png");

// stores functions to call to check control states
Player.controls =
{
	left: function()
	{
		return GameEngine.keyboard.keyDown(bmacSdk.KEYBOARD.LEFT)
			|| bmacSdk.INPUT.gamepadButtonPressed(bmacSdk.INPUT.FIRST_PLAYER, bmacSdk.INPUT.GB_DPAD_LEFT);
	},
	right: function()
	{
		return GameEngine.keyboard.keyDown(bmacSdk.KEYBOARD.RIGHT)
			|| bmacSdk.INPUT.gamepadButtonPressed(bmacSdk.INPUT.FIRST_PLAYER, bmacSdk.INPUT.GB_DPAD_RIGHT);
	},
	up: function()
	{
		return GameEngine.keyboard.keyDown(bmacSdk.KEYBOARD.UP)
			|| bmacSdk.INPUT.gamepadButtonPressed(bmacSdk.INPUT.FIRST_PLAYER, bmacSdk.INPUT.GB_DPAD_UP);
	},
	down: function()
	{
		return GameEngine.keyboard.keyDown(bmacSdk.KEYBOARD.DOWN)
			|| bmacSdk.INPUT.gamepadButtonPressed(bmacSdk.INPUT.FIRST_PLAYER, bmacSdk.INPUT.GB_DPAD_DOWN);
	},
	machete: function()
	{
		return GameEngine.keyboard.keyDown("z")
			|| bmacSdk.INPUT.gamepadButtonDown(bmacSdk.INPUT.FIRST_PLAYER, bmacSdk.INPUT.GB_A);
	},
	interact: function()
	{
		return GameEngine.keyboard.keyPressed("x")
			|| bmacSdk.INPUT.gamepadButtonPressed(bmacSdk.INPUT.FIRST_PLAYER, bmacSdk.INPUT.GB_B);
	},
}

Player.prototype = Object.create(Actor.prototype);

Player.prototype.update = function()
{
	//DEBUG CHEAT
	if (GameEngine.keyboard.keyPressed("p"))
	{
		sampleGame.tileManager.peek();
	}
	
	// take input and set desired movement
	if (Player.controls.left())
	{
		this.desiredMovement.x--;
	}
	if (Player.controls.right())
	{
		this.desiredMovement.x++;
	}
	if (Player.controls.up())
	{
		this.desiredMovement.y--;
	}
	if (Player.controls.down())
	{
		this.desiredMovement.y++;
	}
	if (Player.controls.machete())
	{
		this.swingMachete();
	}
	
	// display a UI helper for the player to interact with things
	var tileX = sampleGame.tileManager.worldToTileX(this.transform.position.x);
	var tileY = sampleGame.tileManager.worldToTileY(this.transform.position.y);
	var currentTile = sampleGame.tileManager.getTile(tileX, tileY);
	var interactionMessage = "";
	if (currentTile instanceof tile)
	{
		var resource = terainKey[currentTile.terrainType].resource;
		if (resource !== undefined && currentTile.growthLevel < growthMax)
		{
			if (sampleGame.villagerManager.hasResourceFlagAt(tileX, tileY))
			{
				//TODO: resource name string
				interactionMessage = "(X): Unflag " + resource;
				
				if (Player.controls.interact())
				{
					sampleGame.villagerManager.unflagResourceAt(tileX, tileY);
				}
{'fraction_non_alphanumeric': 0.1384942021884697, 'fraction_numerical': 0.008492569002123142, 'mean_word_length': 4.633854645814168, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5862042', 'n_tokens_mistral': 2461, 'n_tokens_neox': 2259, 'n_words': 324}