117 lines
3.9 KiB
Python
117 lines
3.9 KiB
Python
import pygame as pg
|
|
import enum
|
|
from settings import *
|
|
|
|
class Player(pg.sprite.Sprite):
|
|
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, 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):
|
|
def __init__(self, game, x, y):
|
|
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/mine.bmp')
|
|
#self.image.fill(YELLOW)
|
|
self.image = pg.transform.scale(self.image, (TILESIZE, TILESIZE))
|
|
self.rect = self.image.get_rect()
|
|
self.x = x
|
|
self.y = y
|
|
|
|
def update(self):
|
|
self.rect.x = self.x * TILESIZE
|
|
self.rect.y = self.y * TILESIZE
|
|
|
|
|
|
class Bomb(pg.sprite.Sprite):
|
|
def __init__(self, game, x, y):
|
|
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/bomb.bmp')
|
|
#self.image.fill(YELLOW)
|
|
self.image = pg.transform.scale(self.image, (TILESIZE, TILESIZE))
|
|
self.rect = self.image.get_rect()
|
|
self.x = x
|
|
self.y = y
|
|
|
|
def update(self):
|
|
self.rect.x = self.x * TILESIZE
|
|
self.rect.y = self.y * TILESIZE
|
|
|
|
|
|
class Grenade(pg.sprite.Sprite):
|
|
def __init__(self, game, x, y):
|
|
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/grenade.bmp')
|
|
#self.image.fill(YELLOW)
|
|
self.image = pg.transform.scale(self.image, (TILESIZE, TILESIZE))
|
|
self.rect = self.image.get_rect()
|
|
self.x = x
|
|
self.y = y
|
|
|
|
def update(self):
|
|
self.rect.x = self.x * TILESIZE
|
|
self.rect.y = self.y * TILESIZE
|
|
|
|
|