1
0

define a resource class for every entity that needs to be controlled on the game map

This commit is contained in:
andrea
2025-08-01 22:24:38 +02:00
parent a5831085ba
commit c6c53caeee
2 changed files with 38 additions and 21 deletions

View File

@@ -5,6 +5,7 @@ from PIL import Image as _Image
from PIL import ImageDraw as _ImageDraw
from utils import logs as _logs
from bot_libs import syms as _bot_syms
from entities import resource as _resource
class BrSimMap():
@@ -43,7 +44,8 @@ class BrSimMap():
for i in range(self.world_width):
#if i == 0 or i == self.world_width - 1: width.append(self.mountain_sym)
#else: width.append(self.field_sym)
width.append(self.field_sym)
width.append(None)
#width.append(self.field_sym)
for i in range(self.world_height):
#if i == 0 or i == self.world_height - 1: self.game_map.append(mon)
#else: self.game_map.append(_copy.deepcopy(width))
@@ -53,18 +55,22 @@ class BrSimMap():
def populate_map(self):
for player in self.players:
p_coord_x, p_coord_y= player.get_coordinates()
if not player.is_alive(): self.game_map[p_coord_y][p_coord_x]= self.dead_player_sym
elif player.player_gender_is_male(): self.game_map[p_coord_y][p_coord_x]= self.player_male_sym
elif player.player_gender_is_female(): self.game_map[p_coord_y][p_coord_x]= self.player_female_sym
else: self.game_map[p_coord_y][p_coord_x]= self.player_nonbinary_sym
self.game_map[p_coord_y][p_coord_x]= player
#if not player.is_alive(): self.game_map[p_coord_y][p_coord_x]= self.dead_player_sym
#elif player.player_gender_is_male(): self.game_map[p_coord_y][p_coord_x]= self.player_male_sym
#elif player.player_gender_is_female(): self.game_map[p_coord_y][p_coord_x]= self.player_female_sym
#else: self.game_map[p_coord_y][p_coord_x]= self.player_nonbinary_sym
for item in self.items:
i_coord_x, i_coord_y= item.get_coordinates()
self.game_map[i_coord_y][i_coord_x]= self.item_sym
self.game_map[p_coord_y][p_coord_x]= item
#self.game_map[i_coord_y][i_coord_x]= self.item_sym
def _set_coordinates(self, target):
x= _random.randint(1, self.world_width -2) # from 1 to width-2 because 1 cell is occupied by the mountain
y= _random.randint(1, self.world_height -2)
while self.get_map_matrix()[y][x] != self.field_sym:
resource= self.get_map_matrix()[y][x]
while resource:
#while self.get_map_matrix()[y][x] != self.field_sym:
_logs.log_debug('_set_coordinates: collision, regenerate coordinates')
x= _random.randint(1, self.world_width -2)
y= _random.randint(1, self.world_height -2)
@@ -95,7 +101,15 @@ class BrSimMap():
game_map= self.get_map_matrix()
for y in game_map:
for x in y:
res+= x
if not x: el= self.field_sym
#XXX how to manage mountains?
elif x.is_player():
if x.player_gender_is_male(): el= self.player_male_sym
elif x.player_gender_is_female(): el= self.player_female_sym
else: el= self.player_nonbinary_sym
elif x.is_item():
el= self.item_sym
res+= el
res+= '\n'
return res
@@ -111,21 +125,23 @@ class BrSimMap():
for y in range(self.world_height):
for x in range(self.world_width):
pixel= self.game_map[y][x]
if pixel == self.field_sym:
resource= self.game_map[y][x]
if not resource:
pixel_color= _bot_syms.MAP_IMAGE_FIELD
elif pixel == self.mountain_sym:
pixel_color= _bot_syms.MAP_IMAGE_MOUNTAIN
elif pixel == self.item_sym:
# XXX how to manage mountains? maybe another class?
#elif resource == self.mountain_sym:
#pixel_color= _bot_syms.MAP_IMAGE_MOUNTAIN
elif resource.is_item():
pixel_color= _bot_syms.MAP_IMAGE_ITEM
elif pixel == self.player_male_sym:
pixel_color= _bot_syms.MAP_IMAGE_PLAYER_MALE
elif pixel == self.player_female_sym:
pixel_color= _bot_syms.MAP_IMAGE_PLAYER_FEMALE
elif pixel == self.player_nonbinary_sym:
pixel_color= _bot_syms.MAP_IMAGE_PLAYER_NONBINARY
elif pixel == self.dead_player_sym:
pixel_color= _bot_syms.MAP_IMAGE_DEATH_PLAYER
elif resource.is_player():
if not resource.is_alive():
pixel_color= _bot_syms.MAP_IMAGE_DEATH_PLAYER
elif resource.player_gender_is_male():
pixel_color= _bot_syms.MAP_IMAGE_PLAYER_MALE
elif resource.player_gender_is_female():
pixel_color= _bot_syms.MAP_IMAGE_PLAYER_FEMALE
elif resource.player_gender_is_not_binary():
pixel_color= _bot_syms.MAP_IMAGE_PLAYER_NONBINARY
scaled_x_coord= x * scale_x
scaled_y_coord= y * scale_y

View File

@@ -5,6 +5,7 @@ from entities import resource as _resource
class BrSimPlayer(_resource.BrSimResource):
def __init__(self, name, inventory= None):
super()
self.id= str(_uuid.uuid4())
self.name= name
self.stats= ''