''' ''' playfield tutorial - part 1 ''' ''' by greg smith ''' ''' ''' use c coordinates ''' OPTION C_COORDS dim x as int 'position of car from 0-480 dim y as int 'position of car from 0-300 dim z as int 'which image of car dim sprite_field as int 'the sprite number of the playfield sprites dim sprite_car as int 'the sprite number of the car sprites dim car_left as int 'index into car sprite for going left dim car_right as int 'index into car sprite for going right dim car_up as int 'index into car sprite for going up dim car_down as int 'index into car sprite for going down ''' ''' initialization ''' sub init sprite_field = 0 'playfield sprite sprite_car = 1 'car sprite car_left=0 'car left image car_right=1 'car right image car_up=2 'car up image car_down=3 'car down image ''' ''' the playfield sprite has 9 bitmaps ''' one for each of the different areas of the ''' playfield sprite sprite_field, "playfield.pic" ''' ''' the car has 4 bitmaps one for each direction sprite sprite_car, "car.pic" ''' ''' the car 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=car_right 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 car_x as int '0-159 for the x coord on the screen dim car_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 car_x = x mod 160 ' compute the car's position on the screen car_y = y mod 100 ' compute the car's position on the screen move sprite_field, 0, 0, field 'display the current field move sprite_car, car_x, car_y, z 'display the car paper dkgrey 'transparent color for the car redraw 'redraw all the sprites end sub ''' ''' process the keyboard ''' sub get_keys if key(#KEY_UP) then 'move the car up y=y-3 z=car_up end if if key(#KEY_DOWN) then 'move the car down y=y+3 z=car_down end if if key(#KEY_LEFT) then 'move the car left x=x-3 z=car_left end if if key(#KEY_RIGHT) then 'move the car right x=x+3 z=car_right end if end sub ''' ''' main subroutine ''' sub mainsub init while true repaint get_keys wend end sub ''' ''' call the main subroutine ''' mainsub