25
25
import tcod .render
26
26
import tcod .sdl .mouse
27
27
import tcod .sdl .render
28
+ from tcod import libtcodpy
28
29
29
30
# ruff: noqa: S311
30
31
@@ -746,76 +747,76 @@ def on_draw(self) -> None:
746
747
for y in range (SAMPLE_SCREEN_HEIGHT ):
747
748
for x in range (SAMPLE_SCREEN_WIDTH ):
748
749
if SAMPLE_MAP [x , y ] != "#" :
749
- tcod .console_set_char_background (
750
+ libtcodpy .console_set_char_background (
750
751
sample_console ,
751
752
x ,
752
753
y ,
753
- tcod .color_lerp ( # type: ignore
754
+ libtcodpy .color_lerp ( # type: ignore
754
755
LIGHT_GROUND ,
755
756
DARK_GROUND ,
756
- 0.9 * tcod .dijkstra_get_distance (self .dijkstra , x , y ) / self .dijkstra_dist ,
757
+ 0.9 * libtcodpy .dijkstra_get_distance (self .dijkstra , x , y ) / self .dijkstra_dist ,
757
758
),
758
759
tcod .BKGND_SET ,
759
760
)
760
- for i in range (tcod .dijkstra_size (self .dijkstra )):
761
- x , y = tcod .dijkstra_get (self .dijkstra , i )
762
- tcod .console_set_char_background (sample_console , x , y , LIGHT_GROUND , tcod .BKGND_SET )
761
+ for i in range (libtcodpy .dijkstra_size (self .dijkstra )):
762
+ x , y = libtcodpy .dijkstra_get (self .dijkstra , i )
763
+ libtcodpy .console_set_char_background (sample_console , x , y , LIGHT_GROUND , tcod . constants .BKGND_SET )
763
764
764
765
# move the creature
765
766
self .busy -= frame_length [- 1 ]
766
767
if self .busy <= 0.0 :
767
768
self .busy = 0.2
768
769
if self .using_astar :
769
- if not tcod .path_is_empty (self .path ):
770
- tcod .console_put_char (sample_console , self .px , self .py , " " , tcod .BKGND_NONE )
771
- self .px , self .py = tcod .path_walk (self .path , True ) # type: ignore
772
- tcod .console_put_char (sample_console , self .px , self .py , "@" , tcod .BKGND_NONE )
770
+ if not libtcodpy .path_is_empty (self .path ):
771
+ libtcodpy .console_put_char (sample_console , self .px , self .py , " " , tcod . constants .BKGND_NONE )
772
+ self .px , self .py = libtcodpy .path_walk (self .path , True ) # type: ignore
773
+ libtcodpy .console_put_char (sample_console , self .px , self .py , "@" , tcod . constants .BKGND_NONE )
773
774
else :
774
- if not tcod .dijkstra_is_empty (self .dijkstra ):
775
- tcod .console_put_char (sample_console , self .px , self .py , " " , tcod .BKGND_NONE )
776
- self .px , self .py = tcod .dijkstra_path_walk (self .dijkstra ) # type: ignore
777
- tcod .console_put_char (sample_console , self .px , self .py , "@" , tcod .BKGND_NONE )
775
+ if not libtcodpy .dijkstra_is_empty (self .dijkstra ):
776
+ libtcodpy .console_put_char (sample_console , self .px , self .py , " " , tcod . constants .BKGND_NONE )
777
+ self .px , self .py = libtcodpy .dijkstra_path_walk (self .dijkstra ) # type: ignore
778
+ libtcodpy .console_put_char (sample_console , self .px , self .py , "@" , tcod . constants .BKGND_NONE )
778
779
self .recalculate = True
779
780
780
781
def ev_keydown (self , event : tcod .event .KeyDown ) -> None :
781
782
if event .sym == tcod .event .KeySym .i and self .dy > 0 :
782
783
# destination move north
783
- tcod .console_put_char (sample_console , self .dx , self .dy , self .oldchar , tcod .BKGND_NONE )
784
+ libtcodpy .console_put_char (sample_console , self .dx , self .dy , self .oldchar , tcod . constants .BKGND_NONE )
784
785
self .dy -= 1
785
786
self .oldchar = sample_console .ch [self .dx , self .dy ]
786
- tcod .console_put_char (sample_console , self .dx , self .dy , "+" , tcod .BKGND_NONE )
787
+ libtcodpy .console_put_char (sample_console , self .dx , self .dy , "+" , tcod . constants .BKGND_NONE )
787
788
if SAMPLE_MAP [self .dx , self .dy ] == " " :
788
789
self .recalculate = True
789
790
elif event .sym == tcod .event .KeySym .k and self .dy < SAMPLE_SCREEN_HEIGHT - 1 :
790
791
# destination move south
791
- tcod .console_put_char (sample_console , self .dx , self .dy , self .oldchar , tcod .BKGND_NONE )
792
+ libtcodpy .console_put_char (sample_console , self .dx , self .dy , self .oldchar , tcod . constants .BKGND_NONE )
792
793
self .dy += 1
793
794
self .oldchar = sample_console .ch [self .dx , self .dy ]
794
- tcod .console_put_char (sample_console , self .dx , self .dy , "+" , tcod .BKGND_NONE )
795
+ libtcodpy .console_put_char (sample_console , self .dx , self .dy , "+" , tcod . constants .BKGND_NONE )
795
796
if SAMPLE_MAP [self .dx , self .dy ] == " " :
796
797
self .recalculate = True
797
798
elif event .sym == tcod .event .KeySym .j and self .dx > 0 :
798
799
# destination move west
799
- tcod .console_put_char (sample_console , self .dx , self .dy , self .oldchar , tcod .BKGND_NONE )
800
+ libtcodpy .console_put_char (sample_console , self .dx , self .dy , self .oldchar , tcod . constants .BKGND_NONE )
800
801
self .dx -= 1
801
802
self .oldchar = sample_console .ch [self .dx , self .dy ]
802
- tcod .console_put_char (sample_console , self .dx , self .dy , "+" , tcod .BKGND_NONE )
803
+ libtcodpy .console_put_char (sample_console , self .dx , self .dy , "+" , tcod . constants .BKGND_NONE )
803
804
if SAMPLE_MAP [self .dx , self .dy ] == " " :
804
805
self .recalculate = True
805
806
elif event .sym == tcod .event .KeySym .l and self .dx < SAMPLE_SCREEN_WIDTH - 1 :
806
807
# destination move east
807
- tcod .console_put_char (sample_console , self .dx , self .dy , self .oldchar , tcod .BKGND_NONE )
808
+ libtcodpy .console_put_char (sample_console , self .dx , self .dy , self .oldchar , tcod . constants .BKGND_NONE )
808
809
self .dx += 1
809
810
self .oldchar = sample_console .ch [self .dx , self .dy ]
810
- tcod .console_put_char (sample_console , self .dx , self .dy , "+" , tcod .BKGND_NONE )
811
+ libtcodpy .console_put_char (sample_console , self .dx , self .dy , "+" , tcod . constants .BKGND_NONE )
811
812
if SAMPLE_MAP [self .dx , self .dy ] == " " :
812
813
self .recalculate = True
813
814
elif event .sym == tcod .event .KeySym .TAB :
814
815
self .using_astar = not self .using_astar
815
816
if self .using_astar :
816
- tcod .console_print (sample_console , 1 , 4 , "Using : A* " )
817
+ libtcodpy .console_print (sample_console , 1 , 4 , "Using : A* " )
817
818
else :
818
- tcod .console_print (sample_console , 1 , 4 , "Using : Dijkstra" )
819
+ libtcodpy .console_print (sample_console , 1 , 4 , "Using : Dijkstra" )
819
820
self .recalculate = True
820
821
else :
821
822
super ().ev_keydown (event )
@@ -824,11 +825,11 @@ def ev_mousemotion(self, event: tcod.event.MouseMotion) -> None:
824
825
mx = event .tile .x - SAMPLE_SCREEN_X
825
826
my = event .tile .y - SAMPLE_SCREEN_Y
826
827
if 0 <= mx < SAMPLE_SCREEN_WIDTH and 0 <= my < SAMPLE_SCREEN_HEIGHT and (self .dx != mx or self .dy != my ):
827
- tcod .console_put_char (sample_console , self .dx , self .dy , self .oldchar , tcod .BKGND_NONE )
828
+ libtcodpy .console_put_char (sample_console , self .dx , self .dy , self .oldchar , tcod . constants .BKGND_NONE )
828
829
self .dx = mx
829
830
self .dy = my
830
831
self .oldchar = sample_console .ch [self .dx , self .dy ]
831
- tcod .console_put_char (sample_console , self .dx , self .dy , "+" , tcod .BKGND_NONE )
832
+ libtcodpy .console_put_char (sample_console , self .dx , self .dy , "+" , tcod . constants .BKGND_NONE )
832
833
if SAMPLE_MAP [self .dx , self .dy ] == " " :
833
834
self .recalculate = True
834
835
0 commit comments