大聪胡 2022-05-31 19:07 采纳率: 100%
浏览 35
已结题

【代码报错】Python

谁能帮我看一下这个代码哪里错了,我老报错
from Walimaker import *
setup(1024,512)

bg_far1=Character('./Background/scroll_bg_far.png')
bg_far2=Character('./Background/scroll_bg_far.png')
bg_far2.x=2048
hills1=Character('./Background/hills-scroll.png')
hills2=Character('./Background/hills-scroll.png')
hills2.x=2048
hills1.y=-50
hills2.y=-50
bg_grass1=Character('./Background/bg_grass.png')
bg_grass2=Character('./Background/bg_grass.png')
bg_grass2.x=2048

horse_run_img=['./Sprite/Horse/horse-run-00.png',
'./Sprite/Horse Ice/ice-horse-run-01.png',
'./Sprite/Horse Ice/ice-horse-run-02.png',
'./Sprite/Horse Ice/ice-horse-run-03.png',
'./Sprite/Horse Ice/ice-horse-run-04.png',
'./Sprite/Horse Ice/ice-horse-run-05.png',
'./Sprite/Horse Ice/ice-horse-run-06.png',]
horse_jump_img=['./Sprite/Horse/horse-run-00.png',
'./Sprite/Horse Ice/ice-horse-jump-01.png',
'./Sprite/Horse Ice/ice-horse-jump-02.png',
'./Sprite/Horse Ice/ice-horse-jump-03.png',
'./Sprite/Horse Ice/ice-horse-jump-04.png',
'./Sprite/Horse Ice/ice-horse-jump-05.png',
'./Sprite/Horse Ice/ice-horse-jump-06.png',]
horse_img={'run':horse_run_img,'jump':horse_jump_img}

horse=Character(horse_img)
horse.state='run'

horse.play_anim()#播放图片
#horse.dt=0.005极快的速度 更改马的速度
horse.set_dt('run',0.01)
horse.set_dt('jump',0.01)
horse.goto(-400,-110)#更改位置x,y
horse.ay=-0.9
#金币 Sprite 动画精灵 Sheet 清单
coin_img=SpriteSheet('./Sprite/coin_gold.png',8,1)
coin1=Character(coin_img)
coin1.play_anim()
coin1.scale(3)
coin1.x=1000
coin2=Character(coin_img)
coin2.play_anim()
coin2.scale(3)
coin2.x=2000
#计分
text=TextBox(100)#字体大小
text.print('吃屎量:0')
text.goto(0,150)
score=0#计分

#蝙蝠
bat_img=SpriteSheet('./Sprite/bat.png',4,4)
bat1.play_anim()
bat2=Character(bat_img[13:])
bat2.play_anim()
bat1.scale(3)
bat2.scale(3)
bat1.x=1500
bat2.x=3000

while True:
bg_far1.backward(10)
bg_far2.backward(10)
hills1.backward(10)
hills2.backward(10)
bg_grass1.backward(10)
bg_grass2.backward(10)
if bg_far1.x<-2030:
bg_far1.x=bg_far2.x+2040
if bg_far2.x<-2030:
bg_far2.x=bg_far1.x+2040
if hills1.x<-2030:
hills1.x=hills2.x+2040
if hills2.x<-2030:
hills2.x=hills1.x+2040
if bg_grass1.x<-2030:
bg_grass1.x=bg_grass2.x+2040
if bg_grass2.x<-2030:
bg_grass2.x=bg_grass1.x+2040
#小马的跳跃
horse.vy+=horse.ay
if horse.collide (bg_grass1) or horse.collide (bg_grass2):
horse.vy=max(0,horse.vy)
horse.state='run'
if key_pressed(K_SPACE):
horse.state='jump'
horse.vy=15

horse.y+=horse.vy
#金币
coin1.backward(10)
coin2.backward(10)
if coin1.x<1000:
    coin1.x=1000
    horse.play_snd('./snd/金币.wav')
if coin2.x<1000:
    coin2.x<1000
    ('./snd/金币.wav')
if horse.collide(coin1):
    coin1.x=1500
    score +=1
    text.print(f'吃屎量:{score}')
if horse.collide(coin2):
    coin2.x=1500
    score +=1
    text.print(f'吃屎量:{score}')

bat1.backward(10)
bat2.backward(10)

if bat1.x<-1500:
    bat1.x=-1500
if bat2.x<-1500:
    bat2.x=-1500
if horse.collide(bat1) or horse.collide(bat2):
    text.print('noooooooooooooo')
    while True:
        if key_pressed(K_r):
            bat1.x=1500
            bat2.x=2500
            score=0
            text.print(f'吃屎量:{score}')
            break
        update()


update()
  • 写回答

2条回答 默认 最新

  • 我是肖某人 2022-06-05 15:47
    关注

    你这个用的是Walimaker数据库,下载不到,我只能简单改一下,因为语法很奇怪

    from Walimaker import *
    setup(1024,512)
    
    bg_far1=Character('./Background/scroll_bg_far.png')
    bg_far2=Character('./Background/scroll_bg_far.png')
    bg_far2.x=2048
    hills1=Character('./Background/hills-scroll.png')
    hills2=Character('./Background/hills-scroll.png')
    hills2.x=2048
    hills1.y=-50
    hills2.y=-50
    bg_grass1=Character('./Background/bg_grass.png')
    bg_grass2=Character('./Background/bg_grass.png')
    bg_grass2.x=2048
    
    horse_run_img=['./Sprite/Horse/horse-run-00.png',
               './Sprite/Horse Ice/ice-horse-run-01.png',
               './Sprite/Horse Ice/ice-horse-run-02.png',
               './Sprite/Horse Ice/ice-horse-run-03.png',
               './Sprite/Horse Ice/ice-horse-run-04.png',
               './Sprite/Horse Ice/ice-horse-run-05.png',
               './Sprite/Horse Ice/ice-horse-run-06.png',]
    horse_jump_img=['./Sprite/Horse/horse-run-00.png',
               './Sprite/Horse Ice/ice-horse-jump-01.png',
               './Sprite/Horse Ice/ice-horse-jump-02.png',
               './Sprite/Horse Ice/ice-horse-jump-03.png',
               './Sprite/Horse Ice/ice-horse-jump-04.png',
               './Sprite/Horse Ice/ice-horse-jump-05.png',
               './Sprite/Horse Ice/ice-horse-jump-06.png',]
    horse_img={'run':horse_run_img,'jump':horse_jump_img}
    
    horse=Character(horse_img)
    horse.state='run'
    
    horse.play_anim()#播放图片
    #horse.dt=0.005极快的速度 更改马的速度
    horse.set_dt('run',0.01)
    horse.set_dt('jump',0.01)
    horse.goto(-400,-110)#更改位置x,y
    horse.vy=0
    horse.ay=-0.9
    #金币 Sprite 动画精灵  Sheet 清单
    coin_img=SpriteSheet('./Sprite/coin_gold.png',8,1)
    coin1=Character(coin_img)
    coin1.play_anim()
    coin1.scale(3)
    coin1.x=1000
    coin2=Character(coin_img)
    coin2.play_anim()
    coin2.scale(3)
    coin2.x=2000
    #计分
    text=TextBox(100)#字体大小
    text.print('吃屎量:0')
    text.goto(0,150)
    score=0#计分
    
    #蝙蝠
    bat_img=SpriteSheet('./Sprite/bat.png',4,4)
    bat1=Character(bat_img[13:])
    bat1.play_anim()
    bat2=Character(bat_img[13:])
    bat2.play_anim()
    bat1.scale(3)
    bat2.scale(3)
    bat1.x=1500
    bat2.x=3000
    
    
    
    while True:
        bg_far1.backward(10)
        bg_far2.backward(10)
        hills1.backward(10)
        hills2.backward(10)
        bg_grass1.backward(10)
        bg_grass2.backward(10)
        if bg_far1.x<-2030:
            bg_far1.x=bg_far2.x+2040
        if bg_far2.x<-2030:
            bg_far2.x=bg_far1.x+2040
        if hills1.x<-2030:
            hills1.x=hills2.x+2040
        if hills2.x<-2030:
            hills2.x=hills1.x+2040
        if bg_grass1.x<-2030:
            bg_grass1.x=bg_grass2.x+2040
        if bg_grass2.x<-2030:
            bg_grass2.x=bg_grass1.x+2040
        #小马的跳跃
        horse.vy+=horse.ay
        if horse.collide (bg_grass1) or horse.collide (bg_grass2):
            horse.vy=max(0,horse.vy)
            horse.state='run'
            if key_pressed(K_SPACE):
                horse.state='jump'
                horse.vy=15
        
        horse.y+=horse.vy
        #金币
        coin1.backward(10)
        coin2.backward(10)
        if coin1.x<1000:
            coin1.x=1000
            horse.play_snd('./snd/金币.wav')
        if coin2.x<1000:
            coin2.x<1000
            ('./snd/金币.wav')
        if horse.collide(coin1):
            coin1.x=1500
            score +=1
            text.print(f'吃屎量:{score}')
        if horse.collide(coin2):
            coin2.x=1500
            score +=1
            text.print(f'吃屎量:{score}')
    
        bat1.backward(10)
        bat2.backward(10)
    
        if bat1.x<-1500:
            bat1.x=-1500
        if bat2.x<-1500:
            bat2.x=-1500
        if horse.collide(bat1) or horse.collide(bat2):
            text.print('noooooooooooooo')
            while True:
                if key_pressed(K_r):
                    bat1.x=1500
                    bat2.x=2500
                    score=0
                    text.print(f'吃屎量:{score}')
                    break
                update()
    
        
        update()
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 6月15日
  • 已采纳回答 6月7日
  • 创建了问题 5月31日

悬赏问题

  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法