Ejemplo n.º 1
0
    def render(self):
        timer = int(time.time())
        surface = self.registry.get('surface')

        font = pygame.font.SysFont("Arial", 16,
                                   bold=True)  #Font / size PEARDECK
        text = font.render(
            "Variables used: Outside & inside temp, setpoints, window tint, Building kW/h",
            True, (255, 255, 255))  #RGB values / text color
        text2 = font.render("Effects: Speed of ducks, timer, bullets, score",
                            True, (255, 255, 255))
        #surface.blit(text,(320 - text.get_width() // 2, 240 - text.get_height() // 2)) #Location
        surface.blit(text, (
            300,
            400,
        ))  #changes location
        surface.blit(text2, (300, 420))
        sprites = self.registry.get('sprites')
        x, y = self.dogPosition
        width, height = DOG_FRAME

        # Always have round + controls
        self.renderNotices()
        self.renderControls()

        # Update animation frame
        if (self.frame % 15) == 0:
            self.animationFrame += 1

        # First the dog walks/sniffs
        if self.animationFrame < 5:
            x += 1
            self.dogPosition = (x, y)
            rect = ((width * self.animationFrame), 0, width, height)

        # Then the dog jumps
        else:
            self.animationDelay = 16
            animationFrame = self.animationFrame % 5
            rect = ((width * animationFrame), height, width, height)

            # Trigger barking
            if (self.barkCount < 2) and not pygame.mixer.get_busy():
                self.registry.get('soundHandler').enqueue('bark')
                self.barkCount += 1

            # First Jump frame
            if (animationFrame == 1):
                self.dogPosition = (x + adjwidth(5)), (y - adjheight(10))

            # Second jump frame
            elif (animationFrame == 2):
                self.dogPosition = (x + adjwidth(5)), (y + adjheight(5))

            elif (animationFrame > 2):
                return  # Animation is over

        # Add the dog
        surface.blit(sprites, self.dogPosition, rect)
Ejemplo n.º 2
0
    def render(self):
        timer = int(time.time())
        surface = self.registry.get('surface')
        sprites = self.registry.get('sprites')
        x, y = self.dogPosition
        width, height = DOG_FRAME

        # Always have round + controls
        self.renderNotices()
        self.renderControls()

        # Update animation frame
        if (self.frame % 15) == 0:
            self.animationFrame += 1

        # First the dog walks/sniffs
        if self.animationFrame < 5:
            x += 1
            self.dogPosition = (x, y)
            rect = ((width * self.animationFrame), 0, width, height)

        # Then the dog jumps
        else:
            self.animationDelay = 16
            animationFrame = self.animationFrame % 5
            rect = ((width * animationFrame), height, width, height)

            # Trigger barking
            if (self.barkCount < 2) and not pygame.mixer.get_busy():
                self.registry.get('soundHandler').enqueue('bark')
                self.barkCount += 1

            # First Jump frame
            if (animationFrame == 1):
                self.dogPosition = (x + adjwidth(5)), (y - adjheight(10))

            # Second jump frame
            elif (animationFrame == 2):
                self.dogPosition = (x + adjwidth(5)), (y + adjheight(5))

            elif (animationFrame > 2):
                return  # Animation is over

        # Add the dog
        surface.blit(sprites, self.dogPosition, rect)
Ejemplo n.º 3
0
    def render(self):
        timer = int(time.time())
        surface = self.registry.get('surface')
        sprites = self.registry.get('sprites')
        x, y = self.dogPosition
        width, height = DOG_FRAME

        # Always have round + controls
        self.renderNotices()
        self.renderControls()

        # Update animation frame
        if (self.frame % 15) == 0:
            self.animationFrame += 1

        # First the dog walks/sniffs
        if self.animationFrame < 5:
            x += 1
            self.dogPosition = (x, y)
            rect = ((width * self.animationFrame), 0, width, height)

        # Then the dog jumps
        else:
            self.animationDelay = 16
            animationFrame = self.animationFrame % 5
            rect = ((width * animationFrame), height, width, height)

            # Trigger barking
            if (self.barkCount < 2) and not pygame.mixer.get_busy():
                self.registry.get('soundHandler').enqueue('bark')
                self.barkCount += 1

            # First Jump frame
            if (animationFrame == 1):
                self.dogPosition = (x + adjwidth (5)), (y - adjheight (10))

            # Second jump frame
            elif (animationFrame == 2):
                self.dogPosition = (x + adjwidth (5)), (y + adjheight (5))

            elif (animationFrame > 2):
                return # Animation is over

        # Add the dog
        surface.blit(sprites, self.dogPosition, rect)
Ejemplo n.º 4
0
    def renderControls(self):
        img = self.registry.get('controlImgs')
        surface = self.registry.get('surface')
        round = self.registry.get('round')
        controlImgs = self.registry.get('controlImgs')

        # Show round number
        ah20 = int(adjheight(20))
        font = pygame.font.Font(FONT, ah20)
        text = font.render(("R= %d" % round), True, FONT_GREEN, FONT_BLACK)
        surface.blit(text, ROUND_POSITION)

        # Show the bullets
        startingX, startingY = SHOT_POSITION
        surface.blit(controlImgs, SHOT_POSITION, SHOT_RECT)
        for i in range(self.gun.rounds):
            x = startingX + adjwidth(10) + adjwidth(i * 18)
            y = startingY + adjheight(5)
            surface.blit(controlImgs, (x, y), BULLET_RECT)

        # Show the hit counter
        surface.blit(controlImgs, HIT_POSITION, HIT_RECT)
        startingX, startingY = HIT_DUCK_POSITION

        for i in range(config_master.testnum):
            x = startingX + adjwidth(i * 18)
            y = startingY
            if self.hitDucks[i]:
                surface.blit(img, (x, y), HIT_DUCK_RED_RECT)
            else:
                surface.blit(img, (x, y), HIT_DUCK_WHITE_RECT)

        # Show the score
        ah20 = int(adjheight(20))
        surface.blit(img, SCORE_POSITION, SCORE_RECT)
        font = pygame.font.Font(FONT, ah20)
        text = font.render(str(self.registry.get('score')), True, FONT_WHITE)
        x, y = FONT_STARTING_POSITION
        x -= text.get_width()
        surface.blit(text, (x, y))
Ejemplo n.º 5
0
    def renderControls(self):
        img = self.registry.get('controlImgs')
        surface = self.registry.get('surface')
        round = self.registry.get('round')
        controlImgs = self.registry.get('controlImgs')

        # Show round number
        font = pygame.font.Font(FONT, adjheight (20))
        text = font.render(("R= %d" % round), True, FONT_GREEN, FONT_BLACK);
        surface.blit(text, ROUND_POSITION);

        # Show the bullets
        startingX, startingY = SHOT_POSITION
        surface.blit(controlImgs, SHOT_POSITION, SHOT_RECT)
        for i in range(self.gun.rounds):
            x = startingX + adjwidth (10) + adjwidth (i * 18)
            y = startingY + adjheight (5)
            surface.blit(controlImgs, (x, y), BULLET_RECT)

        # Show the hit counter
        surface.blit(controlImgs, HIT_POSITION, HIT_RECT)
        startingX, startingY = HIT_DUCK_POSITION
        for i in range(10):
            x = startingX + adjwidth (i * 18)
            y = startingY
            if self.hitDucks[i]:
                surface.blit(img, (x, y), HIT_DUCK_RED_RECT)
            else:
                surface.blit(img, (x, y), HIT_DUCK_WHITE_RECT)

        # Show the score
        surface.blit(img, SCORE_POSITION, SCORE_RECT)
        font = pygame.font.Font(FONT, adjheight (20))
        text = font.render(str(self.registry.get('score')), True, FONT_WHITE);
        x, y = FONT_STARTING_POSITION
        x -= text.get_width();
        surface.blit(text, (x,y));
Ejemplo n.º 6
0
HIT_DUCK_RED_RECT = adjrect(200, 44, 18, 15)
SCORE_POSITION = adjpos(620, 440)
SCORE_RECT = adjrect(69, 43, 130, 43)
FONT = os.path.join('media', 'arcadeclassic.ttf')
FONT_STARTING_POSITION = adjpos(730, 442)
FONT_GREEN = 154, 233, 0
FONT_BLACK = 0, 0, 0
FONT_WHITE = 255, 255, 255
ROUND_POSITION = adjpos(60, 410)
SHOT_BG_POSITION = adjpos(60, 440)
SHOT_POSITION = adjpos(60, 440)
SHOT_RECT = adjrect(0, 43, 70, 43)
BULLET_RECT = adjrect(200, 59, 13, 17)
NOTICE_POSITION = adjpos(370, 120)
NOTICE_RECT = adjrect(0, 86, 128, 63)
NOTICE_WIDTH = adjwidth(128)
NOTICE_LINE_1_HEIGHT = adjheight(128)
NOTICE_LINE_2_HEIGHT = adjwidth(150)

registry = None


class BaseState(object):
    def __init__(self):
        global registry
        self.registry = registry
        self.timer = int(time.time())
        self.notices = set()
        self.gun = Gun(self.registry)
        self.hitDucks = [False for i in range(10)]
        self.hitDuckIndex = 0
Ejemplo n.º 7
0
HIT_DUCK_RED_RECT = adjrect (200, 44, 18, 15)
SCORE_POSITION = adjpos (620, 440)
SCORE_RECT = adjrect (69, 43, 130, 43)
FONT = os.path.join('media', 'arcadeclassic.ttf')
FONT_STARTING_POSITION = adjpos (730, 442)
FONT_GREEN = 154, 233, 0
FONT_BLACK = 0, 0, 0
FONT_WHITE = 255, 255, 255
ROUND_POSITION = adjpos (60, 410)
SHOT_BG_POSITION = adjpos (60, 440)
SHOT_POSITION = adjpos (60, 440)
SHOT_RECT = adjrect (0, 43, 70, 43)
BULLET_RECT = adjrect (200, 59, 13, 17)
NOTICE_POSITION = adjpos (370, 120)
NOTICE_RECT = adjrect (0, 86, 128, 63)
NOTICE_WIDTH = adjwidth (128)
NOTICE_LINE_1_HEIGHT = adjheight (128)
NOTICE_LINE_2_HEIGHT = adjwidth (150)

registry = None

class BaseState(object):
    def __init__(self):
        global registry
        self.registry = registry
        self.timer = int(time.time())
        self.notices = set()
        self.gun = Gun(self.registry)
        self.hitDucks = [False for i in range(10)]
        self.hitDuckIndex = 0