+ # implement scrolling by 480x480
+ # first get the number of pages to span across. If the width is
+ # exactly fitting in the page use totalwidth/480 else totalwidth/480+1
+ # (integer divison)
+ if tileset.get_width () % 480 == 0:
+ totalpages_cols = tileset.get_width () / 480
+ else:
+ totalpages_cols = tileset.get_width () / 480 + 1
+
+ if tileset.get_height () % 480 == 0:
+ totalpages_rows = tileset.get_height () / 480
+ else:
+ totalpages_rows = tileset.get_height () / 480 + 1
+
+ # set the current page
+ curpage_cols = 0
+ curpage_rows = 0
+
+ # cursor row and column
+ cursor_row = 0
+ cursor_col = 0
+
+ # the code for scrolling through the tileset is quite complicated here are the steps
+ # first we determine the total number of pages (number of row pages and col pages
+ # then when scrolling we check for two things:
+ # first horizontal scrolling:
+ # logic goes like this
+ # left arrow key movement:
+ # is the cursor col < 0 ? if so, is it the first page? if so, then set the
+ # cursor col to the last col of the last page. This unfortunately is not so easy
+ # because it need not be 10. So we determine the last col as follows:
+ # total width of the tileset image modulo 480 = this gives us a multiple of 48
+ # since we are using 48x48 tiles and the tileset file size is a multiple of 48.
+ # then we divide that value by 48 which gives us a number between 0 and 9.
+ # this is the last col. If it is not the first page, we simply set the cursor
+ # column to 9 and reduce the page by 1.
+ # right arrow movement:
+ # simply if it is the last col and last page we simply reset the
+ # page to 0 and the cursor col to 0. Otherwise page is incremented by 1
+ # and col is still set to 0. simple logic
+
+ # vertical scrolling using the same logic
+