@ -28,9 +28,21 @@ class GameWindow:
def load_image ( self , path , transparent_color = None ) :
def load_image ( self , path , transparent_color = None ) :
image_path = os . path . join ( os . path . dirname ( __file__ ) , " .. " , " assets " , path )
image_path = os . path . join ( os . path . dirname ( __file__ ) , " .. " , " assets " , path )
image = sdl2 . ext . load_image ( image_path )
image = Image . open ( image_path )
if transparent_color :
image = image . convert ( " RGBA " )
datas = image . getdata ( )
new_data = [ ]
for item in datas :
if item [ : 3 ] == transparent_color :
new_data . append ( ( 255 , 255 , 255 , 0 ) )
else :
new_data . append ( item )
image . putdata ( new_data )
# Ridimensiona l'immagine in base a cell_size
# Ridimensiona l'immagine in base a cell_size
return self . factory . from_surface ( image )
scale = self . cell_size / / 20
image = image . resize ( ( image . width * scale , image . height * scale ) , Image . NEAREST )
return self . factory . from_surface ( sdl2 . ext . pillow_to_surface ( image ) )
def draw_text ( self , text , font , position , color ) :
def draw_text ( self , text , font , position , color ) :
sprite = self . factory . from_text ( text , color = color , fontmanager = font )
sprite = self . factory . from_text ( text , color = color , fontmanager = font )
@ -42,7 +54,7 @@ class GameWindow:
def draw_image ( self , x , y , sprite , tag , anchor = " nw " ) :
def draw_image ( self , x , y , sprite , tag , anchor = " nw " ) :
sprite . position = ( x , y )
sprite . position = ( x , y )
self . renderer . copy ( sprite , dstrect = ( x , y , sprite . size [ 0 ] , sprite . size [ 1 ] ) )
self . renderer . copy ( sprite , dstrect = sprite . position )
def draw_rectangle ( self , x , y , width , height , tag , outline = " red " ) :
def draw_rectangle ( self , x , y , width , height , tag , outline = " red " ) :
self . renderer . draw_rect ( ( x , y , width , height ) , color = sdl2 . ext . Color ( 255 , 0 , 0 ) )
self . renderer . draw_rect ( ( x , y , width , height ) , color = sdl2 . ext . Color ( 255 , 0 , 0 ) )