diff --git a/images/robot1.bmp b/images/robot1.bmp new file mode 100644 index 0000000..e20fa62 Binary files /dev/null and b/images/robot1.bmp differ diff --git a/main.py b/main.py index ffe2cc8..245cba8 100644 --- a/main.py +++ b/main.py @@ -79,13 +79,13 @@ class Game: if event.key == pg.K_ESCAPE: self.quit() if event.key == pg.K_LEFT: - self.player.move(dx=-1) + self.player.move(dx=-1, direction='Left') if event.key == pg.K_RIGHT: - self.player.move(dx=1) + self.player.move(dx=1, direction='Right') if event.key == pg.K_UP: - self.player.move(dy=-1) + self.player.move(dy=-1, direction='Up') if event.key == pg.K_DOWN: - self.player.move(dy=1) + self.player.move(dy=1, direction='Down') def show_start_screen(self): pass diff --git a/sprites.py b/sprites.py index 7b1d70e..bfc1696 100644 --- a/sprites.py +++ b/sprites.py @@ -1,28 +1,64 @@ import pygame as pg +import enum from settings import * class Player(pg.sprite.Sprite): - def __init__(self, game, x, y): + def __init__(self, game, x, y, direction = 'Right'): self.groups = game.all_sprites pg.sprite.Sprite.__init__(self, self.groups) self.game = game #self.image = pg.Surface((TILESIZE, TILESIZE)) self.image = pg.image.load('images/robot.bmp') + self.baseImage = pg.image.load('images/robot.bmp') #self.image.fill(YELLOW) self.image = pg.transform.scale(self.image, (TILESIZE, TILESIZE)) + self.baseImage = pg.transform.scale(self.image, (TILESIZE, TILESIZE)) self.rect = self.image.get_rect() self.x = x self.y = y + self.direction = direction - def move(self, dx=0, dy=0): - self.x += dx - self.y += dy + def move(self, dx=0, dy=0, direction = ''): + if direction == self.direction: + if self.direction == Direction.Right.name: + if dx > 0: + self.x += dx + + if self.direction == Direction.Up.name: + if dy < 0: + self.y += dy + + if self.direction == Direction.Down.name: + if dy > 0: + self.y += dy + + if self.direction == Direction.Left.name: + if dx < 0: + self.x += dx + + elif direction != self.direction: + self.direction = direction + print(self.direction) + """if self.direction == Direction.Up.name: + self.image = pg.transform.rotate(self.baseImage, 90) + if self.direction == Direction.Right.name: + self.image == pg.transform.rotate(self.baseImage, 360) + if self.direction == Direction.Down.name: + self.image == pg.transform.rotate(self.baseImage, -90) + if self.direction == Direction.Left.name: + self.image == pg.transform.rotate(self.baseImage, -180)""" + def update(self): self.rect.x = self.x * TILESIZE self.rect.y = self.y * TILESIZE +class Direction(enum.Enum): + Up = 1; + Left = 2; + Down = 3; + Right = 4; class Mine(pg.sprite.Sprite):