Compare commits
3 Commits
9ad177b459
...
18bccfded8
| Author | SHA256 | Date | |
|---|---|---|---|
|
|
18bccfded8 | ||
|
|
c6c53caeee | ||
|
|
a5831085ba |
@@ -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():
|
||||||
@@ -44,7 +45,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,23 +55,27 @@ 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_player_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_item_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)
|
||||||
target.set_player_coordinates(x, y)
|
target.set_coordinates(x, y)
|
||||||
|
|
||||||
def init_players_coordinates(self):
|
def init_players_coordinates(self):
|
||||||
for player in self.players:
|
for player in self.players:
|
||||||
@@ -109,7 +115,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
|
||||||
|
|
||||||
@@ -125,21 +139,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
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
import random as _random
|
import random as _random
|
||||||
|
from entities import resource as _resource
|
||||||
|
|
||||||
class BrSimItem():
|
class BrSimItem(_resource.BrSimResource):
|
||||||
|
|
||||||
# test
|
# test
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.coord_x= 0
|
self.coord_x= 0
|
||||||
self.coord_y= 0
|
self.coord_y= 0
|
||||||
|
|
||||||
|
def is_item(self):
|
||||||
|
return True
|
||||||
|
|
||||||
def get_name(self):
|
def get_name(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
@@ -21,10 +25,3 @@ class BrSimItem():
|
|||||||
|
|
||||||
def is_cure(self):
|
def is_cure(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_item_coordinates(self):
|
|
||||||
return self.coord_x, self.coord_y
|
|
||||||
|
|
||||||
def set_item_coordinates(self, x, y):
|
|
||||||
self.coord_x= x
|
|
||||||
self.coord_y= y
|
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import random as _random
|
import random as _random
|
||||||
import uuid as _uuid
|
import uuid as _uuid
|
||||||
|
from entities import resource as _resource
|
||||||
|
|
||||||
class BrSimPlayer():
|
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= ''
|
||||||
@@ -19,18 +21,12 @@ class BrSimPlayer():
|
|||||||
self.equipped_weapon= None
|
self.equipped_weapon= None
|
||||||
self.gender= _random.sample(['m', 'f', '-'], 1)[0] # for now get a random gender
|
self.gender= _random.sample(['m', 'f', '-'], 1)[0] # for now get a random gender
|
||||||
self.reputation= 50 #Like RDR2 the player can be evil(0) or good(100). This should influence the sponsors and internal alliance
|
self.reputation= 50 #Like RDR2 the player can be evil(0) or good(100). This should influence the sponsors and internal alliance
|
||||||
self.coord_x= 0
|
|
||||||
self.coord_y= 0
|
def is_player(self):
|
||||||
|
return True
|
||||||
|
|
||||||
### control methods
|
### control methods
|
||||||
|
|
||||||
def get_player_coordinates(self):
|
|
||||||
return self.coord_x, self.coord_y
|
|
||||||
|
|
||||||
def set_player_coordinates(self, x, y):
|
|
||||||
self.coord_x= x
|
|
||||||
self.coord_y= y
|
|
||||||
|
|
||||||
def get_name_and_stats(self):
|
def get_name_and_stats(self):
|
||||||
health= '♥️' * self.health or '☠️'
|
health= '♥️' * self.health or '☠️'
|
||||||
strength= '⚔️' * self.damage
|
strength= '⚔️' * self.damage
|
||||||
|
|||||||
18
entities/resource.py
Normal file
18
entities/resource.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
class BrSimResource():
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.coord_x= 0
|
||||||
|
self.coord_y= 0
|
||||||
|
|
||||||
|
def is_player(self):
|
||||||
|
return False
|
||||||
|
|
||||||
|
def is_item(self):
|
||||||
|
return False
|
||||||
|
|
||||||
|
def get_coordinates(self):
|
||||||
|
return self.coord_x, self.coord_y
|
||||||
|
|
||||||
|
def set_coordinates(self, x, y):
|
||||||
|
self.coord_x= x
|
||||||
|
self.coord_y= y
|
||||||
Reference in New Issue
Block a user