Skip to content
Snippets Groups Projects
Commit ffd482c9 authored by Robert Seimetz's avatar Robert Seimetz
Browse files

Rework classes to ensure compatibility with rotation and reflection of imgs

parent 4062c997
No related branches found
No related tags found
No related merge requests found
......@@ -93,13 +93,15 @@ class _Object(pygame.sprite.Sprite):
# location - Tupel mit den Koordinaten in der Form (x,y) - Bsp. (19,23)
# scale - Die Größe des Sprites in der Form (Höhe, Breite) - Bsp. (23,23)
# imagename - Name des Bildes - Bsp. "golden.png"
def __init__(self, location, scale, imagename):
def __init__(self, location, scale, imagename, rotation, reflect_x, reflect_y):
pygame.sprite.Sprite.__init__(self)
size = [int(scale[0]),int(scale[1])]
self.rect = pygame.Rect(location, scale)
self.imagename = imagename
self.image = pygame.image.load("./img/"+self.imagename)
self.image = pygame.transform.scale(self.image,size)
self.image = pygame.transform.rotate(self.image, rotation)
self.image = pygame.transform.flip(self.image, reflect_x, reflect_y)
def update(self):
pass
......@@ -111,7 +113,7 @@ class _AnimatedObject(pygame.sprite.Sprite):
# location - Tupel mit den Koordinaten in der Form (x,y) - Bsp. (19,23)
# scale - Die Größe des Sprites in der Form (Höhe, Breite) - Bsp. (23,23)
# imagename - Name des Bildes - Bsp. "golden.png"
def __init__(self, location, scale, imagename, spritesize):
def __init__(self, location, scale, imagename, spritesize, rotation, reflect_x, reflect_y):
pygame.sprite.Sprite.__init__(self)
self.size = [int(scale[0]),int(scale[1])]
self.rect = pygame.Rect(location, scale)
......@@ -130,6 +132,8 @@ class _AnimatedObject(pygame.sprite.Sprite):
self.maxframe[1] = self.spritesheet.get_rect().height / self.spritesize[1]
self.image = get_image_from_Spritesheet(self.spritesheet, self.spritesize, self.current_frame, self.size).convert_alpha()
self.image = pygame.transform.rotate(self.image, rotation)
self.image = pygame.transform.flip(self.image, reflect_x, reflect_y)
def update(self):
if (timer()-self.time_lastframe) > (1/self.animationspeed):
......@@ -147,15 +151,19 @@ class _Character(pygame.sprite.Sprite):
# location - Tupel mit den Koordinaten in der Form (x,y) - Bsp. (19,23)
# scale - Die Größe des Sprites in der Form (Höhe, Breite) - Bsp. (23,23)
# imagename - Name des Bildes - Bsp. "golden.png"
def __init__(self, location, scale, imagename, tilemap):
def __init__(self, location, scale, imagename, tilemap, rotation, reflect_x, reflect_y):
pygame.sprite.Sprite.__init__(self)
self.rect = pygame.Rect(location, scale)
self.imagename = imagename
self.image = pygame.image.load("./img/"+self.imagename)
self.image = pygame.transform.scale(self.image,scale)
self.image = pygame.transform.rotate(self.image, rotation)
self.image = pygame.transform.flip(self.image, reflect_x, reflect_y)
self.base_image = self.image
self.map = tilemap
def __str__(self):
return "Position: " + str(self.rect.left) +", "+str(self.rect.top)+"\n"+"Velocity: " + str(self.move[0]) +", "+str(self.move[1])
......@@ -223,9 +231,9 @@ class Tilemap():
return surface
class Projectile(pygame.sprite.Sprite):
def __init__(self, pos, move, size, image, speed):
def __init__(self, pos, move, size, image, speed, rotation=0, reflect_x=False, reflect_y=False):
pygame.sprite.Sprite.__init__(self)
_Object.__init__(self, pos, size, image)
_Object.__init__(self, pos, size, image, rotation, reflect_x, reflect_y)
self.rect.topleft = pos
if move == [0, 0]:
move = [speed, 0]
......
......@@ -7,8 +7,8 @@ from gameparts.basics import _Physics, _Character, rotate_image
class LinearEnemy(_Character, _Physics):
def __init__(self, location, size, image, tilemap, walls, direction):
_Character.__init__(self, location, size, image, tilemap)
def __init__(self, location, size, image, tilemap, walls, direction, rotation=0, reflect_x=False, reflect_y=False):
_Character.__init__(self, location, size, image, tilemap, rotation, reflect_x, reflect_y)
_Physics.__init__(self, walls)
self.bouncetype = "invert"
self.move = direction
......@@ -21,8 +21,8 @@ class LinearEnemy(_Character, _Physics):
_Physics.update(self)
class RandomEnemy(_Character, _Physics):
def __init__(self, location, size, image, tilemap, walls, speed, interval):
_Character.__init__(self, location, size, image, tilemap)
def __init__(self, location, size, image, tilemap, walls, speed, interval, rotation=0, reflect_x=False, reflect_y=False):
_Character.__init__(self, location, size, image, tilemap, rotation, reflect_x, reflect_y)
_Physics.__init__(self, walls)
self.speed = speed
self.bouncetype = "invert"
......@@ -67,8 +67,8 @@ class RandomEnemy(_Character, _Physics):
_Physics.update(self)
class FollowingEnemy(_Character, _Physics):
def __init__(self, location, size, image, tilemap, walls, speed, player):
_Character.__init__(self, location, size, image, tilemap)
def __init__(self, location, size, image, tilemap, walls, speed, player, rotation=0, reflect_x=False, reflect_y=False):
_Character.__init__(self, location, size, image, tilemap, rotation, reflect_x, reflect_y)
_Physics.__init__(self, walls)
self.speed = speed
self.bouncetype = "invert"
......
......@@ -5,10 +5,10 @@ from settings import *
from gameparts.basics import _Object, _AnimatedObject, timer, get_image_from_Spritesheet
class Coin(_Object):
def __init__(self, location, size, image="Golden.png"):
_Object.__init__(self, location, size, image)
def __init__(self, location, size, image="Golden.png", rotation=0, reflect_x=False, reflect_y=False):
_Object.__init__(self, location, size, image, rotation, reflect_x, reflect_y)
class AnimatedCoin(_AnimatedObject):
def __init__(self, location, scale, image="CoinAnimated.png", spritesize=(16,16)):
_AnimatedObject.__init__(self, location, scale, image, spritesize)
def __init__(self, location, scale, image="CoinAnimated.png", spritesize=(16,16), rotation=0, reflect_x=False, reflect_y=False):
_AnimatedObject.__init__(self, location, scale, image, spritesize, rotation, reflect_x, reflect_y)
self.animationspeed = 4
......@@ -5,8 +5,8 @@ from settings import *
from gameparts.basics import _Physics, _Character, rotate_image
class LinearPlayer(_Character,_Physics):
def __init__(self, location, size, image, tilemap, walls):
_Character.__init__(self, location, size, image, tilemap)
def __init__(self, location, size, image, tilemap, walls, rotation=0, reflect_x=False, reflect_y=False):
_Character.__init__(self, location, size, image, tilemap, rotation, reflect_x, reflect_y)
_Physics.__init__(self, walls)
self.keys = {
"up": pygame.K_w,
......@@ -77,8 +77,8 @@ class LinearPlayer(_Character,_Physics):
_Physics.update(self)
class AnglePlayer(_Character,_Physics):
def __init__(self, location, size, image, tilemap, walls):
_Character.__init__(self, location, size, image, tilemap)
def __init__(self, location, size, image, tilemap, walls, reflect_x=False, reflect_y=False):
_Character.__init__(self, location, size, image, tilemap, 0, reflect_x, reflect_y)
_Physics.__init__(self, walls)
self.keys = {
"up": pygame.K_w,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment