<s> import sys <EOL> import os <EOL> sys . path . insert ( <NUM_LIT:0> , os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT:..>' ) ) <EOL> testinfo = "<STR_LIT>" <EOL> tags = "<STR_LIT>" <EOL> import pyglet <EOL> from pyglet . window import key <EOL> pyglet . resource . path . append ( pyglet . resource . get_script_home ( ) ) <EOL> pyglet . resource . reindex ( ) <EOL> import cocos <EOL> import cocos . layer <EOL> from cocos import tiles , actions , layer <EOL> import cocos . sprite <EOL> class DriveCar ( actions . Driver ) : <EOL> def step ( self , dt ) : <EOL> self . target . rotation += ( keyboard [ key . RIGHT ] - keyboard [ key . LEFT ] ) * <NUM_LIT> * dt <EOL> self . target . acceleration = ( keyboard [ key . UP ] - keyboard [ key . DOWN ] ) * <NUM_LIT> <EOL> if keyboard [ key . SPACE ] : self . target . speed = <NUM_LIT:0> <EOL> super ( DriveCar , self ) . step ( dt ) <EOL> scroller . set_focus ( self . target . x , self . target . y ) <EOL> def tint_green_hexmap_borders ( hexmap ) : <EOL> columns = len ( hexmap . cells ) <EOL> rows = len ( hexmap . cells [ <NUM_LIT:0> ] ) <EOL> for col in [ <NUM_LIT:0> , columns - <NUM_LIT:1> ] : <EOL> for j in range ( rows ) : <EOL> hexmap . set_cell_color ( col , j , ( <NUM_LIT:0> , <NUM_LIT:255> , <NUM_LIT:0> ) ) <EOL> for col in range ( columns ) : <EOL> for k in [ <NUM_LIT:0> , rows - <NUM_LIT:1> ] : <EOL> hexmap . set_cell_color ( col , k , ( <NUM_LIT:0> , <NUM_LIT:255> , <NUM_LIT:0> ) ) <EOL> def main ( ) : <EOL> global keyboard , scroller , old_ij , old_cell , old_highlighted_color <EOL> from cocos . director import director <EOL> director . init ( width = <NUM_LIT> , height = <NUM_LIT> , autoscale = False , resizable = True ) <EOL> car_layer = layer . ScrollableLayer ( ) <EOL> car = cocos . sprite . Sprite ( '<STR_LIT>' ) <EOL> car_layer . add ( car ) <EOL> car . position = ( <NUM_LIT:200> , <NUM_LIT:100> ) <EOL> car . max_forward_speed = <NUM_LIT:200> <EOL> car . max_reverse_speed = - <NUM_LIT:100> <EOL> car . do ( DriveCar ( ) ) <EOL> scroller = layer . ScrollingManager ( ) <EOL> map_loaded = tiles . load ( '<STR_LIT>' ) <EOL> test_layer = map_loaded [ '<STR_LIT>' ] <EOL> tint_green_hexmap_borders ( test_layer ) <EOL> scroller . add ( test_layer ) <EOL> scroller . add ( car_layer ) <EOL> old_ij = '<STR_LIT>' <EOL> old_highlighted_color = None <EOL> old_cell = None <EOL> main_scene = cocos . scene . Scene ( scroller ) <EOL> keyboard = key . KeyStateHandler ( ) <EOL> director . window . push_handlers ( keyboard ) <EOL> def on_key_press ( key , modifier ) : <EOL> if key == pyglet . window . key . Z : <EOL> if scroller . scale == <NUM_LIT> : <EOL> scroller . do ( actions . ScaleTo ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> else : <EOL> scroller . do ( actions . ScaleTo ( <NUM_LIT> , <NUM_LIT:2> ) ) <EOL> elif key == pyglet . window . key . D : <EOL> test_layer . set_debug ( True ) <EOL> elif key == pyglet . window . key . Q : <EOL> tint_red_hexmap_borders ( test_layer ) <EOL> director . window . push_handlers ( on_key_press ) <EOL> def on_mouse_motion ( x , y , dx , dy ) : <EOL> global scroller , old_ij , old_cell , old_highlighted_color <EOL> vx , vy = scroller . pixel_from_screen ( x , y ) <EOL> ij = test_layer . get_key_at_pixel ( vx , vy ) <EOL> if ij == old_ij : <EOL> return <EOL> if old_cell : <EOL> p , q = old_ij <EOL> if old_highlighted_color is None : <EOL> test_layer . set_cell_color ( p , q , ( <NUM_LIT:255> , <NUM_LIT:255> , <NUM_LIT:255> ) ) <EOL> del old_cell . properties [ '<STR_LIT>' ] <EOL> else : <EOL> test_layer . set_cell_color ( p , q , old_highlighted_color [ : <NUM_LIT:3> ] ) <EOL> old_ij = ij <EOL> i , j = ij <EOL> print ( i , j ) <EOL> old_cell = test_layer . get_cell ( i , j ) <EOL> if old_cell is None : <EOL> return <EOL> old_highlighted_color = old_cell . properties . get ( '<STR_LIT>' , None ) <EOL> test_layer . set_cell_color ( i , j , ( <NUM_LIT:255> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> director . window . push_handlers ( on_mouse_motion ) <EOL> director . run ( main_scene ) <EOL> description = """<STR_LIT>""" <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> print ( description ) <EOL> main ( ) </s>
