Mapa i spacerujacy po niej agent

This commit is contained in:
Justyna Wojsz 2021-03-15 11:14:56 +01:00
parent 6685798f74
commit b3ce8e812c
6 changed files with 39 additions and 30 deletions

Binary file not shown.

View File

@ -5,14 +5,29 @@ try:
except (ModuleNotFoundError, ImportError):
from constans import GREEN,GREEN_2,WHITE,ROWS,COLUMNS,SQUARE_SIZE
#sth goes wrong with imports so its for preventing errors
try:
from .piece import *
except (ModuleNotFoundError, ImportError):
from piece import *
#from .constans import GREEN,GREEN_2,WHITE,ROWS,COLUMNS,SQUARE_SIZE
class Board:
def __init__(self):
self.board = []
self.board = [[0 for j in range(COLUMNS)] for i in range(ROWS)]
for x in range(ROWS):
for y in range(COLUMNS):
self.board[x][y]=Piece(x,y)
def get_piece(self,x,y):
print(self.board[x][y], x, y)
return self.board[x][y]
def draw_squares(self,win):
win.fill(GREEN_2)
for row in range(ROWS):
for col in range(row % 2, ROWS, 2):
for col in range(row % 2, ROWS, 2):
pygame.draw.rect(win,GREEN,(row*SQUARE_SIZE, col*SQUARE_SIZE, SQUARE_SIZE,SQUARE_SIZE))

View File

@ -1,29 +1,15 @@
class Piece:
PADDING = 10
OUTLINE = 2
def __init__(self,row,col,color):
def __init__(self,row,col):
self.row = row
self.col = col
self.color = color
self.free = True
if self.color == GREEN:
self.direction = -1
else:
self.direction = 1
self.x = 0
self.y = 0
self.claculate_position()
def claculate_position(self):
self.x = SQUARE_SIZE * self.col + SQUARE_SIZE // 2
self.y = SQUARE_SIZE * self.row + SQUARE_SIZE // 2
def draw(self,win):
radius = SQUARE_SIZE//2 - self.PADDING
pygame.draw.circle(win,self.color, (self.x, self.y),radius + self.OUTLINE)
pygame.draw.circle(win,self.color, (self.x, self.y),radius)
self.mushroom = False
self.isSbThere = False
def change_status(self):
print(self.isSbThere, self.row, self.col)
self.isSbThere = not self.isSbThere

16
main.py
View File

@ -1,5 +1,5 @@
import pygame
from container.constans import WIDTH, HEIGHT,SQUARE_SIZE
from container.constans import WIDTH, HEIGHT,SQUARE_SIZE,ROWS,COLUMNS
from container.board import Board
FPS = 8
@ -14,13 +14,17 @@ detective =pygame.image.load(r'C:\Users\ledio\Desktop\projekt si\container\detec
def main():
run = True
clock = pygame.time.Clock() #for fps
board = Board()
#board.manage_rows_and_col(ROWS,COLUMNS)
#agent location
#managing agent location
current_column = 0
current_row = 0
current_piece = board.get_piece(current_row,current_column)
current_piece.change_status()
#calculate desireable location to pixels
def claculate_position(x,y):
@ -42,10 +46,14 @@ def main():
current_column -= 1
if key_input[pygame.K_UP] and current_row != 0:
current_row -= 1
if key_input[pygame.K_RIGHT] and current_column != 9:
if key_input[pygame.K_RIGHT] and current_column != COLUMNS - 1:
current_column += 1
if key_input[pygame.K_DOWN] and current_row != 5:
if key_input[pygame.K_DOWN] and current_row != 6 - 1:
current_row += 1
current_piece.change_status()
current_piece = board.get_piece(current_row,current_column)
current_piece.change_status()
board.draw_squares(WIN)
WIN.blit(detective, (claculate_position(current_column,current_row)[0], claculate_position(current_column,current_row)[1]))