I have a question about the classes, is it about if having two classes (a father and another daughter) could get a list (global) that is in the father and join new elements from the daughter?
And if that is how I could do it, then I have managed to access the list I wanted but when it comes to joining elements to that list, the ones that had already appeared do not appear and I do not know if it is because I really take the list I want or because when joining elements in some way the previous ones are eliminated. The doubt arose as a result of this:
class Galapago:
tortugas=[]
l_line=drawlib.make_line_list()
l_sprite= drawlib.make_sprite_list()
def __init__(self):
drawlib.start_render()
sprite=drawlib.make_sprite("/home/Documentos/Proyecto2/ship (6).png",0.5)
drawlib.set_center_x(sprite,0)
drawlib.set_center_y(sprite,0)
drawlib.set_angle(sprite,90)
drawlib.finish_render()
self.x= 0
self.y= 0
self.angle= 90
self.color= colors.BLACK
self.widht= 1
self.sprite=sprite
self.pen= 1 #con el 1 pintará con el 0 no hara nada
Galapago.l_sprite.append(self.sprite)
the daughter class would be:
class Radio_Galapago(galapagoo.Galapago):
def __init__(self):
drawlib.start_render()
self.sprite=drawlib.make_sprite("/home/Documentos/Proyecto2/microbit.png",0.1)
n= random.randint(0,768)
x=drawlib.set_center_x(self.sprite,n)
y=drawlib.set_center_y(self.sprite,n)
drawlib.set_angle(self.sprite,0)
drawlib.draw_sprite(self.sprite)
drawlib.finish_render()
galapagoo.Galapago.l_sprite.append(self.sprite)
When I do this if I send print(l_sprite)
I only see one element
The code that I am trying to create from these two classes and that is therefore giving me error is the following:
import Radio_Galapago
import galapagoo
import drawlib
import colors
drawlib.open_window(1024, 768, "Prueba Radio_Galapago")
drawlib.set_background_color(colors.OCEAN_BOAT_BLUE)
alex=galapagoo.Galapago()
microbit=Radio_Galapago.Radio_Galapago()
senal=microbit.power_ratio(alex)
print(galapagoo.Galapago.l_sprite)
print(Galapago.l_sprite)
def pintar(tortuga, microbit):
drawlib.start_render()
drawlib.draw_list(Galapago.l_sprite)
drawlib.finish_render()
drawlib.pause(5)
"""def buscar(self,busca_senal):
drawlib.start_render()
drawlib.draw_list(pintar)
busca_senal.forward(100)
while senal < (-50):
drawlib.start_render()
drawlib.draw_list(pintar)
senal_1= self.power_ratio(busca_senal)
drawlib.finish_render()
if senal_1 < senal:
drawlib.start_render()
drawlib.draw_list(pintar)
busca_senal.forward(100)
drawlib.finish_render()
elif self.power_ratio(busca_senal)> senal_1:
busca_senal.right(25)
busca_senals.forward(100)
drawlib.finish_render()
drawlib.pause(3)"""
alex.penup()
pintar(alex,microbit)
#buscar(microbit, alex)