pygame熊猫吃竹子

import pygame,sys
from pygame.locals import *
import random

BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
WHITE = (255, 255, 255)
RED=(255, 0, 0)
TEXTCOLOR = BLACK

def drawText(text,font,surface,x,y):
    textobj=font.render(text,1,TEXTCOLOR)
    textrect=textobj.get_rect()
    textrect.topleft=(x,y)
    surface.blit(textobj,textrect)

pygame.init()

font=pygame.font.SysFont(None,48)

windowSurface=pygame.display.set_mode((1200,800))
brand=pygame.image.load("brand.png")
brand_size=pygame.transform.scale(brand,(120,120))
brand_position=pygame.Rect(10,10,300,260)

panda=pygame.image.load("pandas.png")
panda_size=pygame.transform.scale(panda,(120,120))
position=pygame.Rect(500,680,120,120)

bamboo=pygame.image.load("bamboo2.png")
bamboo_size=pygame.transform.scale(bamboo,(50,50))


bamboo_list=[]

for i in range(100):
    bamboo_list.append(pygame.Rect(random.randint(100,1000),random.randint(-6000,100),1,1))

mainClock=pygame.time.Clock()
moveLeft = moveRight = False
PLAYERMOVERATE = 3

speed=20
score=0
start=False

pygame.display.set_caption("俞兆林品牌小游戏_熊猫大战竹子(空格键开始游戏!)")


while True:
    
    windowSurface.fill((255,250,205))
    windowSurface.blit(panda_size,position)
    windowSurface.blit(brand_size,brand_position)
    
    for event in pygame.event.get():
        if event.type==QUIT:
            pygame.quit()
            sys.exit()

        if event.type==KEYDOWN:
            if event.key==K_LEFT or event.key==ord('a'):
                moveRight=False
                moveLeft=True
            if event.key==K_RIGHT or event.key==ord('d'):
                moveLeft=False
                moveRight=True

        if event.type==KEYUP:
            if event.key==K_LEFT or event.key==ord('a'):
                moveLeft=False
            if event.key==K_RIGHT or event.key==ord('d'):
                moveRight=False

            if event.key==K_SPACE:
                start=True


    if start ==True:
        if moveRight and position.right<1200:
            position.right+=PLAYERMOVERATE

        if moveLeft and position.left > 0:
            position.left-=PLAYERMOVERATE


        for i in bamboo_list:
            i.move_ip(0,1 * PLAYERMOVERATE)
    

        for i in bamboo_list:
            if i.colliderect(position)==False:
                windowSurface.blit(bamboo_size,i)
            elif i.colliderect(position)==True:
                bamboo_list.remove(i)
                score +=1

    
    drawText("score:",font, windowSurface,950,40 )
    drawText(str(score) + " / 100",font, windowSurface,1060,42 )


    pygame.display.update()
    mainClock.tick(80)

图片公司版权所有!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值