def render(self, screen, rotation_direction, enemy): if self.facing == 'right': face = self.right_face elif self.facing == 'left': face = self.left_face pos = self.get_position() target_angle = self.angle + rotation_direction if self.is_dead and self.opacity > 0: position = self.get_position() self.opacity = self.opacity - 5 blit_alpha(screen, face, (position.x, position.y), self.opacity) elif not self.is_dead: # rotate angle pointer rotated_pointer, rotated_pointer_pos = self._get_new_rotated_pos( face, pos, target_angle) screen.blit(rotated_pointer, rotated_pointer_pos) screen.blit(face, pos) angle_surface = self.angle_font.render( str(int(self.angle)), True, (127, 0, 108), (255, 255, 255)) position = Vector2( pos.x, pos.y + (face.get_height() - angle_surface.get_height())) screen.blit(angle_surface, position) # check for firing if self.velocity != 0: angle = self.angle * (math.pi / 180) # converted to radians VelocityY = self.velocity * math.sin(angle) VelocityX = self.velocity * math.cos(angle) position = self.get_position() initial_x, initial_y = position.x, position.y self.seconds += self.dt ball_x = initial_x + (VelocityX * self.seconds) ball_y = initial_y - (VelocityY * self.seconds - .5 * self.gravity * self.seconds ** 2) screen.blit(self.mobile_fire, (ball_x, ball_y)) # check if we hit something if enemy: enemy_pos = enemy.get_position() hit = (ball_x + self.width > enemy_pos.x and ball_x < enemy_pos.x + enemy.width and ball_y + self.height > enemy_pos.y and ball_y < enemy_pos.y + enemy.height) if hit and not enemy.is_dead: enemy.is_dead = True # reset velocity and seconds when we're outside the window if ball_y >= initial_y: self.velocity = 0 self.seconds = 0
def draw(self, sm, screen): if len(sm.scenes) > 1: sm.scenes[-2].draw(sm, screen) # draw a transparent bg bgSurf = pygame.Surface((830,830)) bgSurf.fill((globals.BLACK)) utils.blit_alpha(screen, bgSurf, (0,0), self.alpha * 0.7) utils.drawText(screen, 'You lose!', 150, 150, globals.WHITE, self.alpha) self.esc.draw(screen, alpha=self.alpha)
def draw(self, sm, screen): if len(sm.scenes) > 1: sm.scenes[-2].draw(sm, screen) # DIBUJAR UN Bacground opaco bgSurf = pygame.Surface((1000, 560)) bgSurf.fill((globals.NEGRO)) utils.blit_alpha(screen, bgSurf, (0,0), self.alpha * 0.7) utils.drawText(screen, "PERDISTE", 250, 250, globals.BLANCO, self.alpha) self.esc.draw(screen, alpha = self.alpha)
def draw(self, surface): # Draw the arrow if self.button.is_selected: if not self.button.is_circular: if self.button.option == self.limit_option: blit_alpha(surface, self.spr_arrow, self.x, self.y, self.button.opacity) else: surface.blit(self.spr_arrow, (self.x, self.y)) else: surface.blit(self.spr_arrow, (self.x, self.y)) else: blit_alpha(surface, self.spr_arrow, self.x, self.y, self.button.opacity)
def splash_screen(self): """Generate the initial Buey splashscreen.""" self.background.fill((0, 0, 0)) bg = load_png('splash_bg.png') self.background.blit(bg, (0, 0)) self.splash_track.play(1) for i in range(0, 255, 10): self.background.set_alpha(i) self.screen.blit(self.background, (0, 0)) pygame.display.flip() pygame.time.wait(10) buey_spritesheet = load_png('buey_sprite.png') buey_spritesheet_pos = buey_spritesheet.get_rect() buey_spritesheet_pos.centerx = self.background.get_rect().centerx buey_spritesheet_pos.centery = self.background.get_rect().centery for i in range(0, 255, 4): self.background.blit(bg, (0, 0)) blit_alpha(self.background, buey_spritesheet, buey_spritesheet_pos, i) self.screen.blit(self.background, (0, 0)) pygame.display.flip() pygame.time.wait(10) pygame.time.wait(1500) fade_out = pygame.Surface(self.screen.get_size()) for i in range(0, 255, 10): self.background.blit(bg, (0, 0)) self.background.blit(buey_spritesheet, buey_spritesheet_pos) fade_out.set_alpha(i) self.background.blit(fade_out, (0, 0)) self.screen.blit(self.background, (0, 0)) pygame.display.flip() pygame.time.wait(10) self.splash_track.stop() pygame.time.wait(200)
def blit(self, screen): utils.blit_alpha(screen, self.background_image, (self.x - 55, 29), 230) i = 0 for itemid, item in enumerate(self.items): if isinstance(item, Menu): Itemtext = Menufont.render(item.name, False, (255, 255, 255)) Icontext = IconFont.render(item.icon, False, (255, 255, 255)) ItemAmount = Menufont.render(str(item.amount), False, (255, 255, 255)) if itemid == self.CursorPoint: utils.blit_alpha(screen, GameplayCursor, (self.x - 50, self.y + 50 * itemid), 200) if i == self.CursorPoint: self.wavys[i].update() self.wavys[i].draw(screen) else: screen.blit(Itemtext, (self.x - 35, self.y + 50 * itemid)) i += 1 screen.blit(Icontext, (self.x + 120, self.y + 50 * itemid)) if item.amount != None: screen.blit(ItemAmount, (self.x + 90, self.y + 50 * itemid))
def draw(self, surface): if self.is_selected: # Draw the box surface.blit(self.spr_box, (self.x, self.y)) # Draw text shadow text_surface = self.font.render(self.text, False, Colors.BROWN) surface.blit(text_surface, (self.x + halign_center(text_surface, self.spr_box) + 3, self.y + 13)) # Draw text text_surface = self.font.render(self.text, False, Colors.LIGHT_WHITE) surface.blit(text_surface, (self.x + halign_center(text_surface, self.spr_box), self.y + 10)) else: # Draw the box blit_alpha(surface, self.spr_box, self.x, self.y, self.opacity) # Draw text shadow text_surface = self.font.render(self.text, False, Colors.BROWN) blit_alpha(surface, text_surface, self.x + halign_center(text_surface, self.spr_box) + 3, self.y + 13, self.opacity) # Draw text text_surface = self.font.render(self.text, False, Colors.LIGHT_WHITE) blit_alpha(surface, text_surface, self.x + halign_center(text_surface, self.spr_box), self.y + 10, self.opacity)
def draw(self, surface): # Draw the arrows self.arrow_left.draw(surface) self.arrow_right.draw(surface) if self.is_selected: # Draw the box surface.blit(self.spr_box, (self.x, self.y)) # Draw text shadow text_surface = self.font.render(self.text, False, Colors.BROWN) surface.blit(text_surface, (self.x + halign_left(text_surface, self.spr_box) + 23, self.y + 13)) # Draw text text_surface = self.font.render(self.text, False, Colors.LIGHT_WHITE) surface.blit(text_surface, (self.x + halign_left(text_surface, self.spr_box) + 20, self.y + 10)) # Draw secondary text shadow text_surface = self.font.render(self.text_secondary, False, Colors.BROWN) surface.blit(text_surface, (self.x + halign_right(text_surface, self.spr_box) - 17, self.y + 13)) # Draw secondary text text_surface = self.font.render(self.text_secondary, False, Colors.LIGHT_WHITE) surface.blit(text_surface, (self.x + halign_right(text_surface, self.spr_box) - 20, self.y + 10)) else: # Draw the box blit_alpha(surface, self.spr_box, self.x, self.y, self.opacity) # Draw text shadow text_surface = self.font.render(self.text, False, Colors.BROWN) blit_alpha(surface, text_surface, self.x + halign_left(text_surface, self.spr_box) + 23, self.y + 13, self.opacity) # Draw text text_surface = self.font.render(self.text, False, Colors.LIGHT_WHITE) blit_alpha(surface, text_surface, self.x + halign_left(text_surface, self.spr_box) + 20, self.y + 10, self.opacity) # Draw secondary text shadow text_surface = self.font.render(self.text_secondary, False, Colors.BROWN) blit_alpha(surface, text_surface, self.x + halign_right(text_surface, self.spr_box) - 17, self.y + 13, self.opacity) # Draw secondary text text_surface = self.font.render(self.text_secondary, False, Colors.LIGHT_WHITE) blit_alpha(surface, text_surface, self.x + halign_right(text_surface, self.spr_box) - 20, self.y + 10, self.opacity)