本文整理汇总了Python中Player.scale方法的典型用法代码示例。如果您正苦于以下问题:Python Player.scale方法的具体用法?Python Player.scale怎么用?Python Player.scale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Player
的用法示例。
在下文中一共展示了Player.scale方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Scene
# 需要导入模块: import Player [as 别名]
# 或者: from Player import scale [as 别名]
class Scene(State):
def __init__(self):
super(Scene, self).__init__()
self.all_object_list = pygame.sprite.Group()
self.troll_list = pygame.sprite.Group()
self.bullet_list = pygame.sprite.Group()
self.player = Player()
self.background = Object()
self.hud = HUD()
self.score = 0
self.game_over = False
def init(self):
self.read_scene()
# Scale background to screen size
self.background.image = pygame.transform.scale(self.background.image, (SCREEN_WIDTH, SCREEN_HEIGHT))
def process_events(self, event):
if event.type == pygame.MOUSEBUTTONDOWN:
return
#self.player.change_color(BLUE)
elif event.type == pygame.KEYDOWN:
if (event.ket == pygame.K_p):
self.pause()
def update(self):
if (not self.is_running):
return
# TEST
pos = pygame.mouse.get_pos()
self.player.rect.x = pos[0]
self.player.rect.y = pos[1]
def draw(self, screen):
screen.fill(WHITE)
#screen.blit(self.background.image, self.background.rect)
self.background.draw(screen)
self.all_object_list.draw(screen)
def read_scene(self):
with open(ResourceManager.scene_path_list[0]) as file:
self.read_background(file)
self.read_player(file)
def read_background(self, file):
file.readline()
image_id = int(file.readline().strip().split(' ')[1])
self.background.init('Image', None, file_name = ResourceManager.image_path_list[image_id])
def read_player(self, file):
file.readline()
image_id = int(file.readline().strip().split(' ')[1])
self.player.init('Image', None, file_name = ResourceManager.image_path_list[image_id], alpha = True)
self.player.move(*map(int, file.readline().strip().split(' ')[1:]))
self.player.rotate(float(file.readline().strip().split(' ')[1]))
self.player.scale(*map(int, file.readline().strip().split(' ')[1:]))
self.all_object_list.add(self.player)
示例2: Scene
# 需要导入模块: import Player [as 别名]
# 或者: from Player import scale [as 别名]
#.........这里部分代码省略.........
self.all_object_list.add(self.teams[Team_side.RIGHT][self.position[i]][-1])
# Assign selection_circle to each player
# Left team
for player in [players for sublist in list(self.teams[Team_side.LEFT].values()) for players in sublist]:
player.selection_circle = self.selection_circle[0].clone()
# Right team
for player in [players for sublist in list(self.teams[Team_side.RIGHT].values()) for players in sublist]:
player.selection_circle = self.selection_circle[1].clone()
#----------------------------------------READ FILE SECTION-----------------------------------------------------
def read_scene(self, file_path):
with open(file_path) as file:
self.read_hud(file)
self.read_field(file)
self.read_red_team(file)
self.read_blue_team(file)
self.read_selection_circle(file)
self.read_ball(file)
self.read_effect(file)
self.read_sound(file)
def read_hud(self, file):
file.readline()
hud_id = int(file.readline().strip().split(' ')[1])
self.hud.init(ResourceManager.instance().hud_path_list[hud_id])
def read_field(self, file):
# Read field
file.readline()
image_id = int(file.readline().strip().split(' ')[1])
self.field.init('Image', file_name = ResourceManager.instance().image_path_list[image_id])
self.field.scale_to(SCREEN_WIDTH, SCREEN_HEIGHT)
self.all_object_list.add(self.field)
# Read goal
file.readline()
image_id_1, image_id_2 = list(map(int, file.readline().strip().split(' ')[1:]))
self.goal.append(Object())
self.goal[-1].init('Image', file_name = ResourceManager.instance().image_path_list[image_id_1])
self.goal[-1].scale_to(SCREEN_WIDTH, SCREEN_HEIGHT)
self.goal[-1].set_layer(-1)
self.goal.append(Object())
self.goal[-1].init('Image', file_name = ResourceManager.instance().image_path_list[image_id_2])
self.goal[-1].scale_to(SCREEN_WIDTH, SCREEN_HEIGHT)
self.goal[-1].set_layer(-1)
self.all_object_list.add(self.goal)
def read_red_team(self, file):
self.teams[Team_side.LEFT] = dict()
file.readline()
image_id = int(file.readline().strip().split(' ')[1])
# Prototype
self.left_player.init('Image', file_name = ResourceManager.instance().image_path_list[image_id])
self.left_player.rotate(float(file.readline().strip().split(' ')[1]))
self.left_player.scale(*map(float, file.readline().strip().split(' ')[1:]))
self.left_player.translate(*map(int, file.readline().strip().split(' ')[1:]))
def read_blue_team(self, file):
self.teams[Team_side.RIGHT] = dict()
file.readline()
image_id = int(file.readline().strip().split(' ')[1])
# Prototype
示例3: Scene
# 需要导入模块: import Player [as 别名]
# 或者: from Player import scale [as 别名]
class Scene(State):
def __init__(self):
super(Scene, self).__init__()
pygame.mixer.init(44100, -16, 4, 2048)
self.all_object_list = pygame.sprite.LayeredUpdates()
self.zombie_list = pygame.sprite.Group()
self.blood_splash = BloodSplash()
self.background = Object()
self.player = Player()
self.zombie_sprite = []
self.grave_list = []
self.hud = HUD()
self.sound_list = dict()
self.bg_music = pygame.mixer.music
self.game_over = False
self.time = pygame.time.get_ticks()
def init(self):
self.read_scene()
# Bring cursor to front
self.all_object_list.move_to_front(self.player)
# Set background music
self.sound_list['background'].play().set_endevent(pygame.constants.USEREVENT)
# Scale background to screen size
self.background.image = pygame.transform.scale(self.background.image, (SCREEN_WIDTH, SCREEN_HEIGHT))
def process_events(self, event):
if event.type == pygame.USEREVENT:
self.sound_list['background'].play()
elif event.type == pygame.MOUSEBUTTONDOWN:
self.sound_list['gunshot'].play()
self.process_raycast()
elif event.type == pygame.KEYDOWN:
if (event.key == pygame.K_p):
if self.is_running:
self.pause()
else:
self.resume()
def update(self):
if (not self.is_running):
return
# Process game
self.process_zombie()
# Update all objects
self.all_object_list.update(self.hud)
self.hud.update()
def draw(self, screen):
screen.fill(WHITE)
self.all_object_list.draw(screen)
apply_all(self.zombie_list.sprites(), 'show_timer', screen)
self.hud.draw(screen)
#--------------------------------------LOGIC PROCESSING SECTION-----------------------------------------------
def process_zombie(self):
# Randomly choose an interval between 0.5 to 1.5 second to spawn another zombie
if (pygame.time.get_ticks() - self.time >= random.randrange(1, 3) * 500):
# Random location for zombie
zombie_pos = random.randrange(0, len(self.grave_list))
# Check if grave's position already had zombie
if (not next((True for zombie in self.zombie_list.sprites() if zombie.pos == zombie_pos), False)):
# Randomly pick zombie from zombie sprite list
zombie = deepcopy(self.zombie_sprite[random.randrange(0, len(self.zombie_sprite))])
zombie.set_pos(zombie_pos)
# Set zombie to the right position
zombie.move_to(*self.grave_list[zombie_pos].get_pos())
zombie.translate(35, -10)
# Set zombie layer
zombie.set_layer(self.grave_list[zombie_pos]._layer - 1)
# Add to zombie list and object list
self.zombie_list.add(zombie)
self.all_object_list.add(zombie)
# Reset timer
self.time = pygame.time.get_ticks()
def process_raycast(self):
mouse_pos = pygame.mouse.get_pos()
hit_zombie = next((zombie for zombie in self.zombie_list.sprites() if zombie.collide_point(list(map(operator.sub, mouse_pos, zombie.get_pos())))), None)
if (hit_zombie is not None):
# Play zombie's death sound
self.sound_list['dying_scream'].play()
# Update hit count
self.hud.update_hit()
# Splash blood
#.........这里部分代码省略.........