...menustart
...menuend
- The MMC3 can swap 64 or 128 tiles at a time in the pattern table
- ...
- Profit!
- The MMC3 lets us swap portions of the pattern table. Sounds familiar...
- You can also use the same trick to give your character new clothes for free
- Sometimes you need complex calculations
- These are hard and slow on the NES
- In many cases, you can pre-compute values and store them in a static array, then just look in the array when you need the value
- Useful for physics, complex movements, exponential decay
- The 6502 does not support multiplication or division by anything other than 2
- Try the “Russian Peasant” method , Google will help you out
- Medieval physics
- Newtonian physics
- 动力,恒速上升和下降
- 每帧向上移动一个像素,直到用尽动力。 每帧向下移动一个像素直到你碰到地面
- Fine for games with falling but not jumping
-
Newton told us that things going through the air move in a parabola
-
We can’t just “move some number of pixels each frame”
-
It’s hard to calculate a parabola on the 6502
-
Use a lookup tabl
-
Store delta movement for each moment in time during a jump
-
Two ways to do this...
- Array values are between 0 and max speed per frame
- Keep track of direction and location in array, move array index each frame
- For a jump, immediately move near the end of the array
- Go back to 0 when we hit the ground
gravity:
data 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1
data 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 2, 1
data 2, 1, 2, 2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
data 3, 3, 3, 3, 3
- Array values are between 0 and max speed, and between 255 and 255-max speed
- Adding large numbers is the same as subtracting small ones
- Add array value and move array index each frame
- Go back to array center when we hit the ground
gravity:
data 253, 253, 254, 253, 254, 254, 254, 254, 254, 254
data 254, 254, 255, 254, 255, 254, 255, 255, 255, 255
data 255, 0, 255, 255, 255, 255, 0, 255, 0, 255, 0, 0, 0
//array center. no movement
data 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1
data 2, 1, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 3, 3
- It’s difficult and impractical to do it per pixel
- Use simple shapes, like rectangles
- Modern games still use similar methods
- Make a collision map, a large array corresponding to the background screen that tells whether each block is impassable
- Update the collision map as the game scrolls
- Test an object’s bounding rectangle against the collision map
- Hard to make on your own
- Create from player input?
- Table lookup?
- Pseudo-random function?
- Random Number Generator
- Setting the random seed, looping on the start screen
set random_seed 1 //anything non-zero
gosub random_number
//register A now holds a random number
set my_var a
- Updating the name table during gameplay is hard.
- It’s easier to restrict your game to 2 screens at a time
- Infinite scrolling backgrounds are good in space shooters