Example #1
0
	def storeLvlTime(self):
		""" Stores player time if best performance for the current level """
	
		# Get previous best time for the level
		prevTime = self.players[0].getTime(self.grid.hashsum.hexdigest())
		# Get current time for the level
		curTime = self.lvlTime.getFrameNb()

		# If best time => store it to the player's list of times
		if prevTime is None or (prevTime is not None and prevTime-curTime) > 0:
			self.players[0].addTime(curTime, self.grid.hashsum.hexdigest())
			self.players[0].saveTimes()
			#print "NEW PERSONAL BEST"
			self.isNewRecord = "LOCAL"

			# Send to website as potential new world record
			# (the website is responsible for validation!)
			http.setWorldTime(self.grid.hashsum.hexdigest(), curTime)
			# ask again what the world record is, to make sure it was validated
			# server-side
			responseTime = http.getWorldTime(self.grid.hashsum.hexdigest())
			if curTime == int(responseTime):
				self.isNewRecord = "WORLD"
Example #2
0
	def initLevel(self, lvlIndex, directory):
		""" Construct level with one ball per player """
		super(GameStateSingleAdventure, self).initLevel(self.currentLvl, directory)

		### Construct objects ###
		self.balls = []

		# Init Paddle
		posX0 = (self.gameDim[0]-PADDLE_WIDTH['INIT']) /2
		posY0 = self.gameDim[1]-3*PADDLE_HEIGHT
		self.players[0].initPaddle(padWidth=PADDLE_WIDTH['INIT'], padHeight=PADDLE_HEIGHT, padColor=self.players[0].color, padPosX0=posX0, padPosY0=posY0)

		# Ball
		posX0 = (self.gameDim[0]-10*BALL_RADIUS) /2
		posY0 = 5*self.gameDim[1]/6
		self.balls.append(Ball(radius=BALL_RADIUS, posX=posX0 , posY=posY0, color=BALL_COLOR))

		### Concatenate objects ###
		self.objects.append(self.players[0].paddle)
		self.objects.append(self.balls[0])

		# Init score chain bonus
		self.chainBonus = 0

		# Init score and boolean bonus
		self.players[0].initScore()
		self.scoreToIncrease = self.players[0].totalScore 	# Score to increase at the end of level
		self.isPerfect = True
		self.brkScore = 0									# Score generated when brick collision, to be printed
		self.isNewRecord = False
		self.lvlTrophy = None

		# Get records for the level
		self.localRecord = self.players[0].getTime(self.grid.hashsum.hexdigest())
		self.worldRecord = http.getWorldTime(self.grid.hashsum.hexdigest())
		if self.worldRecord:
			self.worldRecord = int(self.worldRecord)