当前位置: 首页>>代码示例>>Python>>正文


Python unit.Unit类代码示例

本文整理汇总了Python中unit.Unit的典型用法代码示例。如果您正苦于以下问题:Python Unit类的具体用法?Python Unit怎么用?Python Unit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Unit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self, mainRef, attributes):
        print("Enemy instantiated")
        Unit.__init__(self)
        FSM.__init__(self, 'playerFSM')

        self._mainRef = mainRef
        self._playerRef = mainRef.player
        self._AIworldRef = mainRef.AIworld
        self._enemyListRef = mainRef.enemyList
        self._ddaHandlerRef = mainRef.DDAHandler
        self._stateHandlerRef = mainRef.stateHandler
        self._scenarioHandlerRef = mainRef.scenarioHandler

        #self.topEnemyNode = mainRef.mainNode.attachNewNode('topEnemyNode')
        self.initEnemyNode(mainRef.mainNode)

        utils.enemyDictionary[self.enemyNode.getName()] = self

        self.loadEnemyModel(attributes.modelName)
        self.initAttributes(attributes)
        self.initEnemyAi()

        self.initEnemyDDA()

        self.initEnemyCollisionHandlers()
        self.initEnemyCollisionSolids()

        #self.request('Idle')
        self.request('Disabled')

        # Start enemy updater task
        self.enemyUpdaterTask = taskMgr.add(self.enemyUpdater, 'enemyUpdaterTask')
开发者ID:benregn,项目名称:fuzzy-moon-rocket,代码行数:32,代码来源:enemy.py

示例2: __init__

    def __init__(self, mainObj, position, yon=4, layer=0, attrDict={}):
        self.type = 'Kurt'
        Unit.__init__(self, mainObj, position, yon, attrDict)

        self.image = self.changeImage('Kurt', yon) # Oyunun başında ilk yüklenen unit resim dosyasi
        self.rect = self.image.get_rect()
        self.rect.topleft = position
        self.layer = layer # LayeredUpdates grubu için gerekiyor
        
        self.colRect = copy(Kurt.colRect[self.yon])
        self.colRect.topleft = (self.colRect.topleft[0] + self.rect.topleft[0], self.colRect.topleft[1] + self.rect.topleft[1])
        
        # çarpışmalarda kullanılan noktalar
        self.colPoints = None
        
        self.tolerans = 0
        self.speed = 4
        
        if self.player.type == Player.human_player:
            self.ai = KurtFSM(self, human=True)
        else:
            self.ai = KurtFSM(self)
        
        # unit'in gerçek pozisyonunu (reel sayılarla) tutar. rect'e atılırken int'e dönüştürülür.
        self.yer = Vector2(*self.colRect.center)
开发者ID:dhalsim,项目名称:pyempires,代码行数:25,代码来源:kurt.py

示例3: button_events

 def button_events(self, event):
     # check for clicks on a button 
     # (not in mousebuttondown to allow for mouseover highlight)         
     for button in self.buttons.btn_list:
         if "click" in button.handleEvent(event):
             if button.caption == "B":
                 self.player_command.player_msg = \
                     "That was the round button"
             if button.caption == "hi":
                 self.player_command.player_msg = \
                     "Nothing here but us buttons."
             if button.caption == "MAKE IT SO!":
                 Unit.movement(self.grid_map, self.players)
                 self.player_command.player_msg = ""
     """ check for unit-related button events """
     for player in self.players.active_list:
         for group in player.units:
             for unit in group.group_list:
                 for button in unit.unit_btns:
                     if "click" in button.handleEvent(event):
                         if button.caption == "B":
                             unit.active = "True"
                             unit.txt_status = "Targeting"
                             self.player_command.player_msg = \
                                 "Click on target tile."
                         elif button.caption == "A":
                             unit.txt_status = "A Button"
                         else:
                             unit.txt_status = "Unidentified Button"
开发者ID:timbodude,项目名称:project_alpha,代码行数:29,代码来源:screens.py

示例4: __init__

	def __init__(self, player, sig, model, skeleton, animations, inventory):
		'''
		Constructor
		'''
		Unit.__init__(player, sig, numControllers = 1)
		self.player = player
		self.enabled = False
开发者ID:borgified,项目名称:Hockfire,代码行数:7,代码来源:infantry.py

示例5: generate_one_unit

def generate_one_unit(i, paper, problem_list):
    """
    随机生成一个个体
    """

    unit = Unit()
    unit.id = i + 1

    each_type_count = paper.each_type_count
    while paper.total_score != unit.sum_score:
        unit.problem_list = []
        for j in range(len(each_type_count)):
            one_type_problem = [
                p for p in problem_list
                if p.type == j+1 and is_contain_points(p, paper)]

            for k in range(0, each_type_count[j]):
                length = len(one_type_problem)
                index = randint(0, length - k - 1)
                unit.problem_list.append(one_type_problem[index])
                one_type_problem[index], one_type_problem[length-k-1] = \
                    one_type_problem[length-k-1], \
                    one_type_problem[index]

    return unit
开发者ID:ts25504,项目名称:genetic-algorithm-py,代码行数:25,代码来源:main.py

示例6: __init__

    def __init__(self, is_intaractive_run, an_errhandler):
        """ EvalVisitorを初期化して応答する.
        """
        self.is_test = False
        self.is_intaractive_run = is_intaractive_run
        self.errhandler = an_errhandler
        self.scopes = ScopeList()
        self.is_break = False
        self.is_return = False
        self.return_value = UnitXObject(value=None, varname=None, unit=None, token=None, is_none=True)

        this_dir, _ = os.path.split(__file__)
        data_path = os.path.join(this_dir, Constants.SYSTEM_UNIT_DATA)
        self.unit_manager = UnitManager(data_path) # Sets a database(data/unit_table.dat) for calculating units.
        self.stdlib = Stdlib()
        self.NULL_UNITX_OBJ = UnitXObject(value=None, varname=None, is_none=True, unit=Unit(), token=None)
        
        #
        # Sets a mediator to each classes for a management,
        # because this class is a mediator class.
        # Also, UnitXObject, Unit, Scope classes have to create many new instances.
        # So, We set a mediator by using classmethod.
        #
        self.scopes.set_mediator(self)
        self.unit_manager.set_mediator(self)
        self.stdlib.set_mediator(self)
        UnitXObject.set_mediator(self)
        Unit.set_mediator(self)
        Scope.set_mediator(self)
        DefinedFunction.set_mediator(self)

        UnitXObject.manager = self.get_unit_manager()
        UnitXObject.scopes = self.get_scopes()
开发者ID:supertask,项目名称:UnitX,代码行数:33,代码来源:eval_visitor.py

示例7: visitPrimary

    def visitPrimary(self, ctx):
        """ それぞれのPrimaryの値をUnitXObjectにラップして,応答する.

            Identifier: variable or function
            literal: number, string, boolean, none
            PAREN=(): expression
            BRACK=[]: list
        """
        unit = Unit()
        if ctx.unit(): unit = self.visitUnit(ctx.unit())

        if ctx.Identifier():
            # Here
            varname = ctx.Identifier().getText()
            unitx_obj = UnitXObject(value=None, varname=varname, unit=unit)
            """
            current_scope = self.get_scopes().peek()
            if varname in current_scope:
                unitx_obj = current_scope[varname]
                if not unit.is_empty():
                    unitx_obj.unit = unit
            else:
                unitx_obj = UnitXObject(value=None, varname=varname, unit=unit)
            """

            found_scope = self.get_scopes().peek().find_scope_of(varname)
            if found_scope:
                unitx_obj = found_scope[varname]
                if not unit.is_empty():
                    unitx_obj.unit = unit
            else:
                unitx_obj = UnitXObject(value=None, varname=varname, unit=unit)
            unitx_obj.token = ctx.Identifier().getSymbol()

        elif ctx.literal():
            unitx_obj = self.visitLiteral(ctx.literal())
            unitx_obj.unit = unit

        elif ctx.start.type == UnitXLexer.LPAREN:
            unitx_obj = self.visitExpression(ctx.expression(i=0))
            if not unit.is_empty():
                unitx_obj.unit = unit
            unitx_obj.token = ctx.start

        elif ctx.start.type == UnitXLexer.LBRACK:
            unitx_objs = []
            for an_expr in ctx.expression():
                an_obj = self.visitExpression(an_expr)
                if not unit.is_empty():
                    an_obj.unit = unit
                unitx_objs.append(an_obj)

            unitx_obj = UnitXObject(value = unitx_objs, varname = None, unit=unit, token=ctx.start)

        else:
            if not self.is_intaractive_run:
                raise Exception("Syntax error. EvalVisitor#visitPrimary") # Never happen.

        assert(isinstance(unitx_obj, UnitXObject))
        return unitx_obj
开发者ID:supertask,项目名称:UnitX,代码行数:60,代码来源:eval_visitor.py

示例8: value_unit_to_number

 def value_unit_to_number(self, param, value):
     # string is of the form "32.3L"
     unit = value[-1]
     #v = float(value[:-1])
     v = self.str_to_float(param, value[:-1])
     if (Unit.get(param) != unit):
         v = Unit.convert(unit, Unit.get(param), v)
     return round(v, self.precision)
开发者ID:yashkarandikar,项目名称:ucsd-fitness,代码行数:8,代码来源:param_formatter.py

示例9: __init__

 def __init__(self, constraint, x=0, y=0, direction=(1, 0), kind=0):
     Unit.__init__(self, constraint, x, y, direction, 160, 65)
     if kind:
         self.kind = 'lion'
         self.health = 200
     else:
         self.kind = 'blue'
         self.health = 100
开发者ID:gvpavlov,项目名称:Insaniquarium,代码行数:8,代码来源:alien.py

示例10: handleCubeIntoCollision

	def handleCubeIntoCollision(self, entry):
		try:
			fromName = entry.getFromNodePath().getParent().getName()
			Unit.collideWithObstacle(self.actors[fromName])
			if fromName == "player" and self.collisionSound.status() is not self.collisionSound.PLAYING:
				self.collisionSound.play()
		except:
			pass
开发者ID:tom-anesta,项目名称:team-conventions,代码行数:8,代码来源:main.py

示例11: update

	def update(self, time):
		self.applyForceFrom(-0.1, self.player.getPos())
		
		Unit.update(self, time)
		
		angle = math.atan2(self.player.getY() - self.getY(), \
							self.player.getX() - self.getX())
		self.setH(angle * 180 / math.pi)
开发者ID:tom-anesta,项目名称:team-conventions,代码行数:8,代码来源:droneEnemy.py

示例12: reduce_unit

    def reduce_unit(self, guide_unit=None):
        """
        Combine similar component units and scale, to form an
        equal Quantity in simpler units.

        Returns underlying value type if unit is dimensionless.
        """
        key = (self.unit, guide_unit)
        if key in Quantity._reduce_cache:
            (unit, value_factor) = Quantity._reduce_cache[key]
        else:
            value_factor = 1.0
            canonical_units = {} # dict of dimensionTuple: (Base/ScaledUnit, exponent)
            # Bias result toward guide units
            if guide_unit is not None:
                for u, exponent in guide_unit.iter_base_or_scaled_units():
                    d = u.get_dimension_tuple()
                    if d not in canonical_units:
                        canonical_units[d] = [u, 0]
            for u, exponent in self.unit.iter_base_or_scaled_units():
                d = u.get_dimension_tuple()
                # Take first unit found in a dimension as canonical
                if d not in canonical_units:
                    canonical_units[d] = [u, exponent]
                else:
                    value_factor *= (u.conversion_factor_to(canonical_units[d][0])**exponent)
                    canonical_units[d][1] += exponent
            new_base_units = {}
            for d in canonical_units:
                u, exponent = canonical_units[d]
                if exponent != 0:
                    assert u not in new_base_units
                    new_base_units[u] = exponent
            # Create new unit
            if len(new_base_units) == 0:
                unit = dimensionless
            else:
                unit = Unit(new_base_units)
            # There might be a factor due to unit conversion, even though unit is dimensionless
            # e.g. suppose unit is meter/centimeter
            if unit.is_dimensionless():
                unit_factor = unit.conversion_factor_to(dimensionless)
                if unit_factor != 1.0:
                    value_factor *= unit_factor
                    # print "value_factor = %s" % value_factor
                unit = dimensionless
            Quantity._reduce_cache[key] = (unit, value_factor)
        # Create Quantity, then scale (in case value is a container)
        # That's why we don't just scale the value.
        result = Quantity(self._value, unit)
        if value_factor != 1.0:
            # __mul__ strips off dimensionless, if appropriate
            result = result * value_factor
        if unit.is_dimensionless():
            assert unit is dimensionless # should have been set earlier in this method
            if is_quantity(result):
                result = result._value
        return result
开发者ID:jlmaccal,项目名称:openmm,代码行数:58,代码来源:quantity.py

示例13: handleUnitIntoCollision

	def handleUnitIntoCollision(self, entry):
		try:
			fromName = entry.getFromNodePath().getParent().getName()
			intoName = entry.getIntoNodePath().getParent().getName()
			Unit.collideWithUnit(self.actors[intoName], self.actors[fromName])
			if (fromName == "player" or intoName == "player") and self.collisionSound.status() is not self.collisionSound.PLAYING:
				self.collisionSound.play()
		except:
			pass
开发者ID:tom-anesta,项目名称:team-conventions,代码行数:9,代码来源:main.py

示例14: __init__

	def __init__(self, models = None, anims = None, sphereString = None, game = None, xStart = 0, yStart = 0, zStart = 0):
		Unit.__init__(self, models, anims, sphereString, game, xStart, yStart, zStart)
		
		#set up sounds
		self.deathSound = game.loader.loadSfx(SFX_PATH + "enemy_death.wav")
		
		self.randomMovement = 0
		self.randomMovementMax = 30 * 7
		self.minRandomVel = 1000
		self.maxRandomVel = 2000
开发者ID:tom-anesta,项目名称:team-conventions,代码行数:10,代码来源:enemy.py

示例15: test_hero_attack

 def test_hero_attack(self):
     hero = Unit(100, 100, 5)
     hero.learn(Spell('a', 10, 10, 2))
     self.dungeon.spawn(hero)
     self.dungeon.move_hero('down')
     self.dungeon.move_hero('down')
     self.assertEqual('Nothing in casting range 2',
                      self.dungeon.hero_attack(by="spell"))
     self.dungeon.move_hero('down')
     self.assertIsInstance(self.dungeon.hero_attack(by='spell'), Fight)
开发者ID:sevgo,项目名称:PyCraft,代码行数:10,代码来源:dungeon_test.py


注:本文中的unit.Unit类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。