pygame游戲開發入門例子


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

# 開發團隊:中國軟件開發團隊
# 開發人員:Administrator
# 開發時間:2019/3/23 11:16
# 文件名稱:pygame_demo
# 開發工具:PyCharm
import sys
import pygame
import time
def main():
size=width,height=640,480
pygame.init()
screen=pygame.display.set_mode(size)
color=(0,0,0)
cat=pygame.image.load("cat.ico")
catrect=cat.get_rect()
speed=[5,5]
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit(0)
catrect=catrect.move(speed)
#碰到左右邊緣
if catrect.left<0 or catrect.right>width:
speed[0]=-speed[0]
#碰到上下邊緣
if catrect.top<0 or catrect.bottom>height:
speed[1]=-speed[1]
#通過延時控制移動速度
time.sleep(0.025)

screen.fill(color)
screen.blit(cat,catrect)
pygame.display.flip()
pygame.quit()

if __name__ == '__main__':
main()


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM