<commit_before>#define PTM_RATIO 32

#import "cocos2d.h"
#import "Box2D.h"
#import "Paddle.h"

@implementation Paddle
@synthesize Sprite, Body, Fixture;

-(id) initWithWorld: (b2World*) world: (b2Body*) groundBody {
    if ((self=[super init])) {
        World = world;
        Ground = groundBody;
        
        // Create sprite.
        Sprite = [CCSprite spriteWithFile:@"whitedot.png"
                                              rect:CGRectMake(50, 50, 50, 100)];
        Sprite.position = ccp(50,50);
        
        
        b2BodyDef bodyDef;
        bodyDef.type = b2_dynamicBody;
        bodyDef.position.Set(Sprite.position.x/PTM_RATIO, 
                                  Sprite.position.y/PTM_RATIO);
        bodyDef.userData = Sprite;
        Body = world->CreateBody(&bodyDef);
        
        b2PolygonShape brickShape;
        brickShape.SetAsBox(Sprite.contentSize.width/PTM_RATIO/2,
                            Sprite.contentSize.height/PTM_RATIO/2);
        
        b2FixtureDef shapeDef;
        shapeDef.shape = &brickShape;        
        shapeDef.density = 5.0f;
        shapeDef.friction = 0.4f;
        shapeDef.restitution = 0.1f;
        Fixture = Body->CreateFixture(&shapeDef);
        
        // Restrict paddle along the x axis
        b2PrismaticJointDef jointDef;
        b2Vec2 worldAxis(0.0f, 1.0f);
        jointDef.collideConnected = true;
        jointDef.Initialize(Body, groundBody,
                            Body->GetWorldCenter(), worldAxis);
        world->CreateJoint(&jointDef);
        
        [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:-1 swallowsTouches:YES];
    }
    return self;
}

- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
    BOOL touched = NO;
    
    if (_mouseJoint != NULL) {
        return touched;
    }
    
    CGPoint location = [touch locationInView:[touch view]];
    CCLOG(@"BEGAN location is %.2f x %.2f", location.x,location.y);
    
    location = [[CCDirector sharedDirector] convertToGL:location];
    b2Vec2 locationWorld = b2Vec2(location.x/PTM_RATIO, location.y/PTM_RATIO);
    
    BOOL hit = YES;//[_paddle testPoint:locationWorld];
    
    if (hit) {
        b2MouseJointDef md;
        md.bodyA = Ground;
        md.bodyB = Body;
        md.target = locationWorld;
        md.collideConnected = true;
        md.maxForce = 1000.0f * Body->GetMass();
        
        _mouseJoint = (b2MouseJoint *)World->CreateJoint(&md);
        Body->SetAwake(true);
        
        touched = YES;
    }
    
    return touched;
}

-(void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event {
    
    if (_mouseJoint == NULL) return;
    
    CGPoint location = [touch locationInView:[touch view]];
    location = [[CCDirector sharedDirector] convertToGL:location];
    b2Vec2 bodyPos = Body->GetPosition();
    b2Vec2 locationWorld = b2Vec2(location.x/PTM_RATIO,	location.y/PTM_RATIO);
    
    _mouseJoint->SetTarget(locationWorld);
    
}

-(void)ccTouchCancelled:(UITouch *)touch withEvent:(UIEvent *)event {
    
    if (_mouseJoint) {
        World->DestroyJoint(_mouseJoint);
        _mouseJoint = NULL;
    }
    
}

- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    if (_mouseJoint) {
        World->DestroyJoint(_mouseJoint);
        _mouseJoint = NULL;
    }  
}

-(void)dealloc{
    [super dealloc];
}

@end<commit_msg>Changed ccTouchEnded signature. It's now also called when touch ends.<commit_after>#define PTM_RATIO 32

#import "cocos2d.h"
#import "Box2D.h"
#import "Paddle.h"

@implementation Paddle
@synthesize Sprite, Body, Fixture;

-(id) initWithWorld: (b2World*) world: (b2Body*) groundBody {
    if ((self=[super init])) {
        World = world;
        Ground = groundBody;
        
        // Create sprite.
        Sprite = [CCSprite spriteWithFile:@"whitedot.png"
                                              rect:CGRectMake(50, 50, 50, 100)];
        Sprite.position = ccp(50,50);
        
        
        b2BodyDef bodyDef;
        bodyDef.type = b2_dynamicBody;
        bodyDef.position.Set(Sprite.position.x/PTM_RATIO, 
                                  Sprite.position.y/PTM_RATIO);
        bodyDef.userData = Sprite;
        Body = world->CreateBody(&bodyDef);
        
        b2PolygonShape brickShape;
        brickShape.SetAsBox(Sprite.contentSize.width/PTM_RATIO/2,
                            Sprite.contentSize.height/PTM_RATIO/2);
        
        b2FixtureDef shapeDef;
        shapeDef.shape = &brickShape;        
        shapeDef.density = 5.0f;
        shapeDef.friction = 0.4f;
        shapeDef.restitution = 0.1f;
        Fixture = Body->CreateFixture(&shapeDef);
        
        // Restrict paddle along the x axis
        b2PrismaticJointDef jointDef;
        b2Vec2 worldAxis(0.0f, 1.0f);
        jointDef.collideConnected = true;
        jointDef.Initialize(Body, groundBody,
                            Body->GetWorldCenter(), worldAxis);
        world->CreateJoint(&jointDef);
        
        [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:-1 swallowsTouches:YES];
    }
    return self;
}

- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
    BOOL touched = NO;
    
    if (_mouseJoint != NULL) {
        return touched;
    }
    
    CGPoint location = [touch locationInView:[touch view]];
    CCLOG(@"BEGAN location is %.2f x %.2f", location.x,location.y);
    
    location = [[CCDirector sharedDirector] convertToGL:location];
    b2Vec2 locationWorld = b2Vec2(location.x/PTM_RATIO, location.y/PTM_RATIO);
    
    BOOL hit = YES;//[_paddle testPoint:locationWorld];
    
    if (hit) {
        b2MouseJointDef md;
        md.bodyA = Ground;
        md.bodyB = Body;
        md.target = locationWorld;
        md.collideConnected = true;
        md.maxForce = 1000.0f * Body->GetMass();
        
        _mouseJoint = (b2MouseJoint *)World->CreateJoint(&md);
        Body->SetAwake(true);
        
        touched = YES;
    }
    
    return touched;
}

-(void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event {
    
    if (_mouseJoint == NULL) return;
    
    CGPoint location = [touch locationInView:[touch view]];
    location = [[CCDirector sharedDirector] convertToGL:location];
    b2Vec2 bodyPos = Body->GetPosition();
    b2Vec2 locationWorld = b2Vec2(location.x/PTM_RATIO,	location.y/PTM_RATIO);
    
    _mouseJoint->SetTarget(locationWorld);
    
}

-(void)ccTouchCancelled:(UITouch *)touch withEvent:(UIEvent *)event {
    
    if (_mouseJoint) {
        World->DestroyJoint(_mouseJoint);
        _mouseJoint = NULL;
    }
    
}

- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event {
    if (_mouseJoint) {
        World->DestroyJoint(_mouseJoint);
        _mouseJoint = NULL;
    }  
}

-(void)dealloc{
    [super dealloc];
}

@end
{'fraction_non_alphanumeric': 0.1156770985668324, 'fraction_numerical': 0.016964024568587307, 'mean_word_length': 2.2659980897803247, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4465212', 'n_tokens_mistral': 2340, 'n_tokens_neox': 2183, 'n_words': 400}