junglejourney

changeset 19:56200da13c3e

Started working on plotting and moving the player character. Added support for multiple set of level sprites. Reorganised the memory map to fit the sprites.
author David Boddie <david@boddie.org.uk>
date Sun Aug 14 13:33:50 2011 +0200
parents ddb15fb07db6
children df2cb7f1ff50
files build.py images/bricks.xpm images/flowers.xpm images/leaf1.xpm images/leaf2.xpm images/right1.xpm images/right2.xpm images/rock1.xpm images/rock2.xpm images/stones.xpm images/wall1.xpm images/wall2.xpm images/water.xpm makesprites.py mapcode.oph
diffstat 15 files changed, 674 insertions(+), 181 deletions(-) [+]
line diff
     1.1 --- a/build.py	Sat Aug 13 18:48:27 2011 +0200
     1.2 +++ b/build.py	Sun Aug 14 13:33:50 2011 +0200
     1.3 @@ -49,27 +49,38 @@
     1.4      # Planned memory map
     1.5      # 1900 CODE (map)
     1.6      # 1x00 space
     1.7 -    # 4F00 character table (0xf0/6 = 40 entries)
     1.8 +    # 3300 character table (0xf0/8 = 30 entries)
     1.9      #   n   type (0 missing, 1 player, 2 projectile, 3 explosion, 4)
    1.10      #   n+1 counter/direction
    1.11 -    #   n+2 room offset (0-99)
    1.12 -    #   n+3 x and y steps (0-1, bits 0 and 1)
    1.13 +    #   n+2 x room offset (0-10)
    1.14 +    #   n+3 y room offset (0-10)
    1.15      #   n+4 screen address (low byte)
    1.16      #   n+5 screen address (high byte)
    1.17 +    #   n+6 dx (0-3)
    1.18 +    #   n+7 dy (0-5)
    1.19      #
    1.20      #   first character is always the player
    1.21      #   second character is always the player's weapon
    1.22      #   new characters are added 
    1.23      #
    1.24 -    # 4FF0 starting room (i, j)
    1.25 -    # 4FF2 current room (i, j)
    1.26 -    # 4FF4 lives
    1.27 -    # 4FF6 score (four bytes)
    1.28 -    # 4FFA level
    1.29 -    # 4FFB palette workspace (enough for one 5 byte palette entry)
    1.30 +    # 33F0 starting room (i, j)
    1.31 +    # 33F2 current room (i, j)
    1.32 +    # 33F4 lives
    1.33 +    # 33F6 score (four bytes)
    1.34 +    # 33FA level
    1.35 +    # 33FB palette workspace (enough for one 5 byte palette entry)
    1.36      #
    1.37 -    # 5000 CHARS (character sprites)
    1.38 -    # 5600 SPRITES (map)
    1.39 +    # 3400 CHARS (character sprites)
    1.40 +    #   4 * 2 * 0x30 (player movement)
    1.41 +    #       4 * 0x30 (player demise)
    1.42 +    #   3 * 2 * 0x10 (projectile)
    1.43 +    #   4 * 2 * 0x40 (enemies)
    1.44 +    #       4 * 0x40 (enemy demise)
    1.45 +    #       3 * 0x40 (weapons)
    1.46 +    #       4 * 0x40 (treasure)
    1.47 +    #       1 * 0x40 (exit)
    1.48 +    #
    1.49 +    # 5300 SPRITES (map)
    1.50      # 5780 space
    1.51      # 579c room data (generated)
    1.52      # 5800 screen memory
    1.53 @@ -91,10 +102,10 @@
    1.54      files.append(("CODE", code_start, addresses[-1], code))
    1.55      
    1.56      data = makesprites.read_sprites(makesprites.chars)
    1.57 -    files.append(("CHARS", 0x5000, 0x5000, data))
    1.58 +    files.append(("CHARS", 0x3400, 0x3400, data))
    1.59      
    1.60      data = makesprites.read_sprites(makesprites.tiles)
    1.61 -    files.append(("SPRITES", 0x5600, 0x5600, data))
    1.62 +    files.append(("SPRITES", 0x5300, 0x5300, data))
    1.63      
    1.64      t = read_basic("LOADER").replace("{addr}", "%X" % addresses[-4])
    1.65      
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/images/bricks.xpm	Sun Aug 14 13:33:50 2011 +0200
     2.3 @@ -0,0 +1,32 @@
     2.4 +/* XPM */
     2.5 +static char * bricks_xpm[] = {
     2.6 +"16 24 5 1",
     2.7 +" 	c None",
     2.8 +".	c #000000",
     2.9 +"+	c #008000",
    2.10 +"@	c #FFFF00",
    2.11 +"#	c #FF0000",
    2.12 +".+.+@+...@.#.#..",
    2.13 +"+.+++@+.##@####.",
    2.14 +"++@+++@..###@#..",
    2.15 +".+++@++.##.##@#.",
    2.16 +".+.++++..###@##.",
    2.17 +"+.+++.+.#.#.##..",
    2.18 +".+++++...####@#.",
    2.19 +"................",
    2.20 +"..###...+.+@++..",
    2.21 +"##@.###.@+++@++.",
    2.22 +".#####@.+.++++@.",
    2.23 +"##.#@##..++.+++.",
    2.24 +"#.#####.++.++.+.",
    2.25 +".###@##..+++++..",
    2.26 +"#.###.#..+.+.++.",
    2.27 +"................",
    2.28 +".+@+++...##.@#..",
    2.29 +".++@++@..#@###@.",
    2.30 +"++++@++.#.##@##.",
    2.31 +"+.++++@.######@.",
    2.32 +".++.+++.#.#@#@#.",
    2.33 +"++.+.++..##.###.",
    2.34 +".++.++..#..##@..",
    2.35 +"................"};
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/images/flowers.xpm	Sun Aug 14 13:33:50 2011 +0200
     3.3 @@ -0,0 +1,31 @@
     3.4 +/* XPM */
     3.5 +static char * flowers_xpm[] = {
     3.6 +"16 24 4 1",
     3.7 +" 	c None",
     3.8 +".	c #000000",
     3.9 +"+	c #008000",
    3.10 +"@	c #FFFF00",
    3.11 +"...+.+..+....+..",
    3.12 +".+.+...+...+..+.",
    3.13 +"+....+....+@@...",
    3.14 +"..+.+...@.+@@.++",
    3.15 +"+.+.....+..++.+.",
    3.16 +".....+.@+++.....",
    3.17 +".+...+..+.+..+.+",
    3.18 +".+.+......+.++..",
    3.19 +".+..+..+..+++..+",
    3.20 +"+...+.+...+...+.",
    3.21 +"..@...+.+.+..+..",
    3.22 +".@@@.@..+....+..",
    3.23 +"..@@@@......+...",
    3.24 +"...@@...+...+.+.",
    3.25 +"..@.++.+++....+.",
    3.26 +"....+++++.+.+.+.",
    3.27 +".+...++.++..+..+",
    3.28 +".+...++.....+.+.",
    3.29 +"+..+.+++........",
    3.30 +"..+++.++..+..+.+",
    3.31 +"..+.+.++.+++..+.",
    3.32 +"+..+..++++++.+..",
    3.33 +".+.....++.+...+.",
    3.34 +"...+.+.++...+..+"};
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/images/leaf1.xpm	Sun Aug 14 13:33:50 2011 +0200
     4.3 @@ -0,0 +1,30 @@
     4.4 +/* XPM */
     4.5 +static char * leaf1_xpm[] = {
     4.6 +"16 24 3 1",
     4.7 +" 	c None",
     4.8 +".	c #000000",
     4.9 +"+	c #008000",
    4.10 +"..+++..++.......",
    4.11 +".+++++.+..++++..",
    4.12 +"++++++...++++++.",
    4.13 +"++..+++.++++..++",
    4.14 +"+....++.+++.....",
    4.15 +"+.....+.+++.....",
    4.16 +"......++.+......",
    4.17 +"..+++.+++....++.",
    4.18 +".++++++++..++++.",
    4.19 +".++++.+++.+++++.",
    4.20 +"++++..+++.++++..",
    4.21 +"+++...+++++++...",
    4.22 +"+......+++......",
    4.23 +"....++.++...+++.",
    4.24 +"...++++++..+++++",
    4.25 +"..++..+++.++++.+",
    4.26 +"+......++++++...",
    4.27 +"++.....++++.....",
    4.28 +".++.++.+++..++..",
    4.29 +"..++++.+++..++++",
    4.30 +"+++++..+++.++++.",
    4.31 +"+..+...+++.+....",
    4.32 +"...+...+++.+....",
    4.33 +"...++..++++....."};
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/images/leaf2.xpm	Sun Aug 14 13:33:50 2011 +0200
     5.3 @@ -0,0 +1,31 @@
     5.4 +/* XPM */
     5.5 +static char * leaf2_xpm[] = {
     5.6 +"16 24 4 1",
     5.7 +" 	c None",
     5.8 +".	c #000000",
     5.9 +"+	c #008000",
    5.10 +"@	c #FFFF00",
    5.11 +"..++...+........",
    5.12 +"...++.+++...+...",
    5.13 +"...+++++...+....",
    5.14 +"....++....++....",
    5.15 +"....++.....++...",
    5.16 +"..+.+++.....+...",
    5.17 +".+@+.++..+..++..",
    5.18 +"+@+@.++.+@+..+.+",
    5.19 +"..+..+++@+@+.++.",
    5.20 +"......++.+...+..",
    5.21 +"......++....++..",
    5.22 +"...+..++.....++.",
    5.23 +"..+@++++.+..++..",
    5.24 +".+@+.++.+@..+...",
    5.25 +".....++..+@.++..",
    5.26 +".+...++....++...",
    5.27 +"+@+..++...++....",
    5.28 +".+@++++.+..+++..",
    5.29 +"..+.+++++@+.+.+.",
    5.30 +"....++..@+.+....",
    5.31 +"....++.....++...",
    5.32 +"....++....+.+...",
    5.33 +"....++......+...",
    5.34 +"....++......+..."};
     6.1 --- a/images/right1.xpm	Sat Aug 13 18:48:27 2011 +0200
     6.2 +++ b/images/right1.xpm	Sun Aug 14 13:33:50 2011 +0200
     6.3 @@ -1,23 +1,31 @@
     6.4  /* XPM */
     6.5  static char * right1_xpm[] = {
     6.6 -"16 16 4 1",
     6.7 +"8 24 4 1",
     6.8  " 	c None",
     6.9  ".	c #000000",
    6.10  "+	c #008000",
    6.11  "@	c #FFFF00",
    6.12 -"........++++....",
    6.13 -".......++++++...",
    6.14 -"......++++++++..",
    6.15 -".......@+@@.@...",
    6.16 -".......@@+@@@@..",
    6.17 -"........@+@@@...",
    6.18 -"................",
    6.19 -".....++.+++++...",
    6.20 -"....+++.+++++.+@",
    6.21 -"....++.++.+++.+@",
    6.22 -".....+.++.......",
    6.23 -".......@@++++...",
    6.24 -"........++.++...",
    6.25 -"........+..++...",
    6.26 -".......++++.++..",
    6.27 -".......++++.++.."};
    6.28 +"..+++...",
    6.29 +".++.++..",
    6.30 +".+.+++..",
    6.31 +"++.++++.",
    6.32 +"+++++++.",
    6.33 +".+@@@@..",
    6.34 +".+@@.@..",
    6.35 +".@+@@@@.",
    6.36 +"..+@@@..",
    6.37 +"..+@@...",
    6.38 +".+++++..",
    6.39 +".+++++..",
    6.40 +".++.++..",
    6.41 +"++..+++@",
    6.42 +"++.++++@",
    6.43 +"@@++++..",
    6.44 +"@@......",
    6.45 +".+++++..",
    6.46 +".++.++..",
    6.47 +"+++.+++.",
    6.48 +"++...++.",
    6.49 +"........",
    6.50 +"+++..+++",
    6.51 +"+++..+++"};
     7.1 --- a/images/right2.xpm	Sat Aug 13 18:48:27 2011 +0200
     7.2 +++ b/images/right2.xpm	Sun Aug 14 13:33:50 2011 +0200
     7.3 @@ -1,23 +1,31 @@
     7.4  /* XPM */
     7.5  static char * right2_xpm[] = {
     7.6 -"16 16 4 1",
     7.7 +"8 24 4 1",
     7.8  " 	c None",
     7.9  ".	c #000000",
    7.10  "+	c #008000",
    7.11  "@	c #FFFF00",
    7.12 -"...++++.........",
    7.13 -"..++++++........",
    7.14 -".++++++++.......",
    7.15 -"..@+@@.@........",
    7.16 -"..@@+@@@@.......",
    7.17 -"...@+@@@........",
    7.18 -"................",
    7.19 -"++.+++++........",
    7.20 -"++.+++++.+@.....",
    7.21 -"++.++.++.+@.....",
    7.22 -"++.++...........",
    7.23 -"...@@+++........",
    7.24 -"...+++++........",
    7.25 -"...+.++.........",
    7.26 -"..+.+++++.......",
    7.27 -"..+.+++++......."};
    7.28 +"..+++...",
    7.29 +".++.++..",
    7.30 +".+.+++..",
    7.31 +"++.++++.",
    7.32 +"+++++++.",
    7.33 +".+@@@@..",
    7.34 +".+@@.@..",
    7.35 +".@+@@@@.",
    7.36 +"..+@@@..",
    7.37 +"..+@@...",
    7.38 +".+++++..",
    7.39 +".+++++..",
    7.40 +".++.++..",
    7.41 +".++.+++@",
    7.42 +".++.+++@",
    7.43 +".@@.++..",
    7.44 +".@@.....",
    7.45 +"..++++..",
    7.46 +"..++++..",
    7.47 +"..+++...",
    7.48 +"..+++...",
    7.49 +"........",
    7.50 +"..++++..",
    7.51 +"..++++.."};
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/images/rock1.xpm	Sun Aug 14 13:33:50 2011 +0200
     8.3 @@ -0,0 +1,30 @@
     8.4 +/* XPM */
     8.5 +static char * rock1_xpm[] = {
     8.6 +"16 24 3 1",
     8.7 +" 	c None",
     8.8 +".	c #000000",
     8.9 +"+	c #008000",
    8.10 +".+.+.....+..+.+.",
    8.11 +"..+..+..+.+..+..",
    8.12 +"....+++..+......",
    8.13 +"....++++...+....",
    8.14 +"...++.++...++...",
    8.15 +"..++++.++.++.+..",
    8.16 +"..++++++++.++.+.",
    8.17 +".++.+++.+++.+++.",
    8.18 +"++++.+++++.++.++",
    8.19 +".++.++.++.++.++.",
    8.20 +"..+++++++.+++++.",
    8.21 +"....++.+..++++..",
    8.22 +"................",
    8.23 +".+.+........+...",
    8.24 +"..+.+...+..+.+..",
    8.25 +".+.+...+++..+...",
    8.26 +"......++.++.....",
    8.27 +".....++++.++..+.",
    8.28 +".+..++++.++++..+",
    8.29 +"+.+.++.+++.++.+.",
    8.30 +"...+++++.+++.+..",
    8.31 +"....+.+.+.+..+..",
    8.32 +".+.+.+.+.+..+...",
    8.33 +"+.+.....+..+.+.."};
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/images/rock2.xpm	Sun Aug 14 13:33:50 2011 +0200
     9.3 @@ -0,0 +1,31 @@
     9.4 +/* XPM */
     9.5 +static char * rock2_xpm[] = {
     9.6 +"16 24 4 1",
     9.7 +" 	c None",
     9.8 +".	c #008000",
     9.9 +"+	c #FFFF00",
    9.10 +"@	c #000000",
    9.11 +"................",
    9.12 +".......+........",
    9.13 +"...@............",
    9.14 +".........++++...",
    9.15 +"........@.+.++..",
    9.16 +".@..+....+.+.+..",
    9.17 +"........@.+.+...",
    9.18 +"..@.....@@.@.+..",
    9.19 +".........@@.@...",
    9.20 +"..........@@....",
    9.21 +".....++.........",
    9.22 +"......++........",
    9.23 +"...+.+.+.....@..",
    9.24 +"..@.+.+.........",
    9.25 +".@.@.@+.....@...",
    9.26 +"..@.@...........",
    9.27 +"..@@............",
    9.28 +"..........+.....",
    9.29 +".........+.+....",
    9.30 +".@......@.+...+.",
    9.31 +"........@@......",
    9.32 +"....@...........",
    9.33 +"................",
    9.34 +"................"};
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/images/stones.xpm	Sun Aug 14 13:33:50 2011 +0200
    10.3 @@ -0,0 +1,32 @@
    10.4 +/* XPM */
    10.5 +static char * stones_xpm[] = {
    10.6 +"16 24 5 1",
    10.7 +" 	c None",
    10.8 +".	c #000000",
    10.9 +"+	c #008000",
   10.10 +"@	c #FFFF00",
   10.11 +"#	c #FF0000",
   10.12 +".++.@+.++.++#+.+",
   10.13 +"+#+++.+@++.++++.",
   10.14 +"++@.++.+.+++.+.+",
   10.15 +".+++@++.++@++#++",
   10.16 +"++#++++@++++@+++",
   10.17 +"+.++@.+++@+.++.+",
   10.18 +"@+++++.++++++@++",
   10.19 +"++.++@++.++#++++",
   10.20 +"+#+++.+++.+@++.+",
   10.21 +"++@.++++#+++.+++",
   10.22 +".+++++@++.++++@+",
   10.23 +"++#+.++++++.++++",
   10.24 +"+.+++++@++.++.++",
   10.25 +"++++@+++.+++++.+",
   10.26 +"+.+++.++++@+.+++",
   10.27 +"++++.++.+.+++@+@",
   10.28 +"++#+++@+++++.+++",
   10.29 +".++.++.+.+@+++.+",
   10.30 +"++++@++++.+#.+++",
   10.31 +"+.++++.@++++++@+",
   10.32 +"+++.+++++.+@+.++",
   10.33 +"++@+#+++@++.+++.",
   10.34 +".++.++@.++#++@++",
   10.35 +"++.+@++++.++.++."};
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/images/wall1.xpm	Sun Aug 14 13:33:50 2011 +0200
    11.3 @@ -0,0 +1,30 @@
    11.4 +/* XPM */
    11.5 +static char * wall1_xpm[] = {
    11.6 +"16 24 3 1",
    11.7 +" 	c None",
    11.8 +".	c #000000",
    11.9 +"+	c #008000",
   11.10 +"..+.++..+...+.++",
   11.11 +"+..+++++++.+++..",
   11.12 +"+.+++.++++++++.+",
   11.13 +".+++.+.++++++++.",
   11.14 +".++.+++.+++.+++.",
   11.15 +"+++.++++.+.+.+.+",
   11.16 +"++.+++++.+.++.++",
   11.17 +"+.+++++++.++++..",
   11.18 +"..++++++.+.++.++",
   11.19 +".+.++++.+++..++.",
   11.20 +"+++.+..++++++..+",
   11.21 +".+++.++.+++++++.",
   11.22 +"..+.+++.++++++.+",
   11.23 +"++.+.+.+..+++.++",
   11.24 +"+++.+.++++.+.+++",
   11.25 +".+.+++.++++..++.",
   11.26 +"..++++.+++.+++..",
   11.27 +".++++.+.++.++++.",
   11.28 +"++.++.++..+++...",
   11.29 +"+++..++++..+..++",
   11.30 +".+..++++++...+++",
   11.31 +"+.+.+++++..+..+.",
   11.32 +"..+..+++..+++...",
   11.33 +".+++..+.+..+.+.+"};
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/images/wall2.xpm	Sun Aug 14 13:33:50 2011 +0200
    12.3 @@ -0,0 +1,31 @@
    12.4 +/* XPM */
    12.5 +static char * wall2_xpm[] = {
    12.6 +"16 24 4 1",
    12.7 +" 	c None",
    12.8 +".	c #000000",
    12.9 +"+	c #008000",
   12.10 +"@	c #FFFF00",
   12.11 +"..+++.+.+.+++++.",
   12.12 +".++.++++.+.+.+++",
   12.13 +"++.++@+++.+++.+.",
   12.14 +".+.++++.++++.+++",
   12.15 +"+.++++.+.++.+++.",
   12.16 +"++++.++.+.++.+.+",
   12.17 +"+.+++.++.+.+.++.",
   12.18 +".+.++.+++.+++.++",
   12.19 +"+.+.++.+.++++++.",
   12.20 +".+.+.+.+++@+.+.+",
   12.21 +"+.+.+++.+++++++.",
   12.22 +".+.+.+.++.++.+..",
   12.23 +"+++++++++++.+++.",
   12.24 +".+.+++.+.+.+++.+",
   12.25 +".++.+.+++++.+++.",
   12.26 +"++.+++++.+++.+.+",
   12.27 +"+.+++.+.++++.++.",
   12.28 +"++.+++++.++.++.+",
   12.29 +"+++.+@+.+++++.+.",
   12.30 +".++.+++.++.+.+.+",
   12.31 +"+.+++.++.++.+.+.",
   12.32 +"...+.+.++.++.+.+",
   12.33 +"+.+.+.+.+++.+.+.",
   12.34 +".+.+...+.+...+.."};
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/images/water.xpm	Sun Aug 14 13:33:50 2011 +0200
    13.3 @@ -0,0 +1,31 @@
    13.4 +/* XPM */
    13.5 +static char * water_xpm[] = {
    13.6 +"16 24 4 1",
    13.7 +" 	c None",
    13.8 +".	c #000000",
    13.9 +"+	c #008000",
   13.10 +"@	c #1F1F64",
   13.11 +"................",
   13.12 +"..+...+....+..+.",
   13.13 +".+.......+...+..",
   13.14 +"....+...+..+....",
   13.15 +"..+..+......+...",
   13.16 +".....+..+...+...",
   13.17 +".+......+.+.....",
   13.18 +"..+.+..+..+...+.",
   13.19 +".............+..",
   13.20 +"..+..@@@@@@..+..",
   13.21 +".+..@@@@@.......",
   13.22 +"...@.@@..@@@..+.",
   13.23 +".+.@@..@@@@@@.+.",
   13.24 +"....@@@@@...@...",
   13.25 +".....@@@..@@....",
   13.26 +".+.@@....@@@@...",
   13.27 +"...@@@@@@@@@@.+.",
   13.28 +".....@@@@@......",
   13.29 +"...@@.@@@.@@@...",
   13.30 +".+..@@...@@@....",
   13.31 +".....@@@@@@...+.",
   13.32 +"..+.........+...",
   13.33 +"..+..+...+..+.+.",
   13.34 +"................"};
    14.1 --- a/makesprites.py	Sat Aug 13 18:48:27 2011 +0200
    14.2 +++ b/makesprites.py	Sun Aug 14 13:33:50 2011 +0200
    14.3 @@ -17,7 +17,7 @@
    14.4  along with this program.  If not, see <http://www.gnu.org/licenses/>.
    14.5  """
    14.6  
    14.7 -def read_xpm(path):
    14.8 +def read_xpm(path, symbols = None):
    14.9  
   14.10      lines = open(path).readlines()
   14.11      char_lines = filter(lambda line: line.startswith('"'), lines)
   14.12 @@ -27,7 +27,9 @@
   14.13      width, height, colours = map(int, strings[0].split()[:3])
   14.14      strings = strings[-height:]
   14.15      
   14.16 -    symbols = [(".", 0), ("+", 2), ("@", 3)]
   14.17 +    if not symbols:
   14.18 +        symbols = [(".", 0), ("+", 2), ("@", 3)]
   14.19 +    
   14.20      data = []
   14.21      
   14.22      for s in strings:
   14.23 @@ -40,84 +42,24 @@
   14.24      return data
   14.25  
   14.26  
   14.27 -tiles = [
   14.28 -        ("0000000000000000",)*24,
   14.29 -        ("0002020020000200",
   14.30 -         "0202000200020020",
   14.31 -         "2000020000211000",
   14.32 -         "0020200010211022",
   14.33 -         "2020000020022020",
   14.34 -         "0000020122200000",
   14.35 -         "0200020020200202",
   14.36 -         "0202000000202200",
   14.37 -         "0200200200222002",
   14.38 -         "2000202000200020",
   14.39 -         "0010002020200200",
   14.40 -         "0111010020000200",
   14.41 -         "0011110000002000",
   14.42 -         "0001100020002020",
   14.43 -         "0010220222000020",
   14.44 -         "0000222220202020",
   14.45 -         "0200022022002002",
   14.46 -         "0200022000002020",
   14.47 -         "2002022200000000",
   14.48 -         "0022202200200202",
   14.49 -         "0020202202220020",
   14.50 -         "2002002222220200",
   14.51 -         "0200000220200020",
   14.52 -         "0002020220002002"),
   14.53 -        ("0022200000000000",
   14.54 -         "0222220000222200",
   14.55 -         "2222220002222220",
   14.56 -         "2200222022220022",
   14.57 -         "2000022022200000",
   14.58 -         "2000002022200000",
   14.59 -         "0000002202000000",
   14.60 -         "0022202220000220",
   14.61 -         "0222222220022220",
   14.62 -         "0222202220222220",
   14.63 -         "2222002220222200",
   14.64 -         "2220002222222000",
   14.65 -         "2000000222000000",
   14.66 -         "0000220220002220",
   14.67 -         "0002222220022222",
   14.68 -         "0022002220222202",
   14.69 -         "2000000222222000",
   14.70 -         "2200000222200000",
   14.71 -         "0220220222002200",
   14.72 -         "0022220222002222",
   14.73 -         "2222200222022220",
   14.74 -         "2002000222020000",
   14.75 -         "0002000222020000",
   14.76 -         "0002200222200000"),
   14.77 -        ("0022000200000000",
   14.78 -         "0002202220002000",
   14.79 -         "0002222200020000",
   14.80 -         "0000220000220000",
   14.81 -         "0000220000022000",
   14.82 -         "0020222000002000",
   14.83 -         "0232022002002200",
   14.84 -         "2323022023200202",
   14.85 -         "0020022232320220",
   14.86 -         "0000002202000200",
   14.87 -         "0000002200002200",
   14.88 -         "0002002200000220",
   14.89 -         "0023222202002200",
   14.90 -         "0232022023002000",
   14.91 -         "0000022002302200",
   14.92 -         "0200022000022000",
   14.93 -         "2320022000220000",
   14.94 -         "0232222020022200",
   14.95 -         "0020222223202020",
   14.96 -         "0000220032020000",
   14.97 -         "0000220000022000",
   14.98 -         "0000220000202000",
   14.99 -         "0000220000002000",
  14.100 -         "0000220000002000")
  14.101 -    ]
  14.102 +tiles = [read_xpm("images/flowers.xpm", [(".", "0"), ("@", "1"), ("+", "2")]),
  14.103 +         read_xpm("images/leaf1.xpm"),
  14.104 +         read_xpm("images/leaf2.xpm"),
  14.105 +         read_xpm("images/stones.xpm", [(".", "2"), ("#", "1"), ("+", "0"), ("@", "3")]),
  14.106 +         read_xpm("images/rock1.xpm"),
  14.107 +         read_xpm("images/rock2.xpm", [(" ", "0"), ("#", "1"), ("@", "2"), ("+", "3")]),
  14.108 +         read_xpm("images/bricks.xpm", [(".", "0"), ("#", "1"), ("+", "2"), ("@", "3")]),
  14.109 +         read_xpm("images/wall1.xpm"),
  14.110 +         read_xpm("images/wall2.xpm")]
  14.111  
  14.112  chars = [read_xpm("images/left1.xpm"),
  14.113 -         read_xpm("images/left2.xpm")]
  14.114 +         read_xpm("images/left2.xpm"),
  14.115 +         read_xpm("images/right1.xpm"),
  14.116 +         read_xpm("images/right2.xpm"),
  14.117 +         read_xpm("images/up1.xpm"),
  14.118 +         read_xpm("images/up2.xpm"),
  14.119 +         read_xpm("images/down1.xpm"),
  14.120 +         read_xpm("images/down2.xpm")]
  14.121  
  14.122  
  14.123  def read_sprite(lines):
    15.1 --- a/mapcode.oph	Sat Aug 13 18:48:27 2011 +0200
    15.2 +++ b/mapcode.oph	Sun Aug 14 13:33:50 2011 +0200
    15.3 @@ -261,10 +261,10 @@
    15.4      ; Make sure that the starting room is empty.
    15.5  
    15.6      lda $78
    15.7 -    cmp $4ff0
    15.8 +    cmp $33f0
    15.9      bne not_starting_room
   15.10      lda $79
   15.11 -    cmp $4ff1
   15.12 +    cmp $33f1
   15.13      bne not_starting_room
   15.14  
   15.15      clc
   15.16 @@ -445,41 +445,63 @@
   15.17      lda $7b
   15.18      cmp #1
   15.19      bne not_flowers
   15.20 -    lda #$60
   15.21 +    lda #$00
   15.22      sta $70
   15.23 -    lda #$56
   15.24 +    lda #$53
   15.25      sta $71
   15.26 -    clc
   15.27 -    jmp plot        ; optimise away the rts
   15.28 +    jmp plot_not_blank
   15.29 +
   15.30  not_flowers:
   15.31      cmp #6
   15.32      bne not_tree1
   15.33 -    lda #$c0
   15.34 +    lda #$60
   15.35      sta $70
   15.36 -    lda #$56
   15.37 +    lda #$53
   15.38      sta $71
   15.39 -    clc
   15.40 -    jmp plot        ; optimise away the rts
   15.41 +    jmp plot_not_blank
   15.42 +
   15.43  not_tree1:
   15.44      cmp #7
   15.45      bne not_tree2
   15.46 -    lda #$20
   15.47 +    lda #$c0
   15.48      sta $70
   15.49 -    lda #$57
   15.50 +    lda #$53
   15.51      sta $71
   15.52 -    clc
   15.53 -    jmp plot        ; optimise away the rts
   15.54 +    jmp plot_not_blank
   15.55 +
   15.56  not_tree2:
   15.57      clc
   15.58 -    jsr plot_blank
   15.59 +    jmp plot_blank      ; optimise away the rts
   15.60 +
   15.61 +plot_not_blank:
   15.62 +    clc
   15.63 +    lda $33fa
   15.64 +    and #3
   15.65 +    tax
   15.66 +    plot_add_loop:
   15.67 +        cpx #0
   15.68 +        beq after_plot_add_loop
   15.69 +        clc
   15.70 +        lda $70
   15.71 +        adc #$20
   15.72 +        sta $70
   15.73 +        lda $71
   15.74 +        adc #$01
   15.75 +        sta $71
   15.76 +        dex
   15.77 +        jmp plot_add_loop
   15.78 +
   15.79 +after_plot_add_loop:
   15.80 +    clc
   15.81 +    jsr plot
   15.82      rts
   15.83  
   15.84 -plot_room:          ; $78,$79 = i,j (from $4ff0,$4ff1)
   15.85 +plot_room:          ; $78,$79 = i,j (from $33f0,$33f1)
   15.86      jsr blank_screen
   15.87  
   15.88 -    lda $4ff2
   15.89 +    lda $33f2
   15.90      sta $78
   15.91 -    lda $4ff3
   15.92 +    lda $33f3
   15.93      sta $79
   15.94  
   15.95      lda #$00
   15.96 @@ -552,15 +574,15 @@
   15.97  
   15.98  
   15.99  
  15.100 -plot12x24_y0:           ; $70,$71=source address
  15.101 +plot8x24_y0:            ; $70,$71=source address
  15.102                          ; $72,$73=destination address
  15.103      ldy #15
  15.104  
  15.105 -    plotloop12x24_y0_0:
  15.106 +    plotloop8x24_y0_0:
  15.107          lda ($70),y
  15.108          sta ($72),y
  15.109          dey
  15.110 -        bpl plotloop12x24_y0_0
  15.111 +        bpl plotloop8x24_y0_0
  15.112      clc
  15.113  
  15.114      lda $72
  15.115 @@ -573,12 +595,12 @@
  15.116  
  15.117      ldy #31
  15.118  
  15.119 -    plotloop12x24_y0_1:
  15.120 +    plotloop8x24_y0_1:
  15.121          lda ($70),y
  15.122          sta ($72),y
  15.123          dey
  15.124          cpy #16
  15.125 -        bpl plotloop12x24_y0_1
  15.126 +        bpl plotloop8x24_y0_1
  15.127      clc
  15.128  
  15.129      lda $72
  15.130 @@ -591,16 +613,15 @@
  15.131  
  15.132      ldy #47
  15.133  
  15.134 -    plotloop12x24_y0_2:
  15.135 +    plotloop8x24_y0_2:
  15.136          lda ($70),y
  15.137          sta ($72),y
  15.138          dey
  15.139          cpy #32
  15.140 -        bpl plotloop12x24_y0_2
  15.141 +        bpl plotloop8x24_y0_2
  15.142  
  15.143      rts
  15.144  
  15.145 -
  15.146  ; Sprite data stored in memory: 00 11 22 33 44 55 66 77 88 99 aa bb
  15.147  ;
  15.148  ; Write to screen in this arrangement:
  15.149 @@ -615,30 +636,30 @@
  15.150  ;
  15.151  ; 99 bb
  15.152  
  15.153 -plot12x24_y1:           ; $70,$71=source address
  15.154 +plot8x24_y1:            ; $70,$71=source address
  15.155                          ; $72,$73=destination address
  15.156  
  15.157      ldx #2
  15.158  
  15.159 -    plotloop12x24_y1_loop:
  15.160 +    plotloop8x24_y1_loop:
  15.161  
  15.162          ldy #3
  15.163  
  15.164 -        plotloop12x24_y1_0:
  15.165 +        plotloop8x24_y1_0:
  15.166              lda ($70),y
  15.167              sta ($72),y
  15.168              dey
  15.169 -            bpl plotloop12x24_y1_0
  15.170 +            bpl plotloop8x24_y1_0
  15.171          clc
  15.172  
  15.173          ldy #11
  15.174  
  15.175 -        plotloop12x24_y1_1:
  15.176 +        plotloop8x24_y1_1:
  15.177              lda ($70),y
  15.178              sta ($72),y
  15.179              dey
  15.180              cpy #8
  15.181 -            bpl plotloop12x24_y1_1
  15.182 +            bpl plotloop8x24_y1_1
  15.183          clc
  15.184  
  15.185          lda $70
  15.186 @@ -659,21 +680,21 @@
  15.187  
  15.188          ldy #3
  15.189  
  15.190 -        plotloop12x24_y1_2:
  15.191 +        plotloop8x24_y1_2:
  15.192              lda ($70),y
  15.193              sta ($72),y
  15.194              dey
  15.195 -            bpl plotloop12x24_y1_2
  15.196 +            bpl plotloop8x24_y1_2
  15.197          clc
  15.198  
  15.199          ldy #11
  15.200  
  15.201 -        plotloop12x24_y1_3:
  15.202 +        plotloop8x24_y1_3:
  15.203              lda ($70),y
  15.204              sta ($72),y
  15.205              dey
  15.206              cpy #8
  15.207 -            bpl plotloop12x24_y1_3
  15.208 +            bpl plotloop8x24_y1_3
  15.209          clc
  15.210  
  15.211          lda $70
  15.212 @@ -693,7 +714,38 @@
  15.213          clc
  15.214  
  15.215          dex
  15.216 -        bpl plotloop12x24_y1_loop
  15.217 +        bpl plotloop8x24_y1_loop
  15.218 +
  15.219 +    rts
  15.220 +
  15.221 +plot16x16_y0:           ; $70,$71=source address
  15.222 +                        ; $72,$73=destination address
  15.223 +    ldy #31
  15.224 +
  15.225 +    plotloop16x16_y0_0:
  15.226 +        lda ($70),y
  15.227 +        sta ($72),y
  15.228 +        dey
  15.229 +        bpl plotloop16x16_y0_0
  15.230 +    clc
  15.231 +
  15.232 +    lda $72
  15.233 +    adc #$20
  15.234 +    sta $72
  15.235 +    lda $73
  15.236 +    adc #$01
  15.237 +    sta $73     ; 0x140 - 32
  15.238 +    clc
  15.239 +
  15.240 +    ldy #63
  15.241 +
  15.242 +    plotloop16x16_y0_1:
  15.243 +        lda ($70),y
  15.244 +        sta ($72),y
  15.245 +        dey
  15.246 +        cpy #32
  15.247 +        bpl plotloop16x16_y0_1
  15.248 +    clc
  15.249  
  15.250      rts
  15.251  
  15.252 @@ -750,21 +802,152 @@
  15.253      lda #0
  15.254      rts
  15.255  
  15.256 +player_direction_chars_low: .byte $00,$30,$60,$90,$c0,$f0,$20,$50
  15.257 +player_direction_chars_high: .byte $34,$34,$34,$34,$34,$34,$35,$35
  15.258 +
  15.259  plot_characters:
  15.260 +
  15.261 +    lda $3300
  15.262 +    cmp #1
  15.263 +    bne plot_characters_loop
  15.264 +    clc
  15.265 +
  15.266 +    ; Use lookup tables to load the offsets into the sprite.
  15.267 +
  15.268 +    lda $3301   ; direction
  15.269 +    tax
  15.270 +    lda player_direction_chars_low,x
  15.271 +    sta $70
  15.272 +    lda player_direction_chars_high,x
  15.273 +    sta $71
  15.274 +
  15.275 +    ; Load the screen address.
  15.276 +
  15.277 +    lda $3304
  15.278 +    sta $72
  15.279 +    lda $3305
  15.280 +    sta $73
  15.281 +
  15.282 +    ; Use the dy value to determine which plotting routine to use.
  15.283 +
  15.284 +    lda $3307
  15.285 +    and #1
  15.286 +    bne plot_characters_plot_player1
  15.287 +
  15.288 +    jsr plot8x24_y0
  15.289 +    jmp plot_characters_array
  15.290 +
  15.291 +plot_characters_plot_player1:
  15.292 +    clc
  15.293 +    jsr plot8x24_y1
  15.294 +
  15.295 +plot_characters_array:
  15.296 +    ldx #6
  15.297 +
  15.298 +    plot_characters_loop:
  15.299 +        lda $3300,x
  15.300 +        txa
  15.301 +        clc
  15.302 +        adc #6
  15.303 +        cmp #234
  15.304 +        tax
  15.305 +        bne plot_characters_loop
  15.306 +
  15.307 +    rts
  15.308 +
  15.309 +room_row_offsets_low: .byte $9c,$a6,$b0,$ba,$c4,$ce,$d8,$e2,$ec,$f6
  15.310 +
  15.311 +move_player_left:
  15.312 +
  15.313 +    ; Decrement dx and subtract 8 from the screen address.
  15.314 +
  15.315 +    lda $3301
  15.316 +    and #254    ; remove direction information
  15.317 +    eor #1      ; toggle animation flag
  15.318 +    sta $3301
  15.319 +    lda #0      ; direction = 0
  15.320 +    sta $3301
  15.321 +
  15.322 +    dec $3306
  15.323 +    bpl move_player_left_not_underflow
  15.324 +    lda #3
  15.325 +    sta $3306
  15.326 +
  15.327 +move_player_left_not_underflow:
  15.328 +    sec
  15.329 +    lda $3304   ; screen position -= 8
  15.330 +    sbc #8
  15.331 +    sta $3304
  15.332 +    clc
  15.333      rts
  15.334  
  15.335  move_player:
  15.336      jsr key_input
  15.337      cmp #1
  15.338 -    bne not_left_room
  15.339 +    bne move_player_not_left_key
  15.340 +
  15.341 +    ; Handle the left key.
  15.342 +
  15.343 +    lda $3306           ; read dx
  15.344 +    cmp #0
  15.345 +    beq move_player_check_x
  15.346 +
  15.347 +    jmp move_player_left    ; optimise rts
  15.348 +
  15.349 +move_player_check_x:
  15.350 +
  15.351 +    ; Check the x offset.
  15.352 +
  15.353 +    lda $3302
  15.354 +    cmp #0
  15.355 +    beq move_player_leave_room_left
  15.356 +
  15.357      sec
  15.358 -    lda $4ff3
  15.359 +    sbc #1                  ; dx = dx - 1
  15.360 +    tay
  15.361 +    lda $3303                   ; load the y offset
  15.362 +    tax                         ; as an index
  15.363 +    lda room_row_offsets_low,x  ; read the address of the row
  15.364 +    sta $70
  15.365 +    lda #$57
  15.366 +    sta $71
  15.367 +    lda ($70),y             ; load the tile to the left
  15.368 +
  15.369 +    cmp #0
  15.370 +    bne move_player_not_left_key
  15.371 +
  15.372 +    tya
  15.373 +    sta $3302               ; store the new room x offset
  15.374 +    lda #3
  15.375 +    sta $3306               ; dx = 3
  15.376 +    jmp move_player_left    ; optimise rts
  15.377 +
  15.378 +move_player_leave_room_left:
  15.379 +    sec
  15.380 +    lda $33f3
  15.381      sbc #1
  15.382 -    sta $4ff3
  15.383 +    sta $33f3
  15.384 +    clc
  15.385 +
  15.386 +    ; Set the player's position on the right of the screen.
  15.387 +
  15.388 +    lda #9      ; x = 9
  15.389 +    sta $3302
  15.390 +    lda #2      ; dx = 2
  15.391 +    sta $3306
  15.392 +
  15.393 +    lda $3304
  15.394 +    adc #$30
  15.395 +    sta $3304
  15.396 +    lda $3305
  15.397 +    adc #0
  15.398 +    sta $3305
  15.399 +    
  15.400      sec
  15.401      rts
  15.402  
  15.403  not_left_room:
  15.404 +move_player_not_left_key:
  15.405      clc
  15.406      rts
  15.407  
  15.408 @@ -772,17 +955,17 @@
  15.409                      ; $70=logical colour
  15.410                      ; $71=physical colour
  15.411      lda $70
  15.412 -    sta $4ffb
  15.413 +    sta $33fb
  15.414      lda $71
  15.415 -    sta $4ffc
  15.416 +    sta $33fc
  15.417      lda #0
  15.418 -    sta $4ffd
  15.419 -    sta $4ffe
  15.420 -    sta $4fff
  15.421 +    sta $33fd
  15.422 +    sta $33fe
  15.423 +    sta $33ff
  15.424  
  15.425      lda #$c         
  15.426      ldx #$fb
  15.427 -    ldy #$4f
  15.428 +    ldy #$33
  15.429      jsr $fff1
  15.430      rts
  15.431  
  15.432 @@ -808,10 +991,16 @@
  15.433  chars_file_name: .byte "CHARS", 13
  15.434  
  15.435  sprites_block: .byte <sprites_file_name, >sprites_file_name
  15.436 -               .byte 0, $56, 0, 0
  15.437 -               .byte 0, $56, 0, 0
  15.438 +               .byte 0, $53, 0, 0
  15.439 +               .byte 0, $53, 0, 0
  15.440 +               .byte $60, $03, 0, 0
  15.441 +               .byte $60, $56, 0, 0
  15.442 +
  15.443 +chars_block: .byte <chars_file_name, >chars_file_name
  15.444 +               .byte 0, $34, 0, 0
  15.445 +               .byte 0, $34, 0, 0
  15.446                 .byte $80, $01, 0, 0
  15.447 -               .byte $80, $57, 0, 0
  15.448 +               .byte $80, $35, 0, 0
  15.449  
  15.450  init:
  15.451      lda #255
  15.452 @@ -819,6 +1008,11 @@
  15.453      ldy #>sprites_block
  15.454      jsr $ffdd
  15.455  
  15.456 +    lda #255
  15.457 +    ldx #<chars_block
  15.458 +    ldy #>chars_block
  15.459 +    jsr $ffdd
  15.460 +
  15.461      lda #22         ; MODE 5
  15.462      jsr $ffee
  15.463      lda #5
  15.464 @@ -851,27 +1045,48 @@
  15.465  
  15.466  start_new_game:
  15.467  
  15.468 +    ; Set level.
  15.469 +
  15.470 +    lda #0
  15.471 +    sta $33fa
  15.472 +
  15.473      ; Set starting room and current room.
  15.474  
  15.475      lda #5
  15.476 -    sta $4ff0
  15.477 -    sta $4ff2
  15.478 +    sta $33f0
  15.479 +    sta $33f2
  15.480      lda #5
  15.481 -    sta $4ff1
  15.482 -    sta $4ff3
  15.483 +    sta $33f1
  15.484 +    sta $33f3
  15.485  
  15.486      ; Clear the character table and set player position.
  15.487  
  15.488      ldx #234
  15.489      clear_character_loop:
  15.490          lda #0
  15.491 -        sta $4f00,x
  15.492 +        sta $3300,x
  15.493          txa
  15.494          sec
  15.495          sbc #6
  15.496          tax
  15.497          bpl clear_character_loop
  15.498  
  15.499 +    lda #1      ; player
  15.500 +    sta $3300
  15.501 +    lda #3      ; down
  15.502 +    sta $3301
  15.503 +    lda #5      ; x=5
  15.504 +    sta $3302
  15.505 +    lda #5      ; y=5
  15.506 +    sta $3303
  15.507 +    lda #$60    ; centre of the screen
  15.508 +    sta $3304
  15.509 +    lda #$6b
  15.510 +    sta $3305
  15.511 +    lda #0      ; dx=0
  15.512 +    sta $3306
  15.513 +    lda #0      ; dy=0
  15.514 +    sta $3307
  15.515      rts
  15.516  
  15.517  main:
  15.518 @@ -890,9 +1105,9 @@
  15.519          jsr start_new_game
  15.520  
  15.521          game_loop:
  15.522 -            lda $4ff2
  15.523 +            lda $33f2
  15.524              sta $78
  15.525 -            lda $4ff3
  15.526 +            lda $33f3
  15.527              sta $79
  15.528              jsr plot_room
  15.529