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


Python Car.retarding方法代码示例

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


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

示例1: system

# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import retarding [as 别名]
class GUI:
	"""works with the computer coordinate system (0/0 top left)"""

	def __init__ (self, width, heigth):
		self.width = width
		self.heigth = heigth
		self.windows = pygame.display.set_mode((width,heigth))
		pygame.display.set_caption("Neuro Junk 2012/13")
		self.outerPoly = [(110,215),(230,100),(400,150),(560,105),(650,180),(685,270),(710,400),(615,500),(510,545),(365,540),(315,480),(255,490),(185,540),(125,521),(90,420)]
		self.innerPoly = [(160,215),(230,150),(400,200),(540,155),(600,210),(625,275),(650,380),(600,440),(510,500),(370,480),(380,420),(260,430),(185,500),(150,480)]
		self.car = Car(1400,0.0,35.0,25.0,0.0,130.0,(120,215),0.0, 38.0, 90.0,(15,15),self.innerPoly, self.outerPoly) 
		#mass,acceleration,maxAcc,maxBreakingForce,currentSpeed,maxSpeed,pos,currentLock, maxLock, orientation, length, width
		self.colors = {'black':(0,0,0),'white':(255,255,255),'pink':(255,0,255)}
		self.screen = pygame.display.get_surface()
		self.drawStartUp()

	def drawStartUp(self):
		self.screen.fill(self.colors['white'])
		self.carRect = pygame.draw.rect(self.screen, self.colors['pink'], pygame.Rect(self.car.convertRealPositionToPc()[0], self.car.convertRealPositionToPc()[1], self.car.convertSizeFromMetersToPixel()[0], self.car.convertSizeFromMetersToPixel()[1]))#drawing the car
		#print "Start:"
		#print "pcx: " + str(self.car.convertRealPositionToPc()[0])
		#print "pcy: " + str(self.car.convertRealPositionToPc()[1])
		pygame.draw.polygon(self.screen, self.colors['black'], self.outerPoly,2)
		pygame.draw.polygon(self.screen, self.colors['black'], self.innerPoly,2)
		self.update()
		self.run()
		
	def update(self):
		self.screen.fill(self.colors['white'])
		pygame.draw.polygon(self.screen, self.colors['black'], self.outerPoly,2)
		pygame.draw.polygon(self.screen, self.colors['black'], self.innerPoly,2)
		self.carRect = pygame.draw.rect(self.screen, self.colors['pink'],pygame.Rect(self.car.convertRealPositionToPc()[0], self.car.convertRealPositionToPc()[1], self.car.convertSizeFromMetersToPixel()[0], self.car.convertSizeFromMetersToPixel()[1]))
		pygame.display.update()

	def drawLines(self,lines):
		for mt in lines:
			pygame.draw.line(self.screen, self.colors['black'], mt[0], mt[1],5)
		pygame.display.update()

	def displayInfo(self):
		pygame.font.init()
		font = pygame.font.SysFont("Ubuntu",15)
		test = font.render("Speed: " + str(self.car.currSpeed),1,(255,0,0))
		self.screen.blit(test, (100,100))
		

	def input(self,events):
		for event in events:
			if event.type == QUIT:
				sys.exit(0)
			elif event.type == KEYDOWN and event.key == 113: #Q
				sys.exit(0)
			elif event.type == KEYDOWN and event.key == 273: #Arrow_UP
				self.car.accelerate(1.0)
				#print self.car.currSpeed
			elif event.type == KEYUP and event.key == 273:
				self.car.accelerate(0.0)
			elif event.type == KEYDOWN and event.key == 274: #Arrow_Down
				self.car.retarding(1.0)
			elif event.type == KEYUP and event.key == 274:
				self.car.retarding(0.0)
			elif event.type == KEYDOWN and event.key == 275: #Arrow_right
				self.car.stiring(-0.25)
			elif event.type == KEYUP and event.key == 275:
				self.car.stiring(0.0)
			elif event.type == KEYDOWN and event.key == 276: #Arrow_left
				self.car.stiring(0.25)
			elif event.type == KEYUP and event.key == 276:
				self.car.stiring(0.0)
			elif event.type == KEYDOWN and event.key == K_SPACE:
				self.car.currSpeed = 0.0
				self.car.acceleration = 0.0
			else:
				pass

	def run(self):
		lines = []
		while True:
			self.input(pygame.event.get())
			mt = self.car.nextPos(0.01)
			self.update()
			#print "mt: " + str(mt)
			#lines.append(mt)
			#self.drawLines(lines)
			time.sleep(0.01)
开发者ID:barzuln,项目名称:junkie,代码行数:87,代码来源:gui.py


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