0

Here's my new code working better but still having issues with loading sound and switch animation:

        import os, math
        from superwires import games
                        
        # all files are in the same folder
    class Character(games.Animation):
        #loaded in the same folder
        # yelp = games.load_sound('yahoo-1.wav')
        # laugh = games.load_sound("crowd-laughing.wav")
        STEP = 2
        FLOOR = 0
        GRAVITY = 0.10
        THRUST = -6
        
      
        def __init__(self, x, bottom):
            anim_list = [games.load_image('stickman0.png'),
                             games.load_image('stickman1.png'),
                             games.load_image('stickman2.png'),
                             games.load_image('stickman3.png'),
                             games.load_image('stickman4.png'),
                             games.load_image('stickman5.png'),
                             games.load_image('stickman6.png'),
                             games.load_image('stickman7.png')]
    
            super(Character, self).__init__(images = anim_list ,
                                           x = x,
                                           bottom = bottom,
                                           n_repeats =-1,
                                           repeat_interval = 10)
            Character.Floor = bottom
            self.yVel = 0
            self.is_jumping = False
            self.jumpList = [anim_list[4]]
            self.standList = [anim_list[0]]
            self.resetList = anim_list 
        
        
            
               
        def wrap(self):
            if(self.right >= games.screen.width):
                self.right = games.screen.width
            elif self.left <= 0:
                self.left = 0
    
        def update(self):
            self.wrap()
            if(games.keyboard.is_pressed(games.K_RIGHT)):
                self.x += Character.STEP
            if(games.keyboard.is_pressed(games.K_LEFT)):
                self.x -= Character.STEP
            if not self.is_jumping:
                if(games.keyboard.is_pressed(games.K_SPACE)):
                    self.yVel = Character.THRUST
                    self.is_jumping = True
                    self.images = self.jumpList
            else:
                self.y += math.floor(self.yVel)
                self.yVel += Character.GRAVITY
                if self.bottom >= Character.FLOOR:
                    self.is_jumping = False
                    self.yVel = 0
                    self.bottom = Character.FLOOR
            

I can not seem to switch animations from motion to idle because of this error, i had to rewrite the code and it wont jump because of this error:

    Traceback (most recent call last):
      File "C:\Users\gamer\Desktop\Project_2_Solution\Entry_Main.py", line 24, in <module>
        Joe_Smoe = Character(x = WIDTH/2, bottom = HEIGHT/2)
      File "C:\Users\gamer\Desktop\Project_2_Solution\Character.py", line 35, in __init__
        super(Character, self).__init__(images = anim_list ,
      File "C:\Users\gamer\AppData\Local\Programs\Python\Python310\lib\site-packages\superwires\games.py", line 604, in __init__
        self.sequence.append(pic)
    AttributeError: 'Character' object has no attribute 'sequence'

I do not know what I am doing wrong please help?! near to the end and i also run into error with games.load_sound()

0 Answers0