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

首頁 > 編程 > Python > 正文

pygame學習筆記(3):運動速率、時間、事件、文字

2020-02-23 00:42:51
字體:
來源:轉載
供稿:網友

1、運動速率

上節中,實現了一輛汽車在馬路上由下到上行駛,并使用了pygame.time.delay(200)來進行時間延遲。看了很多參考材料,基本每個材料都會談到不同配置機器下運動速率的問題,有的是通過設定頻率解決,有的是通過設定速度解決,自己本身水平有限,看了幾篇,覺得還是《Beginning Game Development with Python and Pygame》這里面提到一個方法比較好。代碼如下,代碼里更改的地方主要是main里的代碼,其中利用clock=pygame.time.Clock()來定義時鐘,speed=250.0定義了速度,每秒250像素,time_passed=clock.tick()為上次運行時間單位是毫秒,time_passed_seconds=time_passed/1000.0將單位改為秒,distance_moved=time_passed_seconds*speed時間乘以速度得到移動距離,這樣就能保證更加流暢。

代碼如下:
import pygame,sys
def lineleft():
    plotpoints=[]
    for x in range(0,640):
        y=-5*x+1000
        plotpoints.append([x,y])
    pygame.draw.lines(screen,[0,0,0],False,plotpoints,5)
    pygame.display.flip()
def lineright():
    plotpoints=[]
    for x in range(0,640):
        y=5*x-2000
        plotpoints.append([x,y])
    pygame.draw.lines(screen,[0,0,0],False,plotpoints,5)
    pygame.display.flip()   
def linemiddle():
    plotpoints=[]
    x=300
    for y in range(0,480,20):
        plotpoints.append([x,y])
        if len(plotpoints)==2:
            pygame.draw.lines(screen,[0,0,0],False,plotpoints,5)
            plotpoints=[]
    pygame.display.flip()
def loadcar(yloc):
    my_car=pygame.image.load('ok1.jpg')
    locationxy=[310,yloc]
    screen.blit(my_car,locationxy)
    pygame.display.flip()

   
if __name__=='__main__':
    pygame.init()
    screen=pygame.display.set_caption('hello world!')
    screen=pygame.display.set_mode([640,480])
    screen.fill([255,255,255])
    lineleft()
    lineright()
    linemiddle()
 
    clock=pygame.time.Clock()
    looper=480
    speed=250.0
    while True:
        for event in pygame.event.get():

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 桃园市| 邢台市| 奎屯市| 大厂| 兴国县| 诏安县| 榆社县| 巧家县| 偏关县| 博兴县| 开阳县| 茂名市| 扶绥县| 郁南县| 府谷县| 尼勒克县| 雷州市| 金寨县| 遂平县| 德州市| 巴彦淖尔市| 阿瓦提县| 普兰店市| 运城市| 唐海县| 边坝县| 扶沟县| 宜兰县| 蓝田县| 申扎县| 城市| 大丰市| 茂名市| 类乌齐县| 教育| 祥云县| 辽宁省| 毕节市| 赣榆县| 文昌市| 当雄县|