国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python通過Pygame繪制移動的矩形實例代碼

2020-02-16 11:27:15
字體:
來源:轉載
供稿:網友

Pygame是一個多用于游戲開發的模塊。

本文實例主要是在演示框里實現一個移動的矩形實例代碼,完整代碼如下:

#moving rectangle projectimport pygamefrom pygame.locals import *pygame.init()screen = pygame.display.set_mode((600,500))pygame.display.set_caption("Drawing Rectangles")pos_x = 300pos_y = 250vel_x = 2vel_y = 1while True:  for event in pygame.event.get():    if event.type in (QUIT,KEYDOWN):      pygame.quit()  screen.fill((0,0,200))  # move the rectangle  pos_x += vel_x  pos_y += vel_y  # keep rectangle on the screen  if pos_x > 500 or pos_x < 0:    vel_x = -vel_x  if pos_y > 400 or pos_y < 0:    vel_y = -vel_y  # draw the rectangle  color = 255,255,0  width = 0 #solid fill  pos = pos_x,pos_y,100,100  pygame.draw.rect(screen,color,pos,width)  pygame.display.update()   

演示如下:

總結

以上就是本文關于Python通過Pygame繪制移動的矩形實例代碼的全部內容,希望對大家有所幫助。感興趣的朋友可以繼續參閱本站其他相關專題,如有不足之處,歡迎留言指出。感謝朋友們對本站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 彭水| 崇阳县| 安庆市| 东乡县| 汽车| 怀化市| 府谷县| 秦安县| 涿鹿县| 长兴县| 梅河口市| 五华县| 南丰县| 淮南市| 彰化市| 常德市| 高尔夫| 贡觉县| 仁怀市| 洪洞县| 集贤县| 绥棱县| 江达县| 永仁县| 大姚县| 临武县| 绥滨县| 安多县| 嘉禾县| 宽甸| 铁力市| 甘谷县| 休宁县| 河间市| 卫辉市| 阳新县| 白朗县| 威远县| 万全县| 平遥县| 平果县|