def on_key_press(self, k, m): if k == key.BACKSPACE: self.name.element.text = self.name.element.text[0:-1] return True elif k == key.ENTER: if len(self.name.element.text) <= 2: w, h = director.get_window_size() label_s = Label( 'Name too short! Choose at least 3 characters', font_name=_font_, font_size=20, anchor_y='top', anchor_x='center') label_s.position = (w/2., 700.) self.add(label_s) elif len(self.name.element.text) >= 15: w, h = director.get_window_size() label_l = Label( 'Name too long! Not more than 15 characters allowed', font_name=_font_, font_size=20, anchor_y='top', anchor_x='center') label_l.position = (w/2., 750.) self.add(label_l) else: new_score(self.name.element.text, self.wave) director.pop() return True elif k == key.ESCAPE: director.pop() return True return False
def create_page_select(self): '''创建关卡选择的页面选择器''' levels = self.get_all_level() count_pre_pages = 10 pages = len(levels) // count_pre_pages + 1 self.page_count = pages last_page = Label('上一页') next_page = Label('下一页') y = 100 lx = 320 - 54 nx = 320 + 10 for i in range(pages): # 从中间开始放页码 if i < pages / 2: x = 320 - (pages / 2 - i) * 20 lx = 320 - pages / 2 * 20 - 64 else: x = 320 + (i - pages / 2) * 20 nx = 320 + pages / 2 * 20 + 10 label = Label(str(i + 1), position=(x, y)) last_page.position = (lx, y) next_page.position = (nx, y) r = Rect(label.x, label.y, 10, 16) self.page_select.append([r, label]) self.add(label) lr = Rect(last_page.x, last_page.y, 50, 20) nr = Rect(next_page.x, next_page.y, 50, 20) self.page_select.append([lr, last_page]) self.page_select.append([nr, next_page]) self.add(last_page) self.add(next_page)
def __init__(self): super(Credits, self).__init__() opts = { 'font_name': 'against myself', 'font_size': 70, 'anchor_x': 'center', 'anchor_y': 'center', } label = Label('Credits', color=(0x00, 0x00, 0x00, 0xff), **opts) label.position = 400, 500 self.add(label, z=1) label = Label('Credits', color=(0xff, 0xff, 0xff, 0xff), **opts) label.position = 400, 503 self.add(label, z=2) shadow = DEVELOPERS.replace("white", "black") developers = HTMLLabel(shadow, width=760, height=300, multiline=True) developers.position = 20, 298 self.add(developers, z=1) developers = HTMLLabel(DEVELOPERS, width=760, height=300, multiline=True) developers.position = 20, 300 self.add(developers, z=2)
def __init__(self, wave): super().__init__() w, h = director.get_window_size() self.wave = wave self.font_title = { 'font_name': _font_, 'font_size': 72, 'anchor_y': 'top', 'anchor_x': 'center' } title = Label('GameOver', **self.font_title) title.position = (w/2., h) self.add(title, z=1) self.font_label = { 'font_name': _font_, 'font_size': 40, 'anchor_y': 'top', 'anchor_x': 'center' } label = Label('Enter your name:', **self.font_label) label.position = (w/2., 600.) self.add(label) self.name = Label('', color=(192, 192, 192, 255), **self.font_label) self.name.position = (w/2., 530.) self.add(self.name)
def __init__(self, scene): from cocos.text import Label from cocos.actions import FadeIn from zombie.constants import VERSION super(TitleScreen, self).__init__() self.scene = scene title_label = Label( 'Zombie+ Ultra', font_name='Extrude', font_size=48, anchor_x='center', anchor_y='center', ) version_label = Label( VERSION, font_name='TinyUnicode', font_size=32, anchor_x='center', ) title_label.position = 320, 240 version_label.position = 320, (240 / 4) * 3 title_label.do(FadeIn(duration=10)) version_label.do(FadeIn(duration=10)) self.add(title_label) self.add(version_label)
def __init__(self, wave): super().__init__() self.wave = wave if check_score(wave) is False: self.in_highscore = False else: self.place = check_score(wave) self.in_highscore = True w, h = director.get_window_size() text1 = Label('+++ Game Over! +++', font_name=_font_, font_size=30, anchor_x='center', anchor_y='center') text1.position = w/2., h/2. + 65 if self.in_highscore: text2 = Label( 'You reached wave %d ' % wave + 'and place %d of the highscore' % self.place, font_name=_font_, font_size=20, anchor_x='center', anchor_y='center') else: text2 = Label( 'You reached wave %d' % wave, font_name=_font_, font_size=20, anchor_x='center', anchor_y='center') text2.position = w/2., h/2. self.add(text1) self.add(text2)
def __init__(self): super(Start, self).__init__() label = Label('打砖块', font_size=42) label2 = Label('press any key to start') label.position = (230, 300) label2.position = (240, 150) self.count = 0 self.add(label) self.add(label2) self.schedule(self.update)
def __init__( self, win = False): super(GameOver,self).__init__( 32,32,32,64) w,h = director.get_window_size() if win: soundex.play('oh_yeah.mp3') msg = 'YOU WIN' else: soundex.play('no.mp3') msg = 'GAME OVER' label = Label(msg, font_name='Edit Undo Line BRK', font_size=54, anchor_y='center', anchor_x='center' ) label.position = ( w/2.0, h/2.0 ) self.add( label ) angle = 5 duration = 0.05 accel = 2 rot = Accelerate(Rotate( angle, duration//2 ), accel) rot2 = Accelerate(Rotate( -angle*2, duration), accel) effect = rot + (rot2 + Reverse(rot2)) * 4 + Reverse(rot) label.do( Repeat( Delay(5) + effect ) ) if hiscore.hiscore.is_in( status.status.score ): self.hi_score = True label = Label('Enter your name:', font_name='Edit Undo Line BRK', font_size=36, anchor_y='center', anchor_x='center', color=(32,32,32,255), ) label.position = ( w/2.0, h/2.0 ) label.position = (w//2, 300) self.add( label ) self.name= Label('', font_name='Edit Undo Line BRK', font_size=36, anchor_y='center', anchor_x='center', color=(32,32,32,255), ) self.name.position=(w//2,250) self.add(self.name) else: self.hi_score = False
def __init__(self): super(Credits, self).__init__() programmer = Label("Programmer: Theodor Margolis") programmer.position = director.window.width / 4, director.window.height / 2 asteroids = Label("Asteroids | by-> phaelax") asteroids.position = director.window.width / 4, director.window.height / 6 planets = Label("16 PLANET SPRITES | Planets by -> Unnamed") planets.position = director.window.width / 4, director.window.height / 8 self.add(programmer) self.add(asteroids) self.add(planets)
def __init__(self, levels=1, gold=0, deadcount=0): super(GuoCangDongHua, self).__init__() label = Label('第' + str(levels) + '关', font_size=42) label2 = Label('金币: ' + str(gold) + ' 死亡次数: ' + str(deadcount)) label3 = Label('按任意键继续') label.position = (230, 300) label2.position = (230, 150) label3.position = (240, 100) self.levels = levels self.gold = gold self.deadcount = deadcount self.add(label) self.add(label2) self.add(label3)
def __init__(self, levels=1, gold=0, deadcount=0): super(GameOver, self).__init__() self.levels = levels self.gold = gold self.deadcount = deadcount label = Label('游戏结束', font_size=42) label.position = (180, 300) label2 = Label('第'+str(levels)+'关 '+'金币: ' + str(gold) + ' 死亡次数: ' + str(deadcount)) label2.position = (230, 150) label3 = Label('按R键从第一关重新开始,按C键继续本关') label3.position = (180, 120) self.add(label) self.add(label2) self.add(label3)
def __init__(self, levels=1, gold=0, deadcount=0): super(GameComplite, self).__init__() self.levels = levels self.gold = gold self.deadcount = deadcount label = Label('恭喜通关', font_size=42) label.position = (180, 300) label2 = Label('第' + str(levels) + '关 ' + '金币: ' + str(gold) + ' 死亡次数: ' + str(deadcount)) label2.position = (230, 150) label3 = Label('按任意键从新开始') label3.position = (240, 120) self.add(label) self.add(label2) self.add(label3)
def __init__(self): super(Layer2, self).__init__(231, 76, 60, 1000) # Same Label code as before but this time with different text text = Label("This is the second scene") text.position = director._window_virtual_width / 2, director._window_virtual_height / 2 self.add(text)
def __init__(self): super(LogoLayer, self).__init__() self.img = pyglet.resource.image("jungle.png") self.img.anchor_x = self.img.width / 2 self.img.anchor_y = self.img.height / 2 name = Label("Man Is But A Worm", font_name=FONT, font_size=40, anchor_x="center", anchor_y="center") name.position = WIDTH / 2, HEIGHT * 3 / 4 self.add(name) info = Label("Press space to act", font_name=FONT, font_size=18, anchor_x="center", anchor_y="center") info.position = WIDTH / 2, HEIGHT / 5 self.add(info) sound.start_music()
def __init__(self): super().__init__(*Options.BACKGROUND_COLOR) version = Label(font_name=Options.FONT_NAME, font_size=16, color=Options.FONT_COLOR_NOT_SELECTED, anchor_x="right", anchor_y="bottom") version.position = director.get_window_size()[0] - 5, 5 version.element.text = _("Version: {}").format(Options.VERSION) self.add(version)
def __init__(self): super().__init__() width, height = director.get_window_size() paused = Label(_("PAUSE"), font_name="Ubuntu", font_size=64, bold=True, color=Options.FONT_COLOR, anchor_x="center", anchor_y="center") paused.position = width // 2, height // 2 paused.do(Repeat(FadeOut(0.3) + FadeIn(0.3))) # blink self.add(paused)
def __init__(self, hud): super(GameOver, self).__init__() self.hud = hud self.is_on_exiting = True levels =self.hud.levels gold = self.hud.gold death = self.hud.death label = Label('Game Over', **font_set(42)) centerx = director.get_window_size()[0] / 2 label.position = (centerx, 300) info = 'Level: ' + str(levels) + ' Gold: ' + str(gold) + ' Death: ' + str(death) label2 = Label(info, **font_set(22)) label2.position = (centerx, 150) label3 = Label('press R to restart, press C to continue', **font_set(18)) label3.position = (centerx, 120) self.add(label) self.add(label2) self.add(label3)
def __init__( self, win): super(GameOver,self).__init__( 32,32,32,64) w,h = director.get_window_size() if (win == False): label = Label('Game Over', font_name='Edit Undo Line BRK', font_size=54, anchor_y='center', anchor_x='center' ) if (win == True): label = Label('You Won', font_name='Edit Undo Line BRK', font_size=54, anchor_y='center', anchor_x='center' ) label.position = ( w/2.0, h/2.0 ) self.add( label )
def __init__(self, message): """Initialize an error layer.""" super(ErrorLayer, self).__init__() w, h = director.get_window_size() lbl_title = Label("Fatal Error", bold=True, font_size=64, anchor_x="center", anchor_y="center", color=(255,255,255,0)) lbl_title.position = w * 0.5, h * 0.75 lbl_title.do(FadeIn(1)) self.add(lbl_title) lbl_message = Label(message, anchor_x="center", anchor_y="center", font_size=12, color=(255,255,255,0)) lbl_message.position = w * 0.5, h * 0.5 lbl_message.do(FadeIn(1)) self.add(lbl_message) lbl_advice = Label("Please restart the application once you have fixed the problem.", font_size=10, anchor_x="center", anchor_y="center", color=(255,255,255,0)) lbl_advice.position = w * 0.5, h * 0.25 lbl_advice.do(Accelerate(FadeIn(3), 2)) self.add(lbl_advice)
def __init__(self): super(LogoLayer, self).__init__() # self.img = pyglet.resource.image('jungle.png') # self.img.anchor_x = self.img.width / 2 # self.img.anchor_y = self.img.height / 2 name = Label('Man Is But A Worm', font_name = FONT, font_size = 40, anchor_x = 'center', anchor_y = 'center') name.position = WIDTH / 2, HEIGHT * 3 / 4 self.add(name) info = Label('Press space to act', font_name = FONT, font_size = 18, anchor_x = 'center', anchor_y = 'center') info.position = WIDTH / 2, HEIGHT / 5 self.add(info) sound.start_music()
def __init__(self, picture): super(ChooseOneLayer, self).__init__() global text1, text2, first_file_is_right, second_file_is_right try: self.img = pyglet.resource.image(picture) except AttributeError: print(AttributeError) frame1_image = Sprite("res/frame_black.png") frame1_image.position = (180, 300) self.add(frame1_image) frame2_image = Sprite("res/frame_white.png") frame2_image.position = (620, 300) self.add(frame2_image) if os.path.isfile( 'files/blue_bot.py') and text1 == 'Ничего не загружено': first_file_is_right = 1 text1 = 'Загружен файл с прошлой игры' if os.path.isfile( 'files/red_bot.py') and text2 == 'Ничего не загружено': second_file_is_right = 1 text2 = 'Загружен файл с прошлой игры' if first_file_is_right == 0: label1 = Label(text1, color=(255, 0, 0, 255)) elif first_file_is_right == 1: label1 = Label(text1, color=(255, 255, 255, 255)) if second_file_is_right == 0: label2 = Label(text2, color=(255, 0, 0, 255)) elif second_file_is_right == 1: label2 = Label(text2, color=(255, 255, 255, 255)) label1.position = (40, 460) label2.position = (480, 460) self.add(label1) self.add(label2)
def __init__(self, hud): super(GuoCangDongHua, self).__init__() self.hud = hud levels = self.hud.levels gold = self.hud.gold death = self.hud.death ll = 'Level ' + str(levels) gdl = 'Gold: ' + str(gold) + ' Death: ' + str(death) color = (164, 164, 164, 200) label = Label(ll, **font_set(42, color)) label2 = Label(gdl, **font_set(22, color)) label3 = Label('press any key to continue', **font_set(18, color)) self.is_on_exiting = True centerx = director.get_window_size()[0]/2 label.position = (centerx, 300) label2.position = (centerx, 200) label3.position = (centerx, 150) self.add(label) self.add(label2) self.add(label3)
def __init__(self): super(Editor, self).__init__() label = Label('关卡编辑器') label2 = Label('按S键保存') # 以下两个标签用于提示用户编辑窗的位置 buttom = 299 top = 451 line1 = Sprite('images/line.png', position=(0, buttom), anchor=(0, 0)) line2 = Sprite('images/line.png', position=(0, top), anchor=(0, 0)) self.saveflag = Label('未保存', position=(300, 0)) label.position = (0, 0) label2.position = (200, 0) self.add(label) self.add(label2) self.add(self.saveflag) self.add(line1) self.add(line2) # 鼠标按下标志和坐标 self.mouse_press_left = False self.mouse_press_right = False self.mouse_x = 0 self.mouse_y = 0 # 编辑区属性 self.editor_bottom = 300 self.editor_top = 450 self.editor_left = 0 self.editor_right = 640 # 预定坐标 self.postmp = [] self.create_grid() # 存储坐标 self.pos = [] # 存储bloks self.blocks = [] self.schedule(self.update)
def __init__(self): width, height = director.get_window_size() super(HiScoresLayer, self).__init__(32, 32, 32, 16, width=width, height=height-86) self.font_title = {} self.font_title['font_name'] = 'Times New Roman' self.font_title['font_size'] = 72 self.font_title['color'] = (204, 164, 164, 255) self.font_title['anchor_x'] = 'center' self.font_title['anchor_y'] = 'top' title = Label('Scores!', **self.font_title) title.position = (width/2.0, height) self.add(title, z=1) self.table = None
def create_text(self, text, x, y): text = Label(text, font_name="FixedsysTTF", font_size=30, bold=True, color=(255, 255, 255, 255), anchor_x="center", anchor_y="center") text.position = (x, y) self.add(text) return text
def step(self, dt): super(AlienMove, self).step(dt) if self.target.dead: self.target.velocity = (0, 0) return if self.target.x < 20: for alien in aliens: alien.dead = True youlose = Label("You Lose - an alien got past you", font_name="Calibri", font_size=50, anchor_x="center", anchor_y="center") alienlayer.lose = True youlose.position = director.get_window_size()[0] // 2, director.get_window_size()[1] // 2 alienlayer.add(youlose) clock.schedule_once(start_lvl_2, 3) self.target.velocity = (random.randint(-120, -60), random.randint(-20, 20))
def __init__(self): # Remember that I need to pass in an RGBA colour value because it's a ColorLayer super(Layer1, self).__init__(155, 89, 182, 1000) # I make a simple label with no extra parameters such as font or anchors text = Label("This is the first scene") # For the position, I do something we haven't done before # We've been making the position static, but we don't exactly know the width and height of a player's window # Therefore, getting the virtual height and width and then just dividing them by two is a safer bet text.position = director._window_virtual_width / 2, director._window_virtual_height / 2 # And lastly we add it self.add(text)
def main(): global m director.init() m = ScrollingManager() fg = ScrollableLayer() l = Label('foreground') l.position = (100, 100) fg.add(l) m.add(fg) bg = ScrollableLayer(parallax=.5) l = Label('background, parallax=.5') l.position = (100, 100) bg.add(l) m.add(bg) if autotest: m.do( Delay(1) + CallFunc(update_focus, 100, 200) + Delay(1) + CallFunc(update_focus, 200, 100) + Delay(1) + CallFunc(update_focus, 200, 200) ) main_scene = cocos.scene.Scene(m) keyboard = key.KeyStateHandler() director.window.push_handlers(keyboard) def update(dt): m.fx += (keyboard[key.RIGHT] - keyboard[key.LEFT]) * 150 * dt m.fy += (keyboard[key.DOWN] - keyboard[key.UP]) * 150 * dt m.set_focus(m.fx, m.fy) main_scene.schedule(update) director.run (main_scene)
def __init__(self): super().__init__() bg = Sprite("res/keyboard/MyBG.jpg") bg.position = bg.width // 2, bg.height // 2 self.add(bg) title = Label("Над грою працювали: ", font_name='Roboto', font_size=40, bold=True, color=(230, 80, 145, 225)) title.position = (120, 450) self.add(title) y = Label("Кулик Юрій", font_name='Roboto', font_size=35, bold=True, color=(230, 80, 145, 225)) y.position = (260, 380) self.add(y) o = Label("Андріїв Олег", font_name='Roboto', font_size=35, bold=True, color=(230, 80, 145, 225)) o.position = (260, 310) self.add(o) i = Label("Перегінець Іван", font_name='Roboto', font_size=35, bold=True, color=(230, 80, 145, 225)) i.position = (260, 240) self.add(i)
def __init__(self): global p2_score # accesses the score for both players to display it in the final message global p1_score super(endLayer, self).__init__( 52, 152, 219, 1000 ) # initialize this layer with the same conditions as the previous one #text = Label("You Won!") print( IDENTIFIER) #print diagnostic info so we know which player this is score = 0 opScore = -1 if IDENTIFIER == "client1": # if you are the first, assign the score appropraitely score = p2_score opScore = p1_score else: # otherwise, flip flop the score values score = p1_score opScore = p2_score message = "You Lost. Try Again Next Time!" # set the losing message if score > opScore: message = "You Won, Congrats!" # but overwrite it if your score was better #print ("we did it patrick, we saved the city") text = Label( message) # create a label with your victory / loss message text2 = Label( "Your Score: " + str(score) + " Opponent Score: " + str(opScore)) # create another label with the player scores text2.position = director._window_virtual_width / 4, ( director._window_virtual_height / 2) - 30 #place the two different text labels text.position = director._window_virtual_width / 4, director._window_virtual_height / 2 self.add(text) # add the text to the scenen self.add(text2)
def build(self, width, height): self.width, self.height = width, height self.x, self.y = (director.window.width - width) // 2, (director.window.height - height) // 2 title_label = Label(self.popup_ctrl.title, font_name='Calibri', color=rgba_colors["black"], font_size=23, anchor_x='center', anchor_y='center') title_label.x = width // 2 title_label.y = height - 50 self.add(title_label) message_label = Label(self.popup_ctrl.message, font_name='Calibri', color=rgba_colors["black"], font_size=16, anchor_x='center', anchor_y='center') message_label.x = width // 2 message_label.y = height - 100 self.add(message_label) for i, button in enumerate(self.popup_ctrl.buttons): padding = 20 button_container = ColorLayer(*rgba_colors["popup_button_background"], width=(width - padding) // len(self.popup_ctrl.buttons) - padding, height=40) button_container.position = padding * (i + 1) + button_container.width * i, 30 self.add(button_container) self.buttons_container.append(button_container) button_text = Label(button.text, font_name='Calibri', color=rgba_colors["white"], font_size=18, anchor_x='center', anchor_y='center') button_text.position = button_container.x + button_container.width / 2, button_container.y + button_container.height / 2 + 3 self.add(button_text) director.window.push_handlers(self.popup_ctrl)
def create_street_cell_prices_labels(self, prices: StreetPrices): for price_type, price in prices: view_index = self.street_prices_labels_order.index(price_type) price_label = Label("- " + price_type.replace("_", " ").title() + ": $%d" % price, font_name='Calibri', color=(0, 0, 0, 255), font_size=18, anchor_x='center', anchor_y='center') price_label.position = 0, 150 - view_index * 30 self.street_prices_labels[view_index] = price_label self.add(price_label)
def __init__(self): # Here, we initialize the parent class by calling the super function super(BigText, self).__init__() # We then create the label itself big_text_label = Label( "Hello World, ZOOM!", # This argument holds the string to display font_name = "Arial", # Assigns font face font_size = 18, # Assigns font size anchor_x = 'left', # anchors text to left side of x-axis anchor_y = 'center' # anchors text to middle of y-axis ) # Set position of text big_text_label.position= 5,590 # Add label to the layer using the self identifier self.add(big_text_label)
def __init__(self): super(TitleScene, self).__init__() my_layer = ColorLayer(171, 75, 100, 1000) text = Label('super dude', font_size=32, anchor_x='center', anchor_y='center') text.position = GameObj.my_director._window_virtual_width / 2, GameObj.my_director._window_virtual_height / 2 my_layer.add(text) my_layer.is_event_handler = True def new_on_key_press(self, key): GameObj.my_director.replace( FlipX3DTransition(GameScene(), duration=2)) my_layer.on_key_press = new_on_key_press self.add(my_layer)
def __init__(self): # First thing we do in the class is to initialize the parent class, Layer, which is why I called the super function in this case super(HelloWorld, self).__init__() # Then I make a Cocos Label object to display the text. hello_world_label = Label( "Hello World!", # The first thing the Label class requires is a piece of text to display font_name = "Times New Roman", # The next thing we need to input a font. Feel free to replace it with any font you like. font_size = 32, # The third input I give is a font size for the text anchor_x = 'center', # This input parameter tells cocos to anchor the text to the middle of the X axis anchor_y = 'center' # Similar to the input above, this parameter tells cocos to anchor the text to the middle of the Y axis ) # Now I need to give the text its position. hello_world_label.position = 320, 240 # Lastly I need to add the label to the layer # self refers to the object, which in this case is the layer self.add(hello_world_label)
def __init__(self, scene, message, next_layer=None): from cocos.text import Label super(MessageScreen, self).__init__() self.scene = scene self.next_layer = next_layer label = Label( message, font_name='TinyUnicode', font_size=32, anchor_x='center', anchor_y='center', ) label.position = 320, 240 self.add(label)
def set_player_details(self, player: Player, player_index): if self.players_details_labels[player_index] in self.get_children(): self.remove(self.players_details_labels[player_index]) if player is None: return font_size = 30 if self.players_ctrl.current_player.get().color == player.color else 26 player_details = Label(player.color.title() + " - $%d" % player.money, font_name='Calibri', color=rgba_colors[player.color], font_size=font_size, anchor_x='center', anchor_y='center') player_details.position = 0, - player_index * 50 self.players_details_labels[player_index] = player_details self.add(player_details)
def __init__(self): # First thing we do in the class is to initialize the parent class, Layer, which is why I called the super function in this case super(HelloWorld, self).__init__() # Then I make a Cocos Label object to display the text. hello_world_label = Label( "Hello World!", # The first thing the Label class requires is a piece of text to display font_name= "Times New Roman", # The next thing we need to input a font. Feel free to replace it with any font you like. font_size=32, # The third input I give is a font size for the text anchor_x= 'center', # This input parameter tells cocos to anchor the text to the middle of the X axis anchor_y= 'center' # Similar to the input above, this parameter tells cocos to anchor the text to the middle of the Y axis ) # Now I need to give the text its position. hello_world_label.position = 320, 240 # Lastly I need to add the label to the layer # self refers to the object, which in this case is the layer self.add(hello_world_label)
def __init__(self): super(Layer1, self).__init__(246, 226, 76, 255) # self.color = (246, 226, 76) label = Label("PoKeMoN CLoNe", font_name='Pokemon Hollow', font_size=40, bold=True, color=(80, 152, 247, 255), anchor_x='center', anchor_y='center') label.position = (325, 350) self.add(label) self.hud = Label('按任意鍵開始遊戲', font_name='Kozuka Gothic Pr6N B', font_size=20) self.hud.position = (225, 200) self.add(self.hud) self.ash = Sprite('images/ash(1).png') self.ash.position = (80, 60) self.add(self.ash) self.pokemon = Sprite('images/pokemon.png') self.pokemon.position = (490, 80) self.add(self.pokemon)
def __init__(self): super(GameOver, self).__init__(255, 255, 255, 255) self.wp = Label('Game Over', color=(255, 0, 0, 255), font_size=30) self.wp.position = (340, 250) self.add(self.wp) label = Label("妳被皮卡丘吃了!", font_name='Kozuka Gothic Pr6N B', color=(255, 0, 0, 255), font_size=30) label.position = (300, 150) self.add(label) # 添加一个 label 重新开始游戏 self.restart = Label('按任意键重新开始游戏', color=(255, 0, 0, 255), font_size=15) self.restart.position = (330, 100) self.add(self.restart) self.deadash = Sprite('images/zombie-pikachu.png') self.deadash.position = (130, 170) self.add(self.deadash)
def __init__(self): super(GameWin, self).__init__(255, 255, 255, 255) self.muscleash = Sprite('images/ashm.jpg') self.muscleash.position = (170, 230) self.add(self.muscleash) self.wp = Label('Well Play!', color=(255, 0, 0, 255), font_size=30) self.wp.position = (350, 250) self.add(self.wp) label = Label("恭喜你捉到了所有皮卡丘!", font_name='Kozuka Gothic Pr6N B', color=(255, 0, 0, 255), font_size=25) label.position = (250, 120) self.add(label) # 添加一个 label 继续游戏 self.goon = Label('按任意键继续游戏', color=(255, 0, 0, 255), font_size=15) self.goon.position = (350, 80) self.add(self.goon)
def step(self, dt): global win rover = self.target if rover.dead: return if rover.fuel >= 1000: rover.fuel = 1000 if rover.fuel <= 0: rover.fuel = 0 fueldisplaylayer.fuelbar.element.text = "Fuel: " + str(int(rover.fuel // 10)) fueldisplaylayer.fuelbar.draw() for fuel in fuels: if collision([rover.x, rover.y, rover.width, rover.height], [fuel.x, fuel.y, fuel.width, fuel.height]): rover.fuel += 200 fuellayer.remove(fuel) fuels.remove(fuel) del fuel return collisions = [ collision([rover.x, rover.y, rover.width, rover.height], [rock.x, rock.y, rock.width, rock.height]) for rock in rocks] if any(collisions): rover.velocity = (0, 0) youlose = Label("You Crashed", font_name="Calibri", font_size=80, anchor_x="center", anchor_y="center") youlose.position = (500, rover.position[1] + 300) rover.layer.add(youlose) rover.image = pyglet.resource.image("crashedrover.png") scroller1.set_focus(rover.x, rover.y + 200) rover.dead = True clock.schedule_once(crash, 2, rover) super().step(dt) if rover.fuel <= 0: rover.velocity = (0, 0) scroller1.set_focus(rover.x, rover.y + 200) youlose = Label("You Ran out of Fuel", font_name="Calibri", font_size=40, anchor_x="center", anchor_y="center") youlose.position = (500, rover.position[1] + 300) rover.layer.add(youlose) rover.dead = True clock.schedule_once(fuelLose, 2, rover) elif rover.x < 43: rover.x = 43 rover.velocity = (0, rover.velocity[1]) rover.fuel -= 1.2 scroller1.set_focus(rover.x, rover.y + 200) return elif rover.x > 1000 - 43: rover.x = 1000 - 43 rover.velocity = (0, rover.velocity[1]) rover.fuel -= 1.2 scroller1.set_focus(rover.x, rover.y + 200) return elif rover.y > 16800 and not win: rover.y = 16801 rover.velocity = (0, 0) scroller1.set_focus(rover.x, rover.y + 500) youwin = Label("Level 1 Complete - You reached the Kriptanium Mine", font_name="Calibri", font_size=30, anchor_x="center", anchor_y="center") youwin.position = (500, rover.position[1] + 300) rover.layer.add(youwin) win = True clock.schedule_once(lvl1win, 2, rover) return else: rover.velocity = ((keyboard[key.RIGHT] - keyboard[key.LEFT]) * 500, 500 + (int(keyboard[key.UP]) * 2 - int(keyboard[key.DOWN])) * 100) rover.fuel -= 1.2 scroller1.set_focus(rover.x, rover.y + 200)
def _build_components(self): border_rect = rect.Rect(0, 0, self.Size[0], self.Size[1]) border_rect.center = (0, 0) self.activated_border = Rect(border_rect, self.SelectedColor, width=4) if not self.static: self._create_status_border(border_rect, z=3, width=4) # Main card image. main_sprite = Sprite( '{}-{}.png'.format(Klass.Idx2Str[self._c_get('klass')], self._c_get('type')), (0, 0), scale=1.0, ) if self.static: card_cls = all_cards()[self.entity] else: card_cls = self.entity main_image = try_load_image(card_cls.get_image_name()) if main_image is not None: image_sprite = Sprite( main_image, pos(0.0, 0.02, base=self.SizeBase), scale=1.2, ) self.front_sprites['image'] = [image_sprite, 0] mana_sprite = Sprite( 'Mana.png', pos(-0.85, 0.76, base=self.SizeBase), scale=0.9, ) # Mark, name and description. mark_image = try_load_image('Mark-{}.png'.format( self._c_get('package'))) mark_sprite = None if mark_image is None else Sprite( mark_image, pos(0, -0.6, base=self.SizeBase), scale=1.0) name_label = Label(self._c_get('name'), pos(0, -0.08, base=self.SizeBase), font_size=21, anchor_x='center', anchor_y='center', bold=True) desc_label = HTMLLabel(self._render_desc(self._c_get('description')), pos(0, -0.58, base=self.SizeBase), anchor_x='center', anchor_y='center', width=main_sprite.width * 0.9, multiline=True) # [NOTE]: There is an encoding bug when parsing the font name in HTML (in `pyglet\font\win32query.py:311`), # must set font out of HTML. desc_label.element.set_style('font_name', C.UI.Cocos.Fonts.Description.Name) # Race sprite and label. race = self._c_get('race') if race: race_sprite = Sprite('Race.png', pos(0.02, -0.86, base=self.SizeBase), scale=1.0) race_label = hs_style_label(','.join(Race.Idx2Str[r] for r in race), pos(0.02, -0.86, base=self.SizeBase), font_size=22, anchor_y='center') self.front_sprites['race-sprite'] = [race_sprite, 3] self.front_sprites['race-label'] = [race_label, 4] self.front_sprites.update({ 'main': [main_sprite, 1], 'mana-sprite': [mana_sprite, 2], 'name': [name_label, 3], 'desc': [desc_label, 3], }) if mark_sprite is not None: self.front_sprites['mark-sprite'] = [mark_sprite, 2] if self._c_get('type') != Type.Permanent: mana_label = hs_style_label(str(self._c_get('cost')), pos(-0.84, 0.8, base=self.SizeBase), font_size=64, anchor_y='center', color=Colors['white']) self.front_sprites['mana-label'] = [mana_label, 4] back_sprite = Sprite( 'Card_back-Classic.png', (0, 0), scale=1.0, ) self.back_sprites['back'] = [back_sprite, 1] if self._c_get('rarity') not in (Rarity.Basic, Rarity.Derivative): self.front_sprites['rarity-sprite'] = [ Sprite( 'Rarity-{}-{}.png'.format(self._c_get('type'), self._c_get('rarity')), pos(0.0, -0.248, base=self.SizeBase)), 4 ] if self._c_get('type') == Type.Minion: atk_sprite = Sprite('Atk.png', pos(-0.86, -0.81, base=self.SizeBase), scale=1.15) atk_label = hs_style_label(str(self._c_get('attack')), pos(-0.78, -0.8, base=self.SizeBase), anchor_y='center', font_size=64, color=self._get_attack_color()) health_sprite = Sprite('Health.png', pos(0.84, -0.81, base=self.SizeBase), scale=1.05) health_label = hs_style_label(str(self._c_get('health')), pos(0.84, -0.8, base=self.SizeBase), anchor_y='center', font_size=64, color=self._get_health_color()) self.front_sprites.update({ 'attack-sprite': [atk_sprite, 2], 'attack-label': [atk_label, 3], 'health-sprite': [health_sprite, 2], 'health-label': [health_label, 3], }) elif self._c_get('type') == Type.Spell: name_label.position = pos(0, -0.04, base=self.SizeBase) main_sprite.position = pos(0, -0.07, base=self.SizeBase) if mark_sprite is not None: mark_sprite.position = pos(0, -0.57, base=self.SizeBase) elif self._c_get('type') == Type.Weapon: name_label.position = pos(0, -0.01, base=self.SizeBase) main_sprite.position = pos(0, -0.01, base=self.SizeBase) if mark_sprite is not None: mark_sprite.position = pos(0, -0.55, base=self.SizeBase) atk_sprite = Sprite('WeaponAtk.png', pos(-0.81, -0.83, base=self.SizeBase), scale=0.85) atk_label = hs_style_label(str(self._c_get('attack')), pos(-0.78, -0.8, base=self.SizeBase), anchor_y='center', font_size=64) health_sprite = Sprite('WeaponHealth.png', pos(0.82, -0.83, base=self.SizeBase), scale=0.85) health_label = hs_style_label(str(self._c_get('health')), pos(0.83, -0.8, base=self.SizeBase), anchor_y='center', font_size=64) desc_label.element.color = Colors['white'] self.front_sprites.update({ 'attack-sprite': [atk_sprite, 2], 'attack-label': [atk_label, 3], 'health-sprite': [health_sprite, 2], 'health-label': [health_label, 3], }) elif self._c_get('type') == Type.HeroCard: armor_sprite = Sprite('HeroArmor.png', pos(0.85, -0.86, base=self.SizeBase), scale=1.08) armor_label = hs_style_label(str(self._c_get('armor')), pos(0.85, -0.86, base=self.SizeBase), anchor_y='center', font_size=64) self.front_sprites.update({ 'armor-sprite': [armor_sprite, 2], 'armor-label': [armor_label, 3], })
def column_labels(self): for x in range(10): label = Label(string.letters[x].upper(), font_size=12) label.position = (70 + (50 * x), 30) self.add(label)
def __init__(self): super(Layer2, self).__init__(231, 76, 60, 1000) text = Label("This is the second scene") text.position = director._window_virtual_width / 2, director._window_virtual_height / 2 self.add(text)
def __init__(self): super(Layer1, self).__init__(155, 89, 182, 1000) text = Label("This is the first scene") text.position = director._window_virtual_width / 2, director._window_virtual_height / 2 self.add(text)
def line_labels(self): for x in range(10): label = Label(str(10 - x), font_size=12) label.position = (30, 70 + (50 * x)) self.add(label)
def __init__(self, gScene): super(_Score, self).__init__() l = Label("You Kill " + str(gScene.PLAYER.total_kill), color = (0,0,0,255), font_size = 30, anchor_x ='center') l.position = (director._window_virtual_width/2 , director._window_virtual_height - 200) self.add(l)
else: selector = 1 collider_cls = [RectMapCollider, RectMapWithPropsCollider][selector] director.init() tile_filled = Tile('z', {}, pyglet.image.load('white4x3.png')) maps_cache = aux.generate_maps(tile_filled) cases = [ d for d in aux.case_generator( aux.first_expansion(maps_cache, aux.common_base_cases)) ] model = Model(cases) scene = cocos.scene.Scene() label = Label("-----------------", anchor_x='center', anchor_y='center', color=(255, 255, 255, 160)) label.position = 320, 20 scene.add(label, z=10) model.label = label scroller = ScrollingManager() model.scroller = scroller scroller.scale = 8.0 scene.add(scroller, z=1) controller = ControllerLayer() controller.model = model scene.add(controller) director.run(scene)
def __init__(self): super().__init__() bg = Sprite("res/keyboard/HorrorBack.png") bg.position = bg.width // 2, bg.height // 2 self.add(bg) manage = Label("Загальні", font_name='Roboto', font_size=30, bold=True, color=(10, 165, 85, 255)) manage.position = (60, 560) self.add(manage) # ESC ========================================================== key_ESC = Sprite('res/keyboard/key_ESC.png') key_ESC.position = (30, 510) self.add(key_ESC) esc = Label("Вихід/Назад", font_name='Roboto', font_size=20, bold=True, color=(10, 165, 85, 255)) esc.position = (60, 500) self.add(esc) # Pause ======================================================== key_P = Sprite('res/keyboard/key_P.png') key_P.position = (30, 450) self.add(key_P) p = Label("Пауза", font_name='Roboto', font_size=20, bold=True, color=(10, 165, 85, 255)) p.position = (60, 440) self.add(p) # Mute ========================================================= key_M = Sprite('res/keyboard/key_M.png') key_M.position = (30, 390) self.add(key_M) m = Label("Вимкнути/Увімкнути звук", font_name='Roboto', font_size=20, bold=True, color=(10, 165, 85, 255)) m.position = (60, 380) self.add(m) #=============================================================== movement = Label("Дії", font_name='Roboto', font_size=30, bold=True, color=(200, 150, 80, 255)) movement.position = (650, 560) self.add(movement) # Move Right =================================================== right_arrow = Sprite('res/keyboard/right_arrow.png') right_arrow.position = (580, 510) self.add(right_arrow) r_a = Label("Рух вправо", font_name='Roboto', font_size=20, bold=True, color=(220, 150, 80, 255)) r_a.position = (620, 505) self.add(r_a) # Move Left ==================================================== left_arrow = Sprite('res/keyboard/left_arrow.png') left_arrow.position = (580, 450) self.add(left_arrow) l_a = Label("Рух вліво", font_name='Roboto', font_size=20, bold=True, color=(220, 150, 80, 255)) l_a.position = (620, 445) self.add(l_a) # Jump ========================================================= key_B = Sprite('res/keyboard/key_B.png') key_B.position = (580, 390) self.add(key_B) b = Label("Блок", font_name='Roboto', font_size=20, bold=True, color=(220, 150, 80, 255)) b.position = (620, 380) self.add(b) #============================================================== attack = Label("Атака", font_name='Roboto', font_size=30, bold=True, color=(255, 65, 65, 255)) attack.position = (360, 270) self.add(attack) # Attack_1====================================================== key_Z = Sprite('res/keyboard/key_Z.png') key_Z.position = (170, 220) self.add(key_Z) a1 = Label("Атака мечем (Доступно на 1 рівні)", font_name='Roboto', font_size=20, bold=True, color=(255, 65, 65, 255)) a1.position = (200, 215) self.add(a1) # Attack_2====================================================== key_X = Sprite('res/keyboard/key_X.png') key_X.position = (170, 160) self.add(key_X) a2 = Label("Атака мечем (Доступно на 2 рівні)", font_name='Roboto', font_size=20, bold=True, color=(255, 65, 65, 255)) a2.position = (200, 155) self.add(a2) # Attack_3====================================================== key_C = Sprite('res/keyboard/key_C.png') key_C.position = (170, 100) self.add(key_C) a3 = Label("Атака мечем (Доступно на 3 рівні)", font_name='Roboto', font_size=20, bold=True, color=(255, 65, 65, 255)) a3.position = (200, 95) self.add(a3)
def __init__(self): super(YouWin, self).__init__(0, 0, 0, 255) youwin = Label("You Win!!!", font_size=50, anchor_x="center", anchor_y="center") youwin.position = self.width // 2, self.height // 2 self.add(youwin) clock.schedule_once(self.finishScreen, 3)
def win_display(self, dt): youwin = Label("Level 2 Complete - You reached the Zaxzium Pool", font_name="Calibri", font_size=30, anchor_x="center", anchor_y="center") youwin.position = director.get_window_size()[0]//2, director.get_window_size()[1]//2 self.add(youwin) clock.schedule_once(self.endGame, 3)