pygame游戏开发入门例子
生活随笔
收集整理的這篇文章主要介紹了
pygame游戏开发入门例子
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
# *_* coding:utf-8 *_*
# 開發(fā)團隊:中國軟件開發(fā)團隊
# 開發(fā)人員:Administrator
# 開發(fā)時間:2019/3/23 11:16
# 文件名稱:pygame_demo
# 開發(fā)工具: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()
# 開發(fā)團隊:中國軟件開發(fā)團隊
# 開發(fā)人員:Administrator
# 開發(fā)時間:2019/3/23 11:16
# 文件名稱:pygame_demo
# 開發(fā)工具: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()
轉(zhuǎn)載于:https://www.cnblogs.com/it-tsz/p/10585044.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的pygame游戏开发入门例子的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [JLOI2015]管道连接(斯坦纳树)
- 下一篇: 梦到拔小葱是什么意思