本文整理汇总了Python中Level.Level.draw方法的典型用法代码示例。如果您正苦于以下问题:Python Level.draw方法的具体用法?Python Level.draw怎么用?Python Level.draw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Level.Level
的用法示例。
在下文中一共展示了Level.draw方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw
# 需要导入模块: from Level import Level [as 别名]
# 或者: from Level.Level import draw [as 别名]
def draw(self, screen):
Level.draw(self, screen)
if self.selected_obj:
translated = self.camera.translate_to(self.selected_obj.rect)
self.sel_target.draw(screen, translated)
示例2: Game
# 需要导入模块: from Level import Level [as 别名]
# 或者: from Level.Level import draw [as 别名]
class Game(object):
"""Holds all the game objects and runs the game
pygame must be initialised before including this."""
# Constants
# Colors
SCREEN_CLEAR_COLOR = pygame.Color(255, 255, 255)
PLAYER_COLOR = pygame.Color(0, 0, 0)
# Tiles
SOLID_TILE_COLOR = pygame.Color(128, 128, 128)
END_TILE_COLOR = pygame.Color(0, 0, 255)
# Gameplay
GAME_NAME = 'Bounce'
RESOLUTION = (900, 600)
TILE_SIZE = 15 #60x40 tiles
DEF_TIME_SCALE = 0.001 #0.001 is standard time, where each unit is per second
# Timer
TIMER_FONT = pygame.font.SysFont("monospace", 20)
TIMER_COLOR = pygame.Color(0, 0, 0)
TIMER_POSITION = (800, 15)
# Sounds
BOUNCE_VOLUME = 0.8
POPCORN_VOLUME = 0.15
# Controls
NEXT_LEVEL_BTN = K_n
RESTART_BTN = K_r
def __init__(self):
self.timer = Timer(self.TIMER_FONT, self.TIMER_COLOR, self.TIMER_POSITION)
self.time_scale = self.DEF_TIME_SCALE
self.current_level = 0
self.load_next_level()
self.player.POPCORN_SOUND.set_volume(self.POPCORN_VOLUME)
def restart_level(self):
player_start = self.level.load_level(self.current_level)
self.player = Player(player_start, (0, 0), self.PLAYER_COLOR, self.BOUNCE_VOLUME, self.level)
self.timer.time = 0
self.level_complete = False
def load_next_level(self):
self.current_level += 1
self.level = Level([res // self.TILE_SIZE for res in self.RESOLUTION], self.TILE_SIZE, self.SOLID_TILE_COLOR, self.END_TILE_COLOR)
self.restart_level()
def handle_input(self, key_events):
for event in key_events:
if event.key == self.NEXT_LEVEL_BTN:
self.load_next_level()
elif event.key == self.RESTART_BTN:
self.restart_level()
def update(self, delta, key_events):
self.handle_input(key_events)
if not self.level_complete:
special_collisions = self.player.update(delta)
self.level_complete = special_collisions == 'level_complete'
self.timer.update(delta)
def draw(self, display):
self.level.draw(display)
self.player.draw(display)
self.timer.draw(display)
示例3: Game
# 需要导入模块: from Level import Level [as 别名]
# 或者: from Level.Level import draw [as 别名]
class Game():
FPS = 60
SCREEN_SIZE = (1280, 720)
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
DARK_GREY = (10, 10, 10)
MUSIC_FILE = 'data/singsingsing.ogg'
def __init__(self):
pygame.init()
self.font = pygame.font.SysFont('sans-serif', 18, True)
self.surface = pygame.display.set_mode(self.SCREEN_SIZE, 0, 32)
self.state = 'intro'
self.hiscores = Score.read_high_score()
self.menu = Menu(("Start game", "Quit"))
pygame.mixer.music.load(self.MUSIC_FILE)
pygame.mixer.music.play(-1)
def start(self):
while True:
if self.state == 'intro':
# Show the intro and when it's done we move directly to game state
intro = Intro(pygame, self.surface);
new_state = intro.show()
self.state = new_state
elif self.state == 'menu':
# Show the menu and run the menu loop
self.hiscores = Score.read_high_score()
self.show_menu()
elif self.state == 'game':
# Run a game and run the game loop
self.load_level()
self.game_loop()
elif self.state == 'quit':
# Quit, we're done.
pygame.quit()
sys.exit()
# Contains the main menu loop and handles starting and quitting while showing the high scores
def show_menu(self):
pygame.mouse.set_visible(1)
self.menu.drawMenu()
while True:
pygame.time.Clock().tick(self.FPS)
for event in pygame.event.get():
self.menu.handleEvent(event)
if event.type == Menu.MENUCLICKEDEVENT or event.type == QUIT or event.type == KEYDOWN and event.key == K_ESCAPE:
if event.text == "Quit":
self.state = 'quit'
return
elif event.text == 'Start game':
self.state = 'game'
self.menu.deactivate()
return
elif event.type == KEYDOWN and event.key == K_RETURN:
self.state = 'game'
self.menu.deactivate()
return
if self.menu.isActive():
self.menu.drawMenu()
Score.draw_high_scores(self.hiscores, self.surface)
pygame.display.flip()
# Loads and resets a level
def load_level(self):
self.up = False
self.speed = 6
self.nameinput = None
self.level = Level(self)
# The main game loop that updates the level as the game progresses
def game_loop(self):
pygame.mouse.set_visible(0)
while True:
pygame.time.Clock().tick(self.FPS)
events = pygame.event.get()
for event in events:
if event.type == QUIT or event.type == KEYDOWN and event.key == K_ESCAPE:
self.state = 'quit'
return
elif self.state == 'game':
if event.type == KEYDOWN:
if event.key == K_UP:
self.up = True
if event.type == KEYUP:
if event.key == K_UP:
self.up = False
elif self.state == 'gameover':
if event.type == KEYUP:
if event.key == K_RETURN:
if self.nameinput != None:
name = self.nameinput.value
if name == '':
name = 'no name'
Score.update_highscore(name, self.level.get_score(), self.hiscores)
self.state = 'menu'
return
#.........这里部分代码省略.........
示例4:
# 需要导入模块: from Level import Level [as 别名]
# 或者: from Level.Level import draw [as 别名]
""" Clear and background """
screen.fill((255, 255, 255))
screen.blit(background, (0, 0))
if GameStateEnum.mainmenu == gamestate.getState():
""" Update """
""" Draw """
popup.draw(screen)
pass
elif GameStateEnum.running == gamestate.getState():
""" Update """
level.update()
""" Draw """
level.draw(screen)
pass
elif GameStateEnum.shop == gamestate.getState():
""" Upfdate """
""" Draw """
shop.draw(screen)
cursor.draw(screen)
# --- Go ahead and update the screen with what we've drawn.
pygame.display.flip()
# --- Limit to 30 frames per second
clock.tick(30)