Sunday, July 12, 2015

Prototyping: Mother Brain I


In this update, I am adding Mother Brain.


This is pretty much the same process as with the food tubes. The first thing I do is just get the first image from the sheet on screen. So, there you go:


The next thing I do is get her glass tube set up. Here is the back added:


Now, the front glass is a little more complicated. First, I have to copy the section on the sheet which contains the open door. Then, I copy the closed tile and the opened tile. Then, blit the original seection to two new surfaces. One gets the closed part blitted black, and the other gets the opened part blitted closed. In the end, it will probably be tiles just like the base image, but I'm not entirely sure. I'm just trying a different approach to see how things work out.

Here is what it looks like with just the base image copied directly


Now, this image won't actually ever be seen in game. It's only an in-between state. So, we copy the tile from the original and create a new surface for the closed glass. After blitting that together, it looks like it should:

That takes care of closed glass state. Now just take the original glass, and fill a single tile with black to open the glass up.

With both states completed, create a flag on the Mother Brain object which draws the correct glass.

class MotherBrain(object):
    '''
    
    '''
    def __init__(self, col=3, row=5):
        '''
        OK. So we really don't need col, row passed in but I want to make it similar 
        interface to the existing Food class, so I can refactor easier into a more 
        abstract object later.
        '''
        self.sheet, self.rect = load_image(join("assets","motherbrain_sheet.png"))
        self.image = pygame.Surface((TILE_SIZE*5, TILE_SIZE*4)).convert()
        self.image.fill((0,0,0))
        
        self.image.blit(self.sheet, (0,0), (0, 0, 48, 64))
        
        self.top = (col, row)
        
        self.back_glass = pygame.Surface((TILE_SIZE*2, TILE_SIZE*4)).convert()
        self.back_glass.blit(self.sheet, (0,0), (528,0, 16, 64))
        
        # copy the raw image from the sprite sheet.
        self.front_glass_raw = pygame.Surface((TILE_SIZE*2, TILE_SIZE*4)).convert()
        self.front_glass_raw.blit(self.sheet, (0,0), (544, 0, 16, 64))
        
        self.front_glass_closed = pygame.Surface((TILE_SIZE*2, TILE_SIZE*4)).convert()
        self.front_glass_closed.blit(self.front_glass_raw, (0,0)) # blit original glass
        self.front_glass_closed.blit(self.front_glass_raw, (0, TILE_SIZE*2), (0, TILE_SIZE*1, 16, 16))
        
        self.front_glass_opened = pygame.Surface((TILE_SIZE*2, TILE_SIZE*4)).convert()
        self.front_glass_opened.blit(self.front_glass_raw, (0,0)) # blit original glass
        self.front_glass_opened.fill((0,0,0), (0, TILE_SIZE*1, 16, 16))
        
        self.opened = False
        
    def transform(self):
        '''
        Technically, once the glass opens it shouldn't close again, but it is nice to have 
        versatility in code which can be later removed once closer to completion.
        '''
        self.opened = not self.opened
        
        
    def draw(self, surface):
        x, y = pixel_from_tile(2, 5) # back glass (col, row)
        surface.blit(self.back_glass, (x, y))
        x, y = pixel_from_tile(self.top[0], self.top[1])
        surface.blit(self.image, (x, y))
        x, y = pixel_from_tile(6, 5) # front glass (col, row)
        if self.opened:
            surface.blit(self.front_glass_opened, (x, y))
        else:
            surface.blit(self.front_glass_closed, (x, y))

I will definitely be doing this with the tiles themselves. In reality, the open/closed glass should be treated as a door because that's what it is. However, I haven't written any code about doors yet. So, we'll see how that goes. At any rate, that's the update for now.

No comments: