diff --git a/Engine/Agent.py b/Engine/Agent.py index d6e11408..bf8bff11 100644 --- a/Engine/Agent.py +++ b/Engine/Agent.py @@ -1,20 +1,22 @@ +import pygame from Constants import ROWS, COLS, UP, LEFT, DOWN, RIGHT class Agent(object): - def __init__(self, column, row): - self.column = column - self.row = row + def __init__(self, y, x): + self.y = y + self.x = x + self.image = pygame.image.load('Engine/agent.png') - def ifNotOnEdge(self, destination): - if destination == UP: - if self.row - 1 <= 0: - return False - if destination == DOWN: - if self.row + 1 > ROWS: - return False - if destination == LEFT: - if self.column - 1 <= 0: - return False - if destination == RIGHT: - if self.column + 1 > COLS: - return False - return True \ No newline at end of file + # def ifNotOnEdge(self, destination): + # if destination == UP: + # if self.x - 1 <= 0: + # return False + # if destination == DOWN: + # if self.x + 1 > ROWS: + # return False + # if destination == LEFT: + # if self.y - 1 <= 0: + # return False + # if destination == RIGHT: + # if self.y + 1 > COLS: + # return False + # return True \ No newline at end of file diff --git a/Engine/Board.py b/Engine/Board.py index 1cd8af20..5c8b1ca6 100644 --- a/Engine/Board.py +++ b/Engine/Board.py @@ -3,6 +3,7 @@ from Constants import ROWS, COLS, SQUARE_SIZE, GREEN, BLACK, WIDTH class Board: + def __init__(self): self.board = [] @@ -13,5 +14,13 @@ class Board: pygame.draw.rect(win, BLACK, pygame.Rect(row * SQUARE_SIZE, col * SQUARE_SIZE, SQUARE_SIZE, SQUARE_SIZE), 2) def drawAgent(self, win, agent): - dis = WIDTH // ROWS - pygame.draw.rect(win, self.color, (agent.row * dis + 1, agent.column * dis + 1, dis - 2, dis - 2)) \ No newline at end of file + rect = agent.image.get_rect() + rect.center = (agent.x * SQUARE_SIZE + SQUARE_SIZE / 2, agent.y * SQUARE_SIZE + SQUARE_SIZE / 2 - 5) + win.blit(agent.image, rect) + + def drawBombs(self,win, x, y): + image = pygame.image.load('Engine/bomb.png') + image = pygame.transform.scale(image, (SQUARE_SIZE, SQUARE_SIZE)) + rect = image.get_rect() + rect.center = (x * SQUARE_SIZE + SQUARE_SIZE/2 + 5, y * SQUARE_SIZE + SQUARE_SIZE/2 - 5) + win.blit(image, rect) diff --git a/Engine/Game.py b/Engine/Game.py index 12641161..270e10ac 100644 --- a/Engine/Game.py +++ b/Engine/Game.py @@ -1,7 +1,7 @@ import pygame -from Constants import SQUARE_SIZE, GREEN, RIGHT, LEFT, UP, DOWN -from Board import Board -import Agent +from Constants import SQUARE_SIZE, GREEN, RIGHT, LEFT, UP, DOWN, COLS, ROWS +from Engine.Board import Board +from Engine.Agent import Agent class Game: def __init__(self, win): @@ -12,15 +12,31 @@ class Game: self.board = Board() self.agent = Agent(0, 0) self.turn = GREEN + self.goingDown = True + + def update(self): self.board.drawSquares(self.win) - self.board.drawAgent(self,self.win,self.agent) + self.board.drawBombs(self.win, 1, 1) + self.board.drawBombs(self.win, 2, 3) + self.board.drawBombs(self.win, 5, 6) + self.board.drawAgent(self.win,self.agent) pygame.display.update() - def move(self, destination): - if destination == UP and self.agent.ifNotOnEdge(UP): - self.agent.row -= 1 + def move(self): + if self.goingDown: + if self.agent.y + 1 < ROWS: + self.agent.y += 1 + elif self.agent.x + 1 < COLS: + self.agent.x += 1 + self.goingDown = not self.goingDown + else: + if self.agent.y - 1 >= 0: + self.agent.y -= 1 + elif self.agent.x + 1 < COLS: + self.agent.x += 1 + self.goingDown = not self.goingDown diff --git a/Engine/__pycache__/Agent.cpython-39.pyc b/Engine/__pycache__/Agent.cpython-39.pyc new file mode 100644 index 00000000..56cfba29 Binary files /dev/null and b/Engine/__pycache__/Agent.cpython-39.pyc differ diff --git a/Engine/__pycache__/Board.cpython-39.pyc b/Engine/__pycache__/Board.cpython-39.pyc index 97cdcb48..e364f527 100644 Binary files a/Engine/__pycache__/Board.cpython-39.pyc and b/Engine/__pycache__/Board.cpython-39.pyc differ diff --git a/Engine/__pycache__/Game.cpython-39.pyc b/Engine/__pycache__/Game.cpython-39.pyc index 7d034d0e..7f8a4281 100644 Binary files a/Engine/__pycache__/Game.cpython-39.pyc and b/Engine/__pycache__/Game.cpython-39.pyc differ diff --git a/Engine/agent.png b/Engine/agent.png new file mode 100644 index 00000000..2277efef Binary files /dev/null and b/Engine/agent.png differ diff --git a/Engine/bomb.png b/Engine/bomb.png new file mode 100644 index 00000000..429eb78b Binary files /dev/null and b/Engine/bomb.png differ diff --git a/__pycache__/Constants.cpython-39.pyc b/__pycache__/Constants.cpython-39.pyc index 1324c8bd..54da7c20 100644 Binary files a/__pycache__/Constants.cpython-39.pyc and b/__pycache__/Constants.cpython-39.pyc differ diff --git a/main.py b/main.py index 20d61933..3c7e0a54 100644 --- a/main.py +++ b/main.py @@ -9,17 +9,19 @@ FPS = 60 def main(): run = True clock = pygame.time.Clock() + game = Game(WIN) while run: pygame.init() - game = Game(WIN) clock.tick(FPS) for event in pygame.event.get(): if event.type == pygame.QUIT: run = False + + pygame.time.delay(200) + game.move() game.update() - pygame.display.update() main() \ No newline at end of file