本文整理匯總了Python中atom.Atom.reset_with_values方法的典型用法代碼示例。如果您正苦於以下問題:Python Atom.reset_with_values方法的具體用法?Python Atom.reset_with_values怎麽用?Python Atom.reset_with_values使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類atom.Atom
的用法示例。
在下文中一共展示了Atom.reset_with_values方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from atom import Atom [as 別名]
# 或者: from atom.Atom import reset_with_values [as 別名]
#.........這裏部分代碼省略.........
self.newTicks = pygame.time.get_ticks()
delta = self.newTicks - self.oldTime
# react to player inputs
if not self.playerWon:
if not self.playerLost:
self.apply_player_direction(delta)
# perform all atoms processes
largestAtom = None
smallestAtom = None
for atom in self.atoms:
if largestAtom == None:
largestAtom = atom
smallestAtom = atom
# process atom behaviours
atom.process(delta, self.atoms)
atom.move(delta)
# find the largest atom to see if the player has won
if atom.radius > largestAtom.radius:
largestAtom = atom
# find out if the player is the smallest atom
if atom.radius < smallestAtom.radius:
smallestAtom = atom
if largestAtom == self.playerAtom:
self.playerWon = True
if smallestAtom == self.playerAtom:
self.playerLost = True
# update the cameras status
self.camera.process()
def render(self):
# draw a black background
self.screen.fill((0,0,0))
# draw all atoms
for atom in self.atoms:
atom.draw(self.camera)
# the player has become the largest atom!
if self.playerWon:
self.display_player_won()
# the player has become the largest atom!
if self.playerLost:
self.display_player_lost()
# push the rendered scene to the screen
pygame.display.flip()
def display_player_won(self):
text = self.font.render('OWNASAURUS REX!', True, (255,255,255))
textRect = text.get_rect()
textRect.centerx = self.windowWidth / 2
textRect.centery = self.windowHeight / 2
self.screen.blit(text, textRect)
self.display_reset_message()
def display_player_lost(self):
text = self.font.render('You Lost!', True, (255,255,255))
textRect = text.get_rect()
textRect.centerx = self.windowWidth / 2
textRect.centery = self.windowHeight / 2
self.screen.blit(text, textRect)
self.display_reset_message()
def display_reset_message(self):
text = self.font.render("Press 'r' to reset.", True, (255,255,255))
textRect = text.get_rect()
textRect.centerx = self.windowWidth / 2
textRect.centery = (self.windowHeight / 2) + 40
self.screen.blit(text, textRect)
def reset_game(self):
for atom in self.atoms:
x = random.randint(1, self.worldWidth)
y = random.randint(1, self.worldHeight)
mass = random.randint(1, 20)
atom.reset_with_values(x, y, mass)
self.camera.x = self.windowWidth / 2
self.camera.y = self.windowHeight / 2
self.playerAtom.reset_with_values(self.camera.x,
self.camera.y,
PLAYER_STARTING_MASS)
self.playerWon = False
self.playerLost = False