From a8424a3859e10034283184f4605214ad437c76a2 Mon Sep 17 00:00:00 2001 From: s452635 Date: Sat, 17 Apr 2021 15:29:36 +0200 Subject: [PATCH] added sapper asset direction, moved blitting sapper to a separate function called from main --- display_assets.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ main.py | 12 +++++++++++- minefield.py | 7 ++----- 3 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 display_assets.py diff --git a/display_assets.py b/display_assets.py new file mode 100644 index 0000000..4582089 --- /dev/null +++ b/display_assets.py @@ -0,0 +1,47 @@ +import pygame + +import project_constants as const + + +# moved here from minefield +def calculate_screen_position(row, column): + + coords = ( + const.V_SCREEN_PADDING + const.V_TILE_SIZE * column, + const.V_SCREEN_PADDING + const.V_TILE_SIZE * row, + ) + + return coords + + +def display_sapper(sapper_x, sapper_y, sapper_dir): + + sapper_screen_coords = calculate_screen_position( + sapper_x, + sapper_y + ) + + if sapper_dir == const.Direction.UP: + const.SCREEN.blit( + const.ASSET_SAPPER, + sapper_screen_coords + ) + + if sapper_dir == const.Direction.RIGHT: + const.SCREEN.blit( + pygame.transform.rotate(const.ASSET_SAPPER, 90), + sapper_screen_coords + ) + + if sapper_dir == const.Direction.DOWN: + const.SCREEN.blit( + pygame.transform.rotate(const.ASSET_SAPPER, 180), + sapper_screen_coords + ) + + if sapper_dir == const.Direction.LEFT: + const.SCREEN.blit( + pygame.transform.rotate(const.ASSET_SAPPER, 270), + sapper_screen_coords + ) + diff --git a/main.py b/main.py index 2caf71d..a1febf5 100644 --- a/main.py +++ b/main.py @@ -5,6 +5,7 @@ from pyglet.gl import * # for blocky textures # other files of this project import project_constants as const import minefield as mf +from display_assets import display_sapper def main(): @@ -42,6 +43,15 @@ def main(): # draw tiles and mines minefield.draw(const.SCREEN) + + # sapper + display_sapper( + minefield.agent.position[0], + minefield.agent.position[1], + const.Direction.UP + ) + + # update graphics after blitting pygame.display.update() # ============== # @@ -58,7 +68,7 @@ def main(): # Depending on what key we press, the agent will move in that direction # DISCRETION : The only keys that are available are arrow keys - # DISCRETION : is_valid_move is a new brand funcation that now plays a critical role in movement of our Agent (It is NOT just the "check up" function anymore) + # DISCRETION : is_valid_move is a new brand function that now plays a critical role in movement of our Agent (It is NOT just the "check up" function anymore) if keys[pygame.K_RIGHT]: target_row, target_column = minefield.agent.go_right() minefield.is_valid_move(target_row, target_column) diff --git a/minefield.py b/minefield.py index a649f5a..0883a68 100644 --- a/minefield.py +++ b/minefield.py @@ -1,5 +1,4 @@ import json -import ctypes import agent as ag import project_constants as const import tile as tl @@ -82,10 +81,8 @@ class Minefield: # TODO: blit appropriate mine type # current icons don't represent actual types, thus every mine has the same icon (temporary solution) window.blit(mine_asset_options['A'], tile_screen_coords) - - # draw the sapper - sapper_screen_coords = self.calculate_screen_position(self.agent.position[0], self.agent.position[1]) - window.blit(const.ASSET_SAPPER, sapper_screen_coords) + + # draw the sapper has been moved to main # ================ # # === MOVEMENT === #