Ejemplo n.º 1
0
    def __init__(self, pos):
        Entity.__init__(
            self,
            sprite=retro.Sprite(
                image=self.IMG,
                animations=retro.Animations(
                    frame_size=(32, 32),
                    period=3,
                    WALK_L=([0], 0),
                    WALK_U=([0], 0),
                    WALK_R=([0], 0),
                    WALK_D=([0], 0),
                    FEAR_L=([1], 0),
                    FEAR_U=([1], 0),
                    FEAR_R=([1], 0),
                    FEAR_D=([1], 0),
                ),
            ),
            pos=pos,
            speed=2,
            curdir=[0, 0],
            nxtdir=random.choice(([-1, 0], [1, 0])),
        )

        self.state = State(self)
Ejemplo n.º 2
0
    def generate(self):
        x = self.window.rect().right if not self else \
            self[-1].left + (self.window.rect().right // 2)
        y = random.randrange(
            self.OFFSET_HEIGHT,
            self.window.rect().height - self.GAP_HEIGHT -
            Ground.IMG.rect().height - self.OFFSET_HEIGHT)

        ptop = retro.Sprite(self.IMG_TOP)
        ptop.rect.bottom = ptop.rect.top + y
        ptop.rect.left = x

        pbot = retro.Sprite(self.IMG_BOTTOM)
        pbot.rect.top = y + self.GAP_HEIGHT
        pbot.rect.left = x

        self.append(Pipe(ptop=ptop, pbot=pbot))
Ejemplo n.º 3
0
 def draw_score(self):
     score = retro.Sprite(self.window.fonts[4].render(
         text=f"{self.p1.score}   {self.p2.score}",
         color=(200, 200, 200),
     ))
     score.rect.midtop = self.window.rect().midtop
     score.rect.move_ip(0, 10)
     score.draw(self.window)
Ejemplo n.º 4
0
 def draw_scores(self):
     for i, bird in enumerate(self.birds):
         score = retro.Sprite(self.window.fonts[0].render(
             text=str(bird.fitness),
             color=retro.WHITE,
         ))
         score.rect.move_ip(10, 10 + (i * score.rect.h))
         score.draw(self.window)
Ejemplo n.º 5
0
 def draw_score(self):
     score = retro.Sprite(self.window.fonts[0].render(
         text=f"Score: {self.player.score}",
         color=retro.WHITE,
     ))
     score.rect.topright = self.window.rect().topright
     score.rect.move_ip(-10, 10)
     score.draw(self.window)
Ejemplo n.º 6
0
 def draw_score(self, image):
     font = retro.Font(36)
     txt = retro.Sprite(
         font.render(
             text=f"SCORE: {self.score}",
             color=retro.WHITE,
             bgcolor=retro.BLACK,
         ))
     txt.rect.bottomleft = image.rect().bottomleft
     txt.draw(image)
Ejemplo n.º 7
0
    def __init__(self, window):
        self.window = window
        self.restart = False

        self.txt = retro.Sprite(self.window.fonts[4].render(
            text    = "WIN",
            color   = retro.WHITE,
            bgcolor = retro.BLACK,
        ))
        self.txt.rect.center = self.window.rect().center
Ejemplo n.º 8
0
    def draw_ticker(self):
        if self.explode: return

        window = self.lemming.window
        ticker_surface = retro.Sprite(window.fonts[0].render(
            text=f"{self.ticker.remaining}",
            color=retro.WHITE,
        ))
        ticker_surface.rect.midbottom = self.lemming.bounding_rect.midtop
        ticker_surface.draw(window)
Ejemplo n.º 9
0
    def draw_shoot_ticker(self, font, dest):
        if not self.alive: return

        shoot_ticker = retro.Sprite(
            font.render(
                text=f"{self.shoot_ticker.remaining}",
                color=retro.WHITE,
            ))
        shoot_ticker.rect.midbottom = dest.rect().midbottom
        shoot_ticker.draw(dest)
Ejemplo n.º 10
0
    def __init__(self, pos):
        Entity.__init__(
            self,
            sprite=retro.Sprite(
                image=self.IMG,
                animations=retro.Animations(
                    frame_size=(32, 32),
                    period=3,
                    STOP_L=([2], 0),
                    STOP_U=([3], 0),
                    STOP_R=([0], 0),
                    STOP_D=([4], 0),
                    WALK_L=([2, 1], 0),
                    WALK_U=([3, 1], 0),
                    WALK_R=([0, 1], 0),
                    WALK_D=([4, 1], 0),
                ),
            ),
            pos=pos,
            speed=4,
        )

        self.score = 0
        self.powerup = Powerup()
Ejemplo n.º 11
0
 def populate_icons(self):
     for action in Actions.USABLE:
         sprite = retro.Sprite(action.ICON)
         sprite.state = action
         self.icons.append(sprite)