def collide(self, entity): """ this is a pseudo pixel perfect collision detection method, to detect collisions between the level and any entity this is not a true pixel perfect system, because the number of tested pixels is only proportional to the size of image, not equal to the number of pixels in the image. (but tests show it's enought for our use case) tested pixel in a example square: _________________ | . . . | |.................| | . . . | |.................| | . . . | |.................| |___.____.____.___| 4*h + 4*w - 16 pixels tested, for any h and w """ #load the two current displayed images of the level img = ( loaders.image(self.foreground_base+str(int(self.x/1000))+'.png'), loaders.image(self.foreground_base+str(int(self.x/1000)+1)+'.png') ) #place entity at its real place on level clipped = entity.pos_rect().move(self.x, 0) for x in range(0, clipped.width, clipped.width//4): for y in range(0, clipped.height, clipped.height//4): # manage case where we are on the next tile try: if ( (entity.x + x < -(self.x % 1000)+1000) and entity.image[0].get_at((x,y)) != (255, 255, 255, 0) and img[0][0].get_at(( int(entity.x + x + (self.x % 1000)), int(entity.y + y) )) != (255, 255, 255, 0)): return True elif ( entity.image[0].get_at((x,y)) != (255, 255, 255, 0) and img[1][0].get_at(( int(entity.x + x + (self.x % 1000) - 1000), int(entity.y + y) )) != (255, 255, 255, 0)): return True except IndexError, e: #FIXME: find WHY! pass
def image(self): """ Return the image currently displayed by the engine for the entity. """ return loaders.image( os.path.join('skins', self.skin), rotate=-self.angle*5 )
def display(self, screen): """ Display the current two images chunk of the level using current x """ screen.blit(loaders.image(self.background)[0], (0, 0)) screen.blit( loaders.image( self.foreground_base+str(int(self.x/1000))+'.png' )[0], (-(self.x % 1000), 0)) screen.blit( loaders.image( self.foreground_base+str(int((self.x)/1000)+1)+'.png' )[0], (-(self.x % 1000)+1000, 0))
def display(self, screen): screen.blit( loaders.image( os.path.join('skins', self.skin), alpha=(1500 - self.time)/1500. )[0], (self.x, self.y), )
def draw(self, surface, texture, pos, zoom, lifetime): real_coords = (int(self.position[0] * zoom) + pos[0], int(self.position[1] * zoom) + pos[1]) surface.blit( image('data/' + texture, zoom=zoom, alpha=1 - int(10 * self.age / lifetime) / 10.0)[0], real_coords)
def draw(self, surface, texture, pos, zoom, lifetime): real_coords = (int(self.position[0] * zoom) + pos[0], int(self.position[1] * zoom) + pos[1]) surface.blit( image( 'data/'+texture, zoom=zoom, alpha=1-int(10*self.age/lifetime)/10.0)[0], real_coords)