本文整理汇总了Python中pygame.time.get_ticks函数的典型用法代码示例。如果您正苦于以下问题:Python get_ticks函数的具体用法?Python get_ticks怎么用?Python get_ticks使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_ticks函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: endScene
def endScene(self):
fpsClock = PT.Clock()
DURATION = 2000.0
start_time = PT.get_ticks()
ratio = 0.0
while ratio < 1.0:
current_time = PT.get_ticks()
ratio = (current_time - start_time)/DURATION
if ratio > 1.0:
ratio = 1.0
value = int(255*ratio)
fade_color = PC.Color(0, 0, 0, 0)
fade_color.a = value
# PD.rect(Globals.SCREEN, fade_color, (0,0,400,300))
surf = PG.Surface((800, 600))
surf.set_alpha(value)
surf.fill((0, 0, 0))
Globals.SCREEN.blit(surf, (0, 0))
PD.flip()
fpsClock.tick(60)
levelTwoEvents[1] = False
Player.events[4] = False
self.stone_mound = item.Item(54*Setup.PIXEL_SIZE, 26*Setup.PIXEL_SIZE, stone_mound_image)
Globals.WORLD.addEntity(self.stone_mound)
Globals.STATE = LevelTwo()
开发者ID:kzhang12,项目名称:Video-Game-Design,代码行数:25,代码来源:LevelTwo.py
示例2: run
def run(self):
"""Runs the main game loop
"""
FPS = 1.0 / 8.0
lastScreenUpdate = time.get_ticks()
while self._run_game:
if time.get_ticks() - lastScreenUpdate < FPS:
continue
self._processInput()
if self._pause_game is False:
self._moveSnake()
if self._with_opponent:
self._moveOpponent()
if self._collides():
self._run_game = False
if self._eatsApple(self._snake) or \
(self._with_opponent and self._eatsApple(self._opponent)):
self._spawnApple()
self._draw()
self._frames = self._frames + 1
# Slow things down a bit...
lastScreenUpdate = time.get_ticks() + self._delay
开发者ID:peanut-lord,项目名称:python-snake,代码行数:34,代码来源:main.py
示例3: tick
def tick(self, maxMillis):
currentTime = time.get_ticks()
maxTime = currentTime + maxMillis
queueToProcess = self._currentQueue
queueToProcess = (self._currentQueue + 1) % self._numQueues
del self._queues[queueToProcess][:]
q = self._getCurrentQueue()
while len(q) > 0:
event = q.pop(0)
if event.getType() in self._listenerList:
for listener in self._listenerList[event.getType()]:
listener.handle(event)
else:
continue
currentTime = time.get_ticks()
if currentTime >= maxTime:
break
queueEmpty = len(q) == 0
if not queueEmpty:
q.extend(self._queues[self._currentQueue])
self._queues[self._currentQueue], q = q, []
return queueEmpty
开发者ID:MGralka,项目名称:pyz,代码行数:27,代码来源:eventmanagement.py
示例4: main_loop
def main_loop():
"""Main loop for running the actionRPM game"""
# Clock code adapted from Peter's leftover-interval.py
clock = time.Clock()
current_time = time.get_ticks()
leftover = 0.0
while True:
Constants.STATE.draw()
# Set up clock stuff
new_time = time.get_ticks()
frame_time = (new_time - current_time) / 1000.0
current_time = new_time
clock.tick()
#Update the Player & Enemy
leftover += frame_time
while leftover > Constants.INTERVAL:
Constants.STATE.update(Constants.INTERVAL)
leftover -= Constants.INTERVAL
#Begin key presses
pygame.event.pump()
for eve in event.get():
if eve.type == pygame.QUIT:
exit()
elif eve.type == pygame.KEYDOWN and eve.key == pygame.K_m and \
eve.mod & (pygame.KMOD_CTRL or pygame.KMOD_LCTRL):
Constants.STATE = Menu.Menu()
#elif eve.type == pygame.MOUSEBUTTONDOWN:
#print(pygame.mouse.get_pos())
else:
Constants.STATE.keyEvent(eve)
开发者ID:mattgor123,项目名称:CS255-ActionRPM,代码行数:34,代码来源:game.py
示例5: fire_weapon
def fire_weapon(self):
"""Fire the character's weapon."""
last_fired = self.last_fired + self.weapon.fire_rate * 100
if last_fired < time.get_ticks():
self.weapon.fire()
self.last_fired = time.get_ticks()
开发者ID:derrida,项目名称:shmuppy,代码行数:7,代码来源:character.py
示例6: authenticate
def authenticate(self):
""" call this before opening the game
gets the current tick from the server
and synchronizes the game state """
def threaded_recv(retlist):
response, addr = self.client.recv()
retlist.append(response)
pkg_request = Packet(0)
self.client.send(pkg_request)
retlist = []
t = Thread(target=lambda: threaded_recv(retlist))
t.daemon = True
t.start()
wait_start = time.get_ticks()
wait_end = wait_start + 1000
while len(retlist) <= 0 and time.get_ticks() < wait_end:
time.wait(1)
if len(retlist) > 0:
response = retlist[0]
pkg_response = Packet.unpack(response)
self.start_tick = pkg_response.tick
if len(pkg_response.players) <= 0:
raise RuntimeError("Invalid response: %s" % pkg_response)
self.id = pkg_response.players[0][0]
self.set_state(pkg_response, backtrack=False)
else:
raise RuntimeError("Server not responding")
开发者ID:oncer,项目名称:netproto,代码行数:30,代码来源:np_client.py
示例7: run
def run(self):
self.net_tick = 0
self.clients = {}
self.lock = Lock()
self.server = UdpServer(25000)
self.socket_thread = SocketThread(self)
self.socket_thread.start()
print "Server up and running."
self.input_thread = InputThread(self)
self.input_thread.start()
ticks_start = time.get_ticks()
while not self.quit:
ticks = time.get_ticks() - ticks_start - self.net_tick * FRAMETIME
update_count = ticks / FRAMETIME
with self.lock:
for i in xrange(update_count):
self.update()
self.send_new_state()
dead_clients = []
for addr, client in self.clients.items():
client.countdown()
if client.is_dead():
dead_clients.append(addr)
for addr in dead_clients:
print "removing client %s (timeout)" % str(addr)
del self.clients[addr]
time.wait(1)
开发者ID:oncer,项目名称:netproto,代码行数:31,代码来源:np_server.py
示例8: game_loop
def game_loop(self):
"""Function for the main game loop."""
clock = T.Clock()
current_time = T.get_ticks()
leftover = 0.0
while True:
self.play.draw()
P.display.update()
new_time = T.get_ticks()
frame_time = (new_time - current_time) / 1000.0
current_time = new_time
clock.tick()
leftover += frame_time
while leftover > 0.01:
self.play.update()
leftover -= 0.01
P.event.pump()
for e in P.event.get():
if e.type == P.QUIT:
exit()
else:
self.play.handle_keys(e)
开发者ID:jshuay,项目名称:breakout,代码行数:25,代码来源:breakout.py
示例9: render
def render(self):
#Music
if not PX.music.get_busy():
if Globals.CURRENTSONG == HIGHSONG:
PX.music.load(HIGHSONG)
Globals.CURRENTSONG = SONG1
elif Globals.CURRENTSONG == SONG1:
PX.music.load(SONG1)
Globals.CURRENTSONG = SONG0
elif Globals.CURRENTSONG == SONG0:
PX.music.load(SONG0)
Globals.CURRENTSONG = HIGHSONG
PX.music.set_volume(Globals.VOLUME)
PX.music.play(0, 0.0)
lasttime = PT.get_ticks()
#screen.fill(BLACK)
self.current_level.draw(screen, self.player_group)
self.player_group.draw(screen)
self.ui_group.draw(screen)
clock.tick()
PDI.flip()
elapsed = (PT.get_ticks() - lasttime) / 1000.0
if elapsed > 2.0:
elapsed = 2.0
#Update Player and Enemy
while elapsed >= 0 and Globals.ALIVE:
self.player_group.update(INTERVAL, self.PLAYER_X_POS, self.PLAYER_X_NEG, self.PLAYER_Y_POS, \
self.PLAYER_Y_NEG, self.SELECTEDWEAPON, self.ATTACK, self.CROUCH, \
self.USING, self.TOOLS, self.current_level)
Globals.ALIVE = self.new_player.is_alive()
self.current_level.update(INTERVAL, self.player_group)
self.ui_group.update(self.new_player)
elapsed -= INTERVAL
if self.new_player.get_win():
Globals.STATE = Win(self.level_num)
self.USING = False
#Reset jump status
for this_player in self.player_group:
if not this_player.on_ladder():
self.PLAYER_Y_POS = False
#Reset ladder status
self.TOOLS = -1
#Check to see if the player is alive
if not Globals.ALIVE:
while elapsed >= 0:
self.new_player.die(INTERVAL)
elapsed -= INTERVAL
if self.new_player.finishedDying():
#Reset Music
if PX.music.get_busy():
PX.music.stop()
Globals.LASTCHECK = self.current_level.get_last_check()
Globals.STATE = Lose(self.new_player)
开发者ID:rogerzxu,项目名称:OrganDonor,代码行数:59,代码来源:Game_state.py
示例10: find_path_between_points
def find_path_between_points(self, start_tile, end_tile, pathfinder_screen_s):
"""
:param point_a: Tuple(int, int)
:param point_b: Tuple(int, int)
:rtype : List(Tuple)
:rtype time_module: pygame.time
"""
assert isinstance(start_tile, tuple)
assert isinstance(end_tile, tuple)
method_init_time = time.get_ticks()
counter = 0
# Create start and end nodes.
start_node = self.grid.nodes[start_tile]
target_node = self.grid.nodes[end_tile]
# Keep track of the open and closed nodes.
# Add the start node as the first node to start the flood from.
open_nodes = priority_dict()
open_nodes[start_node] = 0
closed_nodes = set()
# start looping
while open_nodes.__len__() > 0:
current_node = open_nodes.pop_smallest()
# Remove the current node from open set and add it to closed set.
#open_nodes.remove(current_node)
closed_nodes.add(current_node)
# Found the end tile.
if current_node == target_node:
complete_path = self.retrace_path(start_node, target_node)
method_run_time = time.get_ticks() - method_init_time
print 'Pathfinding completed in {}ms'.format(method_run_time)
return complete_path
for neighbour_node in self.get_neighbours(current_node):
if neighbour_node in closed_nodes:
continue
assert isinstance(current_node, PathFinder.Node)
assert isinstance(neighbour_node, PathFinder.Node)
new_movement_cost_to_neighbor = current_node.g_cost + 10
# Try to find a lower cost for neighbor, or calculate if it doesn't have one.
if new_movement_cost_to_neighbor < neighbour_node.g_cost or neighbour_node not in open_nodes.keys():
# Calculate the costs for the neighbor
neighbour_node.g_cost = new_movement_cost_to_neighbor
neighbour_node.h_cost = self.get_distance(neighbour_node, target_node)
neighbour_node.parent = current_node
open_nodes[neighbour_node] = neighbour_node.f_cost
开发者ID:rytai,项目名称:ReStart,代码行数:59,代码来源:PathFinder.py
示例11: virtual_status_change
def virtual_status_change(self, power):
from pygame.time import get_ticks
if not self.opening_time:
self.opening_time = get_ticks()
self.opening = (get_ticks() - self.opening_time) * power
if self.opening > self.hard:
self.opening = 0
self.opening_time = False
self.passability = (self.passability + 1) % 2
self.transparency = self.passability
开发者ID:creators1303,项目名称:Hex_Platform,代码行数:10,代码来源:Door.py
示例12: attack
def attack(self):
if(self.isInCar):
return
if self.attacking or time.get_ticks() < self.attack_delay + self.attack_end:
return False
self.attacking = True
self.attack_start = time.get_ticks()
self.current_image = self.attack_image
return True
开发者ID:ivolo,项目名称:Grand-Theft-Australian-Zoo,代码行数:11,代码来源:player.py
示例13: update
def update(self):
if self.running:
if keyboard.right:
self.cannon.move_right()
elif keyboard.left:
self.cannon.move_left()
if keyboard.space:
if get_ticks() - self.cannon.last_fire > self.cannon.firing_interval:
self.bullets.append(Bullet('bullet', self.cannon.pos))
sounds.shot.play()
self.cannon.last_fire = get_ticks()
for bullet in self.bullets[:]:
bullet.update()
if bullet.is_dead():
self.bullets.remove(bullet)
for alien in self.aliens[:]:
alien.update()
if self.cannon.colliderect(alien):
self.explosions.append(Explosion('cannon_explosion', self.cannon.pos))
sounds.explosion.play()
self.running = False
if alien.bottom >= HEIGHT:
self.running = False
for bullet in self.bullets[:]:
if alien.colliderect(bullet):
alien.lives -= 1
if alien.is_dead():
self.explosions.append(Explosion('alien_explosion', alien.pos))
sounds.explosion.play()
self.aliens.remove(alien)
self.score += ALIEN_KILL_SCORE
self.bullets.remove(bullet)
for explosion in self.explosions[:]:
explosion.update()
if explosion.is_finished():
self.explosions.remove(explosion)
if len(self.aliens) == 0 and len(self.explosions) == 0:
self.game.set_game_over_message("YOU WON!!!!!", "#00FFFF")
self.game.change_scene(GAME_OVER_SCENE)
else:
for explosion in self.explosions[:]:
explosion.update()
if explosion.is_finished():
self.explosions.remove(explosion)
if len(self.explosions) == 0:
self.game.set_game_over_message("YOU LOST...", "red")
self.game.change_scene(GAME_OVER_SCENE)
开发者ID:matsrorbecker,项目名称:pgzero_game,代码行数:53,代码来源:game.py
示例14: update
def update(self, field):
from pygame.time import get_ticks
if get_ticks() - self.merge >= self.mob.stats.merge_time:
status = self.main_merger()
if status == 1:
self.mob.health += 1
self.communication.health -= 1
elif status == 0:
self.mob.health -= 1
self.communication.health += 1
self.merge = get_ticks()
return True
开发者ID:creators1303,项目名称:Hex_Platform,代码行数:12,代码来源:Merging.py
示例15: going
def going(self, field, path):
if get_ticks() - self.step_time >= self.mob.stats.step_time:
from bin.Logic import coord_get_offset
coord = coord_get_offset(path, field)
if not field.map[coord[0]][coord[1]][1].passability:
field.map[coord[0]][coord[1]][1].virtual_status_change(1)
else:
from bin.Logic import hex_visible_false
hex_visible_false(field, self.mob.coord, self.mob.stats.view_radius)
self.mob.going(field, path)
self.step_time = get_ticks()
return True
开发者ID:creators1303,项目名称:Hex_Platform,代码行数:12,代码来源:Exploring.py
示例16: check
def check(self, field):
if self.hexagon:
from bin.Logic import coord_get_offset
coord = coord_get_offset(self.hexagon, field)
if field.map[coord[0]][coord[1]][1].exploration:
self.hexagon = False
if get_ticks() - self.find_time >= self.mob.stats.find_time:
return 8
if get_ticks() - self.path_time >= self.mob.stats.path_time:
self.path_time = get_ticks()
self.hexagon = False
return True
开发者ID:creators1303,项目名称:Hex_Platform,代码行数:12,代码来源:Exploring.py
示例17: transmit
def transmit(self):
#Transmit data to empty tx buffer, but for no longer than TIMEOUT.
start = time.get_ticks()
while len(self.tx) and ((time.get_ticks() - start) < TIME_WRITE): #Transmit for no longer than timeout
#Keep statistics on transmission data rate.
self.txData.append(len(self.tx[0]))
self.txTime.append(time.get_ticks())
print '#' + self.tx[0],
self.ser.write(self.tx.popleft())
self.txRate = 1000 * sum(self.txData) / (self.txTime[-1]-self.txTime[0])
self.rxRate = 1000 * sum(self.rxData) / (self.rxTime[-1]-self.rxTime[0])
开发者ID:bnitkin,项目名称:Terminus,代码行数:13,代码来源:link.py
示例18: draw
def draw(self):
if not self.is_jumping:
Player.draw(self)
return
if time.get_ticks() < self.last_jump + self.jump_init_time:
self.current_image = self.jump_images[0]
elif time.get_ticks() < self.last_jump + self.jump_time - self.jump_init_time:
self.current_image = self.jump_images[1]
elif time.get_ticks() < self.last_jump + self.jump_time:
self.current_image = self.jump_images[2]
Player.draw(self)
开发者ID:ivolo,项目名称:Grand-Theft-Australian-Zoo,代码行数:13,代码来源:kangaroo.py
示例19: _foo
def _foo(e):
global _Clic,_Ticks
if e.type==MOUSEBUTTONDOWN:
t = time.get_ticks()
if e.button!=_Clic[0] or t-_Ticks[e.button]>LAPS: _Clic=[e.button,0,0,0,0,0]
_Ticks[e.button] = t
elif e.type==MOUSEBUTTONUP:
t = time.get_ticks()
if t-_Ticks[e.button]>LAPS: _Clic=[e.button,0,0,0,0,0]
else:
_Clic[e.button]+=1
_Ticks[e.button] = t
e.dict.update({'click':_Clic})
开发者ID:602p,项目名称:spacegame,代码行数:13,代码来源:GetEvent.py
示例20: loop
def loop():
clock = PT.Clock()
leftover = 0.0
updates = 0
up = 0
isPlayingMenu = False
isPlaying = False
while Globals.RUNNING:
if not isPlayingMenu:
if Globals.ISMAINMENU:
Globals.MENU_MUSIC.set_volume(Globals.VOLUME/200.0)
Globals.MENU_MUSIC.play(-1)
isPlayingMenu = True
else:
if not Globals.ISMAINMENU:
isPlayingMenu = False
if not isPlaying:
if Globals.ISLEVELONE:
Globals.MUSIC.set_volume(Globals.VOLUME/200.0)
print 'playing'
Globals.MUSIC.play(-1)
isPlaying = True
else:
if not Globals.ISLEVELONE:
Globals.MUSIC.stop()
start_time = PT.get_ticks()
Globals.STATE.render()
if Globals.BRIGHTNESS < 0:
Globals.brightness.fill((0, 0, 0))
Globals.brightness.set_alpha(-1 * Globals.BRIGHTNESS/100.0 * 100)
Globals.SCREEN.blit(Globals.brightness, (0, 0))
elif Globals.BRIGHTNESS > 0:
Globals.brightness.fill((255, 255, 255))
Globals.brightness.set_alpha(Globals.BRIGHTNESS/100.0 * 100)
Globals.SCREEN.blit(Globals.brightness, (0, 0))
PDI.flip()
updates = 0
clock.tick(60)
last = PT.get_ticks()
elapsed = (last - start_time) / 1000.0
Globals.STATE.update(elapsed)
leftover += elapsed
for event in PE.get():
if event.type == PG.QUIT:
Globals.RUNNING = False
else:
Globals.STATE.event(event)
开发者ID:kzhang12,项目名称:Video-Game-Design,代码行数:50,代码来源:GameFrame.py
注:本文中的pygame.time.get_ticks函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论