Skip to content

Latest commit

 

History

History
178 lines (112 loc) · 4.86 KB

CS-98-026_3.md

File metadata and controls

178 lines (112 loc) · 4.86 KB

...menustart

...menuend

Animation

Background Animation

  • The MMC3 can swap 64 or 128 tiles at a time in the pattern table
  • ...
  • Profit!

Foreground Animation

  • 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

Table Lookups

  • 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

Multiplication

  • The 6502 does not support multiplication or division by anything other than 2
  • Try the “Russian Peasant” method , Google will help you out

Gravity

  • Medieval physics
  • Newtonian physics

Medieval Gravity

  • 动力,恒速上升和下降
  • 每帧向上移动一个像素,直到用尽动力。 每帧向下移动一个像素直到你碰到地面
  • Fine for games with falling but not jumping

Newtonian Gravity

  • 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...

Method 1

  • 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

Method 2

  • 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

Collision Detection

  • It’s difficult and impractical to do it per pixel
  • Use simple shapes, like rectangles
  • Modern games still use similar methods

Collision With the World

  • 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

Random Numbers

  • 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

Multi Screen Tip

  • 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