Skip to content

Commit

Permalink
updated player sprites to be transparent
Browse files Browse the repository at this point in the history
  • Loading branch information
Pat Richeal committed Apr 5, 2015
1 parent 8bf6cf1 commit ac6ae79
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 33 deletions.
54 changes: 21 additions & 33 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,28 @@ def __init__(self, x, y):

self.sprites = SpriteSheet("resources/player.png")

self.stillRight = self.sprites.image_at((0, 0, 30, 42), colorkey = (250, 255, 0))
self.stillLeft = self.sprites.image_at((0, 42, 30, 42), colorkey = (250, 255, 0))
self.stillRight = self.sprites.image_at((0, 0, 30, 42))
self.stillLeft = self.sprites.image_at((0, 42, 30, 42))

self.runningRight = (self.sprites.image_at((0, 84, 30, 42), colorkey = (250, 255, 0)),
self.sprites.image_at((30, 84, 30, 42), colorkey = (250, 255, 0)),
self.sprites.image_at((60, 84, 30, 42), colorkey = (250, 255, 0)),
self.sprites.image_at((90, 84, 30, 42), colorkey = (250, 255, 0)),
self.sprites.image_at((120, 84, 30, 42), colorkey = (250, 255, 0)))
self.runningRight = (self.sprites.image_at((0, 84, 30, 42)),
self.sprites.image_at((30, 84, 30, 42)),
self.sprites.image_at((60, 84, 30, 42)),
self.sprites.image_at((90, 84, 30, 42)),
self.sprites.image_at((120, 84, 30, 42)))

self.runningLeft = (self.sprites.image_at((0, 126, 30, 42), colorkey = (250, 255, 0)),
self.sprites.image_at((30, 126, 30, 42), colorkey = (250, 255, 0)),
self.sprites.image_at((60, 126, 30, 42), colorkey = (250, 255, 0)),
self.sprites.image_at((90, 126, 30, 42), colorkey = (250, 255, 0)),
self.sprites.image_at((120, 126, 30, 42), colorkey = (250, 255, 0)))
self.runningLeft = (self.sprites.image_at((0, 126, 30, 42)),
self.sprites.image_at((30, 126, 30, 42)),
self.sprites.image_at((60, 126, 30, 42)),
self.sprites.image_at((90, 126, 30, 42)),
self.sprites.image_at((120, 126, 30, 42)))

self.jumpingRight = (self.sprites.image_at((30, 0, 30, 42), colorkey = (250, 255, 0)),
self.sprites.image_at((60, 0, 30, 42), colorkey = (250, 255, 0)),
self.sprites.image_at((90, 0, 30, 42), colorkey = (250, 255, 0)))
self.jumpingRight = (self.sprites.image_at((30, 0, 30, 42)),
self.sprites.image_at((60, 0, 30, 42)),
self.sprites.image_at((90, 0, 30, 42)))

self.jumpingLeft = (self.sprites.image_at((30, 42, 30, 42), colorkey = (250, 255, 0)),
self.sprites.image_at((60, 42, 30, 42), colorkey = (250, 255, 0)),
self.sprites.image_at((90, 42, 30, 42), colorkey = (250, 255, 0)))
self.jumpingLeft = (self.sprites.image_at((30, 42, 30, 42)),
self.sprites.image_at((60, 42, 30, 42)),
self.sprites.image_at((90, 42, 30, 42)))

self.image = self.stillRight

Expand Down Expand Up @@ -227,25 +227,13 @@ def __init__(self, image, x, y):

class SpriteSheet(object):
def __init__(self, fileName):
self.sheet = pygame.image.load(fileName).convert()
self.sheet = pygame.image.load(fileName)

def image_at(self, rectangle, colorkey = None):
def image_at(self, rectangle):
rect = pygame.Rect(rectangle)
image = pygame.Surface(rect.size).convert()
image = pygame.Surface(rect.size, pygame.SRCALPHA, 32).convert_alpha()
image.blit(self.sheet, (0, 0), rect)
if colorkey is not None:
if colorkey is -1:
colorkey = image.get_at((0,0))
image.set_colorkey(colorkey, pygame.RLEACCEL)
return image

def images_at(self, rects, colorkey = None):
return [self.image_at(rect, colorkey) for rect in rects]

def load_strip(self, rect, image_count, colorkey = None):
tups = [(rect[0]+rect[2]*x, rect[1], rect[2], rect[3])
for x in range(image_count)]
return self.images_at(tups, colorkey)

def main():
pygame.init()
Expand Down
Binary file modified resources/player.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ac6ae79

Please sign in to comment.