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


Python Game.tick方法代码示例

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


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

示例1: Display

# 需要导入模块: from Game import Game [as 别名]
# 或者: from Game.Game import tick [as 别名]

#.........这里部分代码省略.........
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000,
			    0b00000]]]

	def __init__(self):
		# Init LCD 
		self.lcdString = [[' ' for col in range(Layer.WIDTH)] for row in range(Layer.HEIGHT)]
		# Init layer
		self.canvas  = Layer()
		self.runner  = Layer()
		self.barrier = Layer()
		# Init pixelSet
		self.pixelSet = [list(Layer.EMPTY) for i in range(8)]
		# Init LCD
		self.lcd = Adafruit_CharLCDPlate()
		self.lcd.begin(16, 2)
		self.lcd.backlight(Adafruit_CharLCDPlate.ON)
		# Init Game
		self.game = Game(self.lcd)

	def mergeLayers(self):
		# Merge layer to canvas
		#self.canvas.mergeLayer(self.runner).mergeLayer(self.barrier)
		self.canvas.mergeLayer(self.barrier)
		self.canvas.mergeLayer(self.runner)


	def updateLcdString(self):
		# Update game screen
		count = 0
		for row in range(Layer.HEIGHT):
			for col in range(Layer.WIDTH):
				if self.canvas.bitmap[row][col] == Layer.EMPTY:
					self.lcdString[row][col] = ' '
				else:
					index = self.findInPixelSet(self.canvas.bitmap[row][col], count)
					#print '[', str(row), '][', str(col), ']: ' + str(index)
					#print self.canvas.bitmap[row][col]
					if index == -1:
						self.pixelSet[count] = list(self.canvas.bitmap[row][col])
						self.lcdString[row][col] = chr(count)
						count += 1
					else:
						self.lcdString[row][col] = chr(index)

		# Update score board
		score = str(self.game.score)
		index = 0
		for i in range(Layer.WIDTH - len(score), Layer.WIDTH):
			self.lcdString[0][i] = score[index]
			index += 1
		

	def loadCharset(self):
		for i, item in enumerate(self.pixelSet):
			self.lcd.createChar(i, item)

	def findInPixelSet(self, pixel, count):
		for i in range(count):
			if self.pixelSet[i] == pixel:
				return i
		return -1

	def draw(self):
		if self.game.state == Game.STATE_START:
			self.lcd.message('Press SELECT to\n  START GAME    ')
		elif self.game.state == Game.STATE_END:
			self.lcd.message('  SCORE ' + str(self.game.score) + '\n   GAME  OVER   ')
		else:
			line_1 = ''.join(self.lcdString[0])
			line_2 = ''.join(self.lcdString[1])
			
			self.lcd.message(line_1 + '\n' + line_2)
			self.loadCharset()

	def drawBarriers(self):
		for barrier in self.game.barriers:
			self.barrier.drawPointX(barrier[1], barrier[0], self.game.frame, self.BARRIER[self.game.frame])

	def drawRunner(self):
		self.runner.drawPointY(1, 0, self.RUNNER[self.game.runner])

	def run(self):
		while True:
			self.game.tick()
			if self.game.state == Game.STATE_RUNNING:
				self.drawBarriers()
				self.drawRunner()
				self.mergeLayers()
				self.updateLcdString()

			self.game.gameOver(self.barrier.bitmap[1][1], self.runner.bitmap[1][1])
			self.draw()
			
			self.canvas  = Layer()
			self.runner  = Layer()
			self.barrier = Layer()
			sleep(.03)
开发者ID:Blueve,项目名称:RaspberryPiLCDRunner,代码行数:104,代码来源:Display.py


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