define a resource class for every entity that needs to be controlled on the game map
This commit is contained in:
@@ -5,6 +5,7 @@ from PIL import Image as _Image
|
|||||||
from PIL import ImageDraw as _ImageDraw
|
from PIL import ImageDraw as _ImageDraw
|
||||||
from utils import logs as _logs
|
from utils import logs as _logs
|
||||||
from bot_libs import syms as _bot_syms
|
from bot_libs import syms as _bot_syms
|
||||||
|
from entities import resource as _resource
|
||||||
|
|
||||||
|
|
||||||
class BrSimMap():
|
class BrSimMap():
|
||||||
@@ -43,7 +44,8 @@ class BrSimMap():
|
|||||||
for i in range(self.world_width):
|
for i in range(self.world_width):
|
||||||
#if i == 0 or i == self.world_width - 1: width.append(self.mountain_sym)
|
#if i == 0 or i == self.world_width - 1: width.append(self.mountain_sym)
|
||||||
#else: width.append(self.field_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):
|
for i in range(self.world_height):
|
||||||
#if i == 0 or i == self.world_height - 1: self.game_map.append(mon)
|
#if i == 0 or i == self.world_height - 1: self.game_map.append(mon)
|
||||||
#else: self.game_map.append(_copy.deepcopy(width))
|
#else: self.game_map.append(_copy.deepcopy(width))
|
||||||
@@ -53,18 +55,22 @@ class BrSimMap():
|
|||||||
def populate_map(self):
|
def populate_map(self):
|
||||||
for player in self.players:
|
for player in self.players:
|
||||||
p_coord_x, p_coord_y= player.get_coordinates()
|
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
|
self.game_map[p_coord_y][p_coord_x]= player
|
||||||
elif player.player_gender_is_male(): self.game_map[p_coord_y][p_coord_x]= self.player_male_sym
|
#if not player.is_alive(): self.game_map[p_coord_y][p_coord_x]= self.dead_player_sym
|
||||||
elif player.player_gender_is_female(): self.game_map[p_coord_y][p_coord_x]= self.player_female_sym
|
#elif player.player_gender_is_male(): self.game_map[p_coord_y][p_coord_x]= self.player_male_sym
|
||||||
else: self.game_map[p_coord_y][p_coord_x]= self.player_nonbinary_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:
|
for item in self.items:
|
||||||
i_coord_x, i_coord_y= item.get_coordinates()
|
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):
|
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
|
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)
|
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')
|
_logs.log_debug('_set_coordinates: collision, regenerate coordinates')
|
||||||
x= _random.randint(1, self.world_width -2)
|
x= _random.randint(1, self.world_width -2)
|
||||||
y= _random.randint(1, self.world_height -2)
|
y= _random.randint(1, self.world_height -2)
|
||||||
@@ -95,7 +101,15 @@ class BrSimMap():
|
|||||||
game_map= self.get_map_matrix()
|
game_map= self.get_map_matrix()
|
||||||
for y in game_map:
|
for y in game_map:
|
||||||
for x in y:
|
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'
|
res+= '\n'
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@@ -111,21 +125,23 @@ class BrSimMap():
|
|||||||
|
|
||||||
for y in range(self.world_height):
|
for y in range(self.world_height):
|
||||||
for x in range(self.world_width):
|
for x in range(self.world_width):
|
||||||
pixel= self.game_map[y][x]
|
resource= self.game_map[y][x]
|
||||||
if pixel == self.field_sym:
|
if not resource:
|
||||||
pixel_color= _bot_syms.MAP_IMAGE_FIELD
|
pixel_color= _bot_syms.MAP_IMAGE_FIELD
|
||||||
elif pixel == self.mountain_sym:
|
# XXX how to manage mountains? maybe another class?
|
||||||
pixel_color= _bot_syms.MAP_IMAGE_MOUNTAIN
|
#elif resource == self.mountain_sym:
|
||||||
elif pixel == self.item_sym:
|
#pixel_color= _bot_syms.MAP_IMAGE_MOUNTAIN
|
||||||
|
elif resource.is_item():
|
||||||
pixel_color= _bot_syms.MAP_IMAGE_ITEM
|
pixel_color= _bot_syms.MAP_IMAGE_ITEM
|
||||||
elif pixel == self.player_male_sym:
|
elif resource.is_player():
|
||||||
pixel_color= _bot_syms.MAP_IMAGE_PLAYER_MALE
|
if not resource.is_alive():
|
||||||
elif pixel == self.player_female_sym:
|
pixel_color= _bot_syms.MAP_IMAGE_DEATH_PLAYER
|
||||||
pixel_color= _bot_syms.MAP_IMAGE_PLAYER_FEMALE
|
elif resource.player_gender_is_male():
|
||||||
elif pixel == self.player_nonbinary_sym:
|
pixel_color= _bot_syms.MAP_IMAGE_PLAYER_MALE
|
||||||
pixel_color= _bot_syms.MAP_IMAGE_PLAYER_NONBINARY
|
elif resource.player_gender_is_female():
|
||||||
elif pixel == self.dead_player_sym:
|
pixel_color= _bot_syms.MAP_IMAGE_PLAYER_FEMALE
|
||||||
pixel_color= _bot_syms.MAP_IMAGE_DEATH_PLAYER
|
elif resource.player_gender_is_not_binary():
|
||||||
|
pixel_color= _bot_syms.MAP_IMAGE_PLAYER_NONBINARY
|
||||||
|
|
||||||
scaled_x_coord= x * scale_x
|
scaled_x_coord= x * scale_x
|
||||||
scaled_y_coord= y * scale_y
|
scaled_y_coord= y * scale_y
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ from entities import resource as _resource
|
|||||||
class BrSimPlayer(_resource.BrSimResource):
|
class BrSimPlayer(_resource.BrSimResource):
|
||||||
|
|
||||||
def __init__(self, name, inventory= None):
|
def __init__(self, name, inventory= None):
|
||||||
|
super()
|
||||||
self.id= str(_uuid.uuid4())
|
self.id= str(_uuid.uuid4())
|
||||||
self.name= name
|
self.name= name
|
||||||
self.stats= ''
|
self.stats= ''
|
||||||
|
|||||||
Reference in New Issue
Block a user