added sapper asset direction, moved blitting sapper to a separate function called from main
This commit is contained in:
parent
1d9a07a7ce
commit
a8424a3859
47
display_assets.py
Normal file
47
display_assets.py
Normal file
@ -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
|
||||||
|
)
|
||||||
|
|
12
main.py
12
main.py
@ -5,6 +5,7 @@ from pyglet.gl import * # for blocky textures
|
|||||||
# other files of this project
|
# other files of this project
|
||||||
import project_constants as const
|
import project_constants as const
|
||||||
import minefield as mf
|
import minefield as mf
|
||||||
|
from display_assets import display_sapper
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@ -42,6 +43,15 @@ def main():
|
|||||||
|
|
||||||
# draw tiles and mines
|
# draw tiles and mines
|
||||||
minefield.draw(const.SCREEN)
|
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()
|
pygame.display.update()
|
||||||
|
|
||||||
# ============== #
|
# ============== #
|
||||||
@ -58,7 +68,7 @@ def main():
|
|||||||
|
|
||||||
# Depending on what key we press, the agent will move in that direction
|
# Depending on what key we press, the agent will move in that direction
|
||||||
# DISCRETION : The only keys that are available are arrow keys
|
# 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]:
|
if keys[pygame.K_RIGHT]:
|
||||||
target_row, target_column = minefield.agent.go_right()
|
target_row, target_column = minefield.agent.go_right()
|
||||||
minefield.is_valid_move(target_row, target_column)
|
minefield.is_valid_move(target_row, target_column)
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import json
|
import json
|
||||||
import ctypes
|
|
||||||
import agent as ag
|
import agent as ag
|
||||||
import project_constants as const
|
import project_constants as const
|
||||||
import tile as tl
|
import tile as tl
|
||||||
@ -83,9 +82,7 @@ class Minefield:
|
|||||||
# current icons don't represent actual types, thus every mine has the same icon (temporary solution)
|
# 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)
|
window.blit(mine_asset_options['A'], tile_screen_coords)
|
||||||
|
|
||||||
# draw the sapper
|
# draw the sapper has been moved to main
|
||||||
sapper_screen_coords = self.calculate_screen_position(self.agent.position[0], self.agent.position[1])
|
|
||||||
window.blit(const.ASSET_SAPPER, sapper_screen_coords)
|
|
||||||
|
|
||||||
# ================ #
|
# ================ #
|
||||||
# === MOVEMENT === #
|
# === MOVEMENT === #
|
||||||
|
Loading…
Reference in New Issue
Block a user