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


Python Field.draw方法代码示例

本文整理汇总了Python中field.Field.draw方法的典型用法代码示例。如果您正苦于以下问题:Python Field.draw方法的具体用法?Python Field.draw怎么用?Python Field.draw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在field.Field的用法示例。


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

示例1: Game1pInvisible

# 需要导入模块: from field import Field [as 别名]
# 或者: from field.Field import draw [as 别名]
class Game1pInvisible(Game):
  def __init__(self):
    Game.__init__(self)
    self.field = Field(10, 20, invisible = True)
    
  def start(self):
    while True:
      # restart
      self.field.restart()
      while True:
        # display
        self.screen.fill(BLACK)
        self.screen.blit(self.field.draw(), (20, 20))
        pygame.display.flip()
        # routine work
        quit, restart = Game.routine(self)
        if quit: return
        if restart: break
开发者ID:music960633,项目名称:PyTetris,代码行数:20,代码来源:game.py

示例2: Game1p4wide

# 需要导入模块: from field import Field [as 别名]
# 或者: from field.Field import draw [as 别名]
class Game1p4wide(Game):
  def __init__(self):
    Game.__init__(self)
    self.field = Field(4, 20)

  def start(self):
    while True:
      # restart
      self.field.restart()
      self.field.recieveAttack(1)
      self.field.clearAttack()
      while True:
        # display
        self.screen.fill(BLACK)
        self.screen.blit(self.field.draw(), (20, 20))
        pygame.display.flip()
        # routine work
        quit, restart = Game.routine(self)
        if quit: return
        if restart: break
开发者ID:music960633,项目名称:PyTetris,代码行数:22,代码来源:game.py

示例3: Field

# 需要导入模块: from field import Field [as 别名]
# 或者: from field.Field import draw [as 别名]
    for ant in ants:
        Matrix.SetPixel(ant.coordinates[1], ant.coordinates[0], 200, 0, 0)
	#base
    Matrix.SetPixel(base[1], base[0], 100, 255, 100)


field = Field("field.txt", (30, 40))

field.food.append((10, 10))
field.food.append((20, 20))

for i in range(1, 21):
    field.units.append(Ant(Color(0, 0, 100), 30, 40, i))
    field.add_occupied((30, 40))

offscreenCanvas = Matrix.CreateFrameCanvas()

i = 1
while True:
    i+=1
    offscreenCanvas.Clear()
    field.draw()
    field.generate_next()
    colorize(field.food, field.base, field.units)
    if i % 10 == 0:
        i = 1
        field.evaporate_pheromones()
    time.sleep(1)
    offscreenCanvas = Matrix.SwapOnVSync(offscreenCanvas)

开发者ID:AngelTsanev,项目名称:AntColony,代码行数:31,代码来源:simulator.py

示例4: Match

# 需要导入模块: from field import Field [as 别名]
# 或者: from field.Field import draw [as 别名]
class Match(object):
    snd_whistle = pygame.mixer.Sound("data/sound/etw/fischiolungo.wav")
 
    #TODO: add field choice
    def __init__(self,teamA,teamB):
        self.goal_image=pygame.image.load("data/goal.png")
        self.start_image=pygame.image.load("data/start.png")
        self.message_drawing_time=50
        self.message_image=self.start_image
        self.clock_image=pygame.image.load("data/clock.png")
        self.is_finished=False
        self.teamA_filename=teamA
        self.teamB_filename=teamB
        
        self.match_time=0
        self.human_players=[-1,0,0] #max two players, player num 0 does not exist
        self.pause=False
        self.ball=Ball()
        self.player_list=[]
        self.team={}#

        #read xml file to get colors !
        self.team[-1]=Team(self.teamA_filename)
        self.team[1]=Team(self.teamB_filename)
        

    def init(self,nbr_players_human_teamA,nbr_players_teamA,nbr_players_human_teamB,nbr_players_teamB,difficulty=8,length=60):
        Player_CPU.difficulty=difficulty
        Player_GK.difficulty=difficulty

        self.goal_image=pygame.image.load("data/goal.png")
        self.start_image=pygame.image.load("data/start.png")
        self.message_drawing_time=50
        self.message_image=self.start_image
        self.clock_image=pygame.image.load("data/clock.png")
        self.is_finished=False
        
        self.match_time=length
        self.human_players=[-1,0,0] #max two players, player num 0 does not exist
        self.pause=False
        self.ball=Ball()
        self.player_list=[]
        
        human_players_teamA=[]
        human_players_teamB=[]
        if (nbr_players_human_teamA>0):
            human_players_teamA.append( 1+len(human_players_teamA)+len(human_players_teamB) )
        if (nbr_players_human_teamA>1):
            human_players_teamA.append( 1+len(human_players_teamA)+len(human_players_teamB) )
        if (nbr_players_human_teamB>0):
            human_players_teamB.append( 1+len(human_players_teamA)+len(human_players_teamB) )
        if (nbr_players_human_teamB>1):
            human_players_teamB.append( 1+len(human_players_teamA)+len(human_players_teamB) )

        self.field=Field(self.team[-1].top_color,self.team[-1].bottom_color,self.team[1].top_color,self.team[1].bottom_color)
        self.cam=Camera(self.field)

        self.team[-1].create_from_xml(-1,nbr_players_teamA,human_players_teamA,self)
        self.player_list+=self.team[-1].players
        
        self.team[1].create_from_xml(1,nbr_players_teamB,human_players_teamB,self)
        self.player_list+=self.team[1].players
        
        print("Match starts")
        
    
    def update(self):
        Inputs.readkeys()#read all the actual keys
        if (Inputs.player_just_Start[1] or Inputs.player_just_Start[2]):
            self.pause=not self.pause
            if (self.match_time<=0):
                self.is_finished=True
            else:
                if (configuration["sound"]=="on"):
                    Match.snd_whistle.play()
        
        if (not self.pause):
            if (self.message_drawing_time<10):
                if (self.message_drawing_time>0):
                    self.message_drawing_time-=1*configuration["delta_time"]
                    if (self.message_drawing_time>5)and(self.message_image==self.start_image):#kick off
                        if (configuration["sound"]=="on"):
                            Match.snd_whistle.play()
                        self.message_drawing_time=5


                if (self.match_time>0):#when time is out, players stop
                    self.match_time-=1.0/30*configuration["delta_time"] #30 FPS
                    self.team[-1].update(self)
                    self.team[1].update(self)
                if (-1<self.match_time<0):
                    if (configuration["sound"]=="on"):
                        Match.snd_whistle.play()

                self.ball.update(self)
            else:
                self.message_drawing_time-=1*configuration["delta_time"]
            #camera moves even if there is a message
            if (self.ball.owner==0):
                self.cam.aim_to([self.ball.pos[0],self.ball.pos[1],self.ball.pos[2]/2],0,50)
#.........这里部分代码省略.........
开发者ID:PierreND,项目名称:pyNekketsu,代码行数:103,代码来源:match.py

示例5: GameManager

# 需要导入模块: from field import Field [as 别名]
# 或者: from field.Field import draw [as 别名]
class GameManager(Runnable):
  def __init__(self,settingFileName = "setting/gameSettings.conf"):
    super().__init__()
    #self.testInitialize()
    self.initialize(settingFileName)
    time.sleep(2)
  def defaultInitialize(self):
#    self.specialUnit = GameObject(move = MoveByKeyAsUnit(velocity = 50))
    self._viewPoint = None
    self.bullets = RunnableList()
    self.units = RunnableList()
    self.items = RunnableList()
    self.bases = RunnableList()
    self.debugObjects = RunnableList()
    self.field = Field(self)
  def initialize(self,settingFilename):
    self.defaultInitialize()
    file = open(settingFilename, "r")
    self.field.loadField(file.readline().strip())
    for team in (0,1):
      gen = self.field.getUnitPosition(team)
      for aiName,(point,direction) in zip(file.readline().split(),gen):
        if aiName == "debug":
          unit = Unit(point,direction,self,team,len(self.units))
          self.addDebugUnit(unit)
          self.units.append(unit)
          continue
        elif aiName == "player":
          unit = Unit(point,direction,self,team,len(self.units), aiManager = PlayerManager())
          self._viewPoint = unit
#          self.addDebugUnit(unit,UNIT_MAX_ROLL_ANGLE,UNIT_MAX_SPEED)
          self.units.append(unit)
          continue
        else:
          self.units.append(Unit(point,direction,self,team,len(self.units),AiManager(aiName)))
    self.debugmode = eval(file.readline())
    if self.debugmode:
      pass
    for i in self.units:
      i.sendStartingMessage()
    if self._viewPoint is None:
      self._viewPoint = GameObject(direction = -1.57079633, move = MoveByKey(speed = 5))
      self.debugObjects.append(self._viewPoint)
    self._defeatTeam = 0

  def addDebugUnit(self,unit,angle = 0.3,velocity = 10):
    self.debugUnit = unit
    self.debugUnit.setMove(MoveByKeyAsUnit(angle = angle, velocity = velocity))
    self._viewPoint = self.debugUnit
        
  def writeEndMessage(self,unit,file):
    file.write("endGame")
    if self._defeatTeam == 3:
      file.write("drawGame")
    elif self._defeatTeam == 0:
      file.write("canceled this Game")
    else:
      file.write("team ")
      file.write(self._defeatTeam)
      file.write(" win")
  def writeStartingMessage(self,unit,file):
    file.write("startInit")
    self.writeMessageUnit(unit,file)
    self.writeMessageField(self.field,file)
    file.write("endInit\n")
    self.writeMessage(unit,file)
  def writeMessage(self,unit,file):
    file.write("start")
    for i in self.bases:
      self.writeMessageBase(i,file)
    for i in self.units:
      if i.getTeamFlag() == unit.getTeamFlag():
        self.writeMessageUnit(i,file)
        continue
      if abs(i.getPosition() - unit.getPosition()) < RADIUS_OF_THE_VISILITY_ARIA:
        self.writeMessageUnit(i,file)
        continue
    for i in self.bullets:
      if abs(i.getPosition() - unit.getPosition()) <RADIUS_OF_THE_VISILITY_ARIA:
        self.writeMessageBullet(i,file)
    for i in self.items:
      if i.checkAvailable:
        if abs(i.getPosition() - unit.getPosition()) <RADIUS_OF_THE_VISILITY_ARIA:
          self.writeMessageItem(i,file)
    file.write("end")
  def writeMessageUnit(self,unit,file):
    file.write("unit")
    for i in unit.encode():
      file.write(str(i))
  def writeMessageBullet(self,bullet,file):
    file.write("bullet")
    for i in bullet.encode():
      file.write(str(i))
  def writeMessageBase(self,base,file):
    file.write("base")
    for i in base.encode():
      file.write(str(i))
  def writeMessageItem(self,item,file):
    file.write("item")
    for i in item.encode():
#.........这里部分代码省略.........
开发者ID:ymzk,项目名称:AiContest2012,代码行数:103,代码来源:gameManager.py


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