예제 #1
0
    def __init__(self, sourceDict):
        # set the attributes on this object
        self.__dict__.update(sourceDict)

        # calculate the aabb, width and height for this source
        self.aabb = aabb.AABB()
        for (x, y) in self.points:
            self.aabb.add(x, y)
        self.width = self.aabb.maxX - self.aabb.minX
        self.height = self.aabb.maxY - self.aabb.minY

        # calculate animation offset
        if self.numFrames:
            self.frameOffset = self.width / self.numFrames
        else:
            self.frameOffset = 0

        # calculate texture coordinates for this source
        self.coords = []
        frameOffset = 0
        frameWidth = 1.0 / self.numFrames
        for i in range(0, self.numFrames):
            frameCoords = []
            for x, y in self.points:
                tx = (((x + (float)(self.width) / 2.0) / self.width) /
                      self.numFrames)
                ty = 1 - ((y + (float)(self.height) / 2.0) / self.height)
                frameCoords.append((tx + frameOffset, ty))
            self.coords.append(frameCoords)
            frameOffset += frameWidth
예제 #2
0
    def __init__(self, level,*args, **kwargs):
        super(Token,self).__init__(token_map[level],*args,**kwargs)
        #self.scale=0.3

        self.lower_bound=((self.x-self.width//2),(self.y-self.height//2))
        self.upper_bound=((self.x+self.width//2),(self.y+self.height//2))
        self.bounding_box=aabb.AABB(self.lower_bound,self.upper_bound)
예제 #3
0
    def __init__(self, *args, **kwargs):
        super(Btoken, self).__init__(bindertoken_image, *args, **kwargs)
        self.scale = 0.06

        self.lower_bound = ((self.x - self.width // 2),
                            (self.y - self.height // 2))
        self.upper_bound = ((self.x + self.width // 2),
                            (self.y + self.height // 2))
        self.bounding_box = aabb.AABB(self.lower_bound, self.upper_bound)
예제 #4
0
    def __init__(self, *args, **kwargs):
        super(Power_up, self).__init__(pwrup_image, *args, **kwargs)
        self.scale = 0.3
        self.is_pwrup = True

        self.lower_bound = ((self.x - self.width // 2),
                            (self.y - self.height // 2))
        self.upper_bound = ((self.x + self.width // 2),
                            (self.y + self.height // 2))
        self.bounding_box = aabb.AABB(self.lower_bound, self.upper_bound)
예제 #5
0
    def __init__(self, *args, **kwargs):
        super(Power_up,self).__init__(pwrup_image,*args,**kwargs)
        self.scale=0.3
        self.is_pwrup=True
        self.speed_up=False
        self.make_invincible=False
        self.make_armed=False
        self.make_insubstantial=False

        self.lower_bound=((self.x-self.width//2),(self.y-self.height//2))
        self.upper_bound=((self.x+self.width//2),(self.y+self.height//2))
        self.bounding_box=aabb.AABB(self.lower_bound,self.upper_bound)
예제 #6
0
    def __init__(self, *args, **kwargs):
        super(Hidden_token, self).__init__(hidden_token_image, *args, **kwargs)
        self.scale = 0.5

        self.visible = False
        self.found = False

        self.lower_bound = ((self.x - self.width // 2),
                            (self.y - self.height // 2))
        self.upper_bound = ((self.x + self.width // 2),
                            (self.y + self.height // 2))
        self.bounding_box = aabb.AABB(self.lower_bound, self.upper_bound)
예제 #7
0
    def __init__(self,img,*args,**kwargs):
        super(Mob,self).__init__(img,*args,**kwargs)
        
        self.affected_by_gravity=False
        self.supported=False
        self.acc=self.height*2

        self.lower_bound=((self.x-self.width//2),(self.y-self.height//2))
        self.upper_bound=((self.x+self.width//2),(self.y+self.height//2))
        self.bounding_box=aabb.AABB(self.lower_bound,self.upper_bound)

        self.is_enemy=False
        self.is_avatar=False
예제 #8
0
    def __init__(self, *args, **kwargs):
        super(Token2, self).__init__(donut_image,
                                     x=925,
                                     y=500,
                                     *args,
                                     **kwargs)
        self.scale = 0.3

        self.lower_bound = ((self.x - self.width // 2),
                            (self.y - self.height // 2))
        self.upper_bound = ((self.x + self.width // 2),
                            (self.y + self.height // 2))
        self.bounding_box = aabb.AABB(self.lower_bound, self.upper_bound)
예제 #9
0
    def update(self,dx,dy,dt):

        next_x=self.x+dx
        next_y=self.y+dy
        
        if dx or dy:   
            if self.can_move_there(next_x,next_y):
                self.x=next_x
                self.y=next_y
                self.supported=False
                                     

        self.lower_bound=((self.x-self.width//2),(self.y-self.height//2))
        self.upper_bound=((self.x+self.width//2),(self.y+self.height//2))
        self.bounding_box=aabb.AABB(self.lower_bound,self.upper_bound)

        self.check_bounds()
예제 #10
0
def generate_world(level):

    global col_width,col_height
    
    for i,m in enumerate(layouts[level]):
        for j,n in enumerate(m):
            if n:
                new_tile=tile.Tile(tile.tile_mapping[n],batch=tile_batch)
                new_tile.x=new_tile.width*j
                new_tile.y=viewport.window.height-(new_tile.height*i)
                if n in tile.solid_tile_types:
                    grid_solid_tile_mapping[(j,height_in_tiles-i-1)]=new_tile
                    new_tile.lower_bound=(new_tile.x,(new_tile.y-new_tile.height))
                    new_tile.upper_bound=((new_tile.x+new_tile.width),new_tile.y)
                    new_tile.bounding_box=aabb.AABB(new_tile.lower_bound,new_tile.upper_bound)
                static_objects.append(new_tile)
                
                
    col_width=static_objects[0].width
    col_height=static_objects[0].height
예제 #11
0
파일: mob.py 프로젝트: juliamcd19/AIS-game
    def can_move_there(self, x, y):

        lower_bound = ((x - self.width // 2), (y - self.height // 2))
        upper_bound = ((x + self.width // 2), (y + self.height // 2))

        new_box = aabb.AABB(lower_bound, upper_bound)
        no_collision = True

        for occ_tile_pt in self.get_occupied_tiles(x, y):
            if occ_tile_pt in world.grid_solid_tile_mapping.keys():
                occ_tile = world.grid_solid_tile_mapping[occ_tile_pt]
                if occ_tile.bounding_box.collides_with(new_box) or \
                   new_box.collides_with(occ_tile.bounding_box):
                    no_collision = False
                    if self.is_enemy:
                        self.change_velocity(0)
                    dx = abs(self.x - occ_tile.x)
                    dy = abs(self.y - occ_tile.y)
                    if self.y >= occ_tile.y + self.height // 2:
                        self.supported = True

        return no_collision
예제 #12
0
 def update_bounding_box(self):
     self.lower_bound=((self.x-self.width//2),(self.y-self.height//2))
     self.upper_bound=((self.x+self.width//2),(self.y+self.height//2))
     self.bounding_box=aabb.AABB(self.lower_bound,self.upper_bound)
예제 #13
0
        # Initialise the overlap flag.
        isOverlap = True

        while isOverlap:
            # Generate a random particle position.
            position[0] = boxSize[0] * random.random()
            position[1] = boxSize[1] * random.random()

            # Compute the lower and upper AABB bounds.
            lowerBound[0] = position[0] - radiusLarge
            lowerBound[1] = position[1] - radiusLarge
            upperBound[0] = position[0] + radiusLarge
            upperBound[1] = position[1] + radiusLarge

            # Generate the AABB.
            AABB = aabb.AABB(lowerBound, upperBound)

            # Query AABB overlaps.
            particles = treeLarge.query(AABB)

            # Flag as no overlap (yet).
            isOverlap = False

            # Test overlap.
            for j in range(0, len(particles)):
                if overlaps(position, positionsLarge[particles[j]],
                            periodicity, boxSize, cutOff):
                    isOverlap = True
                    break

    # Insert the particle into the tree.