国产探花免费观看_亚洲丰满少妇自慰呻吟_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繪制移動的矩形實例代碼的全部內容,希望對大家有所幫助。感興趣的朋友可以繼續參閱本站其他相關專題,如有不足之處,歡迎留言指出。感謝朋友們對本站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 蓝山县| 二连浩特市| 青岛市| 雷山县| 泸州市| 达尔| 丰宁| 苗栗县| 乌什县| 苍南县| 洪雅县| 广西| 共和县| 镇康县| 鄂托克旗| 卢湾区| 健康| 贵港市| 定陶县| 溧水县| 涞水县| 盐亭县| 磴口县| 凭祥市| 宕昌县| 大宁县| 定边县| 普宁市| 宝坻区| 库伦旗| 石嘴山市| 盐源县| 大新县| 北宁市| 文化| 个旧市| 皋兰县| 苗栗县| 花莲县| 九龙城区| 宝清县|