猫史档案馆


咋回事?难道……?

用户:WMoSo岛同号WMoSo岛同号查看:3 回复:4 评论:3 创建时间:2021-10-17T17:31:05


最近我的代码又出问题了,难道是……

 

center_image

这些是具体代码……头晕!

import arcade
SCREEN_HEIGHT = 652
SCREEN_WIDTH = 827
SCREEN_TITLE = '我的房子'

class Road(path):
    def __init__(self, image):
        super().__init__(image)
        self.road=road
        img=Sprite(road)
        self.img.center_x = SCREEN_WIDTH//2
        self.img.center_y = SCREEN_HEIGHT//2
class StatusBar():
    def __init__(self):
        self.distance = 0
        self.hp = 2

    def draw_bar(self):
        arcade.draw_rectangle_filled(
            SCREEN_WIDTH//2, SCREEN_HEIGHT-15, SCREEN_WIDTH, 30, arcade.color.BLUE
        )

    def draw_hp(self):
        pos_x = SCREEN_WIDTH//2-50
        pos_y = SCREEN_HEIGHT-20
        arcade.draw_text('血量:', pos_x, pos_y, arcade.color.WHITE,
                  font_name='simhei')
        hearts = arcade.SpriteList()
        for i in range(self.hp):
            heart = arcade.Sprite('heart.png')
            heart.center_x = pos_x+50+heart.width*i
            heart.center_y = pos_y+5
            hearts.append(heart)
        hearts.draw()


class Program(arcade.Window):
    def __init__(self, width, height, title):
        super().__init__(width, height, title)
        center_x = SCREEN_WIDTH//2
        center_y = SCREEN_HEIGHT//2
        self.status=StatusBar()
        self.road=Road('background.bmp')
    def on_draw(self):
        arcade.start_render()
        self.status.draw_bar()
        self.status.draw_hp()

if __name__ == '__main__':
    game = Program(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
    arcade.run()

 


回复

上一页1 页 / 共 1下一页
WMoSo岛同号WMoSo岛同号

报错报在第6行

难道是……命名问题?

谁救救我呀!

点赞0


评论


天真的乌力力yKhY天真的乌力力yKhY

因为没有定义path这个类

第6行的类是要继承的

点赞0


评论


石斛解说石斛解说

没有path类,self.img写成了img

点赞0


评论


伴雪纷飞伴雪纷飞

import arcade
SCREEN_HEIGHT = 652
SCREEN_WIDTH = 827
SCREEN_TITLE = '我的房子'

class Road():
    def __init__(self, image,path):
        super().__init__(image)
        self.road=road
        self.img=Sprite(road)
        self.img.center_x = SCREEN_WIDTH//2
        self.img.center_y = SCREEN_HEIGHT//2
class StatusBar():
    def __init__(self):
        self.distance = 0
        self.hp = 2

    def draw_bar(self):
        arcade.draw_rectangle_filled(
            SCREEN_WIDTH//2, SCREEN_HEIGHT-15, SCREEN_WIDTH, 30, arcade.color.BLUE
        )

    def draw_hp(self):
        pos_x = SCREEN_WIDTH//2-50
        pos_y = SCREEN_HEIGHT-20
        arcade.draw_text('血量:', pos_x, pos_y, arcade.color.WHITE,
                  font_name='simhei')
        hearts = arcade.SpriteList()
        for i in range(self.hp):
            heart = arcade.Sprite('heart.png')
            heart.center_x = pos_x+50+heart.width*i
            heart.center_y = pos_y+5
            hearts.append(heart)
        hearts.draw()


class Program(arcade.Window):
    def __init__(self, width, height, title):
        super().__init__(width, height, title)
        center_x = SCREEN_WIDTH//2
        center_y = SCREEN_HEIGHT//2
        self.status=StatusBar()
        self.road=Road('background.bmp')
    def on_draw(self):
        arcade.start_render()
        self.status.draw_bar()
        self.status.draw_hp()

if __name__ == '__main__':
    game = Program(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
    arcade.run()

这可能是你想改动的

点赞0


评论