import sys
import time,sched
from threading import Timer
import datetime
import numpy as np
import pygame
from pygame import surface
import threading
pygame.init() # 初始化pygame
size = width, height = 600, 600 # 设置窗口大小
screen = pygame.display.set_mode(size) # 显示窗口
color = (255, 255, 255)
fcclock = pygame.time.Clock()
'''zsx = 220
zsy = 100
zenx = 70
zeny = 600
ysx = 320
ysy = 100
yenx = 570
yeny = 600
############################################
f = False
l=False
r=False
cjshuzu = []
xsshuzu = []
o = 5
def you(screen, ystx, ysty, yenx, yeny):
hei = (0, 0, 0)
start = (ystx, ysty)
end = (yenx, yeny)
width = 1222
pygame.draw.line(screen, hei, start, end, 10)
def zuo(screen, zstx, zsty, zenx, zeny):
hei = (0, 0, 0)
start = (zstx, zsty)
end = (zenx, zeny)
width = 1262
pygame.draw.line(screen, hei, start, end, 10) # aaline抗锯齿
'''
lux=0
luy=600
lw=600
while True: # 死循环确保窗口一直显示
s = sched.scheduler(time.time, time.sleep)
screen.fill(color)
# pygame.draw.polygon(screen, (0, 244, 0), p)
fcclock.tick(9) # 设置图像刷新率,如果刷新率太高,图像闪5的太厉害
for event in pygame.event.get(): # 遍历所有事件
if event.type == pygame.QUIT: # 如果单击关闭窗口,则退出
sys.exit()
pygame.quit()
exit()
keys = pygame.key.get_pressed()
if keys[pygame.K_UP]:
f = True
# print('啦啦啦')
if keys[pygame.K_LEFT]:
l = True
if keys[pygame.K_RIGHT]:
r = True
if event.type == pygame.KEYUP:
f = False
l=False
if event.type == pygame.KEYDOWN:
r = False
'''zuo(screen, 230, 105, -60, 610)
you(screen, 310, 105, 720, 610)'''
#天
pygame.draw.rect(screen, (116, 194, 243), (0, 0, 620, 300), 0)
# 绿地
pygame.draw.rect(screen, (0, 244, 0), (0, 300, 620, 400), 0)
# 路
#pygame.draw.rect(screen, (220, 224, 234), (lux, luy, lw, 20), 0)
for i in range(150):#画150条灰色线,每根线宽度是2.
y=i*2#每次y减少2*i,也就是宽度的距离
x=i*2#x每次加2*i,让左边路变得越来越窄
w=i*4#w每次-4*i,让右边的路越来越窄
zw=35#红色变基础宽度
zx=i*0.2
pygame.draw.rect(screen, (220, 224, 234), (lux+x, luy-y, lw-w, 2), 0)
#pygame.draw.rect(screen, (220, 224, 234), (lux, luy - y, lw, 2), 0)
pygame.draw.rect(screen, (250, 0, 0), (lux + x, luy - y, zw-zx , 2), 0)
#左边红色路:x需要在灰色路基础上-一个红色路的基础宽度,y不变。宽度在基础zw上每次-zx宽度。让红色路越来越窄
pygame.draw.rect(screen, (250, 0, 0), (lw-x , luy - y, zw-zx , 2), 0)
dcar = pygame.image.load("d3.png")
car = pygame.transform.scale(dcar, (80, 80)) # 远大近小
screen.blit(car, (250, 450))
pygame.display.update()
pygame.display.flip() # 更新全部显示
pygame两条红线 左边红线x不用加红线基础宽度
猜你喜欢
转载自blog.csdn.net/weixin_40938312/article/details/131092892
今日推荐
周排行