6363tileset : tcod .tileset .Tileset
6464console_render : tcod .render .SDLConsoleRender # Optional SDL renderer.
6565sample_minimap : tcod .sdl .render .Texture # Optional minimap texture.
66- root_console = tcod .console .Console (80 , 50 , order = "F" )
67- sample_console = tcod .console .Console (SAMPLE_SCREEN_WIDTH , SAMPLE_SCREEN_HEIGHT , order = "F" )
66+ root_console = tcod .console .Console (80 , 50 )
67+ sample_console = tcod .console .Console (SAMPLE_SCREEN_WIDTH , SAMPLE_SCREEN_HEIGHT )
6868cur_sample = 0 # Current selected sample.
6969frame_times = [time .perf_counter ()]
7070frame_length = [0.0 ]
@@ -156,9 +156,9 @@ def get_corner_colors(self) -> NDArray[np.uint8]:
156156 def interpolate_corner_colors (self ) -> None :
157157 """Interpolate corner colors across the sample console."""
158158 colors = self .get_corner_colors ()
159- left = np .linspace (colors [0 ], colors [2 ], SAMPLE_SCREEN_HEIGHT )
160- right = np .linspace (colors [1 ], colors [3 ], SAMPLE_SCREEN_HEIGHT )
161- sample_console .bg [:] = np .linspace (left , right , SAMPLE_SCREEN_WIDTH )
159+ top = np .linspace (colors [0 ], colors [1 ], SAMPLE_SCREEN_WIDTH )
160+ bottom = np .linspace (colors [2 ], colors [3 ], SAMPLE_SCREEN_WIDTH )
161+ sample_console .bg [:] = np .linspace (top , bottom , SAMPLE_SCREEN_HEIGHT )
162162
163163 def darken_background_characters (self ) -> None :
164164 """Darken background characters."""
@@ -265,12 +265,12 @@ def __init__(self) -> None:
265265 self .mk_flag = libtcodpy .BKGND_SET
266266 self .bk_flag = libtcodpy .BKGND_SET
267267
268- self .bk = tcod .console .Console (sample_console .width , sample_console .height , order = "F" )
268+ self .background = tcod .console .Console (sample_console .width , sample_console .height )
269269 # initialize the colored background
270- self .bk .bg [:, :, 0 ] = np .linspace (0 , 255 , self .bk .width )[:, np . newaxis ]
271- self .bk .bg [:, :, 2 ] = np .linspace (0 , 255 , self .bk .height )
272- self .bk .bg [:, :, 1 ] = (self .bk .bg [:, :, 0 ].astype (int ) + self .bk .bg [:, :, 2 ]) / 2
273- self .bk .ch [:] = ord (" " )
270+ self .background .bg [:, :, 0 ] = np .linspace (0 , 255 , self .background .width )
271+ self .background .bg [:, :, 2 ] = np .linspace (0 , 255 , self .background .height )[:, np . newaxis ]
272+ self .background .bg [:, :, 1 ] = (self .background .bg [:, :, 0 ].astype (int ) + self .background .bg [:, :, 2 ]) / 2
273+ self .background .ch [:] = ord (" " )
274274
275275 def ev_keydown (self , event : tcod .event .KeyDown ) -> None :
276276 if event .sym in (tcod .event .KeySym .RETURN , tcod .event .KeySym .KP_ENTER ):
@@ -291,7 +291,7 @@ def on_draw(self) -> None:
291291 alpha = (1.0 + math .cos (time .time () * 2 )) / 2.0
292292 self .bk_flag = libtcodpy .BKGND_ADDALPHA (int (alpha ))
293293
294- self .bk .blit (sample_console )
294+ self .background .blit (sample_console )
295295 rect_y = int ((sample_console .height - 2 ) * ((1.0 + math .cos (time .time ())) / 2.0 ))
296296 for x in range (sample_console .width ):
297297 value = x * 255 // sample_console .width
@@ -429,8 +429,8 @@ def on_draw(self) -> None:
429429 bg = GREY ,
430430 bg_blend = libtcodpy .BKGND_MULTIPLY ,
431431 )
432- sample_console .fg [2 : 2 + rect_w , 2 : 2 + rect_h ] = (
433- sample_console .fg [2 : 2 + rect_w , 2 : 2 + rect_h ] * GREY / 255
432+ sample_console .fg [2 : 2 + rect_h , 2 : 2 + rect_w ] = (
433+ sample_console .fg [2 : 2 + rect_h , 2 : 2 + rect_w ] * GREY / 255
434434 )
435435
436436 for cur_func in range (len (self .NOISE_OPTIONS )):
@@ -524,7 +524,7 @@ def ev_keydown(self, event: tcod.event.KeyDown) -> None:
524524 "##############################################" ,
525525)
526526
527- SAMPLE_MAP : NDArray [Any ] = np .array ([[ord (c ) for c in line ] for line in SAMPLE_MAP_ ]). transpose ()
527+ SAMPLE_MAP : NDArray [Any ] = np .array ([[ord (c ) for c in line ] for line in SAMPLE_MAP_ ])
528528
529529FOV_ALGO_NAMES = (
530530 "BASIC " ,
@@ -558,12 +558,12 @@ def __init__(self) -> None:
558558 self .algo_num = libtcodpy .FOV_SYMMETRIC_SHADOWCAST
559559 self .noise = tcod .noise .Noise (1 ) # 1D noise for the torch flickering.
560560
561- map_shape = (SAMPLE_SCREEN_WIDTH , SAMPLE_SCREEN_HEIGHT )
561+ map_shape = (SAMPLE_SCREEN_HEIGHT , SAMPLE_SCREEN_WIDTH )
562562
563- self .walkable : NDArray [np .bool_ ] = np .zeros (map_shape , dtype = bool , order = "F" )
563+ self .walkable : NDArray [np .bool_ ] = np .zeros (map_shape , dtype = bool )
564564 self .walkable [:] = SAMPLE_MAP [:] == ord (" " )
565565
566- self .transparent : NDArray [np .bool_ ] = np .zeros (map_shape , dtype = bool , order = "F" )
566+ self .transparent : NDArray [np .bool_ ] = np .zeros (map_shape , dtype = bool )
567567 self .transparent [:] = self .walkable [:] | (SAMPLE_MAP [:] == ord ("=" ))
568568
569569 # Lit background colors for the map.
@@ -598,7 +598,7 @@ def on_draw(self) -> None:
598598 # Get a 2D boolean array of visible cells.
599599 fov = tcod .map .compute_fov (
600600 transparency = self .transparent ,
601- pov = (self .player_x , self .player_y ),
601+ pov = (self .player_y , self .player_x ),
602602 radius = TORCH_RADIUS if self .torch else 0 ,
603603 light_walls = self .light_walls ,
604604 algorithm = self .algo_num ,
@@ -614,7 +614,7 @@ def on_draw(self) -> None:
614614 brightness = 0.2 * self .noise .get_point (torch_t + 17 )
615615
616616 # Get the squared distance using a mesh grid.
617- x , y = np .mgrid [:SAMPLE_SCREEN_WIDTH , :SAMPLE_SCREEN_HEIGHT ]
617+ y , x = np .mgrid [:SAMPLE_SCREEN_HEIGHT , :SAMPLE_SCREEN_WIDTH ]
618618 # Center the mesh grid on the torch position.
619619 x = x .astype (np .float32 ) - torch_x
620620 y = y .astype (np .float32 ) - torch_y
@@ -659,7 +659,7 @@ def ev_keydown(self, event: tcod.event.KeyDown) -> None:
659659 }
660660 if event .sym in MOVE_KEYS :
661661 x , y = MOVE_KEYS [event .sym ]
662- if self .walkable [self .player_x + x , self .player_y + y ]:
662+ if self .walkable [self .player_y + y , self .player_x + x ]:
663663 self .player_x += x
664664 self .player_y += y
665665 elif event .sym == tcod .event .KeySym .T :
@@ -684,7 +684,7 @@ def __init__(self) -> None:
684684 self .dest_y = 1
685685 self .using_astar = True
686686 self .busy = 0.0
687- self .cost = SAMPLE_MAP . T [:] == ord (" " )
687+ self .cost = SAMPLE_MAP [:] == ord (" " )
688688 self .graph = tcod .path .SimpleGraph (cost = self .cost , cardinal = 70 , diagonal = 99 )
689689 self .pathfinder = tcod .path .Pathfinder (graph = self .graph )
690690
@@ -693,8 +693,8 @@ def __init__(self) -> None:
693693 # draw the dungeon
694694 self .background_console .rgb ["fg" ] = BLACK
695695 self .background_console .rgb ["bg" ] = DARK_GROUND
696- self .background_console .rgb ["bg" ][SAMPLE_MAP . T [:] == ord ("#" )] = DARK_WALL
697- self .background_console .rgb ["ch" ][SAMPLE_MAP . T [:] == ord ("=" )] = ord ("═" )
696+ self .background_console .rgb ["bg" ][SAMPLE_MAP [:] == ord ("#" )] = DARK_WALL
697+ self .background_console .rgb ["ch" ][SAMPLE_MAP [:] == ord ("=" )] = ord ("═" )
698698
699699 def on_enter (self ) -> None :
700700 """Do nothing."""
@@ -722,19 +722,19 @@ def on_draw(self) -> None:
722722 np .array (self .pathfinder .distance , copy = True , dtype = np .float32 )
723723 interpolate = self .pathfinder .distance [reachable ] * 0.9 / dijkstra_max_dist
724724 color_delta = (np .array (DARK_GROUND ) - np .array (LIGHT_GROUND )).astype (np .float32 )
725- sample_console .rgb . T ["bg" ][reachable ] = np .array (LIGHT_GROUND ) + interpolate [:, np .newaxis ] * color_delta
725+ sample_console .rgb ["bg" ][reachable ] = np .array (LIGHT_GROUND ) + interpolate [:, np .newaxis ] * color_delta
726726
727727 # draw the path
728- path = self .pathfinder .path_to ((self .dest_y , self .dest_x ))[1 :, :: - 1 ]
728+ path = self .pathfinder .path_to ((self .dest_y , self .dest_x ))[1 :]
729729 sample_console .rgb ["bg" ][tuple (path .T )] = LIGHT_GROUND
730730
731731 # move the creature
732732 self .busy -= frame_length [- 1 ]
733733 if self .busy <= 0.0 :
734734 self .busy = 0.2
735735 if len (path ):
736- self .player_x = int (path .item (0 , 0 ))
737- self .player_y = int (path .item (0 , 1 ))
736+ self .player_y = int (path .item (0 , 0 ))
737+ self .player_x = int (path .item (0 , 1 ))
738738
739739 def ev_keydown (self , event : tcod .event .KeyDown ) -> None :
740740 """Handle movement and UI."""
@@ -772,46 +772,46 @@ def ev_mousemotion(self, event: tcod.event.MouseMotion) -> None:
772772
773773
774774# draw a vertical line
775- def vline (m : NDArray [np .bool_ ], x : int , y1 : int , y2 : int ) -> None :
775+ def vline (map_ : NDArray [np .bool_ ], x : int , y1 : int , y2 : int ) -> None :
776776 if y1 > y2 :
777777 y1 , y2 = y2 , y1
778778 for y in range (y1 , y2 + 1 ):
779- m [ x , y ] = True
779+ map_ [ y , x ] = True
780780
781781
782782# draw a vertical line up until we reach an empty space
783- def vline_up (m : NDArray [np .bool_ ], x : int , y : int ) -> None :
784- while y >= 0 and not m [ x , y ]:
785- m [ x , y ] = True
783+ def vline_up (map_ : NDArray [np .bool_ ], x : int , y : int ) -> None :
784+ while y >= 0 and not map_ [ y , x ]:
785+ map_ [ y , x ] = True
786786 y -= 1
787787
788788
789789# draw a vertical line down until we reach an empty space
790- def vline_down (m : NDArray [np .bool_ ], x : int , y : int ) -> None :
791- while y < SAMPLE_SCREEN_HEIGHT and not m [ x , y ]:
792- m [ x , y ] = True
790+ def vline_down (map_ : NDArray [np .bool_ ], x : int , y : int ) -> None :
791+ while y < SAMPLE_SCREEN_HEIGHT and not map_ [ y , x ]:
792+ map_ [ y , x ] = True
793793 y += 1
794794
795795
796796# draw a horizontal line
797- def hline (m : NDArray [np .bool_ ], x1 : int , y : int , x2 : int ) -> None :
797+ def hline (map_ : NDArray [np .bool_ ], x1 : int , y : int , x2 : int ) -> None :
798798 if x1 > x2 :
799799 x1 , x2 = x2 , x1
800800 for x in range (x1 , x2 + 1 ):
801- m [ x , y ] = True
801+ map_ [ y , x ] = True
802802
803803
804804# draw a horizontal line left until we reach an empty space
805- def hline_left (m : NDArray [np .bool_ ], x : int , y : int ) -> None :
806- while x >= 0 and not m [ x , y ]:
807- m [ x , y ] = True
805+ def hline_left (map_ : NDArray [np .bool_ ], x : int , y : int ) -> None :
806+ while x >= 0 and not map_ [ y , x ]:
807+ map_ [ y , x ] = True
808808 x -= 1
809809
810810
811811# draw a horizontal line right until we reach an empty space
812- def hline_right (m : NDArray [np .bool_ ], x : int , y : int ) -> None :
813- while x < SAMPLE_SCREEN_WIDTH and not m [ x , y ]:
814- m [ x , y ] = True
812+ def hline_right (map_ : NDArray [np .bool_ ], x : int , y : int ) -> None :
813+ while x < SAMPLE_SCREEN_WIDTH and not map_ [ y , x ]:
814+ map_ [ y , x ] = True
815815 x += 1
816816
817817
@@ -829,7 +829,7 @@ def traverse_node(bsp_map: NDArray[np.bool_], node: tcod.bsp.BSP) -> None:
829829 node .y += random .randint (0 , node .height - new_height )
830830 node .width , node .height = new_width , new_height
831831 # dig the room
832- bsp_map [node .x : node .x + node .width , node .y : node .y + node .height ] = True
832+ bsp_map [node .y : node .y + node .height , node .x : node .x + node .width ] = True
833833 else :
834834 # resize the node to fit its sons
835835 left , right = node .children
@@ -877,7 +877,7 @@ class BSPSample(Sample):
877877
878878 def __init__ (self ) -> None :
879879 self .bsp = tcod .bsp .BSP (1 , 1 , SAMPLE_SCREEN_WIDTH - 1 , SAMPLE_SCREEN_HEIGHT - 1 )
880- self .bsp_map : NDArray [np .bool_ ] = np .zeros ((SAMPLE_SCREEN_WIDTH , SAMPLE_SCREEN_HEIGHT ), dtype = bool , order = "F" )
880+ self .bsp_map : NDArray [np .bool_ ] = np .zeros ((SAMPLE_SCREEN_HEIGHT , SAMPLE_SCREEN_WIDTH ), dtype = bool )
881881 self .bsp_generate ()
882882
883883 def bsp_generate (self ) -> None :
@@ -923,7 +923,7 @@ def on_draw(self) -> None:
923923 # render the level
924924 for y in range (SAMPLE_SCREEN_HEIGHT ):
925925 for x in range (SAMPLE_SCREEN_WIDTH ):
926- color = DARK_GROUND if self .bsp_map [x ][ y ] else DARK_WALL
926+ color = DARK_GROUND if self .bsp_map [y , x ] else DARK_WALL
927927 libtcodpy .console_set_char_background (sample_console , x , y , color , libtcodpy .BKGND_SET )
928928
929929 def ev_keydown (self , event : tcod .event .KeyDown ) -> None :
@@ -1274,7 +1274,7 @@ def on_draw(self) -> None:
12741274 bb = bb .clip (0 , 255 )
12751275
12761276 # fill the screen with these background colors
1277- sample_console .bg .transpose (2 , 1 , 0 )[...] = (rr , gg , bb )
1277+ sample_console .bg .transpose (2 , 0 , 1 )[...] = (rr , gg , bb )
12781278
12791279
12801280#############################################
@@ -1380,7 +1380,7 @@ def redraw_display() -> None:
13801380 context .sdl_renderer .draw_color = (0 , 0 , 0 , 255 )
13811381 context .sdl_renderer .clear ()
13821382 # SDL renderer support, upload the sample console background to a minimap texture.
1383- sample_minimap .update (sample_console .rgb . T ["bg" ])
1383+ sample_minimap .update (sample_console .rgb ["bg" ])
13841384 # Render the root_console normally, this is the drawing step of context.present without presenting.
13851385 context .sdl_renderer .copy (console_render .render (root_console ))
13861386 # Render the minimap to the screen.
0 commit comments