A moving platform that carries you, the way Mario's lifts do
A hole in the ground with a lift going back and forth over it. Play it, step onto the lift and let go of the pad: the square rides it across and back, and walks off its far end onto the other side. The program is 420 instructions in 1,122 bytes, built and checked the same way.
Play it here Change it on the desk The cartridge, to play anywhere that plays NES cartridges: platforms.nes
On the screen
Standing on something that moves means moving with it
In Super Mario Bros. a lift is an object like an enemy, kept in the same slots and moved a step at a time. When Mario stands on one, the game moves him by the lift’s own step on the same frame, so he keeps his place on it without anything being pressed. We watched a lift in 1-2 carry him and checked every step. This cartridge does it the same way, in the order that makes it work: the lift moves first, then the square on it by the same, and only then whatever the pad asks for.
| this cartridge | Super Mario Bros. | |
|---|---|---|
| which way the lift moves | across | vertically |
| pixels a step, and frames between steps | 1, every 1 | 1, every 1 |
| pixels it travels end to end | 48 | none: it leaves the bottom of the screen and comes back in at the top |
| frames the player stood on it | 158 | 77 |
| steps that moved the player by the same, of those taken while standing with nothing pressed its way for a second | 68 of 68 | 72 of 72 |
| the player's height above the lift held steady | yes | yes |
As written
The part of the program this lesson is about. The whole program is a plain text file: platforms.s
;; Across: Right adds 10/256 a frame up to 1.5 pixels a frame; without
;; it the speed falls by the same until it is 0. Then the right edge's
;; two corners are looked up: in a block, the square goes back to touch
;; it and its speed across is taken away.
;; The lift: a pixel a frame along its path, turning at either end (x
;; 80, where the hole begins, and x 128, where its far end meets the far
;; side). A square standing on it is moved the same pixel on the same
;; frame, before anything the pad asks for; and moved by the step the
;; lift just took, so the turn comes after the carry (turned first, the
;; square went one way while the lift went the other, once at each end).
lift:
LDA $30
CLC
ADC $31
STA $30
LDA $32
BEQ carried
LDA $11
CLC
ADC $31
STA $11
carried:
LDA $30
CMP #$50
BEQ turn
CMP #$80
BNE moved
turn:
LDA #$00
SEC
SBC $31
STA $31
moved:
RTSBefore this one: Ground, a block and a wall, solid the way Mario's are
Next: A coin from a block and the score, the way Mario's are