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 create_cell_owner_label(self, owner_observable: Observable): owner = owner_observable.get() color = rgba_colors[owner.color if owner is not None else "black"] owner_text = owner.color.title() if owner is not None else "No One" self.owner_label = Label("Owner: " + owner_text, font_name='Calibri', color=color, font_size=20, anchor_x='center', anchor_y='center') self.owner_label.position = 0, 30 self.add(self.owner_label)
def __init__(self): super(TestLayer, self).__init__() x, y = director.get_window_size() self.color1 = [255, 0, 0, 255] self.color2 = [0, 0, 255, 255] self.label = Label('', (x // 2, y // 2)) self.label.do(Rotate(360, 10)) self.label.do( Repeat( Delay(1) + CallFunc(self.set_color, 0) + Delay(1) + CallFunc(self.set_color, 1) + Delay(1) + CallFunc(self.set_color, 2))) self.add(self.label) self.set_color(2)
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 add_cities(self): self.update_properties() for tx, x in enumerate(self.get("rails").cells): for ty, y in enumerate(x): try: city_loc = str(tx) + "," + str(ty) self.get("rails").cells[int( Config.conf_cities_by_tile[city_loc].event_x)][int( Config.conf_cities_by_tile[city_loc].event_y )].properties["city"] = city_loc if Config.conf_cities_by_tile[ city_loc].type == "viking" or Config.conf_cities_by_tile[ city_loc].type == "service": citysprite_name = Config.conf_cities_by_tile[ city_loc].type else: citysprite_name = "generic" city_w = int(Config.conf_cities_by_tile[city_loc].width) city_h = int(Config.conf_cities_by_tile[city_loc].height) citysprite = Sprite( self.gallery.content["city"][citysprite_name], position=(((tx + (city_w // 3) + 1) * self.get("rails").tw - (32 * (city_w % 2)), (ty + (city_h // 3) + 1) * self.get("rails").tw - (32 * (city_h % 2))))) self.get("rails").add(citysprite) if not (Config.conf_cities_by_tile[city_loc].type == "viking" or Config.conf_cities_by_tile[city_loc].type == "service"): self.get("rails").add( Label(Config.conf_cities_by_tile[city_loc].name, ((tx + 1.5) * self.get("rails").tw, (ty + 0) * self.get("rails").tw), color=(25, 50, 75, 255), italic=True, bold=True, font_name="Arial", font_size=12, anchor_x="center", anchor_y="bottom"), name="label_city_" + city_loc) except: A = 1
def __init__(self): super(ConfigMenu, self).__init__() menu = ConfigMenuMenu() fo = pyglet.font.load(menu.font_item['font_name'], menu.font_item['font_size']) fo_height = int((fo.ascent - fo.descent) * 0.9) font_item = {} font_item['font_name'] = menu.font_item['font_name'] font_item['font_size'] = menu.font_item['font_size'] + 10 font_item['anchor_x'] = "right" font_item['x'] = 770 font_item['y'] = int(180) font_item['text'] = 'Options' label = Label(**font_item) self.add(menu) self.add(label)
def __init__(self, game, interface, meta): super().__init__(211, 214, 246, 255) self.game = game self.meta = meta self.interface = interface toaster_sprite = Sprite('toaster11.svg') toaster_sprite.scale = 0.5 toaster_sprite.position = (director.get_window_size()[0] / 2, director.get_window_size()[1] / 2) self.add(toaster_sprite) self.label = Label(font_name="Helvetica", font_size=50) self.label.position = (toaster_sprite.position[0] - 110, toaster_sprite.position[0] - 175) self.add(self.label) self.timer = 0 self.schedule_interval(self.update_timer, 1)
def __init__(self): super(MouseInput, self).__init__() # This time I set variables for the position rather than hardcoding it # I do this because we will want to alter these values later self.position_x = 100 self.position_y = 240 # Once again I make a label self.text = Label("No mouse interaction yet", font_name="Helvetica", font_size=24, x=self.position_x, y=self.position_y) # Then I just add the text! self.add(self.text)
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(TitleControlLayer, self).__init__() w, h = director.get_window_size() # logo = Sprite('Moon_1.jpg') # lh = logo.height # logo.position = (w//2, h//2) # self.add(logo) self.add( Label("Click to Continue", font_size=16, x=w // 2, y=10, anchor_x='center', anchor_y='bottom', color=(200, 200, 200, 255), font_name='Prototype'))
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): Layer.__init__(self) self.position = Vector2() ## posicao fixa da layer self.anchor = Vector2() self.score_label = Label( "0", position=(880, 350), font_name="Ravie", align="center", anchor_x="center") # texto onde mostra o score atual self.add(self.score_label) self.pause_label = Label("( ESC )", position=(820, 190), font_name="Ravie", align="center", anchor_x="center") self.add(self.pause_label) self.pause_label = Label("Sair", position=(885, 190), font_name="Ravie", align="center", anchor_x="center", color=(214, 178, 152, 255)) self.add(self.pause_label) self.pause_label = Label("( P )", position=(820, 210), font_name="Ravie", align="center", anchor_x="center") self.add(self.pause_label) self.pause_label = Label(" Pause", position=(880, 210), font_name="Ravie", align="center", anchor_x="center", color=(214, 178, 152, 255)) self.add(self.pause_label) self.time_label = Label( "00:00", position=(880, 250), font_name="Ravie", align="center", anchor_x="center") # texto onde mostra o score atual self.add(self.time_label) self.next_piece = Piece(POS_NX_PIECE)
def _load_interface(self): self._load_button_gen("button", "exit", events.emit_show_city_generic, "button_exit", 0, 1, 0.95) self._load_button_gen("display", "city_table", events.emit_return_to_map, "button_city_table", 0, 1, 1) self.label_cityname = Label( director.core.query_mover("Transarctica").in_city, (director.window.width * self.button_positions["label_cityname"]["X"], director.window.height * self.button_positions["label_cityname"]["Y"]), color=(210, 200, 128, 255), font_name="Arial", bold=True, font_size=24, anchor_x="center", anchor_y="center") self.add(self.label_cityname) label_stores_1 = self._load_label_gen("label_stores_1") self.add(label_stores_1, name="label_stores_1") self.get("label_stores_1").element.text = " " label_stores_2 = self._load_label_gen("label_stores_2") self.add(label_stores_2, name="label_stores_2") self.get("label_stores_2").element.text = " " label_stores_3 = self._load_label_gen("label_stores_3") self.add(label_stores_3, name="label_stores_3") self.get("label_stores_3").element.text = " " label_lignite_you_have = self._load_label_gen("label_lignite_you_have") self.add(label_lignite_you_have, name="label_lignite_you_have") self.get("label_lignite_you_have").element.text = " " for j in range(50): self.button_positions["sprite_trade_bracket" + str(j)] = { "X": 0.05 + (0.225 * (j % 4)), "Y": 1.03 - (0.183 * (j // 4)) } self.button_positions["button_buy" + str(j)] = { "X": 0.225 + (0.225 * (j % 4)), "Y": 0.896 - (0.183 * (j // 4)) } self.button_positions["button_sell" + str(j)] = { "X": 0.225 + (0.225 * (j % 4)), "Y": 0.846 - (0.183 * (j // 4)) } self._load_trade_boxes()
def __init__(self): super().__init__(0, 0, 255, 255) events.settingsevents.push_handlers(self) global x, y self.width = int(x * 0.75) self.height = int(y * 0.6) self.posleft = int(-self.width) self.poscenter = int((x / 2) - (self.width / 2)) self.posright = int(x) self.x = self.posright self.y = int((y * 0.37) - (self.height / 2)) self.active = self._active = False miscInfo = Label("Coming Soon", anchor_x="center", anchor_y="center", font_size=35, multiline=True, width=(self.width * 0.8), align="center") miscInfo.x = self.width / 2 miscInfo.y = self.height / 2 self.add(miscInfo)
def __init__(self): super(Menu, self).__init__(20, 20, 20, 255) self.title = cocos.text.Label( "Galaxy Hopper!", font_name="Calibri", font_size=32, anchor_x="center", anchor_y="center" ) self.title.position = self.width / 2, self.height / 2 + 70 self.add(self.title) self.playBtn = cocos.layer.ColorLayer(200, 200, 200, 255, 220, 70) self.playBtn.position = self.width // 2 - 110, self.height // 2 - 75 self.playBtnText = Label("Play", anchor_x="center", anchor_y="center", font_name="Calibri", font_size=20, color=(0, 0, 0, 255)) self.playBtnText.position = (self.width // 2, self.height // 2 - 40) self.add(self.playBtn) self.add(self.playBtnText)
def create_level_select(self): '''创建关卡选择器''' levels = self.get_all_level() count_pre_pages = 10 for i in range(0, len(levels)): page = i // count_pre_pages if i % 10 < 5: offect_y = 200 else: offect_y = 150 # 每一排5个选择 所以用 数量 i 除以 5 取余 offect_x = 640 * page + 40 + (i % 5) * 120 label = Label('第' + str(levels[i]) + '关', position=(offect_x, offect_y)) self.add(label) # 40,20 宽度和高度是试验出来的 r = Rect(label.x, label.y, 40, 20) self.level_select.append([r, label]) self.level_select_position.append((label.x, label.y))
def __init__(self, model: GameModel): from Main import Main super(DefaultRenderer, self).__init__(model) self.add(self.model.bat) self.add(self.model.ball) self.add(self.model.enemy) self.add(self.model.wall_left) self.add(self.model.wall_right) self.add(self.model.wall_top) self.add(self.model.wall_bottom) self.label_time = Label("Time: ", font_name="Arial", font_size=36, align="center") self.label_time.position = (Main.SCREEN_WIDTH / 2, Main.SCREEN_HEIGHT / 2) self.add(self.label_time)
def __init__(self): """Initialize an empty behavior.""" super(Behavior, self).__init__ self.display_name = None self.display_name_cached = None self.display_name_label = Label("", font_size=8, font_name="Cabin Bold", anchor_x="center", anchor_y="bottom", color=(255, 255, 255, 255)) self.object = None self.observers = collections.defaultdict(list) self.attributes = collections.defaultdict(BehaviorAttribute) self.association = None self.association_selection = None self.association_selection_shaker = ShakeRecognizer.ShakeRecognizer() self.association_name = "Associate" self.association_mode = False
def on_enter(self): super(StatusMenu,self).on_enter() self.add(Sprite(os.path.join("images","background.png"),scale=2,position=(500,30)),z=-1) #self.add(Sprite(os.path.join("images","background.png"),scale=2,opacity=255,position=(500,30)),z=-1) #changed the sprite to be darker #self.add(Sprite(os.path.join("images","background.png"),scale=2,opacity=255,position=(500,30)),z=-1) text1 = Label(text="# Units: ",font_name='Rabiohead',anchor_y='center',position=(20,STATUS_BAR_HEIGHT/2),font_size=27,color=(255,255,255,255),multiline=False) self.add(text1) text2 = Label(text="# Idle CPUs: ",font_name='Rabiohead',anchor_y='center',position=(195,STATUS_BAR_HEIGHT/2),font_size=27,color=(255,255,255,255),multiline=False) self.add(text2) self.selectedUnitText = "" self.selectedUnitLabel = Label(text="Selected Unit: " + self.selectedUnitText,font_name='Rabiohead',anchor_y='center',position=(440,STATUS_BAR_HEIGHT/2),font_size=24,color=(255,255,255,255),multiline=False) self.add(self.selectedUnitLabel) # self.health = Label(text="Health: ",font_name="Rabiohead",anchor_y="center",position=(20,STATUS_BAR_HEIGHT/2),font_size=27,color=(255,255,255,255),multiline=False) # self.add(self.health) # health = 0 # totalhealth = 0 # for building in self.player.units: # health += self.player.units[building].health # totalhealth += self.player.units[building].health # self.curHealth = int((float(health) / totalhealth) * 100.0) # self.curHealthLabel = Label(text=str(self.curHealth) + "%",font_name='Rabiohead',anchor_y='center',position=(130,STATUS_BAR_HEIGHT/2),font_size=27,color=(255,255,255,255),multiline=False) # self.add(self.curHealthLabel) self.menuButton = MenuButton(960,10) self.add(self.menuButton,z=1) self.cm.add(self.menuButton) self.musicButton = ToggleMusicButton(885,18) self.add(self.musicButton,z=1) self.cm.add(self.musicButton) self.soundButton = ToggleSoundButton(820,15) self.add(self.soundButton,z=1) self.cm.add(self.soundButton) self.oldunitCount = len(self.controller.player.units) self.oldCpuCount = len(self.controller.player.idleCPUs) self.unitCountLabel = Label(text=str(self.oldunitCount),font_name='Rabiohead',anchor_y='center',position=(130,STATUS_BAR_HEIGHT/2),font_size=27,color=(255,255,255,255),multiline=False) self.cpuCountLabel = Label(text=str(self.oldCpuCount),font_name='Rabiohead',anchor_y='center',position=(390,STATUS_BAR_HEIGHT/2),font_size=27,color=(255,255,255,255),multiline=False) self.add(self.unitCountLabel) self.add(self.cpuCountLabel) self.schedule(self.step) self.soundX = Label(text="X",font_name='Rabiohead',anchor_y='center',position=(795,37),font_size=50,bold=True,color=(255,255,255,255),multiline=False) self.musicX = Label(text="X",font_name='Rabiohead',anchor_y='center',position=(867,37),font_size=50,bold=True,color=(255,255,255,255),multiline=False) if self.settingsMenu.settingsMenuOn: self.add(settingsMenu)
def __init__(self): super().__init__() pole = cocos.sprite.Sprite('pole.png', position=(300,240)) pole.scale = 1/3.2 pole.scale_x = 1.0365 # pole.scale_y = 0.936 background = layer.Layer() midle = layer.Layer() foreground = MouseInput() from cocos.text import Label self.lbl = Label('0', (50, 440), color=(255, 255, 255, 255)) background.add(pole) background.add(self.lbl) self.add(background) blue_prived = Object(2 + j, 50, 'blue.png', 50, kuda1) blue_prived.sprite.scale = 1 / 14 privedenia.append(blue_prived) for complex_number in graf.keys(): dots.append(cocos.sprite.Sprite('dot.png', position=(complex_number.real * coef + left_offset, complex_number.imag * coef + down_offset))) dots[-1].scale = 1 / 2 midle.add(dots[-1]) dots_graf.update({complex_number: dots[-1]}) dots_to_graf.update({dots[-1]: complex_number}) def callback(dt, *args, **kwargs): global Pack_c blue_prived.moving(dt, self) foreground.pacman.moving(dt, self, collide = True, pacman=True) Pack_c = foreground.pacman.vert midle.add(blue_prived.sprite) self.add(midle) self.add(foreground) self.schedule(callback)
def __init__(self, parent_layer, message, image): super(MessageAlert, self).__init__() self.message_layer = ImageLayer(image) self.message_layer_height = 400 # sets the constants self.message_layer_width = 300 # set the constants self.parent_layer = parent_layer self.message = message self.message_label = Label( self.message, font_name='Rabiohead', font_size=26, x=self.message_layer_width / 2, y=self.message_layer_height / 2, width=self.message_layer_width - 100, height=self.message_layer_height - 100, color=(0, 0, 0, 255), anchor_x='center', anchor_y='center', multiline = True) # added text to specified parent layer(should be the # self.game_controller_layer of controller.py) self.message_label.position = 30, -240 self.message_layer.add(self.message_label) self.message_layer.position = 0, 0 self.parent_layer.add(self.message_layer)
def _load_interface(self): self._load_button_gen("button", "exit", events.emit_return_to_map, "button_exit", 0, 1, 0.95) self._load_button_gen("display", "city_table", events.emit_return_to_map, "button_city_table", 0, 1, 1) self.label_cityname = Label("Nomads!", (director.window.width * self.button_positions["label_cityname"]["X"], director.window.height*self.button_positions["label_cityname"]["Y"]), color=(210,200,128,255), font_name="Arial", bold=True, font_size=24, anchor_x="center", anchor_y="center") self.add(self.label_cityname) label_line_1 = self._load_label_gen("label_line_1") self.add(label_line_1, name="label_line_1") self.get("label_line_1").element.text=" " label_line_2 = self._load_label_gen("label_line_2") self.add(label_line_2, name="label_line_2") self.get("label_line_2").element.text=" " label_line_3 = self._load_label_gen("label_line_3") self.add(label_line_3, name="label_line_3") self.get("label_line_3").element.text=" " label_line_4 = self._load_label_gen("label_line_4") self.add(label_line_4, name="label_line_4") self.get("label_line_4").element.text=" " label_line_5 = self._load_label_gen("label_line_5") self.add(label_line_5, name="label_line_5") self.get("label_line_5").element.text=" "
def __init__(self, parent_layer, message, has_image_background, x, y, width, height, font): self.parent_layer = parent_layer self.background_layer = ImageLayer(os.path.join('images','tutorial','background.png')) self.message = message self.has_image_background = has_image_background self.message_label = Label( self.message, font_name='Rabiohead', font_size=font, width=width, height=height, color=(0, 0, 0, 255), anchor_x='center', anchor_y='center', multiline = True) if(self.has_image_background == True): # Position needs to be worked out self.background_layer.postition = 300, 500 self.parent_layer.add(self.background_layer) self.message_label.position = 50, 50 self.background_layer.add(self.message_label) else: self.message_label.position = x, y self.parent_layer.add(self.message_label)
def show_message(self, msg, callback=None): w, h = director.get_window_size() self.msg = Label(msg, font_size=52, font_name='Arial', anchor_y='center', anchor_x='center') self.msg.position = (w // 2.0, h) self.add(self.msg) actions = Accelerate(MoveBy((0, -h / 2.0), duration=0.5)) + \ Delay(1) + \ Accelerate(MoveBy((0, -h / 2.0), duration=0.5)) + \ Hide() if callback: actions += CallFunc(callback) self.msg.do(actions)
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, player=None): director.init() self.main_layer = GameScreen(self) self.ball = Ball() self.main_layer.add(self.ball) self.bouncer = Bouncer() self.main_layer.add(self.bouncer) self.score = 0 self.score_label = Label("Score: 0", font_size=32) self.score_label.position = 20, 400 self.main_layer.add(self.score_label) self.main_scene = Scene(self.main_layer) self.collision_manager = CollisionManagerGrid(0, 640, 0, 400, 5, 5) self.collision_manager.add(self.ball) self.collision_manager.add(self.bouncer) self.player = player
def __init__(self, parent): super().__init__() reswidth, resheight = [int(res) for res in cfg.configuration["Core"]["defaultres"].split("x")] self.txtBoxWidth = elements.TextBox(self, 0, 0, default_text=str(reswidth), charLimit=4) seperator = Label("X", anchor_x = "center", anchor_y = "center", font_size = 15, color = (255, 255, 255, 255)) seperator.x = self.txtBoxWidth.width seperator.y = 0 self.width = (self.txtBoxWidth.width * 2) self.height = self.txtBoxWidth.height self.txtBxHeight = elements.TextBox(self, self.width, 0, default_text=str(resheight), charLimit=4) self.x = parent.width - (self.width + (parent.width * 0.1)) self.y = parent.height * 0.3 self.txtBoxWidth.parentx = parent.x + self.x self.txtBoxWidth.parenty = parent.y + self.y self.txtBxHeight.parentx = parent.x + self.x self.txtBxHeight.parenty = parent.y + self.y self.add(self.txtBoxWidth) self.add(seperator) self.add(self.txtBxHeight) self.showing = self._showing = True self.schedule_interval(self.changed, 0.5) self.resume_scheduler()
def __init__(self, text, position, info, action, color=(255, 255, 255, 255), **kw): x, y = position ninepatch = kw.pop('ninepatch', 'border-9p.png') super(TextButton, self).__init__( ninepatch, Label(text, x=x, y=y, color=color, anchor_x='left', anchor_y='bottom', font_name='Prototype')) for k, v in kw.items(): setattr(self, k, v) self.info = info self.on_click = action
def __init__(self, player, width, height): Layer.__init__(self) self.width = width self.height = height self.player = player.domain msg = Label( 'health %s, sticks: %s' % (self.player.health, self.player._inventory.get('sticks')), font_name='somebitch', anchor_x='left', anchor_y='bottom', # really - it's top of screen width=width, height=25, x=5, y=-3, ) color = (73, 106, 44, 255) hudBackground = ColorLayer(*color, width=self.width, height=25) hudBackground.position = (0, 0) self.add(hudBackground) self.add(msg, name='msg') self.schedule(self.update)