warmCabin

Mega Man 2 Moving Platforms Writeup

May 18th, 2021 (edited)
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. Unlike Super Mario World, moving platforms in Mega Man 2 have absolutely no correlation with the background graphics.
  2. In fact, their movement is rather robust; if you move them around in a level editor, they'll often find their way back to the track
  3. and continue like nothing happened. In this document, we will explore how this path data is enocded and implemented.
  4.  
  5. All addresses are for Rockman 2.
  6.  
  7. == Path data ==
  8. Crashman path data: $9B43
  9. Wily 4 path data: $9BBB
  10. Path start pointers: $9B25
  11. Path lengths: $9B3C
  12. Path Number: Computed based on screen number.
  13.  
  14. == Velocity vectors ==
  15. VY subpixel: $9B2C
  16. VY pixel: $9B30
  17. VX subpixel: $9B34
  18. VX pixel: None!
  19. Flags: $9B38 - used to set facing direction appropriately.
  20.  
  21. == Misc. ==
  22. Sprite timers: $04E0
  23. Screen Numbers: $0440
  24. Platform subroutine: $9A79 (roughly)
  25.  
  26. Path data is stored in pairs: target coord, next direction. The game can tell whether target is supposed to be X or Y based on direction.
  27. 0 = down
  28. 1 = left
  29. 2 = up
  30. 3 = right
  31.  
  32. Compute the Path Number, then use that as an index into the length and start_pointer tables.
  33. Your start pointer is a pointer into either of the path data tables.
  34. The platform's sprite timer is its current path index, which is added to the start pointer to determine where the next piece of data comes from.
  35. This index increments by two each time, and the length is even. When index equals length, it goes back to 0.
  36.  
  37. Path Numbers:
  38. Crashman: 0 - 2
  39. Wily 4: 3 - 6
  40.  
  41. These numbers are computed based on the screen number. In Crash (stage == 7), it's screen number - 4. In Wily 4 (all other stages), it's screen number - 1B.
  42. So these things really can't exist outside of the seven screens they were meant to be in.
  43.  
  44. The game checks if Path Number < 3, and looks at the Crashman path data. Otherwise it uses the Wily 4 Path data.
  45.  
  46. Velocity vectors:
  47. Use the facing direction to index into the 4-byte velocity vector tables. They basically tell the platforms what's up. And left. And down. And right.
  48. You can adjust horizontal speeds to a maximum of (just under) 1 pixel per frame, and vertical speeds to a maximum of (just under) 128 pixels per frame.
  49. There is no VX pixel because that math is actually handled a bit differently.
  50. X speed is scalar, and added or subtracted from position based on the facing flag.
  51. Y speed is treated as signed, sort of. It's always added to your position.
  52.  
  53. One thing to note is that the game checks for pixel equality at each path corner. So if you want your platforms to go faster than 1 pixel per frame,
  54. you might find that they fly off into oblivion. Luckily, the game resets subpixels at each corner, so if your path works once, it will continue to work forever.
  55.  
  56. ==========
  57.  
  58. What's interesting here is the path numbers are deliberately set not to overlap, but the path data still uses separate tables for the separate stages.
  59. It seems like you could unify the path data into one big table and save some trouble. However, this won't work. Let's count up how many turns each path makes
  60. in the vanilla game.
  61.  
  62. Crash:
  63. 0: 4
  64. 1: 14
  65. 2: 42
  66. Total: 60
  67.  
  68. Wily 4:
  69. 3: 34
  70. 4: 12
  71. 5: 24
  72. 6: 10
  73. Total: 80
  74.  
  75. Total total: 140
  76.  
  77. We need 280 bytes to store this information. So this idea of path data banks is NECESSARY.
  78. If you want to make this system extensible for custom levels, you might want even MORE banks.
  79. You could try to decouple the Path Number calculation from the stage number, but the data is packed pretty tight there. There's no room to spare
  80. between the path lengths and the Crashman path data. So you'd want to take this data and push it somewhere else.
  81. I don't know if sprites have metadata or if it's simply type, X, Y in the level data, but that would be a great place to store path number if possible.
  82.  
  83. But without any significant rewrites, we have:
  84. 7 platforms in consecutive rooms across 2 stages with a maximum of 256 path segments.
  85.  
  86. You can cheese the 2-stage limit by making sure the room numbers line up for the non-Wily 4 stages.
  87. e.g. Bubble has platforms in rooms 1 and 2, Wood has platforms in rooms 3 and 4. But that sounds confusing and stifling.
  88.  
Advertisement
Add Comment
Please, Sign In to add comment