本文整理汇总了Python中menu.Menu.up方法的典型用法代码示例。如果您正苦于以下问题:Python Menu.up方法的具体用法?Python Menu.up怎么用?Python Menu.up使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类menu.Menu
的用法示例。
在下文中一共展示了Menu.up方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from menu import Menu [as 别名]
# 或者: from menu.Menu import up [as 别名]
def main():
ser = serial.Serial('/dev/ttyAMA0', 7600, timeout=0)
menu = Menu(MENU_STRUCTURE, 20, 4, output='lcd')
menu.show()
while True:
data = ser.read(8).strip()
if data:
if data == 'c': # clockwise
menu.down()
elif data == 'a': # anti-clockwise
menu.up()
elif data == 'p': # press
menu.select()
menu.show()
sleep(0.01)
示例2: main
# 需要导入模块: from menu import Menu [as 别名]
# 或者: from menu.Menu import up [as 别名]
def main():
menu = Menu(MENU_STRUCTURE, 20, 4, output='terminal')
def show():
for i in range(20):
print('')
menu.show()
show()
kgen = getch(0.1)
while True:
key = kgen.next()
if key:
if key == 'B':
menu.down()
elif key == 'A':
menu.up()
elif key in [' ', '\n']:
menu.select()
show()
示例3: __init__
# 需要导入模块: from menu import Menu [as 别名]
# 或者: from menu.Menu import up [as 别名]
class Game:
def __init__(self, debug=False):
self._debug = debug
self._pause = False
self.character = "character\\megaman.json"
self.backdrop = constants.BLACK
self.monster_sprite_list = pygame.sprite.Group()
self.scenery_sprite_list = pygame.sprite.Group()
self.bullet_sprite_list = pygame.sprite.Group()
self.player_sprite_list = pygame.sprite.Group()
self.platform_sprite_list = pygame.sprite.Group()
self.ladder_sprite_list = pygame.sprite.Group()
self.door_sprite_list = pygame.sprite.Group()
self.moving_platforms_list = pygame.sprite.Group()
self.spawners = []
self.ui_lifebar = []
self.object_list = {}
self.create_objects()
self.ui_list = []
self.main_menu = Menu()
self.menu_flag = True
self.start_level = None
self.load_splash()
#GAME
def load_splash(self):
self.clear()
self.add_title("Run & Gun")
self.add_button("New",(constants.DWIDTH/2)-50, 350, 100,50,
constants.WHITE, constants.BLUE, self.start_game)
self.add_button("Quit",(constants.DWIDTH/2)-50, 450, 100,50,
constants.WHITE, constants.BLUE, self.exit_game)
def start_game(self):
self.clear()
self.lives = 3
self.ui_list += self.main_menu.draw_menu()
self.current_level = [self.main_menu.selected_name(), 0, 0, "R"]
def exit_game(self):
pygame.quit()
sys.exit()
def load_level(self, level):
if self.start_level == None:
self.start_level = level[0]
self.menu_flag = False
player_hp = -1
if hasattr(self, 'player'):
player_hp = self.player.get_life()
self.clear()
self.level = Level(self.main_menu.get_level_json(level[0]))
if level[1] != 0:
self.level.player_x = int(level[1])
if level[2] != 0:
self.level.player_y = int(level[2])
self.scenery_sprite_list = self.level.build_scenery()
self.platform_sprite_list = self.level.build_platforms()
self.ladder_sprite_list = self.level.build_ladders()
self.door_sprite_list = self.level.build_doors()
self.monster_sprite_list = self.level.build_monsters()
self.spawners = self.level.build_spawners()
self.backdrop = self.level.backdrop
self.add_player(self.character, self.level.player_x,
self.level.player_y, level[3])
if player_hp > 0:
self.player.set_life(player_hp)
self.add_camera()
self.add_lifebar(25, 25, 'player', self.player)
if self.level.boss and not(self.main_menu.boss_check(self.start_level)):
self.boss = self.level.boss_mob
self.monster_sprite_list.add(self.boss)
self.add_lifebar(constants.DWIDTH - 50, 25, 'boss', self.boss)
def reload_level(self):
monsters = self.monster_sprite_list
player_hp = self.player.get_life()
self.menu_flag = False
self.clear()
self.monster_sprite_list = monsters
self.scenery_sprite_list = self.level.build_scenery()
self.platform_sprite_list = self.level.build_platforms()
self.ladder_sprite_list = self.level.build_ladders()
self.door_sprite_list = self.level.build_doors()
self.spawners = self.level.build_spawners()
self.backdrop = self.level.backdrop
self.add_player(self.character, self.level.player_x, self.level.player_y, "R")
self.add_camera()
self.player.set_life(player_hp)
self.add_lifebar(25, 25, 'player', self.player)
if self.level.boss and not(self.main_menu.boss_check(self.start_level)):
self.boss = self.level.boss_mob
self.monster_sprite_list.add(self.boss)
self.add_lifebar(constants.DWIDTH - 50, 25, 'boss', self.boss)
#Add functions
def add_camera(self):
self.camera = Camera(self.level.width, self.level.height)
#.........这里部分代码省略.........
示例4: Game
# 需要导入模块: from menu import Menu [as 别名]
# 或者: from menu.Menu import up [as 别名]
class Game():
def __init__(self):
# variables -----------------------------------------------
# load background
self.backg = Background(BKG_FOLDER + "stars.png")
# set initial score
self.score = 0
# load sound and music volume from file
# if there's a problem with the file, simply create a new one with default values
try:
volume = pickle.load( open( "volume.p", "rb" ) )
except:
volume = { "sound": 100, "music": 30 }
pickle.dump( volume, open( "volume.p", "wb" ) )
# sounds
self.laserSnd = pygame.mixer.Sound(SND_FOLDER + "laser.wav")
self.explodeSnd = pygame.mixer.Sound(SND_FOLDER + "explosion.wav")
self.powerUpSnd = pygame.mixer.Sound(SND_FOLDER + "powerUp.wav")
# put everything into a list so it's easier to change the volume
# the list elements are the same objects as the initial ones
# as python copies by reference and not by value (I would have
# preferred to use pointers, to avoid ambiguity, but oh well...)
self.sounds = [self.laserSnd,self.explodeSnd,self.powerUpSnd]
# set volume for all sound objects
for snd in self.sounds:
snd.set_volume(volume["sound"]/100.) # set new volume
# music
self.music = pygame.mixer.music.load(MUS_FOLDER + "reachingForTheSun.mp3")
pygame.mixer.music.play(-1) # loop
pygame.mixer.music.set_volume(volume["music"]/100.)
# creating user ship
self.userShip = ShipY001()
self.userShip.speed = 10
# group of all sprites
self.userSprites = pygame.sprite.Group()
self.laserSprites = pygame.sprite.Group()
self.aiSprites = pygame.sprite.Group()
self.powerUpSprites = pygame.sprite.Group()
# add to groups
self.userSprites.add(self.userShip)
# Creating main menu
self.menu = Menu(["Quit","Credits","Volume","Play"],self.backg)
# Creating pause menu (could be generated later, but shouldn't impact performance)
self.pause = Menu(["Quit","Volume","Restart","Continue"],self.backg)
# Creating volume menu (could be generated later, but shouldn't impact performance)
self.volume = Volume(self.backg,volume)
self.volumeBack = 0 # some stupid flag to tell us whether we came from the main menu
# of from the pause menu
# Creating credits
self.credits = Credits(["Sound: Obtained from Freesound",
"Music: 'Reaching for the Sun' by Deshiel and Bacon92",
"Graphics: Filipa Silva",
"Code: Alexandre Lopes"],
self.backg)
# gameState
# Available states: menu, credits ,game, gameOver
self.gameState = "menu"
# -----------------------------------------------
def handle(self,event):
# some flags (this could be re-done in a better way, but for now it works)
wasPressedNow = 0 # this is for some stupid hack, see below
# Menu ===============================================================
if self.gameState == "menu":
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE or event.key == pygame.K_RETURN:
if self.menu.press() == 3: # play pressed
self.gameState = "game" # begin game
elif self.menu.press() == 2: # volume pressed
self.gameState = "volume" # show volume menu
wasPressedNow = 1
self.volumeBack = 1
elif self.menu.press() == 1: # credits pressed
self.gameState = "credits" # show credits
wasPressedNow = 1 # stupid hack to prevent event from being
#.........这里部分代码省略.........