Python2

贡献者:abcdeabcdeabcde 类别:英文 时间:2017-01-21 12:21:58 收藏数:19 评分:0.5
返回上页 举报此文章
请选择举报理由:




收藏到我的文章 改错字
import pygame
pygame.init()
screen = pygame.display.set_mode([800,600])
pygame.display.set_caption("Smiley Pong")
keepGoing = True
pic = pygame.image.load("CrazySmiley.bmp")
colorkey = pic.get_at((0,0))
pic.set_colorkey(colorkey)
picx = 0
picy = 0
BLACK = (0,0,0)
WHITE = (255,255,255)
timer = pygame.time.Clock()
speedx = 5
speedy = 5
paddlew = 200
paddleh = 25
paddlex = 300
paddley = 550
picw = 100
pich = 100
points = 0
lives = 5
font = pygame.font.SysFont("Times", 24)
while keepGoing:
for event in pygame.event.get():
if event.type == pygame.QUIT:
keepGoing = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_F1:
points = 0
lives = 5
picx = 0
picy = 0
speedx = 5
speedy = 5
picx += speedx
picy += speedy
if picx <= 0 or picx >= 700:
speedx = -speedx * 1.1
if picy <= 0:
speedy = -speedy + 1
if picy >= 500:
lives -= 1
speedy = -5
speedx = 5
picy = 499
screen.fill(BLACK)
screen.blit(pic, (picx, picy))
#drawing
paddlex = pygame.mouse.get_pos()[0]
paddley -= paddlew/2
pygame.draw.rect(screen, WHITE, (paddlex, paddley, paddlew, paddleh))
#abcde
if picy + pich >= paddley and picy + pich <= paddley + paddleh \
and speedy > 0:
if picx + picw/2 >= paddlex and picx + picw/2 <= paddlex + \
paddlew:
speedy = -speedy
points += 1
#abcdf
draw_string = "Lives: " + str(lives) + "Points: " + str(points)
if lives < 1:
speedx = speedy = 0
draw_string = "Game Over. Your score was: " + str(points)
draw_string += ". Press F1 to play again. "
text = font.render(draw_string, True,WHITE)
text_rect = text.get_rect()
text_rect.centerx = screen.get_rect().centerx
text_rect.y = 10
screen.blit(text, text_rect)
pygame.display.update()
timer.tick(60)
pygame.quit()
声明:以上文章均为用户自行添加,仅供打字交流使用,不代表本站观点,本站不承担任何法律责任,特此声明!如果有侵犯到您的权利,请及时联系我们删除。
文章热度:
文章难度:
文章质量:
说明:系统根据文章的热度、难度、质量自动认证,已认证的文章将参与打字排名!

本文打字排名TOP20

登录后可见

用户更多文章推荐