''' ''' playfield tutorial - part 2 ''' The animated lemming ''' ''' by greg smith ''' ''' ''' use c coordinates ''' OPTION C_COORDS dim x as int 'position of lemming from 0-480 dim y as int 'position of lemming from 0-300 dim z_dir as int 'which direction of lemming dim z_cnt as int 'animation image of lemming dim sprite_field as int 'the sprite number of the playfield sprites dim sprite_lemming as int 'the sprite number of the lemming sprites dim lemming_left as int 'index into lemming sprite for going left dim lemming_right as int 'index into lemming sprite for going right dim lemming_up as int 'index into lemming sprite for going up dim lemming_down as int 'index into lemming sprite for going down ''' ''' initialization ''' sub init sprite_field = 0 'playfield sprite sprite_lemming = 31 'lemming sprite is largest possible sprite - on top lemming_left=0 'lemming left image lemming_right=5 'lemming right image lemming_up=10 'lemming up image lemming_down=15 'lemming down image ''' ''' the playfield sprite has 9 bitmaps ''' one for each of the different areas of the ''' playfield sprite sprite_field, "playfield.pic" ''' ''' the lemming has 20 bitmaps 5 for each direction sprite sprite_lemming, "lemming.pic" ''' ''' the lemming can be anywhere on the playfield from ''' x = 0-480 ''' y = 0-300 x=240 'center of the playfield y=150 'center of the playfield z_dir=lemming_right ' lemming faces right z_cnt=0 ' animation counter end sub sub repaint dim field_x as int '0,1,2 for the horizontal bitmap dim field_y as int '0,1,2 for the vertical bitmap dim field as int '0-8 for the bitmap currently visible dim lemming_x as int '0-159 for the x coord on the screen dim lemming_y as int '0-99 for the y coord on the screen field_x = x / 160 ' compute the horizontal bitmap field_y = y / 100 ' compute the vertical bitmap field = field_y*3 + field_x ' combine them to compute the bitmap number lemming_x = x mod 160 ' compute the lemming's position on the screen lemming_y = y mod 100 ' compute the lemming's position on the screen move sprite_field, 0, 0, field 'display the current field move sprite_lemming, lemming_x, lemming_y, z_dir+z_cnt 'display the lemming paper white 'transparent color for the lemming redraw 'redraw all the sprites end sub ''' ''' increment the z_cnt variable ''' sub update_z_cnt z_cnt=(z_cnt+1) MOD 5 end sub ''' ''' process the keyboard ''' sub get_keys if key(#KEY_UP) then 'move the lemming up y=y-3 z_dir=lemming_up update_z_cnt end if if key(#KEY_DOWN) then 'move the lemming down y=y+3 z_dir=lemming_down update_z_cnt end if if key(#KEY_LEFT) then 'move the lemming left x=x-3 z_dir=lemming_left update_z_cnt end if if key(#KEY_RIGHT) then 'move the lemming right x=x+3 z_dir=lemming_right update_z_cnt end if end sub ''' ''' main subroutine ''' sub mainsub init while true repaint get_keys wend end sub ''' ''' call the main subroutine ''' mainsub