码迷,mamicode.com
首页 > 编程语言 > 详细

python 小白之路(跳动的球)

时间:2019-01-06 23:00:32      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:gif   set   .com   alt   white   date()   while   rip   分享   

 # -*- coding: utf-8 -*-

"""
Spyder Editor

This is a temporary script file.
"""
import pygame,sys
pygame.init()
size = width,height =  600, 400
speend = [1,1]
WHITE = 255,255,255
screen =pygame.display.set_mode(size)
pygame.display.set_caption("dj")
ball = pygame.image.load("dj.gif")
ballrect =ball.get_rect()

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
    ballrect = ballrect.move(speend[0],speend[1])
    if ballrect.left < 0 or ballrect.right >width:
           speend[0] = -speend[0]
    if ballrect.top < 0 or ballrect.bottom > height:
           speend[1] = -speend[1]
    screen.fill(WHITE)
    screen.blit(ball,ballrect)
    pygame.display.update()
    

技术分享图片

技术分享图片

技术分享图片

技术分享图片

技术分享图片

技术分享图片

—————————————————————————————————————————————————————

# -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""
import pygame,sys
pygame.init()
size = width,height = 600, 400
speend = [1,1]
WHITE = 255,255,255
screen =pygame.display.set_mode(size)
pygame.display.set_caption("dj")
ball = pygame.image.load("dj.gif")
ballrect =ball.get_rect()
fps = 300
fclock =pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
ballrect = ballrect.move(speend[0],speend[1])
if ballrect.left < 0 or ballrect.right >width:
speend[0] = -speend[0]
if ballrect.top < 0 or ballrect.bottom > height:
speend[1] = -speend[1]
screen.fill(WHITE)
screen.blit(ball,ballrect)
pygame.display.update()
fclock.tick(fps)

—————————————————————————————————————————————————————

 技术分享图片

技术分享图片

 

python 小白之路(跳动的球)

标签:gif   set   .com   alt   white   date()   while   rip   分享   

原文地址:https://www.cnblogs.com/llhhcc/p/10230759.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!