program MoonBuggy;
var 

// Take a look at the VBM commands in the help (press F1)
// and also in the platform section of the help file
//
// Note that TRSE for VIC 20 is using zero pages from $8F downwards
// and VBM uses zero pages from $00 upwards.
// The Zero page memory in between can be used by your programs.
// See VBM Memory in the Platforms help section for details. 

// Scrolling landscape with pixel testing to keep the buggy on the ground

@export "resources/charsets/moonspr.flf" "resources/charsets/moonspr.bin" 1
@export "resources/charsets/moonchar.flf" "resources/charsets/moonchar.bin" 89


buggy: incbin( "resources/charsets/moonspr.bin", $4000 ); // moon buggy
chars: incbin( "resources/charsets/moonchar.bin", $4008 ); // individual tile characters
map: incbin( "resources/charsets/moonmap.bin", $42d8 ); // full screen map of tiles



	i, j : byte;
	y : byte;


procedure setUpScreenShiftLeft();
begin

	vbmInitScreenShiftLeft(0);

end;


begin
	// set the default display mode showing all 20 columns
	vbmSetDisplayMode( 0 );
	
	// set screen scrolling routine to match the screen mode
	setUpScreenShiftLeft();
	
	// set the colour memory to RED
	vbmClearColor( RED );
	
	// change colour of moon buggy title
	fill(^$9414, WHITE, 20);
	fill(^$9428, CYAN, 20);
	fill(^$943c, PURPLE, 20);


	// set screen colour
	SCREEN_BG_COLOR := SCREEN_BG_BLACK + BLACK;

	// draw tilemap of main screen
	vbmDrawTileMap( #map, #chars, 0,0, 20,191 );

	y := 100;

	while (true) offpage do
	begin
	
		// draw buggy
		vbmSetPosition1( 76, y );
		vbmDrawTileE( #buggy );

		waitforraster( 0 );	

		// erase buggy
		vbmDrawTileE( #buggy );
		
		// scroll screen
		//vbmScreenShiftLeft( 168, 176);

		vbmScreenShiftLeft( 152, 191 );
		
		// calculate new y position for buggy
		if (vbmTestPixel2( 76, y+8 ) = 0) then
			y := y + 1
		else
			y := y - 1;

	end;
	
end.
