Exemple #1
0
 def blit(self):
     if self.hitpoints <= 0:
         return
     cannon_center = [
         (self.pos[i] + (2.0 + self.type) / 2) * common.block_size
         for i in range(2)
     ]
     delta = [
         self.player.battle_player.pos[i] - cannon_center[i]
         for i in range(2)
     ]
     if delta[0] == 0:
         if delta[1] < 0:
             pic = 0
         else:
             pic = 15
     else:
         angle = math.atan(delta[1] / delta[0])
         angle = angle / (2 * math.pi) + 1.23
         if delta[0] < 0:
             angle += 0.5
         pic = int((1 - angle) * 30)
         while pic < 0:
             pic += 30
     try:
         common.blit(
             self.cannon_pic[pic],
             (self.pos[0] * common.block_size,
              self.pos[1] * common.block_size),
         )
     except IndexError:
         print(pic, angle)
         raise
Exemple #2
0
 def print_time(self):
     time = int(max(self.phase.time_left, 0))
     time_surface = common.font.render(str(time), True, (0, 0, 0))
     common.blit(
         time_surface,
         ((common.screen.get_width() - time_surface.get_width()) / 2, 0),
     )
Exemple #3
0
    def draw_backbuffer(self, draw_cannons=True):
        common.backbuffer.blit(self.surface, (0, 0))
        all_fields = common.coords(common.field_size)
        all_fields.reverse()
        for pos in all_fields:
            self.blit_ground(pos)
            self.update(pos, draw_cannons)

        common.blit(common.backbuffer)
 def __init__(self, next_phase):
     State.__init__(self)
     announce_text = getattr(game.field.map,
                             next_phase.phase_name + "_phase_text")
     self.make_announce_surface(*announce_text)
     common.blit(
         self.announce_surface,
         divide(
             subtract(common.screen.get_size(),
                      self.announce_surface.get_size()), 2),
     )
     common.update()
     self.start_time = pygame.time.get_ticks()
     self.next_phase = next_phase
Exemple #5
0
    def draw(self):
        if self.hidden:
            return
        # Widget is inactive
        if self.inactive:
            if not self.inactive_surface:
                # Create 50% transparent surface
                self.inactive_surface = self.normal_surface.convert_alpha()
                alpha = pygame.surfarray.pixels_alpha(self.inactive_surface)
                np.floor_divide(alpha, array(2).astype(np.uint8), alpha)
                del alpha
            common.blit(self.inactive_surface, self.pos)
            self.highlighted = False
            return

        # This widget can't be highlighted
        if not self.on_click:
            common.blit(self.normal_surface, self.pos)
            return

        # Is the mouse pointer above the widget?
        if not Widget.freeze_highlight:
            self.highlighted = True
            mouse_pos = pygame.mouse.get_pos()
            for i in (0, 1):
                if (not self.pos[i] <= mouse_pos[i] <=
                        self.pos[i] + self.normal_surface.get_size()[i]):
                    self.highlighted = False
        else:
            self.highlighted = Widget.freeze_highlight == self

        if self.highlighted:
            surf = self.highlight_surface
        else:
            surf = self.normal_surface
        common.blit(surf, self.pos)
Exemple #6
0
 def draw(self):
     common.blit(self.shot_pic, self.get_pos(), centered=True)
Exemple #7
0
def draw_background():
    common.backbuffer = menu_back.convert()
    common.blit(common.backbuffer)
Exemple #8
0
 def draw_cursor(self):
     if self.finished:
         return
     draw_at = multiply(add(self.selected_castle.pos, (-4, -4)),
                        common.block_size)
     common.blit(self.select_pic, draw_at)
 def draw_cursor(self):
     if self.get_free_cannon() and game.phase.time_left > 0:
         pic = self.crosshair_pic
     else:
         pic = self.empty_crosshair_pic
     common.blit(pic, self.pos, centered=True)