| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1386 人关注过本帖
标题:各位大佬,为什么我的地板不动
只看楼主 加入收藏
新手白
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2021-8-10
结帖率:100%
收藏
 问题点数:0 回复次数:2 
各位大佬,为什么我的地板不动
代码:
import sys
import pygame
import random,os

# Constants 常量
W,H = 288,512
FPS = 30

# Setup 设置
pygame.init()
SCREEN = pygame.display.set_mode((W,H))
pygame.display.set_caption('  flappy bird  ')
CLOCK = pygame.time.Clock()

# Haterials 素材
IMAGES = {}
for image in os.listdir('999'):
    name,extension = os.path.splitext(image)
    path = os.path.join('999',image)
    IMAGES[name] = pygame.image.load(path)


FLOOR_Y = H - IMAGES['floor'].get_height()
start = pygame.mixer.Sound('999')
die = pygame.mixer.Sound('999')
flap = pygame.mixer.Sound('999')
hit = pygame.mixer.Sound('999')
score = pygame.mixer.Sound('999')

def main():
    while True:
        start.play()
        IMAGES['bgpic'] = IMAGES[random.choice(['day','night'])]
        color = random.choice(['red','yellow','blue'])
        IMAGES['birds'] = [IMAGES[color+'-up'],IMAGES[color+'-mid'],IMAGES[color+'-down']]
        pipe = IMAGES[random.choice(['green-pipe','red-pipe'])]
        IMAGES['pipes'] = [pipe,pygame.transform.flip(pipe,False,True)]
        menv_window()
        game_window()
        end_window()


def menv_window():

    floor_gap = IMAGES['floor'].get_width() - W
    floor_x = 0

    guide_x = (W - IMAGES['guide'].get_width())/2
    guide_y = (FLOOR_Y - IMAGES['guide'].get_height())/2
    bird_x = W * 0.2
    bird_y = (H - IMAGES['red-up'].get_height())/2

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
                return

        floor_x -= 4
        if floor_x <= - floor_gap:
            floor_x = 0

        SCREEN.blit(IMAGES['bgpic'],(0,0))
        SCREEN.blit(IMAGES['floor'],(0,FLOOR_Y))
        SCREEN.blit(IMAGES['guide'],(guide_x,guide_y))
        SCREEN.blit(IMAGES['birds'][0],(bird_x,bird_y))
        pygame.display.update()
        CLOCK.tick(FPS)


def game_window():
   
    floor_gap = IMAGES['floor'].get_width() - W
    floor_x = 0


    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_SPACE:
                    return

        floor_x -= 4
        if floor_x <= - floor_gap:
            floor_x = 0

        SCREEN.blit(IMAGES['bgpic'],(0,0))
        SCREEN.blit(IMAGES['pipes'][0],(W/2,H/2))
        SCREEN.blit(IMAGES['floor'],(0,FLOOR_Y))
        SCREEN.blit(IMAGES['birds'][0],(W/2,H*0.3))
        pygame.display.update()
        CLOCK.tick(FPS)



def end_window():

    floor_gap = IMAGES['floor'].get_width() - W
    floor_x = 0


    gameover_x = (W - IMAGES['gameover'].get_width())/2
    gameover_y = (FLOOR_Y - IMAGES['gameover'].get_height())/2

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
                return

        floor_x -= 4
        if floor_x <= - floor_gap:
            floor_x = 0

        SCREEN.blit(IMAGES['bgpic'],(0,0))
        SCREEN.blit(IMAGES['floor'],(0,FLOOR_Y))
        SCREEN.blit(IMAGES['gameover'],(gameover_x,gameover_y))
        SCREEN.blit(IMAGES['birds'][0],(W / 2,H * 0.3))
        pygame.display.update()
        CLOCK.tick(FPS)



main()



图片请各位大佬自行寻找
要添加地址的地方为999
搜索更多相关主题的帖子: IMAGES event pygame SCREEN if 
2021-08-17 15:50
蟒蛇出洞
Rank: 2
等 级:论坛游民
威 望:1
帖 子:41
专家分:22
注 册:2021-8-19
收藏
得分:0 
我那晓得
2021-08-19 10:23
古123
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:219
专家分:1098
注 册:2017-2-5
收藏
得分:0 
在b站看到的代码吧,我也照这个做过。
图片附件: 游客没有浏览图片的权限,请 登录注册

画圈位置你把地板图片x坐标定死了0,当然不动,把0换成floor_x。
2021-08-20 20:26
快速回复:各位大佬,为什么我的地板不动
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027009 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved