本文整理匯總了Python中pygame.sprite.Group.remove方法的典型用法代碼示例。如果您正苦於以下問題:Python Group.remove方法的具體用法?Python Group.remove怎麽用?Python Group.remove使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pygame.sprite.Group
的用法示例。
在下文中一共展示了Group.remove方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: run_game
# 需要導入模塊: from pygame.sprite import Group [as 別名]
# 或者: from pygame.sprite.Group import remove [as 別名]
def run_game():
pygame.init()
ai_settings = Settings()
""" Screen settings and such"""
screen = pygame.display.set_mode(
(ai_settings.screen_width, ai_settings.screen_height))
pygame.display.set_caption("Alien Invasion")
stats = GameStats(ai_settings)
bg_color = (230, 230, 230)
"""background screen color; grey"""
ship = Ship(ai_settings, screen)
bullets = Group()
aliens = Group()
gf.create_fleet(ai_settings, screen, ship, aliens)
while True:
gf.check_events(ai_settings, screen, ship, bullets)
ship.update()
gf.update_bullets(ai_settings, screen, ship, aliens, bullets)
gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets)
gf.update_screen(ai_settings, screen, ship, aliens, bullets)
for bullet in bullets.copy():
if bullet.rect.bottom <= 0:
bullets.remove(bullet)
print(len(bullets))
示例2: run_game
# 需要導入模塊: from pygame.sprite import Group [as 別名]
# 或者: from pygame.sprite.Group import remove [as 別名]
def run_game():
pygame.init()
ai_settings = Settings()
screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height))
pygame.display.set_caption("Alien Invasion")
# make a ship
ship = Ship(ai_settings, screen)
bullets = Group()
aliens = Group()
alien = Alien(ai_settings, screen)
gf.create_fleet(ai_settings, screen, aliens)
while True:
gf.check_events(ai_settings, screen, ship, bullets)
ship.update()
gf.update_bullets(bullets)
gf.update_screen(ai_settings, screen, ship, aliens, bullets)
bullets.update()
# Get rid of bullets that have disappeared.
for bullet in bullets.copy():
if bullet.rect.bottom <= 0:
bullets.remove(bullet)
print(len(bullets))
示例3: remove
# 需要導入模塊: from pygame.sprite import Group [as 別名]
# 或者: from pygame.sprite.Group import remove [as 別名]
def remove(self, *sprites):
for current_sprite in sprites:
if current_sprite not in self: continue
row, col = self.get_cell_row_col(current_sprite)
self.cells[row][col] = None
Group.remove(self, *sprites)
示例4: remove
# 需要導入模塊: from pygame.sprite import Group [as 別名]
# 或者: from pygame.sprite.Group import remove [as 別名]
def remove(self, *sprites):
"""Removes as normal but also updates the formation array"""
Group.remove(self, *sprites)
for current_sprite in sprites:
row = current_sprite.row
col = current_sprite.col
self.formation[col][row] = None
if col == self.rightmost_col or col == self.leftmost_col:
self.adjust_borders()
示例5: handle_event
# 需要導入模塊: from pygame.sprite import Group [as 別名]
# 或者: from pygame.sprite.Group import remove [as 別名]
def handle_event(self, event):
if isinstance(event, UpdateEvent):
loop = get_loop()
group = Group(loop.render.sprites())
for member in pygame.sprite.spritecollide(loop.bg_sprite, loop.render, False):
if member in group:
group.remove(member)
for sprite in group:
loop.rm_object(sprite)
pygame.sprite.groupcollide(loop.projectiles, loop.enemies, True, True)
if pygame.sprite.spritecollide(loop.you, loop.enemies, False):
loop.rm_object(loop.you)
lose()
示例6: run_game
# 需要導入模塊: from pygame.sprite import Group [as 別名]
# 或者: from pygame.sprite.Group import remove [as 別名]
def run_game():
# Initialize game and create a screen object.
pygame.init()
ai_settings = Settings()
screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height))
pygame.display.set_caption("Zombie Tower Ultimate Sonic The Next Generation Super EX")
play_button = Button(ai_settings, screen, "Play")
# Set the background color
ship = Ship(screen, ai_settings)
bullets = Group()
bomb = Group()
lasercheat = Group()
nuke = Nuke(ai_settings, screen, ship)
block = Block(ai_settings, screen, nuke)
wall = Wall(ai_settings, screen, ship)
lift = Lift(ai_settings, screen, nuke)
aliens = Group()
alien = Alien(ai_settings, screen)
# Start the main loop for the game.
stats = GameStats(ai_settings, bomb, aliens, bullets)
sb = Scoreboard(ai_settings, screen, stats)
gf.create_fleet(ai_settings, screen, ship, aliens)
while True:
# Watch for keyboard and mouse events.
gf.check_events(ai_settings, screen, stats, ship, bullets, lasercheat, aliens, nuke, play_button, bomb, wall, lift)
if stats.game_active:
ship.update()
gf.update_aliens(ai_settings, stats, screen, ship, aliens, bomb, wall)
ai_settings.counterpnts -= 1
if ai_settings.counterpnts <=0:
ai_settings.counterpnts = 60
stats.score += 1
sb.prep_score()
bullets.update()
bomb.update(aliens, ai_settings, screen)
gf.update_screen(ai_settings, screen, stats, sb, ship, bullets, lasercheat, aliens, nuke, play_button, wall, bomb, lift, block)
# Get rid of bullets that have disappeared.
for bullet in bullets.copy():
if bullet.rect.right >= 1200:
bullets.remove(bullet)
print(len(bullets))
示例7: WvmSpritesList
# 需要導入模塊: from pygame.sprite import Group [as 別名]
# 或者: from pygame.sprite.Group import remove [as 別名]
class WvmSpritesList():
"""A class listing all the Sprites of the game."""
def __init__(self, config, screen):
"""Initialize the sprite list."""
self.config = config
self.screen = screen
#initialize the sprites
self.wiz = Wizard(config, self)
self.monsters = Group()
self.missiles = Group()
def update_all(self):
"""Update the positions of all sprites."""
self.update_missiles()
self.wiz.update()
self.monsters.update()
def update_missiles(self):
"""update magic missiles positions"""
self.missiles.update()
# remove the missiles that have left the screen
for mi in self.missiles.copy():
if mi.rect.left >= self.screen.get_rect().right:
self.missiles.remove(mi)
def draw(self):
self.screen.fill(self.config.bg_color)
for mi in self.missiles:
mi.draw_missile()
self.wiz.blitme()
for mo in self.monsters:
mo.blitme()
def fire_missile(self):
"""Fire a missile if limit not reached yet."""
if len(self.missiles) < self.wiz.magic_missile_allowed:
self.missiles.add(MagicMissile(self.config, self))
def create_monster(self):
"""Create a new monster and place it randomly at the right."""
monster=Monster(self.config, self)
#TODO move the monster
self.monsters.add(monster)
示例8: run_game
# 需要導入模塊: from pygame.sprite import Group [as 別名]
# 或者: from pygame.sprite.Group import remove [as 別名]
def run_game():
pygame.init()
ai_settings = Settings()
screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height))
pygame.display.set_caption("Alien Invasion")
ship = Ship(ai_settings, screen)
bullets = Group()
while True:
gf.check_events(ai_settings, screen, ship, bullets)
ship.update()
bullets.update()
gf.update_screen(ai_settings, screen, ship, bullets)
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
screen.fill(ai_settings.bg_color)
ship.blitme()
pygame.display.flip()
bullets.update()
for bullet in bullets.copy():
if bullet.rect.bottom <= 0:
bullets.remove(bullet)
print(len(bullets))
示例9: __init__
# 需要導入模塊: from pygame.sprite import Group [as 別名]
# 或者: from pygame.sprite.Group import remove [as 別名]
class ObstacleManager:
obstacle_types = {Beer: 89,
Nyan: 2,
EnergyDrink: 3,
HealthPack: 4,
Vodka: 10
}
obstacles = []
counter = 0
default_speed = 0
def __init__(self, gameboard, speed, max_obstacles, collision_strategy_factory, player):
self.max_obstacles = max_obstacles
self.gameboard = gameboard
self.width = gameboard.width
self.height = gameboard.height
self.speed = speed
self.default_speed = speed
self.obstacle_group = Group()
self.collision_strategy_factory = collision_strategy_factory
self.player = player
def update(self, time_passed):
delete_list = []
for obstacle in self.obstacles:
if obstacle.y > self.height:
delete_list.append(obstacle)
else:
obstacle.update(time_passed)
for obstacle in delete_list:
self.obstacles.remove(obstacle)
obstacle.kill()
def blit(self):
for obstacle in self.obstacles:
obstacle.blit()
def create_obstacle(self):
if len(self.obstacles) <= self.max_obstacles:
self.counter += 1
if self.counter % 10 == 0:
obstacle = self.__select_obstacle_type()(self.gameboard,
(random.randint(0, self.width), -40),
self.speed * (1 + (random.random()-0.5) * 0.2))
self.obstacles.append(obstacle)
self.obstacle_group.add(obstacle)
def __select_obstacle_type(self):
total = sum(w for c, w in self.obstacle_types.items())
r = random.uniform(0, total)
upto = 0
for c, w in self.obstacle_types.items():
if upto + w > r:
return c
upto += w
def detect_collision(self):
collisions = spritecollide(self.player, self.obstacle_group, True)
for c in collisions:
self.collision_strategy_factory.get_strategy(c).on_collision()
self.obstacles.remove(c)
c.kill()
def accelerate_obstacles(self, speed):
self.speed += speed
if self.speed > 1.5:
self.speed = 1.5
def reset(self):
self.speed = self.default_speed
for obstacle in self.obstacles:
obstacle.kill()
self.obstacle_group.remove(obstacle)
self.obstacles = []
示例10: __init__
# 需要導入模塊: from pygame.sprite import Group [as 別名]
# 或者: from pygame.sprite.Group import remove [as 別名]
class Game:
def __init__(self, screen):
self.screen = screen
self.map_screen = self.screen.subsurface(0, 0, MAP_WIDTH, MAP_HEIGHT)
#pygame.display.set_icon(pygame.image.load(os.path.join("images", "ui","icon.png")))
self.loaded_maps = {}
self.current_map = None
pygame.mouse.set_visible(1);
self.hasKey = False
self.animalsFreed = False
self.soundUtil = SoundUtil()
self.soundUtil.sound_on = True
self.pauseMenu = PauseScreen(self)
self.cursor = Sprite()
self.cursor.rect = Rect(0,0,1,1)
self.hud = Hud(self)
self.player_group = Group()
self.player = Taz(image_util.load_image("tasmanian.png"), 1, 1, self)
self.player.inUse = True
self.player.current_image = self.player.image
self.hud.set_player(self.player)
self.last_rendered_achievement = 0
self.achievement_countdown = 0
self.clock = pygame.time.Clock()
self.achievements_done = []
self.pressed = []
for key in pygame.key.get_pressed():
self.pressed.append( True )
self.loadLevel("jail.txt")
self.isGameOver = False
self.returnToMainMenu = False
def reset(self):
self.player_group.remove(self.player)
self.current_map.game_objects.remove(self.player)
self.player = self.player.newPlayer()
self.player.inUse = True
self.player.current_image = self.player.image
self.pressed = []
for key in pygame.key.get_pressed():
self.pressed.append( False )
self.loadLevel("jail.txt")
self.player.x = TILE_SIZE
self.player.y = TILE_SIZE
self.player.rect.left = self.player.x + self.player.left_offset
self.player.rect.top = self.player.y + self.player.top_offset
def loadLevel(self, file):
self.pressed = []
for key in pygame.key.get_pressed():
self.pressed.append( False )
if file in self.loaded_maps:
self.current_map = self.loaded_maps[file]
self.current_map.reset()
else:
self.current_map = Map(file, self.screen, self)
self.loaded_maps[file] = self.current_map
self.current_map.intialize()
def change_maps(self, dest, x, y):
if self.player.isInCar:
self.current_map.game_objects.remove(self.player.car)
self.current_map.not_player.remove(self.player.car)
self.loadLevel(dest)
self.player.x = x * TILE_SIZE
self.player.y = y * TILE_SIZE
self.player.rect.left = self.player.x + self.player.left_offset
self.player.rect.top = self.player.y + self.player.top_offset
if self.player.isInCar:
if isinstance(self.player.car, ImperviousCar):
self.player.car = Car(None,0,0,self)
self.player.car.driver = self.player
self.player.car.driving = True
self.player.car.x = x * TILE_SIZE
self.player.car.y = y * TILE_SIZE
self.player.car.rect.left = self.player.car.x
self.player.car.rect.top = self.player.car.y
self.player.car.avoidMapLinks()
self.current_map.game_objects.add(self.player.car)
#.........這裏部分代碼省略.........
示例11: TrySprite
# 需要導入模塊: from pygame.sprite import Group [as 別名]
# 或者: from pygame.sprite.Group import remove [as 別名]
#.........這裏部分代碼省略.........
# Feet mask
self.feet_mask = mask.Mask((self.rect.width, 1))
h = self.rect.height
s_at = self.feet_mask.set_at
g_at = self.mask.get_at
for x in xrange(self.rect.width):
if g_at((x, h - 1)):
s_at((x, 0), 1)
#~ @property
#~ def dirty(self):
#~ return self._dirty
#~
#~ @dirty.setter
#~ def dirty(self, value):
#~ if self.dirty == 1:
#~ old = self.dirty_rect
#~ else:
#~ old = self.rect
#~ self.dirty_rect = old.union(self.rect)
#~ self._dirty = value
def add_guest(self, sprite):
""" Add a guest sprite to this sprite.
The guest sprite will be updated after the host.
"""
self.guests.add(sprite)
sprite.guest = True
sprite.host = self
def remove_guest(self, sprite):
""" Remove a guest sprite to this sprite. """
self.guests.remove(sprite)
sprite.guest = False
sprite.host = None
def add_host(self, sprite):
""" Add a host for this sprite.
This sprite will be updated after the host sprite.
"""
self.host = sprite
self.guest = True
sprite.guests.add(self)
def remove_host(self):
""" Remove a host from this sprite. """
self.host.guests.remove(self)
self.host = None
self.guest = False
def one_layer_down(self):
""" Moves the sprite one layer down in the render group.
This will make the sprite be seen below other sprites
in the same group.
"""
for g in self.groups():
if isinstance(g, TryGroup):
g.one_layer_down(self)
示例12: EventLoop
# 需要導入模塊: from pygame.sprite import Group [as 別名]
# 或者: from pygame.sprite.Group import remove [as 別名]
class EventLoop(object):
def __init__(self):
self.objs = {}
self.events = []
self.render = RenderUpdates()
self.projectiles = Group()
self.enemies = Group()
self.you = None
self.bg_sprite = BGSprite(pygame.display.get_surface())
# Since we don't care about MOST EVENTS
pygame.event.set_allowed(None)
pygame.event.set_allowed([ MOUSEBUTTONDOWN, KEYDOWN, QUIT, UPDATEEVENT, SPAWNEVENT ])
def add_object(self, obj, type=""):
if isinstance(obj, HandlesEvents):
if obj.events == ALL:
try:
self.objs[ALL].append(obj)
except KeyError:
self.objs[ALL] = [ obj ]
else:
for event in obj.events:
try:
self.objs[event].append(obj)
except KeyError:
self.objs[event] = [ obj ]
if isinstance(obj, Sprite):
self.render.add(obj)
if type == "enemy":
self.enemies.add(obj)
if type == "projectile":
self.projectiles.add(obj)
if type == "you":
self.you = obj
def rm_object(self, obj):
for key in self.objs.keys():
self.render.remove(obj)
if obj in self.objs[key]:
self.objs[key].remove(obj)
if self.projectiles.has(obj):
self.projectiles.remove(obj)
if self.enemies.has(obj):
self.enemies.remove(obj)
print "Removed {0}".format(obj)
def enqueue(self, event):
if isinstance(event, Event):
return self.events.append(event)
elif isinstance(event, list):
return [ self.enqueue(ev) for ev in event ]
def tick(self):
try:
event = self.events.pop()
except IndexError:
event = None
if event is not None:
if isinstance(event, TargettedEvent):
event.get_target().handle_event(event)
for obj in self.objs[ALL]:
obj.handle_event(event)
else:
for obj in self.objs[type(event)] + self.objs[ALL]:
if obj.handles_event(event):
obj.handle_event(event)
if random.randint(0, 10000000) == 26:
return win()
if random.randint(0, 10000000) == 26:
return lose()
py_events = map(lambda event: PygameEvent(event), pygame.event.get())
for py_event in py_events:
for obj in reduce(lambda obj_list, obj: obj_list + obj, map(lambda key: self.objs[key], filter(lambda handler_type: issubclass(handler_type, PygameEvent) if handler_type != ALL else False, self.objs.keys())), []):
if obj.handles_event(py_event):
obj.handle_event(py_event)
示例13: Level
# 需要導入模塊: from pygame.sprite import Group [as 別名]
# 或者: from pygame.sprite.Group import remove [as 別名]
class Level(object):
fg_color = 0, 0, 0
jungle = load_image("tilegrass.png")
cliff = load_image("tilecliff.png")
lab = load_image("tilemetal.png")
def __init__(self):
self.pups = Group()
self.tiles = Group()
def reset(self):
self.__init__()
def update(self):
for pup in self.pups:
if pup.state == 0 or pup.state == 3:
self.pups.remove(pup)
self.tiles.add(pup)
for pup in self.tiles:
if pup.state == 1 or pup.state == 2:
self.tiles.remove(pup)
self.pups.add(pup)
def draw_hud(self, screen, player):
bounds = screen.get_rect()
pixfont = "./data/fonts/pixelated.ttf"
self.player = player
file_in = open("score.txt","r")
for line in file_in:
self.score = str(line)
self.currentscore = self.score
self.display_score = int(self.currentscore) + int(self.player.scorenum)
font = pygame.font.Font(pixfont, 15)
self.scoredisplay = font.render(("SCORE:"+" "+str(self.display_score)), True, self.fg_color)
rect = self.scoredisplay.get_rect()
rect.center = bounds.centerx - 360, bounds.centery - 160
screen.blit(self.scoredisplay, rect)
if self.wlimit > 0:
self.whistles = font.render(("WHISTLES:"+" "+str(self.wlimit - self.player.whistlecount)), True, self.fg_color)
rect = self.whistles.get_rect()
rect.center = bounds.centerx + 340, bounds.centery - 140
screen.blit(self.whistles, rect)
if self.tlimit > 0:
self.treats = font.render(("TREATS:"+" "+str(self.tlimit - self.player.treatcount)), True, self.fg_color)
rect = self.treats.get_rect()
rect.center = bounds.centerx + 350, bounds.centery - 160
screen.blit(self.treats, rect)
def draw(self, screen, player):
bounds = screen.get_rect()
if self.type == "jungle":
self.bg = load_image("junglebg1.png")
elif self.type == "cliff":
self.bg = load_image("cliffbg.png")
elif self.type == "lab":
self.bg = load_image("labbg.png")
rect = self.bg.get_rect()
rect.center = bounds.centerx, bounds.centery
screen.blit(self.bg, rect)
示例14: EditorLevel
# 需要導入模塊: from pygame.sprite import Group [as 別名]
# 或者: from pygame.sprite.Group import remove [as 別名]
class EditorLevel(object):
def __init__(self, editor, level_file=None):
self.editor = editor
self.font_manager = editor.font_manager
if level_file is not None:
(name, player_start, player_direction, board, enemies, powerups) = level_loader.load(level_file)
else:
player_start = None
player_direction = None
board = None
enemies = []
powerups = []
self.board = Board(constants.HORIZONTAL_TILES, constants.VERTICAL_TILES)
for x in xrange(0, constants.HORIZONTAL_TILES):
for y in xrange(0, constants.VERTICAL_TILES):
if board is None:
if x == 0 or y == 0 or x == constants.HORIZONTAL_TILES - 1 or y == constants.VERTICAL_TILES - 1:
tile = Tile("W", Point(x, y))
else:
tile = Tile("G", Point(x, y))
else:
tile = Tile(board.get_tile(x, y).type, Point(x, y))
self.board.set_tile(x, y, tile)
self.tiles = OrderedUpdates([tile for tile in self.board])
self.entities = Group()
if player_start is not None:
player_entity = Entity("PLAYER", editor_constants.ENTITY_DATA_MAP["PLAYER"], player_start, self.font_manager)
player_entity.rotate(player_direction, 1)
self.entities.add(player_entity)
for (position, direction, waypoint_type, waypoints) in enemies:
entity = Entity("ENEMY", editor_constants.ENTITY_DATA_MAP["ENEMY"], position, self.font_manager)
entity.rotate(direction, 1)
actual_waypoints = []
for waypoint in waypoints:
actual_waypoints.append(Entity("WAYPOINT", editor_constants.WAYPOINT_DATA, waypoint, self.font_manager))
entity.waypoints.set_waypoints(actual_waypoints)
self.entities.add(entity)
for powerup in powerups:
entity = Entity(powerup.type, editor_constants.ENTITY_DATA_MAP[powerup.type], powerup.position, self.font_manager)
self.entities.add(entity)
self.toolbars = Group()
vertical_toolbar = VerticalToolbar(self, self.font_manager)
self.toolbars.add(vertical_toolbar)
self.player_exists = bool([entity for entity in self.entities if entity.name == "PLAYER"])
self.entity_to_create = vertical_toolbar.selected.name
self.mode = MODE_ADD
self.rotating = False
self.pending_actions = []
self.action_stack = []
self.undone_action_stack = []
self.selected_entities = []
self.waypoint_entity_selected = None
def add_action(self, action_type, *args):
self.undone_action_stack = []
self.pending_actions.append(action_type(self, *args))
def get_entity(self, position):
data = editor_constants.ENTITY_DATA_MAP[self.entity_to_create]
return Entity(self.entity_to_create, data, position, self.font_manager)
def add_entity(self, entity):
if entity.name == "PLAYER":
self.player_exists = True
self.entities.add(entity)
def remove_entity(self, entity):
if entity.name == "PLAYER":
self.player_exists = False
self.entities.remove(entity)
if entity in self.selected_entities:
entity.select(False)
self.selected_entities.remove(entity)
if entity is self.waypoint_entity_selected:
entity.select(False)
self.waypoint_entity_selected = None
def delete_selection(self):
self.add_action(DeleteSelectionAction, list(self.selected_entities))
def set_selection(self, entities):
self.clear_selection()
for entity in entities:
if not entity in self.entities:
raise Exception("Tried to select non-existent entity.")
entity.select(True)
#.........這裏部分代碼省略.........
示例15: LumberjackGame
# 需要導入模塊: from pygame.sprite import Group [as 別名]
# 或者: from pygame.sprite.Group import remove [as 別名]
class LumberjackGame(Microgame):
def __init__(self):
# TODO: Initialization code here
Microgame.__init__(self)
self.jack = Man()
self.count = 0
self.mycount = pygame.font.SysFont("arial", 50, bold = True)
self.left, self.left_rect = _load_image(join("games","Lumberjack","images","timberman_normalleft.png"), 105, 400)
self.left_chop, self.leftc_rect = _load_image(join("games","Lumberjack","images","timberman_chopleft.png"), 130, 450)
self.right, self.right_rect = _load_image(join("games","Lumberjack","images","timberman_normalright.png"), 500, 400)
self.right_chop, self.rightc_rect = _load_image(join("games","Lumberjack","images","timberman_chopright.png"), 375, 450)
self.stump = load(join("games","Lumberjack","images","stump.png"))
self.sprites = Group(self.jack)
self.background = load(join("games","Lumberjack","images","forest.png"))
self.tree = Group(treeBlock(LEFT_POSITION, 550, 1))
def start(self):
# TODO: Startup code here
music.load(join("games","Lumberjack","music","tree_song.ogg"))
music.play()
self.generateTree()
def stop(self):
# TODO: Clean-up code here
music.stop()
def generateTree(self):
_ , min_y = self.tree.sprites()[len(self.tree.sprites()) - 1].rect.topleft
cur_tree = 0
for n in range(0, (len(self.tree.sprites()) - 1)):
_ , y = self.tree.sprites()[n].rect.topleft
if y < min_y:
min_y = y
cur_tree = n
if min_y > 0 and min_y <= 550:
tree_type = self.tree.sprites()[cur_tree].type
if tree_type == 2:
self.tree.add(treeBlock(LEFT_POSITION, (min_y - 140), randint(1,2)))
elif tree_type == 0:
self.tree.add(treeBlock(LEFT_POSITION, (min_y - 140), randint(0,1)))
else:
self.tree.add(treeBlock(LEFT_POSITION, (min_y - 140), randint(0,2)))
def updateTree(self, side):
max_y = locals.HEIGHT
cur_tree = 0
for n in range(0, (len(self.tree.sprites()))):
_ , y = self.tree.sprites()[n].rect.topleft
if 550 == y:
max_y = y
cur_tree = n
print max_y, self.tree.sprites()[cur_tree].type
if self.tree.sprites()[cur_tree].type == side:
self.lose()
else:
self.tree.remove(self.tree.sprites()[cur_tree])
#self.tree.update()
for each in self.tree:
each.update()
def update(self, events):
# TODO: Update code here
self.sprites.update()
self.generateTree()
#Process user input
sound_chop = pygame.mixer.Sound(join("games","Lumberjack","music","axe_chop.wav"))
if self.jack.image == self.left_chop:
self.jack.image = self.left
self.jack.rect = self.left_rect
elif self.jack.image == self.right_chop:
self.jack.image = self.right
self.jack.rect = self.right_rect
for event in events:
if event.type == KEYDOWN and event.key == K_LEFT:
self.count += 1
sound_chop.play()
self.jack.image = self.left_chop
self.jack.rect = self.leftc_rect
self.updateTree(2)
elif event.type == KEYDOWN and event.key == K_RIGHT:
self.count += 1
sound_chop.play()
self.jack.image = self.right_chop
self.jack.rect = self.rightc_rect
self.updateTree(0)
def render(self, surface):
# TODO: Rendering code here
surface.fill(Color(255, 255, 255))
surface.blit(self.background, (0, 0), area = None, special_flags = 0)
self.tree.draw(surface)
surface.blit(self.stump, (318, 690), area = None, special_flags = 0)
self.sprites.draw(surface)
label = self.mycount.render(str(self.count), 1, (255, 255, 255))
if self.count <= 9:
surface.blit(label, (398, 200))
else:
surface.blit(label, (385, 200))
#.........這裏部分代碼省略.........