<commit_before>from OpenGL.GL import *
from objloader import *
from filenames import *
from directions import *

def drawTrail(x1, y1, x2, y2, width = 5., height = 3., color = (1., 0., 0., 1.), playerTrail = False):
    glColor4f(color[0], color[1], color[2], color[3])
    glPushMatrix()
    
    distanceFromPlayer = 5.1
    
    if (x1 == x2): # vertical
        x1 -= width/2
        x2 += width/2
        if (y1 < y2):
            y1 -= width/2 # south to north
            if (playerTrail):
                y2 = max(y2-distanceFromPlayer, y1)
        else:
            y1 += width/2 # north to south
            if (playerTrail):
                y2 = min(y2+distanceFromPlayer, y1)

    elif (y1 == y2): # horizontal
        y1 -= width/2
        y2 += width/2
        if (x1 < x2): 
            x1 -= width/2 # west to east
            if (playerTrail):
                x2 = max(x2-distanceFromPlayer, x1)
        else:
            x1 += width/2 # east to west
            if (playerTrail):
                x2 = min(x2+distanceFromPlayer, x1)

    """
    glBegin(GL_QUADS);
    glVertex3f(x1, y1, 0.1);
    glVertex3f(x1, y2, 0.1);
    glVertex3f(x2, y2, 0.1);
    glVertex3f(x2, y1, 0.1);
    glEnd();
    """

    glBegin(GL_QUADS);
    glVertex3f(x1, y1, height);
    glVertex3f(x1, y2, height);
    glVertex3f(x1, y2, 0.);
    glVertex3f(x1, y1, 0.);
    glEnd();

    glBegin(GL_QUADS);
    glVertex3f(x1, y1, 0.1);
    glVertex3f(x2, y1, 0.1);
    glVertex3f(x2, y1, height);
    glVertex3f(x1, y1, height);
    glEnd();
    
    glBegin(GL_QUADS);
    glVertex3f(x1, y1, height);
    glVertex3f(x2, y1, height);
    glVertex3f(x2, y2, height);
    glVertex3f(x1, y2, height);
    glEnd();
    
    glPopMatrix()

class Player:
    def __init__(self):
        self.model = OBJ(Filenames.models.player, swapyz=True)
        self.x = 0.
        self.y = 0.
        self.z = 0.
        self.direction = Direction()
        self.trailPoints = []
        self.saveTrailPoint()
        self.killed = False
        
    def saveTrailPoint(self):
        self.trailPoints.append((self.x, self.y))
    
    def steerRight(self):
        self.direction.steerRight()
        self.saveTrailPoint()
        
    def steerLeft(self):
        self.direction.steerLeft()
        self.saveTrailPoint()
        
    def step(self, enabled = True):

        if((self.x > 200 or self.x < 0) or (self.y > 200 or self.y < 0)):
            self.killed = True
        else:			
            if (not enabled):
              return
            increment = 0.5
            if (self.direction.current() == NORTH):
                 self.y += increment
            elif (self.direction.current() == SOUTH):
                 self.y -= increment
            elif (self.direction.current() == EAST):
                 self.x += increment
            elif (self.direction.current() == WEST):
                 self.x -= increment
        i = 1
        crashed = False
        while(i < len(self.trailPoints) - 1):
            if(self.x == self.trailPoints[i][0] and self.x == self.trailPoints[i+1][0]):
               if(self.y >= self.trailPoints[i][1] and self.y <= self.trailPoints[i+1][1]) or (self.y >= self.trailPoints[i+1][1] and self.y <= self.trailPoints[i][1]):
                    crashed = True
                    print "player crashed at {0} {1}".format(self.trailPoints[i][0], self.trailPoints[i+1][0])
            i += 1           

    def reset(self):
        self.x = 0.
        self.y = 0.
        self.z = 0.
        self.direction = Direction()
        self.trailPoints = []
        self.saveTrailPoint()	
        self.killed = False

    def was_killed(self):
        return 	self.killed

    def draw(self):
        glPushMatrix()<commit_msg>collision detection done<commit_after>from OpenGL.GL import *
from objloader import *
from filenames import *
from directions import *

def drawTrail(x1, y1, x2, y2, width = 5., height = 3., color = (1., 0., 0., 1.), playerTrail = False):
    glColor4f(color[0], color[1], color[2], color[3])
    glPushMatrix()
    
    distanceFromPlayer = 5.1
    
    if (x1 == x2): # vertical
        x1 -= width/2
        x2 += width/2
        if (y1 < y2):
            y1 -= width/2 # south to north
            if (playerTrail):
                y2 = max(y2-distanceFromPlayer, y1)
        else:
            y1 += width/2 # north to south
            if (playerTrail):
                y2 = min(y2+distanceFromPlayer, y1)

    elif (y1 == y2): # horizontal
        y1 -= width/2
        y2 += width/2
        if (x1 < x2): 
            x1 -= width/2 # west to east
            if (playerTrail):
                x2 = max(x2-distanceFromPlayer, x1)
        else:
            x1 += width/2 # east to west
            if (playerTrail):
                x2 = min(x2+distanceFromPlayer, x1)

    """
    glBegin(GL_QUADS);
    glVertex3f(x1, y1, 0.1);
    glVertex3f(x1, y2, 0.1);
    glVertex3f(x2, y2, 0.1);
    glVertex3f(x2, y1, 0.1);
    glEnd();
    """

    glBegin(GL_QUADS);
    glVertex3f(x1, y1, height);
    glVertex3f(x1, y2, height);
    glVertex3f(x1, y2, 0.);
    glVertex3f(x1, y1, 0.);
    glEnd();

    glBegin(GL_QUADS);
    glVertex3f(x1, y1, 0.1);
    glVertex3f(x2, y1, 0.1);
    glVertex3f(x2, y1, height);
    glVertex3f(x1, y1, height);
    glEnd();
    
    glBegin(GL_QUADS);
    glVertex3f(x1, y1, height);
    glVertex3f(x2, y1, height);
    glVertex3f(x2, y2, height);
    glVertex3f(x1, y2, height);
    glEnd();
    
    glPopMatrix()

class Player:
    def __init__(self):
        self.model = OBJ(Filenames.models.player, swapyz=True)
        self.x = 0.
        self.y = 0.
        self.z = 0.
        self.direction = Direction()
        self.trailPoints = []
        self.saveTrailPoint()
        self.killed = False
        
    def saveTrailPoint(self):
        self.trailPoints.append((self.x, self.y))
    
    def steerRight(self):
        self.direction.steerRight()
        self.saveTrailPoint()
        
    def steerLeft(self):
        self.direction.steerLeft()
        self.saveTrailPoint()
        
    def step(self, enabled = True):

        if((self.x > 200 or self.x < 0) or (self.y > 200 or self.y < 0)):
            self.killed = True
        else:			
            if (not enabled):
              return
            increment = 0.5
            if (self.direction.current() == NORTH):
                 self.y += increment
            elif (self.direction.current() == SOUTH):
                 self.y -= increment
            elif (self.direction.current() == EAST):
                 self.x += increment
            elif (self.direction.current() == WEST):
                 self.x -= increment
        i = 1
        crashed = False
        while(i < len(self.trailPoints) - 1):
            if(self.x == self.trailPoints[i][0] and self.x == self.trailPoints[i+1][0]):
               if(self.y >= self.trailPoints[i][1] and self.y <= self.trailPoints[i+1][1]) or (self.y >= self.trailPoints[i+1][1] and self.y <= self.trailPoints[i][1]):
                    crashed = True
                    print "player crashed at {0} {1}".format(self.x, self.y)
            if(self.y == self.trailPoints[i][1] and self.y == self.trailPoints[i+1][1]):
               if(self.x >= self.trailPoints[i][0] and self.x <= self.trailPoints[i+1][0]) or (self.x >= self.trailPoints[i+1][0] and self.x <= self.trailPoints[i][0]):
                    crashed = True
                    print "player crashed at {0} {1}".format(self.x, self.y)
            i += 1           

    def reset(self):
        self.x = 0.
        self.y = 0.
        self.z = 0.
        self.direction = Direction()
        self.trailPoints = []
        self.saveTrailPoint()	
        self.killed = False

    def was_killed(self):
        return 	self.killed

    def draw(self):
        glPushMatrix()
{'fraction_non_alphanumeric': 0.14110586132039332, 'fraction_numerical': 0.03882007406461499, 'mean_word_length': 1.7128507100796675, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 13, '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': '4388526', 'n_tokens_mistral': 2842, 'n_tokens_neox': 2727, 'n_words': 598}