@zhongwei1234
2017-10-14T00:38:08.000000Z
字数 1885
阅读 60
只有欣赏一下雷珉毅楠同学
Created on Fri Sep 22 20:57:42 2017@author: ppsair"""background_image_filename = "C:/Users/ppsair/Desktop/python.PNG"sprite_image_filename = "C:/Users/ppsair/Desktop/pythoncanon1.PNG"small_fire_image_filename = "C:/Users/ppsair/Desktop/smallfire.PNG"information="your score : "import pygamefrom pygame.locals import*from sys import exitimport pygame as pyimport mathpygame.init()screen = pygame.display.set_mode((815,450), 0, 32)background = pygame.image.load(background_image_filename)sprite = pygame.image.load(sprite_image_filename)smallfire = pygame.image.load(small_fire_image_filename)delt_t = 0.5B = 0.00004g = 9.8h = 2.5a = 0.0065T_ref = 300T = 300angel = 0while True:for event in pygame.event.get():if event.type == pygame.QUIT:exit()screen.blit(background,(0,0))screen.blit(sprite,(0,350))for event in pygame.event.get():if event.type == pygame.KEYDOWN:if event.type == pygame.K_UP:angel += 1elif event.key == pygame.K_DOWN:angel += -1elif event.key == pygame.K_SPACE:v = 700v_x = v*math.cos(math.radians(angel))v_y = v*math.sin(math.radians(angel))x = 0y = 0while True:x = x + v_x*delt_ty = y + v_y*delt_tp=(1-a*y/T)*(T/T_ref)B_cor = B*math.pow(p,h)v_x = v_x - B_cor*v*v_x*delt_tv_y = v_y - g*delt_t - B_cor*v*v_y*delt_tv = math.sqrt(v_x*v_x + v_y*v_y)score_percentage = int(abs(x/30000*800-779)/779*100)score = str(score_percentage)score = information+scoremy_font=pygame.font.SysFont("arial",64)name_surface=my_font.render(score,True,(0,0,0),(255,255,255))show_angel=pygame.font.SysFont("arial",64)angel_show=show_angel.render(str(angel),True,(0,0,0),(255,255,255))screen.blit(angel_show,(700,0))screen.blit(name_surface,(0,0))if y > 0:pygame.draw.circle(screen,(23,23,23),(int(x/30000*800),int(450-(y/10000*300))),5,5)pygame.display.update()else:screen.blit(smallfire,(x,300))breakpygame.display.update()
这是一个用上下键控制初射角度的抛体运动游戏,有一个根据抛出距离远近打分的机制·,越远分越高,如果在surface上贴入背景图比如大炮和战场,就勉强算一个游戏了