首页 > 其他 > 详细

pygame游戏框架

时间:2019-12-22 22:00:24      阅读:109      评论:0      收藏:0      [点我收藏+]

#_author:来童星
#date:2019/12/22

import pygame

import sys

pygame.init()

size=width,height=640,480

screen=pygame.display.set_mode(size)

color=(0,0,0)

 

ball=pygame.image.load(‘ball.png‘)

ballrect=ball.get_rect()

 

speed=[5,5]

clock=pygame.time.Clock()# 设置时钟,需要使用pygame下的time模块

while True:

  clock.tick(60)# 每秒执行60次

  for event in pygame.event.get():

    if event.type==pygame.QUIT:

      sys.exit()

  ballrect=ballrect.move(speed)

  

  if ballrect<0 or ballrect>width:

    speed[0]=-speed[0]

  if ballrect<0 or ballrect>height:

    speed[1]=-speed[1]

  screen.fill(color)

  screen.blit(ball,ballrect)

  pygame.display.flip()

 

pygame.quit()

output:

技术分享图片

pygame游戏框架

原文:https://www.cnblogs.com/startl/p/12081245.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!