def get_adventure_bg(): select_r = AdventureSelectLayer.SelectR bg = BackgroundLayer() bg.add(draw.Line(pos(select_r, .0), pos(select_r, 1.), Colors['white'], 2)) bg.add(draw.Line(pos(select_r, .0), pos(select_r, 1.), Colors['white'], 2)) return bg
def get_select_deck_bg(): right_l = SelectDeckLayer.RightL left_cx = SelectDeckLayer.LeftCX bg = BackgroundLayer() bg.add(draw.Line(pos(right_l, .0), pos(right_l, 1.), Colors['white'], 2)) bg.add(draw.Line(pos(left_cx, .0), pos(left_cx, 1.), Colors['white'], 2)) return bg
def __init__(self, ctrl): super().__init__(ctrl) self.name = 'Practice Mode' self.add( draw.Line(pos(self.DeckR, 0.0), pos(self.DeckR, 1.0), Colors['white'], 2)) self.add( draw.Line(pos(self.DeckR, self.DiffB), pos(1.0, self.DiffB), Colors['white'], 2)) self.add( draw.Line(pos(self.DeckR, self.StartT), pos(1.0, self.StartT), Colors['white'], 2)) self._rb_list_deck = make_radio_button_list( self, { 'CX': self.DeckCX, 'ListT': self.DeckListT, 'ListB': self.DeckListB, 'ArrowY': self.DeckArrowY, 'Size': self.DeckListSize, }, prefix='deck', scroll=True, ) # Difficulty: False = Normal, True = Expert. self._rb_group_diff = make_radio_button_group(self, [ { 'name': 'Normal', 'position': pos(self.DiffX1, self.DiffY), 'value': False }, { 'name': 'Expert', 'position': pos(self.DiffX2, self.DiffY), 'value': True }, ], 'difficulty') # Klass of AI (Inn Keeper). self._rb_group_ai_class = self._build_ai_class_buttons() self.add( ActiveLabel.hs_style( 'Start Game', pos(self.StartX, self.StartY), callback=self._on_start_game, font_size=36, anchor_x='center', anchor_y='center', ))
def get_game_bg(): right_l = GameBoardLayer.RightL hero_l = GameBoardLayer.HeroL board_l = GameBoardLayer.BoardL te_btn_t, te_btn_b = GameBoardLayer.TurnEndBtnT, GameBoardLayer.TurnEndBtnB hand_ratio = GameBoardLayer.HandRatio bg = BackgroundLayer() # Lines. bg.add(draw.Line(pos(right_l, .0), pos(right_l, 1.), Colors['white'], 2)) bg.add(draw.Line(pos(board_l, .5), pos(right_l, .5), Colors['white'], 2)) bg.add( draw.Line(pos(right_l, te_btn_t), pos(1.0, te_btn_t), Colors['white'], 2)) bg.add( draw.Line(pos(right_l, te_btn_b), pos(1.0, te_btn_b), Colors['white'], 2)) bg.add( draw.Line(pos(board_l, hand_ratio), pos(hero_l, hand_ratio), Colors['white'], 2)) bg.add( draw.Line(pos(board_l, 1 - hand_ratio), pos(hero_l, 1 - hand_ratio), Colors['white'], 2)) bg.add(draw.Line(pos(hero_l, .0), pos(hero_l, 1.), Colors['white'], 2)) bg.add(draw.Line(pos(board_l, .0), pos(board_l, 1.), Colors['white'], 2)) return bg
def get_collection_bg(): deck_l = DeckSelectLayer.DeckL bg = BackgroundLayer() bg.add(draw.Line(pos(deck_l, 0.0), pos(deck_l, 1.0), Colors['white'], 2)) return bg
def __init__(self, game: Game, **kwargs): super(HSGameBoard, self).__init__() # Some positions. right_b = 0.88 right_c = (1 + right_b) / 2 hero_b = 0.66 # Lines. self.add( draw.Line(_pos(right_b, .0), _pos(right_b, 1.), Colors['white'], 2)) self.add(draw.Line(_pos(.0, .5), _pos(1., .5), Colors['white'], 2)) self.add( draw.Line(_pos(.0, .23), _pos(hero_b, .23), Colors['white'], 2)) self.add( draw.Line(_pos(.0, .77), _pos(hero_b, .77), Colors['white'], 2)) self.add( draw.Line(_pos(hero_b, .0), _pos(hero_b, 1.), Colors['white'], 2)) self.cards = [] # Variables for selection. self.active_card = None if game is None: warning('The game is not running, just show the board') return # Players. P0 is current player (show in bottom), P1 is current player (show in top, hide something) player_ids = game.current_player, 1 - game.current_player players = [game.players[player_id] for player_id in player_ids] # Decks. deck_sizes = [len(p.get_zone(Zone.Deck)) for p in players] for ds, y in zip(deck_sizes, [0.15, 0.85]): self.add( text.Label( '牌库:{}'.format(ds), _pos(right_c, y), font_name='SimHei', font_size=16, anchor_x='center', anchor_y='center', bold=True, )) # Manas. manas = [[p.displayed_mana(), p.max_mana, p.overload, p.overload_next] for p in players] for (mana, max_mana, overload, overload_next), y in zip(manas, [0.3, 0.7]): self.add( text.Label( '{}/{}{}{}'.format( mana, max_mana, '' if overload == 0 else '\n(Overload {})'.format(overload), '' if overload_next == 0 else '\n(Overload next {})'.format(overload_next), ), _pos(right_c, y), font_name='SimHei', font_size=16, anchor_x='center', anchor_y='center', color=Colors['blue'], bold=True, multiline=True, width=(1 - right_b) * Width, align='center', )) # Other components of right board. for pi, y in zip(player_ids, [0.42, 0.58]): self.add( text.Label( 'Player {}'.format(pi), _pos(right_c, y), font_name='SimHei', font_size=16, anchor_x='center', anchor_y='center', bold=True, )) # Hands. hands = [p.get_zone(Zone.Hand) for p in players] for pi, (hand, y) in enumerate(zip(hands, [0.115, 0.885])): for i, card in enumerate(hand): # [NOTE]: position need fix here. hand_card = CardSprite(card, _pos(hero_b / (len(hand) + 1) * (i + 1), y), scale=0.35, hidden=(pi == 1)) self.add(hand_card) self.cards.append(hand_card)
def __init__(self): super( TestLayer, self ).__init__() line = draw.Line((0,0), (100,100), (255,255,255,255)) self.add( line )
def __init__(self): super().__init__() #lines towards sheep for lineIndex in range(nVisionLines): dist = distanceToObject(radius, sheepPosition, lines[lineIndex][0], lines[lineIndex][1]) partOFMaxDistance = dist / float(visionLength + radius) partOFMaxDistance = max(0, partOFMaxDistance) partOFMaxDistance = min(1, partOFMaxDistance) if (partOFMaxDistance > 0): partOFMaxDistance = 1 - partOFMaxDistance wolfVision.append(partOFMaxDistance) if (dist < 0): #no hit line = draw.Line( (lines[lineIndex][0][0], lines[lineIndex][0][1]), (lines[lineIndex][1][0], lines[lineIndex][1][1]), (255, 255, 255, 64)) else: #hit line = draw.Line( (lines[lineIndex][0][0], lines[lineIndex][0][1]), (lines[lineIndex][1][0], lines[lineIndex][1][1]), (0, 255, 0, 255)) self.add(line) #lines towards wolf for lineIndex in range(nVisionLines): maxPartOfMaxDistance = 0 for wolfIndex in range(len(wolfPositions)): dist = distanceToObject(radius, wolfPositions[wolfIndex], lines[lineIndex][0], lines[lineIndex][1]) partOFMaxDistance = dist / float(visionLength + radius) partOFMaxDistance = max(0, partOFMaxDistance) partOFMaxDistance = min(1, partOFMaxDistance) if (partOFMaxDistance > 0): partOFMaxDistance = 1 - partOFMaxDistance maxPartOfMaxDistance = max(maxPartOfMaxDistance, partOFMaxDistance) if (dist < 0): #no hit line = draw.Line( (lines[lineIndex][0][0], lines[lineIndex][0][1]), (lines[lineIndex][1][0], lines[lineIndex][1][1]), (255, 255, 255, 0)) else: #hit line = draw.Line( (lines[lineIndex][0][0], lines[lineIndex][0][1]), (lines[lineIndex][1][0], lines[lineIndex][1][1]), (0, 0, 255, 255)) self.add(line) wolfVision.append(maxPartOfMaxDistance) #lines towards walls for lineIndex in range(nVisionLines): dist = distanceFromWall(wallVisionLines[lineIndex]) partOFMaxDistance = dist / float(visionLength) partOFMaxDistance = min(1, partOFMaxDistance) partOFMaxDistance = max(0, partOFMaxDistance) if (partOFMaxDistance > 0): partOFMaxDistance = 1 - partOFMaxDistance wolfVision.append(partOFMaxDistance) #print("array value: " + str(partOFMaxDistance)) if (dist < 0 or dist > visionLength): #no hit line = draw.Line((wallVisionLines[lineIndex][0][0], wallVisionLines[lineIndex][0][1]), (wallVisionLines[lineIndex][1][0], wallVisionLines[lineIndex][1][1]), (255, 255, 255, 64)) else: #hit and is < visionlength from orgin x = wallVisionLines[lineIndex][1][0] y = wallVisionLines[lineIndex][1][1] line = draw.Line((wallVisionLines[lineIndex][0][0], wallVisionLines[lineIndex][0][1]), (wallVisionLines[lineIndex][1][0], wallVisionLines[lineIndex][1][1]), (255, 0, 0, 255)) self.add(line) #draw sheep for lineIndex in range(len(sheepLines)): line = draw.Line( (sheepLines[lineIndex][0][0], sheepLines[lineIndex][0][1]), (sheepLines[lineIndex][1][0], sheepLines[lineIndex][1][1]), (0, 255, 255, 255)) self.add(line) line = draw.Line(wallLines[0][0], wallLines[0][1], (255, 255, 0, 255)) self.add(line) line = draw.Line(wallLines[1][0], wallLines[1][1], (255, 255, 0, 255)) self.add(line) line = draw.Line(wallLines[2][0], wallLines[2][1], (255, 255, 0, 255)) self.add(line) line = draw.Line(wallLines[3][0], wallLines[3][1], (255, 255, 0, 255)) self.add(line) for i in range(len(wolfVision)): print("wolfVision " + str(i) + ":" + str(wolfVision[i]))
def generate_random_level(self): """ Configure and add cocos layers """ # build ! width = self.width height = self.height tiles_w = self.tiles_w tiles_h = self.tiles_h self.z = 0 # add walls #self.map_layer = ti.load(os.path.join(script_dir, 'test.tmx'))['map0'] self.map_layer = self.generator.map(tiles_w, tiles_h) self.map_layer.set_view(0, 0, self.map_layer.px_width, self.map_layer.px_height) # FIXME: Both `scale_x` and `scale_y` self.map_layer.scale = config.scale_x self.add(self.map_layer, z=self.z) self.z += 1 # add floor # TODO: Move to `Generator.inverse(map)` self.visit_layer = ti.load( os.path.join(script_dir, 'assets', 'ones.tmx'))['map0'] for i in range(0, len(self.map_layer.cells)): for j in range(0, len(self.map_layer.cells[i])): col = self.map_layer.cells[i][j] # If wall exists, remove floor if col.tile and col.tile.id > 0: self.visit_layer.cells[i][j].tile = None self.visit_layer.set_view(0, 0, self.visit_layer.px_width, self.visit_layer.px_height) # FIXME: Both `scale_x` and `scale_y` self.visit_layer.scale = config.scale_x self.add(self.visit_layer, z=-1) # add player # Start in random corner corner = randint(0, 3) padding = eu.Vector2(self.map_layer.tw * 1.5, self.map_layer.th * 1.5) corners = [ eu.Vector2(padding.x, padding.y), # Bottom left eu.Vector2(((tiles_w + 1) * self.map_layer.tw) - padding.x, padding.y), # Bottom right eu.Vector2(padding.x, ((tiles_h + 1) * self.map_layer.th) - padding.y), # Top right eu.Vector2( ((tiles_w + 1) * self.map_layer.tw) - padding.x, ((tiles_h + 1) * self.map_layer.th) - padding.y) # Top left ] self.spawn = corners[corner] self.player = Player(self.spawn.x, self.spawn.y) self.add(self.player, z=self.z) self.z += 1 self.score = ScoreLayer(self.player.stats) self.add(self.score, z=self.z) self.z += 1 # Draw sensors # TODO: Decouple into view rendering a = math.radians(self.player.rotation) for sensor in self.player.sensors: rad = a + sensor.angle start = self.player.cshape.center end = start.copy() end.x += math.sin(rad) * sensor.proximity end.y += math.cos(rad) * sensor.proximity sensor.line = draw.Line( start, end, self.player.palette['wall'] + (int(255 * 0.5), )) self.map_layer.add(sensor.line) # Generate obstacles self.create_items()