本文整理汇总了Python中turtle.ontimer函数的典型用法代码示例。如果您正苦于以下问题:Python ontimer函数的具体用法?Python ontimer怎么用?Python ontimer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ontimer函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: spawn_trash
def spawn_trash():
if game_over:
return
#-10 is needed so that the snake can crash into the trash
trash.setpos(random.randint(int(MIN_X/20)+1, int(MAX_X)/20-1)*20,
random.randint(int(MIN_Y)/20+1, int(MAX_Y)/20-1)*20)
#keep track of trash stamps
stamp = trash.stamp()
trash_stamps.append(stamp)
#keep track of trash positions for each stamp
trash_positions.append(trash.pos())
# positions.append((trash.pos()[0]+10, trash.pos()[1]+10))
# positions.append((trash.pos()[0]+10, trash.pos()[1]-10))
# positions.append((trash.pos()[0]-10, trash.pos()[1]-10))
# positions.append((trash.pos()[0]-10, trash.pos()[1]+10))
# trash_positions[stamp] = positions
#keep reverse mapping of position to stamp id
# for position in positions:
# trash_position_values[position] = stamp
global trash_count
trash_count += 1
if trash_count > MAX_TRASH:
trigger_game_over()
calculate_score()
turtle.ontimer(spawn_trash, trash_step_time)
开发者ID:mysticuno,项目名称:MEETY12015MiniProject,代码行数:31,代码来源:snake2.py
示例2: perform_step
def perform_step():
board.step()
board.display()
# In continuous mode, we set a timer to display another generation
# after 25 millisenconds.
if continuous:
turtle.ontimer(perform_step, 25)
开发者ID:MattRijk,项目名称:algorithms,代码行数:7,代码来源:conway_game_of_life.py
示例3: despawn_power_up
def despawn_power_up():
global power_up_present
if power_up_present:
power_up_present = False
recycle_positions.pop()
power_up_turtle.clearstamps()
turtle.ontimer(spawn_power_up, power_up_step_time)
开发者ID:mysticuno,项目名称:MEETY12015MiniProject,代码行数:7,代码来源:snake2.py
示例4: perform_step
def perform_step():
board.step()
board.display()
if continuous:
# calls function in question after t milliseconds
turtle.ontimer(perform_step, 25)
开发者ID:Nagoogin,项目名称:game-of-life,代码行数:7,代码来源:gameOfLife.py
示例5: move_t1
def move_t1():
# first turtle moves a little
t1.left(10)
t1.forward(10)
# repeat it after 100ms
turtle.ontimer(move_t1, 100)
开发者ID:golubaca,项目名称:python-examples,代码行数:7,代码来源:main-2.py
示例6: hands
def hands( freq=166 ):
"""Draw three hands.
:param freq: Frequency of refresh in milliseconds.
"""
global running
now= datetime.datetime.now()
time= now.time()
h, m, s, ms = time.hour, time.minute, time.second, int(time.microsecond/1000)
# Erase old hands.
while turtle.undobufferentries():
turtle.undo()
# Draw new hands.
hand( h*5+m/60+s/3600, .6*R, 3 )
hand( m+s/60, .8*R, 2 )
hand( s+ms/1000, .9*R, 1 )
# Draw date and time
turtle.penup(); turtle.home()
turtle.goto( 0, -120 ); turtle.write( now.strftime("%b %d %H:%M:%S"), align="center", font=("Helvetica", 24, "normal") )
# Reschedule hands function
if running:
# Reset timer for next second (including microsecond tweak)
turtle.ontimer( hands, freq-(ms%freq) )
开发者ID:slott56,项目名称:HamCalc-2.1,代码行数:27,代码来源:logoclok.py
示例7: play
def play(self):
cannon = LaserCannon()
turtle.ontimer(self.add_alien,2000)
turtle.listen()
# Start the event loop.
turtle.mainloop()
开发者ID:eclass2790,项目名称:Alien_Invaders,代码行数:7,代码来源:Alien+Invader.py
示例8: move_t2
def move_t2():
# second turtle moves a little
t2.right(10)
t2.forward(10)
# repeat it after 100ms
turtle.ontimer(move_t2, 100)
开发者ID:golubaca,项目名称:python-examples,代码行数:7,代码来源:main-2.py
示例9: main
def main():
"""
Tous les phase du battleship passe par le main()
et il sert de boucle principal car il est appelé à
tous les 0.5 secondes
"""
if i.phase == "PlaceShip":
i.placeShip()
elif i.phase == "Attack": # Nom fictif
i.attack()
elif i.phase == "win":
print('Vous avez gagné!')
turtle.goto(0,0)
turtle.pencolor('black')
turtle.write('Vous avez gagné!',align="center",font=("Arial",70, "normal"))
i.phase = "exit"
elif i.phase == "lose":
print('Vous avez perdu!')
turtle.goto(0,0)
turtle.pencolor('black')
turtle.write('Vous avez perdu!',align="center",font=("Arial",70, "normal"))
i.phase = "exit"
elif i.phase == "exit":
turtle.exitonclick()
return None
else:
print('out')
turtle.ontimer(main,500)
开发者ID:etiennedub,项目名称:battleship,代码行数:29,代码来源:main.py
示例10: play
def play(): # 게임을 실제로 플레이 하는 함수.
global score
global playing
t.forward(10) # 주인공 거북이 10만큼 앞으로 이동합니다.
if random.randint(1, 5) == 3: # 1~5사이에서 뽑은 수가 3이면(20%확률)
ang = te.towards(t.pos())
te.sethading(ang) # 악당 거북이가 주인공 거북이를 바라봅니다
speed = score + 5 # 점수에 5를 더해서 속도를 올립니다.
# 점수가 올라가면 빨라집니다.
if speed > 15: # 속도가 15를 넘지는 않도록 합니다
speed = 15
te.forward(speed)
if t.distance(te) < 12: # 주인공과 악당의 거리가 12보다 작으면
# 게임을 종료합니다.
text = "Score : " + str(score)
message("Game Over", text)
playing = False
score = 0
if t.distance(ts) < 12: # 주인공과 먹이의 거리가 12보다 작으면(가까우면)
score = score + 1 # 점수를 올립니다.
t.write(score) # 점수를 화면에 표시합니다.
star_x = random.randint(-230, 230)
star_y = random.randint(-230, 230)
ts.goto(star_x, star_y) # 먹이를 다른 곳으로 옮깁니다.
if playing:
t.ontimer(play, 100) # 게임 플레이 중이면 0.1초후
开发者ID:hubls,项目名称:p2_201611092,代码行数:32,代码来源:Turtle+Run+Game.py
示例11: move
def move(self):
self.forward(self.speed)
if self.out_of_bounds():
self.remove()
else:
turtle.ontimer(self.move,200)
if self.end_of_screen():
points(1)
global score
开发者ID:eclass2790,项目名称:Alien_Invaders,代码行数:9,代码来源:Alien+Invader.py
示例12: __init__
def __init__(self, init_heading, speed):
super(Bomb, self).__init__(speed)
self.color('red','red')
self.shape('circle')
self.shapesize(0.4, 0.4)
self.setheading(init_heading)
self.up()
# Start the bomb moving
turtle.ontimer(self.move,100)
开发者ID:eclass2790,项目名称:Alien_Invaders,代码行数:9,代码来源:Alien+Invader.py
示例13: power_up
def power_up():
print('RECYCLE TIME!')
global can_recycle, move_step_time, POWER_UP_TIME
can_recycle = True
snake.pencolor("yellow")
snake.fillcolor('yellow')
move_step_time = int(move_step_time * 2/3)
turtle.ontimer(power_down, POWER_UP_TIME) #power down after POWER_UP_TIME seconds
开发者ID:mysticuno,项目名称:MEETY12015MiniProject,代码行数:10,代码来源:snake2.py
示例14: flashing_block
def flashing_block():
global STAMP_ID
global BLOCK_POS
t.clearstamp(STAMP_ID)
nx,ny = BLOCK_POS
t.setpos(nx,ny)
STAMP_ID = t.stamp()
t.ontimer(flashing_block,100)
开发者ID:mysticuno,项目名称:MEETY12015MiniProject,代码行数:10,代码来源:part4.py
示例15: spawn_food
def spawn_food():
if game_over:
return
food.goto(random.randint(int(MIN_X/20)+1,int(MAX_X)/20-1)*20,
random.randint(int(MIN_Y)/20+1, int(MAX_Y)/20-1)*20)
food_positions.append(food.pos())
food_stamps.append(food.stamp())
turtle.ontimer(spawn_food, food_step_time)
if len(food_stamps) > 5:
food.clearstamp(food_stamps.pop(0))
food_positions.pop(0)
开发者ID:mysticuno,项目名称:MEETY12015MiniProject,代码行数:11,代码来源:snake.py
示例16: spawn_trash
def spawn_trash():
if game_over:
return
trash.goto(random.randint(int(MIN_X/20)+1, int(MAX_X)/20-1)*20 - 10,
random.randint(int(MIN_Y)/20+1, int(MAX_Y)/20-1)*20 - 10)
trash.stamp()
trash_positions.append((trash.pos()[0]+10, trash.pos()[1]+10))
trash_positions.append((trash.pos()[0]+10, trash.pos()[1]-10))
trash_positions.append((trash.pos()[0]-10, trash.pos()[1]-10))
trash_positions.append((trash.pos()[0]-10, trash.pos()[1]+10))
turtle.ontimer(spawn_trash, trash_step_time)
开发者ID:mysticuno,项目名称:MEETY12015MiniProject,代码行数:12,代码来源:snake.py
示例17: move_step
def move_step():
global current_direction
current_direction = temp_current_direction
if detect_collision():
trigger_game_over()
else:
snake.clearstamp(snake_stamps.pop(0))
calculate_next_pos()
snake_positions.pop(0)
add_segment_to_front()
turtle.ontimer(move_step, move_step_time)
开发者ID:mysticuno,项目名称:MEETY12015MiniProject,代码行数:12,代码来源:snake2.py
示例18: move
def move():
global x, y, Vsnake, t, cherry
t = t + 1
turtle.forward(Vsnake)
turtle.stamp();
if cherry > 0:
cherry = cherry - 1
else:
turtle.clearstamps(1)
turtle.ontimer(move, 100)
开发者ID:bonoxu,项目名称:planeGames,代码行数:13,代码来源:snake_v1.py
示例19: spawn_power_up
def spawn_power_up():
if game_over:
return
global power_up_present, can_recycle
if not (power_up_present or can_recycle):
chance = random.random()
if chance <= power_up_chance:
power_up_present = True
power_up_turtle.setpos(random.randint(int(MIN_X/20)+1,int(MAX_X)/20-1)*20,
random.randint(int(MIN_Y)/20+1, int(MAX_Y)/20-1)*20)
power_up_turtle.stamp()
recycle_positions.append(power_up_turtle.pos())
turtle.ontimer(despawn_power_up,10000)
turtle.ontimer(spawn_power_up, power_up_step_time)
开发者ID:mysticuno,项目名称:MEETY12015MiniProject,代码行数:14,代码来源:snake2.py
示例20: update
def update(self):
# update all spiros
nComplete = 0
for spiro in self.spiros:
# update
spiro.update()
# count completed ones
if spiro.drawingComplete:
nComplete+= 1
# if all spiros are complete, restart
if nComplete == len(self.spiros):
self.restart()
# call timer
turtle.ontimer(self.update, self.deltaT)
开发者ID:Unclerojelio,项目名称:python_playground,代码行数:14,代码来源:spiro.py
注:本文中的turtle.ontimer函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论