- UID
- 323679
- 热情
- 4447
- 人气
- 6219
- 主题
- 61
- 帖子
- 4503
- 精华
- 0
- 积分
- 7678
- 分享
- 0
- 记录
- 0
- 相册
- 0
- 好友
- 8
- 日志
- 0
- 在线时间
- 6287 小时
- 注册时间
- 2012-5-13
- 阅读权限
- 30
- 最后登录
- 2020-8-8
升级 53.56% - UID
- 323679
- 热情
- 4447
- 人气
- 6219
- 主题
- 61
- 帖子
- 4503
- 精华
- 0
- 积分
- 7678
- 阅读权限
- 30
- 注册时间
- 2012-5-13
|
稍微可以看一看了,原来是画动画。坐等Python高手进。
import sys
import pygame from Content
import pygbutton from pygame.locals
import *
pygame.init()
#Initialize
variables
startBlue =0,0,255
skyBlue = 50,120,255
grassGreen = 75,180,75
treeGreen = 0,100,0
treeBrown = 100,100,0
TRANSPARENT = 0,255,255
black= 0,0,0
carColour= 255,0,0
building= 173,216,230
Silver=192,192,192
White=255,255,255
carFront=250,128,114
buildTop=220,220,220
wind=245,245,245
buildBlue=70,130,180
#small buildingbridge=128,128,128
#Setup the surfaces
windowSurface = pygame.display.set_mode( (1200,800))
pygame.display.set_caption("Future city")
backgroundSurface = pygame.Surface( (1200,800) )
#Give the windowSurface an initial
colourpygame.draw.rect( backgroundSurface, startBlue, (0, 0, 1200, 800) )
#Draw Background on backgroundSurface
pygame.draw.rect( backgroundSurface, skyBlue , (0, 0, 1200, 600) )
#Skypygame.draw.rect( backgroundSurface, grassGreen , (0, 600, 1200, 200) )
#Ground
#Draw Tree on treeSurface
treeSurface = pygame.Surface( (100, 250) )
treeSurface.set_colorkey(TRANSPARENT)
pygame.draw.rect( treeSurface, TRANSPARENT , (0, 0, 100, 250) )
pygame.draw.polygon(treeSurface, treeGreen, [(55,10),(15,100),(95,100)],0)
pygame.draw.circle(treeSurface, treeGreen, (55,100), 40, 0)
pygame.draw.circle(treeSurface, treeGreen, (55,150), 40, 0)
pygame.draw.rect( treeSurface, treeBrown , (50, 190, 10, 60) )
#
CarcarSurface = pygame.Surface((200, 250))
carSurface.set_colorkey(TRANSPARENT)
pygame.draw.rect( carSurface, skyBlue , (0, 0, 200, 250))
pygame.draw.ellipse( carSurface, carColour , (1, 100, 180, 60))
#car
bottompygame.draw.circle( carSurface, carColour , (160,115), 35, 0)
#car
toppygame.draw.rect( carSurface, black , (160, 55, 2, 25))
#anti
pygame.draw.ellipse(carSurface, White,(30, 110, 50, 20))
#ellipse window
#
pygame.draw.circle(carSurface, Silver, (50,170), 20, 0)
#
pygame.draw.circle(carSurface, Silver, (150,170), 20, 0)
#
BuildingbuildingSurface = pygame.Surface((100, 600))
buildingSurface.set_colorkey(TRANSPARENT)
pygame.draw.rect( buildingSurface, TRANSPARENT , (0, 0, 100, 600))
pygame.draw.rect( buildingSurface, building , (0, 50, 100, 550))
#main
buildingpygame.draw.polygon(buildingSurface, buildTop,[(0,0),(0,50),(100,50)],0)
#
trianglebuildingSurface2 = pygame.Surface((150, 700))
buildingSurface2.set_colorkey(TRANSPARENT)
pygame.draw.rect( buildingSurface2, TRANSPARENT , (0, 0, 150, 700))
pygame.draw.rect( buildingSurface2, building , (0, 50, 150, 650))
#main
buildingpygame.draw.polygon(buildingSurface2, buildTop,[(150,0),(0,50),(150,50)],0)
#triangle#
bridgebridgeSurface = pygame.Surface((170, 40))
bridgeSurface.set_colorkey(TRANSPARENT)
pygame.draw.rect( bridgeSurface, TRANSPARENT , (0, 0, 170, 40))
pygame.draw.rect( bridgeSurface, bridge , (0, 0, 170, 40))
#bridge gray / grey
# Small Building
smallbuildSurface = pygame.Surface((400, 300))
smallbuildSurface.set_colorkey(TRANSPARENT)
pygame.draw.rect( smallbuildSurface, TRANSPARENT , (0, 0, 400, 300))
pygame.draw.circle(smallbuildSurface, buildBlue, (80,100), 80, 0)
pygame.draw.circle(smallbuildSurface, buildBlue, (320,100), 80, 0)
pygame.draw.rect(smallbuildSurface, bridge, (160, 80, 80, 40))
pygame.draw.rect(smallbuildSurface, Silver, (160, 120, 20, 180))
#pillar
pygame.draw.rect(smallbuildSurface, Silver, (220, 120, 20, 180))
#pillar#
windwindSurface = pygame.Surface((200, 200))
windSurface.set_colorkey(TRANSPARENT)
pygame.draw.rect( windSurface, skyBlue , (0, 0, 200, 200))
pygame.draw.ellipse(windSurface, wind,(1, 50, 100, 78))
#ellipse wind white smoke
pygame.draw.ellipse(windSurface, wind,(40, 90, 100, 78))
#ellipse wind
pygame.draw.ellipse(windSurface, wind,(80, 120, 100, 78))
#ellipse wind
pygame.draw.ellipse(windSurface, wind,(90, 90, 100, 78))
#ellipse wind
pygame.draw.ellipse(windSurface, wind,(30, 20, 100, 78))
#ellipse wind
pygame.draw.ellipse(windSurface, wind,(50, 110, 100, 78))
#ellipse wind
pygame.draw.ellipse(windSurface, wind,(60, 10, 100, 78))
#ellipse wind
pygame.draw.ellipse(windSurface, wind,(70, 60, 100, 70))
#ellipse wind
#Create buttons
buttonStart = pygbutton.PygButton((10, 10, 150, 30), "START")
buttonExit= pygbutton.PygButton((140, 10, 100, 30), "EXIT")
#Event Loop
finish=False
play = False
xCar = 600
xWind = 980
xCarJump = -1
xWindJump = -1
startbuttonFlag=False
while finish == False:
#Check Events
for event in pygame.event.get():
if event.type == pygame.QUIT:
finish = True
if "up" in buttonExit.handleEvent(event):
finish = True
if "up" in buttonStart.handleEvent(event):
startbuttonFlag = True
play = True
windowSurface.blit(backgroundSurface,(0,0))
windowSurface.blit(buildingSurface, (30, 190))
windowSurface.blit(buildingSurface2, (300, 90))
windowSurface.blit(bridgeSurface, (130, 300))
windowSurface.blit(smallbuildSurface, (500, 490))
for count in range(0,2):
windowSurface.blit(treeSurface, (1100 - 100*count, 540) )
if play == True and startbuttonFlag==True:
####### Move Car and Wind ########
xCar = xCar + xCarJump
if xCar <= 500:
xCarJump = -xCarJump
xWind = xWind + xWindJump
if xWind <= 780:
xWindJump = -xWindJump
windowSurface.blit(carSurface, (xCar,200))
windowSurface.blit(windSurface, (xWind, 100))
#pygame.display.update()
if startbuttonFlag==False :
#Update Screen
windowSurface.blit(backgroundSurface,(0,0))
windowSurface.blit(buildingSurface, (30, 190))
windowSurface.blit(buildingSurface2, (300, 90))
windowSurface.blit(bridgeSurface, (130, 300))
windowSurface.blit(smallbuildSurface, (500, 490))
for count in range(0,2):
windowSurface.blit(treeSurface, (1100 - 100*count, 540)
buttonStart.draw(windowSurface)
buttonExit.draw(windowSurface)
pygame.display.update()
#Quit
pygame.quit()
sys.exit() |
|