本文整理汇总了Python中Ball.Ball类的典型用法代码示例。如果您正苦于以下问题:Python Ball类的具体用法?Python Ball怎么用?Python Ball使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ball类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, maxSpeed, pos = [0,0]):
Ball.__init__(self, ["pacman-open-right.png"], [0,0], pos)
self.rightImages = [pygame.image.load("pacman-open-right.png"),
pygame.image.load("pacman-closed-right.png")]
self.leftImages = [pygame.image.load("pacman-open-left.png"),
pygame.image.load("pacman-closed-left.png")]
self.upImages = [pygame.image.load("pacman-closed-upwards.png"),
pygame.image.load("pacman-open-upwards.png")]
self.downImages = [pygame.image.load("pacman-closed-downwards.png"),
pygame.image.load("pacman-open-downwards.png")]
self.images = self.rightImages
self.images = self.leftImages
self.images = self.upwardsImages
self.images = self.downwardsImages
self.maxFrame = len(self.images)-1
self.xDirection = "right"
self.yDirection = "none"
self.maxSpeedx = maxSpeed[0]
self.maxSpeedy = maxSpeed[1]
示例2: __init__
def __init__(self, host = "localhost", port = 5555):
self.host = host
self.port = port
self.connected = False
Ball.setPrimary('green')
self.time = None
self.timeout = None
示例3: getBalls
def getBalls(self):
##print "Asking server for data"
if True: #not self.time or self.time - time.time() > self.timeout:
self.time = time.time()
try:
Ball.clear()
##self.connection.sendall("ball")
json_data = self.connection.recv(8000);#self.recv_timeout(self.connection)
##print "Server data: " + json_data
if len(json_data) == 0 or json_data == "none":
return False
i = json_data.index(':')
##dict = {}
##dict['color'] = 'red'
##dict['y'] = 0
##dict['x'] = json_data[i+1:]
##dict['width'] = json_data[:i]
x = int(json_data[i+1:])
width = int(json_data[:i])
return (x, width)
##balls = json.loads(json_data)
##for ball in data:
## Ball.add(Ball(ball))
##
##return Ball.exist()
except:
print sys.exc_info()[1]
print 'hai'
return False
else:
return Ball.exist()
示例4: update
def update(*args):
self = args[0]
width = args[1]
height = args[2]
Ball.update(self, width, height)
self.animate()
self.changed = False
示例5: loopGame
def loopGame(self):
clock = pygame.time.Clock()
ball = Ball([100,100])
paddle = Paddle([width/2,395])
font = pygame.font.Font(None, 25)
sound_collision = pygame.mixer.Sound("music/tick.mp3")
vector = []
posRectx = 90
posRecty = 60
score = 0
for i in range(0, 50):
if(i%5==0):
posRecty = posRecty + 20
posRectx = 80
else:
posRectx = posRectx + 80
rectColid = RectColid([posRectx,posRecty])
vector.append(rectColid)
running_game = True
while running_game:
clock.tick(120)
textoScore = font.render("Score: %d" % score, True, white)
for event in pygame.event.get():
if event.type==QUIT:
running_game = False
keys = pygame.key.get_pressed()
if keys[K_a]:
paddle.imagerect.centerx -= 5
if keys[K_d]:
paddle.imagerect.centerx += 5
if paddle.imagerect.colliderect(ball.imagerect):
if ball.speed[1] > 0:
ball.speed[1] = -ball.speed[1]
for rect in vector:
if rect.imagerect.colliderect(ball.imagerect):
vector.remove(rect)
ball.speed[1] = -ball.speed[1]
sound_collision.play(1)
score += 1
ball.update()
paddle.update()
screen.fill(black)
screen.blit(ball.image, ball.imagerect)
screen.blit(paddle.image, paddle.imagerect)
#Coloca os objetos na tela
for rect in vector:
screen.blit(rect.image, rect.imagerect)
screen.blit(textoScore, [10, 10])
pygame.display.flip()
示例6: __init__
def __init__(self, image, maxSpeed, pos = [0,0]):
Ball.__init__(self, image, [0,0], pos)
self.maxSpeedx = maxSpeed[0]
self.maxSpeedy = maxSpeed[1]
self.didBounceX = False
self.didBounceY = False
示例7: update
def update(*args):
self = args[0]
width = args[1]
height = args[2]
playerPos = args[3]
self.facePlayer(playerPos)
Ball.update(self, width, height)
self.animate()
self.changed = False
示例8: update
def update(*args):
self = args[0]
width = args[1]
height = args[2]
Ball.update(self, width, height,)
self.move()
if self.life > 0:
self.life -= 1
else:
self.living = False
示例9: __init__
def __init__(self, name_image="ship-1.png"):
Screen.__init__(self)
self.keys = {
"up" : [K_UP],
"down" : [K_DOWN],
"left" : [K_LEFT],
"right" : [K_RIGHT],
"rotate_left" : [K_a, K_q],
"rotate_right": [K_d],
"fire" : [K_SPACE],
# test
"lose_life": [K_l] # c'est un L
}
self.image = pygame.image.load('img/' + name_image).convert_alpha()
self.rect = self.image.get_rect()
self.rect.center = self.srect.center
self.ball = Ball(default_center=self.rect.center)
self.vitesse = 2
self.vitesse_rotate = 2
self.orginal = self.image.copy()
self.current_angle = 0
self.cheated = 0
self.max_life = 50
self.life = self.max_life
self.score = Score()
示例10: main
def main():
pygame.init()
world = World(screen_size=(600, 600), one_second=1000.)
ball = Ball()
ball.set_pos(pymunk.Vec2d(2.0, 8.0))
ball.body.velocity = pymunk.Vec2d(1.0, 1.0)
world.add(ball)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT: return
world.step()
world.draw()
示例11: __init__
def __init__(self, master):
self.master = master
# make it cover the entire screen
self.w, self.h = root.winfo_screenwidth(), root.winfo_screenheight()
master.overrideredirect(1)
geometry = "%dx%d+0+0" % (self.w, self.h)
master.geometry(geometry)
self.canvas = Canvas(master, width=self.w, height=self.h)
master.title("My first Game!")
master.bind("<KeyPress>", self.onKeyDown)
master.bind("<KeyRelease>", self.onKeyUp)
self.canvas.pack()
self.playerPaddle = PlayerPaddle(self)
self.cpuPaddle = CpuPaddle(self)
self.ball = Ball(self)
self.playerScore = 0
self.cpuScore = 0
self.master.after(0, self.render)
示例12: __init__
def __init__(self):
w = 500
h = 500
self.pWin = GraphWin("Pong", w, h )
myIMG = Image(Point(250, 250), "linesfinished.gif")
myIMG.draw(self.pWin)
self.b = Ball(self.pWin)
self.p = Paddle(self.pWin)
self.hits = 0
self.score = 0
self.level = 1
self.scoreTitle = Text(Point(350, 25), "Score:")
self.scoreTitle.setTextColor("white")
self.scoreTitle.setSize(25)
self.userScore = Text(Point(405, 25), self.score)
self.userScore.setTextColor("white")
self.userScore.setSize(25)
self.levelTitle = Text(Point(100, 25), "Level:")
self.levelTitle.setTextColor("white")
self.levelTitle.setSize(25)
self.userLevel = Text(Point(150, 25), self.level)
self.userLevel.setTextColor("white")
self.userLevel.setSize(25)
self.scoreTitle.draw(self.pWin)
self.userScore.draw(self.pWin)
self.levelTitle.draw(self.pWin)
self.userLevel.draw(self.pWin)
示例13: run
def run(self):
pygame.init()
pygame.display.set_caption("Greek Pong")
margin = 50
self.player1.reinit(margin, self.gameHeight, self.width)
self.player2.reinit(margin, self.gameHeight, self.width)
player1 = self.player1
player2 = self.player2
ball = Ball(self.width, self.gameHeight, self.screen, self)
black = pygame.Color(0,0,0)
counter = 0
runGame = True
while runGame and self.play:
for event in pygame.event.get():
if (event.type == QUIT):
self.play = False
self.state = False
runGame = False
break
pygame.event.pump()
keys = pygame.key.get_pressed()
mouse = pygame.mouse.get_pressed()
ball.moveBall(self.width, self.gameHeight, player1, player2, self)
player1.movePaddle(keys, self.gameHeight, self.width, ball, self)
player2.movePaddle(keys, self.gameHeight, self.width, ball, self)
player1.useWeaponRack(keys, ball, player2, self)
player2.useWeaponRack(keys, ball, player1, self)
self.checkInstruction(keys)
if counter == 400:
counter = 0
self.redrawAll(player1, player2, ball, counter)
counter += 1
if (self.checkWin(player1, player2)):
runGame = False
break
示例14: __init__
def __init__(self, images, maxSpeed, pos = [0,0], mass = 100):#50):
Ball.__init__(self, images, [0,0], mass, pos)
self.originalImage = self.image
self.image = pygame.transform.scale(self.originalImage, (mass, mass))
self.rect = self.image.get_rect(center = self.rect.center)
self.maxSpeedx = maxSpeed[0]
self.maxSpeedy = maxSpeed[1]
self.realSpeedx = self.speedx
self.realSpeedy = self.speedy
self.accControlx = .1 # Higher number means less acceleration effect ie follows mouse movments more closly any number greater than 1 causes more jitter
self.accControly = .1
#self.viscosityX = 4
#self.viscosityY = 4
self.accx = self.accControlx/(mass/50)
self.accy = self.accControly/(mass/50)
self.mass = mass
self.amFollowing = False
示例15: update
def update(*args):
self = args[0]
width = args[1]
height = args[2]
Ball.update(self, width, height)
self.move()
self.animate()
self.changed = False
#print self.gun.coolDown
if self.gun.coolDown > 0:
if self.gun.coolDown < self.gun.coolDownMax:
self.gun.coolDown += 1
else:
self.gun.coolDown = 0
if self.hurtTimer > 0:
self.hurtTimer -= 1
self.invincible = True
else:
self.invincible = False