Skip to content

Latest commit

 

History

History
205 lines (147 loc) · 4.71 KB

CS-98-026_4.md

File metadata and controls

205 lines (147 loc) · 4.71 KB

...menustart

...menuend

Drawing the Level

  • You may be tempted to have code such as:
set $2007 1
set $2007 5
set $2007 1
...
set $2007 4
  • This works, but is generally a bad idea

  • Use a load function to read that data

load_level:
    //do stuff here
    return
level_data:
    asm
    .incbin “level.dat”
    endasm

use RLE Compression for save ROM size

Sound Effects

;       Select:     Select channel
;       Up/Down:    Select register of current channel
;       Right/Left: Select bit of current register
;       A:          Toggle current bit
;       Start:      Play channel

some samples to start you off

init_sound:
    set $4015 0 //turn off all channels
    set $4015 %00011111 //turn them back on
    return

playsound_jump:
    set $4000 %10011000
    set $4001 %10001100
    set $4002 %01001101
    set $4003 %10010101
    return

playsound_squish:
    set $4000 %10001000
    set $4001 %01001000
    set $4002 %00100101
    set $4003 %01001011
    return

playsound_thump:
    set $4000 %10011111
    set $4001 %10000100
    set $4002 %11010011
    set $4003 %11111100
    return

Programming Palettes

  • Loader function
  • data array
load_palette:
    set $2006 $3f
    set $2006 0
    set x 0
    load_palette_1:
        set $2007 [palette x]
        inc x
        if x < 32 branchto load_palette_1
    return
palette:
    data 0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3
    data 0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3

Multiple Palettes

  • You may want the palette to change when something important happens
  • Easy approach: multiple load functions, multiple palette data arrays
load_overworld_palette:
    //do some stuff
    return
load_evil_palette:
    //do some stuff
    return
overworld_palette:
     //some data
evil_palette:
     //some data

Palette Cycling

  • Sometimes you want certain colors to change over time
    • gold coins in Mario, player gets hurt and flashes
  • Every frame, or every few frames, change part of the palette
  • When called each frame, this code will make one palette color cycle through shades of gold every 8 frame
  • Powers of 2 are easy cycle times to work with
cycle_coin_color:
    set $2006 $3f
    set $2006 19 //foreground color 3
    set which_color & current_frame %111
    set $2007 [coin_colors which_color]
    inc current_frame
    return
coin_colors:
    data $18,$26,$27,$28,$28,$27,$26,$18

Scene Change Palette

  • A scene change (new level, going through a door) often needs to redraw the whole background
  • Rewriting an entire name table cannot be done in a single vblank
  • You need to either take several frames or turn off the PPU during that time
  • If you take several frames to draw, blanking the palette can avoid unsightly graphics

Sprite 0 Hit Tricks

  • Many games use split screen scrolling to scroll one part of the screen and have a static status bar at the top or bottom
  • You may be able to detect multiple times and locations in a frame, if you want to be really cool

Sprite 0 Usage

  • Bit 6 of $2002 tells sprite 0 hit status
  • Three loops for proper usage
    • Wait for end of vblank
    • Wait for bit 6 to clear
    • Wait for bit 6 to hit
  • There’s some code on the webpage for you