<commit_before>#include "Player.h"
#include <algorithm>

//USING_NS_CC;

Player::Player()
{
	_Sprite = Sprite::create("Images/playerShip2_blue.png");
	this->addChild(_Sprite);

	auto screenSize = Director::getInstance()->getWinSize();
	auto pos = Vec2( (screenSize.width/2)*1, 50);
    this->setPosition(pos) ;
	_Destination = pos;

	auto listener = EventListenerTouchOneByOne::create();
	listener->onTouchBegan = CC_CALLBACK_2(Player::onTouchBegan, this);
    listener->onTouchMoved = CC_CALLBACK_2(Player::onTouchMoved, this);
    listener->onTouchEnded = CC_CALLBACK_2(Player::onTouchEnded, this);

	_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
}

Player::~Player()
{
	this->removeAllChildren();
}

float Player::getNormalizedPosX() const
{
	auto winSize = Director::getInstance()->getWinSize();
	return getPosition().x / winSize.width;
}
		
bool Player::onTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event)
{
	 _Destination = touch->getLocation();
	 return true;
}

void Player::onTouchMoved(cocos2d::Touch* touch, cocos2d::Event* event)
{
	_Destination = touch->getLocation();
}

void Player::onTouchEnded(cocos2d::Touch* touch, cocos2d::Event* event)
{
	_Destination = this->getPosition();
}

void Player::Update(float dT)
{
	auto pos = this->getPosition();
	auto dir = _Destination - pos;
	auto len = dir.length();
	dir.normalize();
	auto offset = std::min(len, dT * SHIP_SPEED);

	this->setPosition( pos + dir * offset);
}<commit_msg>Player ship is constrained inside the screen<commit_after>#include "Player.h"
#include <algorithm>

//USING_NS_CC;

Player::Player()
{
	_Sprite = Sprite::create("Images/playerShip2_blue.png");
	this->addChild(_Sprite);

	auto screenSize = Director::getInstance()->getWinSize();
	auto pos = Vec2( (screenSize.width/2)*1, 50);
    this->setPosition(pos) ;
	_Destination = pos;

	auto listener = EventListenerTouchOneByOne::create();
	listener->onTouchBegan = CC_CALLBACK_2(Player::onTouchBegan, this);
    listener->onTouchMoved = CC_CALLBACK_2(Player::onTouchMoved, this);
    listener->onTouchEnded = CC_CALLBACK_2(Player::onTouchEnded, this);

	_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
}

Player::~Player()
{
	this->removeAllChildren();
}

float Player::getNormalizedPosX() const
{
	auto winSize = Director::getInstance()->getWinSize();
	return getPosition().x / winSize.width;
}
		
bool Player::onTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event)
{
	 _Destination = touch->getLocation();
	 return true;
}

void Player::onTouchMoved(cocos2d::Touch* touch, cocos2d::Event* event)
{
	_Destination = touch->getLocation();
}

void Player::onTouchEnded(cocos2d::Touch* touch, cocos2d::Event* event)
{
	_Destination = this->getPosition();
}

void Player::Update(float dT)
{
	// Moves the ship
	auto pos = this->getPosition();
	auto dir = _Destination - pos;
	auto len = dir.length();
	dir.normalize();
	auto offset = std::min(len, dT * SHIP_SPEED);

	pos = pos + dir * offset;

	// And constraint its position without the world
	auto halfShip = _Sprite->getContentSize() / 2;
	pos = pos.getClampPoint( halfShip, Director::getInstance()->getWinSize()-halfShip);

	this->setPosition(pos);
}
{'fraction_non_alphanumeric': 0.153125, 'fraction_numerical': 0.0096875, 'mean_word_length': 6.081858407079646, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': '2238722', 'n_tokens_mistral': 1110, 'n_tokens_neox': 1092, 'n_words': 207}