1. 程式人生 > >python 小白之路(跳動的球)

python 小白之路(跳動的球)

otto all fps pygame type mage ott splay init

# -*- 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 小白之路(跳動的球)