本文整理汇总了Python中display.Display.paint_sprite方法的典型用法代码示例。如果您正苦于以下问题:Python Display.paint_sprite方法的具体用法?Python Display.paint_sprite怎么用?Python Display.paint_sprite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类display.Display
的用法示例。
在下文中一共展示了Display.paint_sprite方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BasicMovement
# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import paint_sprite [as 别名]
#.........这里部分代码省略.........
x = random.randint(0, self.display.bgmax[0])
s = Fass([200, y])
self.barrels.add(s)
def init_meanies(self, counter):
move_index = 0
while counter < self.number_meanies:
mx = random.randint( 0, self.display.bgmax[0]-40 )
my = random.randint( 0, self.display.bgmax[1]-40 )
meanie = Meanie()
meanie.state.set_random_move_index()
meanie.rect.center = mx,my
self.testgroup.add(meanie)
if meanie.overlaps(self.testgroup):
self.testgroup.remove(meanie)
meanie.kill()
self.init_meanies(counter)
else:
self.meanie_list.insert(counter,meanie)
self.meanies.add(self.meanie_list[counter])
counter += 1
if counter == self.number_meanies:
self.start_game()
def start_game(self):
del self.testgroup
self.gameRunning = True
self.mainloop()
def mainloop(self):
self.clock = pygame.time.Clock()
self.player.rect.center = [120,220]
while self.gameRunning:
dirty = []
self.clock.tick(FPS)
self.framerate = self.clock.get_fps()
self.display.paint_background(dirty)
self.player.state.set_current_state(self)
# blit player on screen
d = self.display.paint_sprite(self.player)
dirty.insert(len(dirty), d)
self.steine.update()
self.ladders.update()
self.barrels.update(self)
self.meanies.update(self, dirty)
self.hud.showinfo(self, dirty)
for e in pygame.event.get():
if e.type == QUIT:
self.gameRunning = False
pygame.quit()
sys.exit()
elif e.type == KEYDOWN:
if e.key == K_ESCAPE:
self.gameRunning = False
pygame.quit()
sys.exit()
elif e.key == K_UP and self.player.state.climbing:
self.player.movement[1]= - self.player.speed
elif e.key == K_DOWN and not self.player.state.falling and self.player.state.climbing:
self.player.movement[1]= self.player.speed
elif e.key == K_LEFT:
if self.player.state.falling:
self.player.movement[0] = - self.player.speed/2
else:
self.player.movement[0] = - self.player.speed
elif e.key == K_RIGHT:
if self.player.state.falling:
self.player.movement[0] = self.player.speed/2
else:
self.player.movement[0] = self.player.speed
elif e.type == KEYUP:
if e.key == K_UP or e.key == K_DOWN:
self.player.movement[1] = 0
elif e.key == K_LEFT or e.key == K_RIGHT:
self.player.movement[0] = 0
self.player.update(self)
pygame.display.update(dirty)
示例2: Game
# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import paint_sprite [as 别名]
class Game():
framerate = 0
number_meanies = 32
def __init__(self):
self.display = Display()
self.player = Charactor(self)
self.level = Level(self)
self.hud = Hud()
self.prepare_stage()
def prepare_stage(self):
self.level.load_level(0)
self.start_game()
def start_game(self):
self.gameRunning = True
self.mainloop()
def mainloop(self):
self.clock = pygame.time.Clock()
self.player.rect.center = [self.display.arena[0]/2, self.display.arena[1]/2]
controller = Controller()
while self.gameRunning:
dirty = []
self.clock.tick(FPS)
self.framerate = self.clock.get_fps()
self.display.paint_background(dirty)
self.player.state.set_current_state()
d = self.display.paint_sprite(self.player)
dirty.insert(len(dirty), d)
self.steine.update()
self.ladders.update()
self.barrels.update()
self.meanies.update(dirty)
self.hud.showinfo(self, dirty)
controller.handle_keyboard_input(self.player)
self.player.update()
## Just for debugging - paint hitareas of charactor ##
d = self.draw_hitarea(self.player.feet())
dirty.insert(len(dirty), d)
d = self.draw_hitarea(self.player.middle(), (0,0,255))
dirty.insert(len(dirty), d)
d = self.draw_hitarea(self.player.head(), (0,255,255))
dirty.insert(len(dirty), d)
pygame.display.update(dirty)
def draw_hitarea(self, sprite, color=pygame.Color(255,0,0)):
sfc = pygame.Surface([sprite.rect.width, sprite.rect.height])
sfc.fill(color)
dummy = pygame.sprite.Sprite()
dummy.image = sfc
dummy.rect = sprite.rect
d = self.display.paint_sprite(dummy)
return d
示例3: Game
# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import paint_sprite [as 别名]
#.........这里部分代码省略.........
meanie.state.set_random_move_index()
meanie.rect.center = mx,my
self.testgroup.add(meanie)
if meanie.overlaps(self.testgroup):
self.testgroup.remove(meanie)
meanie.kill()
self.init_meanies(counter)
else:
self.meanies.add(meanie)
counter += 1
if counter == self.number_meanies:
self.start_game()
def start_game(self):
del self.testgroup
self.gameRunning = True
self.mainloop()
def mainloop(self):
self.clock = pygame.time.Clock()
self.player.rect.center = [self.display.arena[0]/2, self.display.arena[1]/2]
controller = Controller()
while self.gameRunning:
dirty = []
self.clock.tick(FPS)
self.framerate = self.clock.get_fps()
self.display.paint_background(dirty)
self.player.state.set_current_state(self)
d = self.display.paint_sprite(self.player)
dirty.insert(len(dirty), d)
self.steine.update()
self.ladders.update()
self.barrels.update()
self.meanies.update(dirty)
self.hud.showinfo(self, dirty)
controller.handle_keyboard_input(self.player)
# for e in pygame.event.get():
#
# if e.type == QUIT:
# self.gameRunning = False
# pygame.quit()
# sys.exit()
# elif e.type == KEYDOWN:
#
# if e.key == K_ESCAPE:
# self.gameRunning = False
# pygame.quit()
# sys.exit()
# elif e.key == K_UP and self.player.state.climbing:
# self.player.movement[1]= - self.player.speed
#
# self.player.face_up()
#
# elif e.key == K_DOWN \
# and not self.player.state.falling \
# and self.player.state.climbing:
#
# self.player.movement[1]= self.player.speed
#
# self.player.face_down()
#
# elif e.key == K_LEFT:
# if self.player.state.falling:
# self.player.movement[0] = - self.player.speed/2
# else:
# self.player.movement[0] = - self.player.speed
#
# if not self.player.state.can_walk_left:
# self.player.movement[0] = 0
#
# self.player.face_left()
#
# elif e.key == K_RIGHT:
# if self.player.state.falling:
# self.player.movement[0] = self.player.speed/2
# else:
# self.player.movement[0] = self.player.speed
#
# if not self.player.state.can_walk_right:
# self.player.movement[0] = 0
#
# self.player.face_right()
#
# elif e.type == KEYUP:
# if e.key == K_UP or e.key == K_DOWN:
# self.player.movement[1] = 0
# elif e.key == K_LEFT or e.key == K_RIGHT:
# self.player.movement[0] = 0
self.player.update()
pygame.display.update(dirty)
示例4: Game
# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import paint_sprite [as 别名]
class Game(Display, Controller):
def __init__(self):
self.framerate = 0
self.number_meanies = 32
self.bricks_in_level = 0
self.display = Display()
self.hud = Hud()
pygame.key.set_repeat(100,5)
self.meanies = pygame.sprite.Group()
self.player = Charactor(self)
self.player.speed = 2
self.level = Level(self)
self.level.load_level(0)
self.start_game()
# self.testgroup = pygame.sprite.Group()
# self.init_meanies(0)
# def init_meanies(self, counter):
#
# while counter < self.number_meanies:
#
# mx = random.randint( 0, self.display.bgmax[0]-40 )
# my = random.randint( 0, self.display.bgmax[1]-40 )
#
# meanie = Meanie()
# meanie.state.set_random_move_index()
# meanie.rect.center = mx,my
# self.testgroup.add(meanie)
#
# if meanie.overlaps(self.testgroup):
# self.testgroup.remove(meanie)
# meanie.kill()
# self.init_meanies(counter)
# else:
# self.meanies.add(meanie)
# counter += 1
#
# if counter == self.number_meanies:
# self.start_game()
def start_game(self):
self.gameRunning = True
self.mainloop()
def mainloop(self):
self.clock = pygame.time.Clock()
self.player.rect.center = [self.display.arena[0]/2, self.display.arena[1]/2]
controller = Controller()
while self.gameRunning:
dirty = []
self.clock.tick(FPS)
self.framerate = self.clock.get_fps()
self.display.paint_background(dirty)
self.player.state.set_current_state(self)
d = self.display.paint_sprite(self.player)
dirty.insert(len(dirty), d)
self.steine.update()
self.ladders.update()
self.barrels.update()
self.meanies.update(dirty)
self.hud.showinfo(self, dirty)
controller.handle_keyboard_input(self.player)
self.player.update()
pygame.display.update(dirty)
示例5: BasicMovement
# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import paint_sprite [as 别名]
#.........这里部分代码省略.........
def start_game(self):
del self.testgroup
self.gameRunning = True
self.mainloop()
def mainloop(self):
print len(self.meanies)
self.clock = pygame.time.Clock()
fnt = pygame.font.Font(None, 20)
self.player.rect.center = [20,220]
# blit background on screen
# self.display.paint_background()
# pygame.display.flip()
while self.gameRunning:
dirty = []
self.clock.tick(_MIN_TICKS_)
framerate = self.clock.get_fps()
dirty_background = self.display.screen.blit(self.display.bg, self.display.bgpos)
# check wether background was "moved"
if self.display.bg_oldpos[0] != self.display.bgpos[0] \
or self.display.bg_oldpos[1] != self.display.bgpos[1]:
dirty.insert(len(dirty), dirty_background)
self.display.bg_oldpos = copy.copy(self.display.bgpos)
self.player.state.set_current_state(self)
# blit player on screen
d = self.display.paint_sprite(self.player)
dirty.insert(len(dirty), d)
self.steine.update()
self.steine.draw(self.display.screen)
self.ladders.update()
self.ladders.draw(self.display.screen)
# d = self.display.paint_sprite(self.stein)
# dirty.insert(len(dirty), d)
# blit meanies on screen
for i in range(0,self.number_meanies):
if self.meanies[i].is_on_screen():
meanie_oldpos = self.meanies[i].rect
# ! make blit position relative to scrolling background !
meanie_pos_x = self.meanies[i].rect.left + self.display.bgpos[0]
meanie_pos_y = self.meanies[i].rect.top + self.display.bgpos[1]
self.meanies[i].rect = meanie_pos_x, meanie_pos_y
d = self.display.paint_sprite(self.meanies[i])
dirty.insert(len(dirty), d)
self.meanies[i].rect = meanie_oldpos
caption = ("bgpos {0} | charpos {1} | fps {2} ").format(
self.display.bgpos,
self.player.rect.center,
framerate
)
txt = fnt.render( caption, 1, (0,0,0), (255,255,0))