本文整理汇总了Python中Player.init方法的典型用法代码示例。如果您正苦于以下问题:Python Player.init方法的具体用法?Python Player.init怎么用?Python Player.init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Player
的用法示例。
在下文中一共展示了Player.init方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Scene
# 需要导入模块: import Player [as 别名]
# 或者: from Player import init [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 init [as 别名]
class Scene(State):
def __init__(self, file_path):
super(Scene, self).__init__()
pygame.mixer.init(44100, -16, 4, 2048)
self.position = ['goalkeeper', 'defender', 'midfielder', 'attacker']
self.all_object_list = pygame.sprite.LayeredUpdates()
self.selection_circle = [] # Prototype
self.left_player = Player() # Prototype
self.right_player = Player() # Prototype
self.teams = collections.defaultdict(dict)
self.field = Object()
self.field_border = Object()
self.goal = []
self.ball = Ball()
self.hud = HUD()
self.goal_image = EffectObject()
self.formation = {Team_side.LEFT: [1, 4, 3, 3], Team_side.RIGHT: [1, 4, 4, 2]}
self.sound_list = dict()
# Game config
self.game_mode = Game_mode.PvP
self.P1_controlled_team = Team_side.LEFT
self.P1_controlled_position = 'midfielder'
self.P2_controlled_team = Team_side.RIGHT
self.P2_controlled_position = 'midfielder'
# Load scene's resources
self.read_scene(file_path)
def init(self):
# Set teams info
# Left team
self.game_mode = self.get_shared_var('mode')
self.formation[self.P1_controlled_team] = self.get_shared_var('P1_formation')
team1_id = self.get_shared_var('P1_team_ID')
self.hud.set_left_team_name(Team_name[team1_id])
self.left_player.setImage(ResourceManager.instance().image_path_list[56 + team1_id])
# Right team
self.formation[self.P2_controlled_team] = self.get_shared_var('P2_formation')
team2_id = self.get_shared_var('P2_team_ID')
self.hud.set_right_team_name(Team_name[team2_id])
self.right_player.setImage(ResourceManager.instance().image_path_list[56 + team2_id])
# Calculate players and ball position
self.calculate_position()
# Set controlled team
self.controlled_team = Team_side.LEFT
# Randomize ball direction
self.ball.set_angle(random.randrange(0, 360, 20))
# Game control
self.game_over = False
self.match_state = Match_state.KICKOFF
self.match_time = 120000
self.time = self.match_time
# Reset score
self.hud.reset_score()
# Set background music
pygame.mixer.stop()
self.sound_list['background'].play().set_endevent(pygame.constants.USEREVENT)
def process_key_press(self, key):
if key[pygame.K_w]:
apply_all(self.teams[self.P1_controlled_team][self.P1_controlled_position], 'move_up')
if key[pygame.K_s]:
apply_all(self.teams[self.P1_controlled_team][self.P1_controlled_position], 'move_down')
if key[pygame.K_UP]:
apply_all(self.teams[self.P2_controlled_team][self.P2_controlled_position], 'move_up')
if key[pygame.K_DOWN]:
apply_all(self.teams[self.P2_controlled_team][self.P2_controlled_position], 'move_down')
def process_events(self, event):
if event.type == pygame.USEREVENT:
self.sound_list['background'].play()
elif event.type == pygame.MOUSEBUTTONDOWN:
return ''
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
if self.is_running:
self.pause()
else:
self.resume()
elif event.key == pygame.K_a:
apply_all(self.teams[self.P1_controlled_team][self.P1_controlled_position], 'stop')
self.P1_controlled_position = self.position[max(0, self.position.index(self.P1_controlled_position) - 1)]
elif event.key == pygame.K_d:
apply_all(self.teams[self.P1_controlled_team][self.P1_controlled_position], 'stop')
self.P1_controlled_position = self.position[min(3, self.position.index(self.P1_controlled_position) + 1)]
elif event.key == pygame.K_LEFT:
apply_all(self.teams[self.P2_controlled_team][self.P2_controlled_position], 'stop')
self.P2_controlled_position = self.position[min(3, self.position.index(self.P2_controlled_position) + 1)]
elif event.key == pygame.K_RIGHT:
apply_all(self.teams[self.P2_controlled_team][self.P2_controlled_position], 'stop')
self.P2_controlled_position = self.position[max(0, self.position.index(self.P2_controlled_position) - 1)]
#.........这里部分代码省略.........
示例3: Scene
# 需要导入模块: import Player [as 别名]
# 或者: from Player import init [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
#.........这里部分代码省略.........