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


Python Timer.elapsed方法代码示例

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


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

示例1: on_vehicle_enter

# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import elapsed [as 别名]
    def on_vehicle_enter(self, e):
        if e.vehicle.group == AIR:
            enter_time = e.tick - self.spawn_times[e.player]

            air_timer = Timer()
            air_timer.elapsed = enter_time

            if e.player in self.results:
                self.results[e.player] = min(air_timer, self.results[e.player])
            else:
                self.results[e.player] = air_timer
开发者ID:chrisw1229,项目名称:bf2-stats,代码行数:13,代码来源:wright_brothers.py

示例2: Bullet

# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import elapsed [as 别名]
class Bullet(TextEntity):
	def __init__(self, owner, layer, vel_x, vel_y):
		TextEntity.__init__(self, owner, layer, char = '+')
		self.setPos(owner.pos_x, owner.pos_y)
		self.setOldPos(owner.pos_x, owner.pos_y)
		self.resistance_x = 0
		self.resistance_y = 0
		self.vel_x = vel_x
		self.vel_y = vel_y
		self.visible = True
		self.liveTimer = Timer()
		self.liveTimer.start()
		self.name = 'Bullet'
	
	def death(self, attacker=None, deathtype=None):
		self.health = -1

	def collideHandler(self):
		for partner in self.touching:
			if partner[0]:
				if partner[0] == self.owner:
					pass # we don't hurt ourselves :D
				else:
					#print "Bullet collided with", partner[0]
					#self.pos_x = partner[1][0]
					#self.pos_y = partner[1][1]
					self.pos_x = self.oldpos_x
					self.pos_y = self.oldpos_y
					self.vel_x = 0
					self.vel_y = 0
					self.health = 0
			else:
				# hit the map
				#print "hit a wall"
				self.pos_x = self.oldpos_x
				self.pos_y = self.oldpos_y
				self.vel_x = 0
				self.vel_y = 0
				self.health = 0

		self.touching = []

	def think(self, frameDT):
		if len(self.touching): self.collideHandler()

		if self.liveTimer.elapsed() > 1000:
			#print "timed out!"
			self.health = 0

		if not self.health:
			#print "died!"
			self.death()
开发者ID:spekode,项目名称:2dengine1,代码行数:54,代码来源:player.py

示例3: do_GET

# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import elapsed [as 别名]
	def do_GET(self):
		fps = Fps()

		init_time = Timer()
		init_time.start()
		cap = cv2.VideoCapture(0)
		try:
			init_time.end()
			print "initialization time : " + str(init_time.elapsed()) + " elapsed"
			self.send_response(httplib.OK)
			self.send_header("Content-type", "multipart/x-mixed-replace;boundary=boundarytag")
			self.end_headers()
			fps.start()
			
			while True:
				t = Timer()
				retval, frame = cap.read()
				
				img = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
				jpg = Image.fromarray(img)
				tmp = StringIO.StringIO()
				t.start()
				jpg.save(tmp, 'JPEG')
				t.end()
				print "frame encoding time : " + str(t.elapsed()) + " elapsed"

				self.wfile.write("--boundarytag")
				self.send_header("Content-type", "image/jpeg")
				self.send_header("Content-Length", len(tmp.getvalue()))
				self.end_headers()
				
				self.wfile.write(tmp.getvalue())
				fps.increase()
		except KeyboardInterrupt:
			print "keboard interrupt"
		finally:
			fps.end()
			cap.release()
			print fps.fps()
开发者ID:sam7292,项目名称:mjpeg_videostreamer,代码行数:41,代码来源:mjpeg_streamer2.py

示例4: gameLoop

# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import elapsed [as 别名]
def gameLoop():
	global frameDT
	frameTime = Timer()
	frameDT = 0.0
	while 1:
		frameTime.start()

		# INPUT
		keys_down, keys_up, other = keyInput.retrieve()

		# UPDATE
		result = game.update(keys_down, keys_up, other)

		# LOGIC
		result = game.run(frameDT)

		# RENDER
		game.camera.snap(frameDT)

		# WAIT
		endFrameTime = frameTime.elapsed()
		if endFrameTime < MaxFPSWait: time.sleep((MaxFPSWait - endFrameTime) / 1000)
		
		frameDT = frameTime.elapsed()
开发者ID:spekode,项目名称:2dengine1,代码行数:26,代码来源:main.py

示例5: Player

# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import elapsed [as 别名]
class Player(TextEntity):
	def __init__(self):
		TextEntity.__init__(self, self, 0)
		self.rateOfFire = 250
		self.shooting = False
		self.shootingTime = Timer().start()
		self.fire_x = 0
		self.fire_y = 0
		self.fire_vel = 50
		self.name = 'Player'

		self.moveRate = 50
		self.moving = False
		self.moveTime = Timer().start()
		self.move_vel = 7

		self.vel_y_max = 10
		self.vel_x_max = 10
		self.resistance_x = 35.0
		self.resistance_y = 35.0

		self.levelMax = 20
		self.levelCur = 0 
		self.levelFuzzieEx = 5 #Chance of a fuzzie spawning during the time (20% chance)

		#self.constaccel_y = 20.0
		#self.vel_x_max = 100.0
		#self.vel_y_max = 100.0
#		self.accel_y = 0.0
		#self.resistance_x = 1.0
	def left(self, key, state):
		if state == True:
			self.moving |= MOVE_LEFT
		else:
			self.moving &= ~MOVE_LEFT
	def right(self, key, state):
		if state == True:
			self.moving |= MOVE_RIGHT
		else:
			self.moving &= ~MOVE_RIGHT
	def up(self, key, state):
		if state == True:
			self.moving |= MOVE_UP
		else:
			self.moving &= ~MOVE_UP
	def down(self, key, state):
		# POWER SLIDE!!!
		#if state == True:
		#	self.resistance_x -= 600
		#else: self.resistance_x += 600
		if state == True:
			self.moving |= MOVE_DOWN
		else:
			self.moving &= ~MOVE_DOWN

	def _move(self):
		if self.moveTime.elapsed() < self.moveRate:
			return
		
		x = y = 0
		if self.moving & MOVE_LEFT: x -= self.move_vel
		if self.moving & MOVE_RIGHT: x += self.move_vel
		if self.moving & MOVE_UP: y -= self.move_vel
		if self.moving & MOVE_DOWN: y += self.move_vel
		
		self.impulse(x, y)
		self.moveTime.restart()

	def _fire(self, x, y):
		if self.shootingTime.elapsed() < self.rateOfFire:
			return
		if not x and not y: return

		getScene().add(Bullet(self, 3, x, y), 3)
		self.shootingTime.restart()

	def fireUp(self, key, state): 
		if self.shooting and not state:
			self.shooting -= 1
			self.fire_y += self.fire_vel
		elif state == True:
			self.shooting += 1
			self.fire_y += -self.fire_vel
	def fireDown(self, key, state):
		if self.shooting and not state:
			self.shooting -= 1
			self.fire_y -= self.fire_vel
		elif state == True:
			self.shooting += 1
			self.fire_y += self.fire_vel
	def fireLeft(self, key, state):
		if self.shooting and not state:
			self.shooting -= 1
			self.fire_x += self.fire_vel
		elif state == True:
			self.shooting += 1
			self.fire_x += -self.fire_vel
	def fireRight(self, key, state):
		if self.shooting and not state:
			self.shooting -= 1
#.........这里部分代码省略.........
开发者ID:spekode,项目名称:2dengine1,代码行数:103,代码来源:player.py

示例6: Fortress

# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import elapsed [as 别名]
class Fortress(Token):
    """represents the fortress object that typically appears in the center of the worldsurf"""
    def __init__(self, app):
        super(Fortress, self).__init__()
        self.app = app
        self.position.x = self.app.world.centerx
        self.position.y = self.app.world.centery
        self.color = (255, 255, 0)
        self.collision_radius = self.app.config['Fortress']['fortress_radius'] * self.app.aspect_ratio
        self.last_orientation = self.orientation 
        self.timer = Timer(self.app.gametimer.elapsed)
        self.sector_size = self.app.config['Fortress']['fortress_sector_size']
        self.lock_time = self.app.config['Fortress']['fortress_lock_time']
        self.reset_timer = Timer(self.app.gametimer.elapsed)
        self.alive = True
        if self.app.config['Graphics']['fancy']:
            self.fortress = pygl2d.image.Image(pkg_resources.resource_stream("resources", 'gfx/psf5.png'))
            self.fortress_rect = self.fortress.get_rect()
            self.fortress.scale((72 * self.app.aspect_ratio) / 128)
  
    def compute(self):
        """determines orientation of fortress"""
        if self.app.ship.alive:
            self.orientation = self.to_target_orientation(self.app.ship) // self.sector_size * self.sector_size #integer division truncates
        if self.orientation != self.last_orientation:
            self.last_orientation = self.orientation
            self.timer.reset()
        if self.timer.elapsed() >= self.lock_time and self.app.ship.alive and self.app.fortress.alive:
            self.app.gameevents.add("fire", "fortress", "ship")
            self.fire()
            self.timer.reset()
        if not self.alive and self.reset_timer.elapsed() > 1000:
            self.alive = True
            
    def fire(self):
        self.app.snd_shell_fired.play()
        self.app.shell_list.append(shell.Shell(self.app, self.to_target_orientation(self.app.ship)))
        
    def draw(self):
        """draws fortress to worldsurf"""
        if self.app.config['Graphics']['fancy']:
            self.fortress.rotate(self.orientation - 90)
            self.fortress_rect.center = (self.position.x, self.position.y)
            self.fortress.draw(self.fortress_rect.topleft)
        else:
            #pygame.draw.circle(worldsurf, (0, 0, 0), (self.position.x, self.position.y), int(30 * self.app.aspect_ratio))
            sinphi = math.sin(math.radians((self.orientation) % 360))
            cosphi = math.cos(math.radians((self.orientation) % 360))
            x1 = 18 * cosphi * self.app.aspect_ratio + self.position.x
            y1 = -(18 * sinphi) * self.app.aspect_ratio + self.position.y
            x2 = 36 * cosphi * self.app.aspect_ratio + self.position.x
            y2 = -(36 * sinphi) * self.app.aspect_ratio + self.position.y
            x3 = (18 * cosphi - -18 * sinphi) * self.app.aspect_ratio + self.position.x
            y3 = (-(-18 * cosphi + 18 * sinphi)) * self.app.aspect_ratio + self.position.y
            x4 = -(-18 * sinphi) * self.app.aspect_ratio + self.position.x
            y4 = -(-18 * cosphi) * self.app.aspect_ratio + self.position.y
            x5 = (18 * cosphi - 18 * sinphi) * self.app.aspect_ratio + self.position.x
            y5 = (-(18 * cosphi + 18 * sinphi)) * self.app.aspect_ratio + self.position.y
            x6 = -(18 * sinphi) * self.app.aspect_ratio + self.position.x
            y6 = -(18 * cosphi) * self.app.aspect_ratio + self.position.y
            pygl2d.draw.line((x1, y1), (x2, y2), self.color, self.app.linewidth)
            pygl2d.draw.line((x3, y3), (x5, y5), self.color, self.app.linewidth)
            pygl2d.draw.line((x3, y3), (x4, y4), self.color, self.app.linewidth)
            pygl2d.draw.line((x5, y5), (x6, y6), self.color, self.app.linewidth)
开发者ID:CogWorks,项目名称:SpaceFortress,代码行数:66,代码来源:fortress.py

示例7: Timer

# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import elapsed [as 别名]
'''
this application is video capture example
'''

import numpy as np
import cv2
from timer import Timer

timer = Timer()
timer.start()
cap = cv2.VideoCapture(0)
timer.end()
print "initialization elapsed : " + str(timer.elapsed())

while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()

    # Our operations on the frame come here
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Display the resulting frame
    cv2.imshow('frame',gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
开发者ID:sam7292,项目名称:mjpeg_videostreamer,代码行数:31,代码来源:video_capture.py

示例8: Bonus

# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import elapsed [as 别名]
class Bonus(Token):
    """bonus symbol"""
    def __init__(self, app):
        super(Bonus, self).__init__()
        self.position.x = 0
        self.position.y = 0
        self.app = app
        self.symbols = self.app.config['Bonus']['non_bonus_symbols']
        self.set_bonus_location()
        self.visible = False
        self.font = self.app.f28
        self.bonus_symbol = self.app.config['Bonus']['bonus_symbol']
        self.current_symbol = None
        self.prior_symbol = None
        if self.app.config['General']['bonus_system'] == "AX-CPT":
            self.bonus_count = 1
        else:
            self.bonus_count = 0
        self.flag = False
        self.probability = self.app.config['Bonus']['bonus_probability']
        self.timer = Timer(self.app.gametimer.elapsed)
        #new attributes for AX-CPT
        self.cue_time = self.app.config['AX-CPT']['cue_visibility']
        self.target_time = self.app.config['AX-CPT']['target_visibility']
        self.isi_time = self.app.config['AX-CPT']['isi_time']
        self.iti_time = self.app.config['AX-CPT']['iti_time']
        self.state = self.app.config['AX-CPT']['state']
        self.ax_prob = self.app.config['AX-CPT']['ax_prob']
        self.ay_prob = self.app.config['AX-CPT']['ay_prob']
        self.bx_prob = self.app.config['AX-CPT']['bx_prob']
        self.by_prob = self.app.config['AX-CPT']['by_prob']
        self.a_symbols = self.app.config['AX-CPT']['a_symbols']
        self.b_symbols = self.app.config['AX-CPT']['b_symbols']
        self.x_symbols = self.app.config['AX-CPT']['x_symbols']
        self.y_symbols = self.app.config['AX-CPT']['y_symbols']
        self.current_pair = "nothing" #either "ax", "ay", "bx", or "by"
        self.current_symbols = self.pick_next_pair()
        self.axcpt_flag = False #bonus is capturable
        
    def generate_new_position(self):
        self.position.x = random.randint(self.app.world.left + 30, self.app.world.right - 30)
        self.position.y = random.randint(self.app.world.top + 30, self.app.world.bottom - 30)
        
    def set_bonus_location(self):
        if self.app.config['General']['bonus_location'] == 'Random':           
            self.generate_new_position()
            while self.get_distance_to_object(self.app.fortress) < self.app.config['Hexagon']['small_hex'] * self.app.aspect_ratio * 1.25:
                self.generate_new_position()
        elif self.app.config['General']['bonus_location'] == 'Probabilistic':
            w = self.app.world.width / 5
            h = self.app.world.height / 5
            probs = map(float, self.app.config['Bonus']['quadrant_probs'].split(','))
            r
            if r <= probs[0]:
                self.position.x = self.app.world.left + w
                self.position.y = self.app.world.top + h
            elif r <= probs[1]:
                self.position.x = self.app.world.left + w * 4
                self.position.y = self.app.world.top + h
            elif r <= probs[2]:
                self.position.x = self.app.world.left + w
                self.position.y = self.app.world.top + h * 4
            else:
                self.position.x = self.app.world.left + w * 4
                self.position.y = self.app.world.top + h * 4
        else:
            self.position.x = self.app.config['Bonus']['bonus_pos_x'] * self.app.aspect_ratio
            self.position.y = self.app.config['Bonus']['bonus_pos_y'] * self.app.aspect_ratio
        
    def draw(self):
        """draws bonus symbol to screen"""
        bonus = pygl2d.font.RenderText("%s" % self.current_symbol, (255, 200, 0), self.font)
        bonus_rect = bonus.get_rect()
        bonus_rect.center = (self.position.x, self.position.y)
        bonus.draw(bonus_rect.topleft)
    
    def get_new_symbol(self):
        """assigns new bonus symbol"""
        self.prior_symbol = self.current_symbol
        if random.random() < self.probability:
            self.current_symbol = self.bonus_symbol
        else:
            self.current_symbol = random.sample(self.symbols, 1)[0]
            self.flag = True
        self.set_bonus_location()
        self.bonus_count += 1
            
    def pick_next_pair(self):
        """picks next cue and target for ax-cpt task"""
        chance = random.random()
        if chance < self.ax_prob:
            self.current_pair = "ax"
            return([random.choice(self.a_symbols), random.choice(self.x_symbols)])
        elif chance < (self.ax_prob + self.ay_prob):
            self.current_pair = "ay"
            return([random.choice(self.a_symbols), random.choice(self.y_symbols)])
        elif chance < (self.ax_prob + self.ay_prob + self.bx_prob):
            self.current_pair = "bx"
            return([random.choice(self.b_symbols), random.choice(self.x_symbols)])
        else: 
#.........这里部分代码省略.........
开发者ID:CogWorks,项目名称:SpaceFortress,代码行数:103,代码来源:bonus.py


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