Daocsm 0 Newbie Poster

im creating a 2d side scroller in my class, and i have a image list out of a sprite sheet.
and when the player goes forward the images show up fine, but i cant seem to get each image to flip when the player turns around and goes back, any advise? or would it be easer to just make a new sprite sheet going the other direction?
here is the class code:

import pygame, sys
pygame.init()


class player(pygame.sprite.Sprite):
    def __init__(self, screen):
        pygame.sprite.Sprite.__init__(self)

        self.loadImages()

        self.frame = 5
        self.delay = 25
        self.pause = 0
        self.reverseYES = 0
        self.forwardYES = 0
        self.justpressed = 0
        self.image = self.imgListFwd[5]
        self.rect = self.image.get_rect()
        self.rect.centerx = 400
        self.rect.centery = 395
        
    def loadImages(self):
        ##forward image load
        imgForwardMaster = pygame.image.load("Sprites/Sprite.png")
        imgForwardMaster = imgForwardMaster.convert()
        
        self.imgListFwd = []
        
        imgSize = (34, 40)
        offset = ((513, 102),(553, 102),(592, 102),(627, 102),(664,102),(700,102))

        for i in range(6):
            fwdImage = pygame.Surface(imgSize)
            fwdImage.blit(imgForwardMaster, (0, 0), (offset[i], imgSize))
            transColor = fwdImage.get_at((1, 1))
            fwdImage.set_colorkey(transColor)
            self.imgListFwd.append(fwdImage)
        ##reverse image load
        imgReverseMaster = pygame.image.load("Sprites/Sprite.png")
        imgReverseMaster = imgReverseMaster.convert()
        
        self.imgListRvs = []
        
        imgSize = (34, 40)
        offset = ((513, 102),(553, 102),(592, 102),(627, 102),(664,102),(700,102))

        for i in range(6):
            RvsImage = pygame.Surface(imgSize)
            RvsImage.blit(imgReverseMaster, (0, 0), (offset[i],imgSize))
            transColor = RvsImage.get_at((0, 0))
            RvsImage.set_colorkey(transColor)
            self.imgListRvs.append(RvsImage)
        for i in range(6):
            pygame.transform.flip(self.imgListRvs[i], 1, 0)
        
    def update(self):
        if self.forwardYES == 1:
            if self.reverseYES == 0:
                self.forward()
        elif self.forwardYES == 0:
            if self.reverseYES == 0:
                self.stop()
        if self.reverseYES == 1:
            if self.forwardYES == 0:
                self.reverse()
        elif self.reverseYES == 0:
            if self.forwardYES == 0:
                self.stop()
    def stop(self):
        ##forward
        if self.justpressed == 1:
            self.frame = 5
            self.image = self.imgListFwd[self.frame]
            self.rect = self.image.get_rect()
            self.rect.center = (400, 395)
        ##reverse
        elif self.justpressed == 2:
            self.frame = 4
            self.image = self.imgListRvs[self.frame]
            self.rect = self.image.get_rect()
            self.rect.center = (400, 395)
            
    def forward(self):
        self.pause += 1
        if self.pause >= self.delay:
            self.pause = 0
            if self.frame >= 4:  
                self.frame = 0
            else:
                self.frame += 1    
            self.image = self.imgListFwd[self.frame]
            self.rect = self.image.get_rect()
            self.rect.center = (400, 395)
    
    def reverse(self):
        self.pause += 1
        if self.pause >= self.delay:
            self.pause = 0
            if self.frame >= 5:  
                self.frame = 0
            else:
                self.frame += 1
            self.image = self.imgListRvs[self.frame]
            self.rect = self.image.get_rect()
            self.rect.center = (400, 395)

also is there a way to check key.events in a class update()? i tried the

for event in pygame.event.get():
        if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_a:
                    ##code
                elif event.key == pygame.K_d:
                    ##code
            elif event.type == pygame.KEYUP:
                if event.key == pygame.K_a:
                    ##code
                elif event.key == pygame.K_d:
                    ##code

but no luck so i just have been passing variables but then it gets a bit cluttered. thanks for the help/advise!

doh! tottaly just relized my mistake! i forgot the "self.imgListRvs =" infront of the
"pygame.transform.flip(self.imgListRvs, 1, 0)"
it just goes to show yeah that you always find your mistakes after you post for help ha!
but any help with the second part about the update key.event would be great!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.