I decided to leave the sound engine alone for a while and start adding other stuff. Here are some questions I've been trying to figure out:
1. How do I make the nametable update routine leave X amount of rows alone? This is essential for status bar and in some stages for parallax scrolling. I want to have this as a "mode", because I'm also using the same routine when drawing entire nametables. I can provide code for the nametable update routine etc, if it's necessary for explaining how its done.
2. What's best way to assemble sprites for objects? I was thinking of using index value for each sprite and having a table that has the distance of each 8x8 sprite from the objects position (top left corner of the object).
3. How does bank swapping work on MMC3 (inesmap 4)? The main issue here is that I don't know what addresses I need to put the banks to "call" them with the bank swapping to change the pattern tables.
4. What is a good way to make hitboxes and test collision between objects (and ground, but that's probably done slightly differently)? I'm assuming that you give two sets of x/y coordinates as a pixel offset from object's position. The coordinates themselves are the two opposite corners of the hitbox. I guess that at least with two objects you do something like this:
--> see if obj_1 hitbox x1 is smaller or bigger than obj_2 hitbox x1
----> if smaller, test if obj_1 hitbox x2 is bigger than obj_2 hitbox x1
------> If true, test y axis with same method
------> If false, end test
----> if bigger, test if obj_1 hitbox x1 is smaller than obj_2 hitbox x2
------> If true, test y axis with same method
------> If false, end test
--> If test with y is true, set a flag in RAM for that there is collision
5. Would this be a good way to process objects?
1. How do I make the nametable update routine leave X amount of rows alone? This is essential for status bar and in some stages for parallax scrolling. I want to have this as a "mode", because I'm also using the same routine when drawing entire nametables. I can provide code for the nametable update routine etc, if it's necessary for explaining how its done.
2. What's best way to assemble sprites for objects? I was thinking of using index value for each sprite and having a table that has the distance of each 8x8 sprite from the objects position (top left corner of the object).
3. How does bank swapping work on MMC3 (inesmap 4)? The main issue here is that I don't know what addresses I need to put the banks to "call" them with the bank swapping to change the pattern tables.
4. What is a good way to make hitboxes and test collision between objects (and ground, but that's probably done slightly differently)? I'm assuming that you give two sets of x/y coordinates as a pixel offset from object's position. The coordinates themselves are the two opposite corners of the hitbox. I guess that at least with two objects you do something like this:
--> see if obj_1 hitbox x1 is smaller or bigger than obj_2 hitbox x1
----> if smaller, test if obj_1 hitbox x2 is bigger than obj_2 hitbox x1
------> If true, test y axis with same method
------> If false, end test
----> if bigger, test if obj_1 hitbox x1 is smaller than obj_2 hitbox x2
------> If true, test y axis with same method
------> If false, end test
--> If test with y is true, set a flag in RAM for that there is collision
5. Would this be a good way to process objects?
Code:
.rsset $0600 ; Object Memory structure
obj_id .rs 16
obj_alive .rs 16
obj_x .rs 16
obj_y .rs 16
obj_hp .rs 16
obj_state .rs 16
obj_sprite .rs 16
obj_timer .rs 16
obj_0 .rs 16 ; Unused RAM space (for now)
obj_1 .rs 16
obj_2 .rs 16
obj_3 .rs 16
obj_4 .rs 16
obj_5 .rs 16
obj_6 .rs 16
obj_7 .rs 16
obj_id .rs 16
obj_alive .rs 16
obj_x .rs 16
obj_y .rs 16
obj_hp .rs 16
obj_state .rs 16
obj_sprite .rs 16
obj_timer .rs 16
obj_0 .rs 16 ; Unused RAM space (for now)
obj_1 .rs 16
obj_2 .rs 16
obj_3 .rs 16
obj_4 .rs 16
obj_5 .rs 16
obj_6 .rs 16
obj_7 .rs 16
Code:
ObjHandler:
LDX #$00 ; Offset in object memory
HandlerLoop:
LDA obj_alive, x ; Make sure that object still exists
CMP #$01
BNE NextObj ; Skip object if its not alive
LDA obj_id, x ; Check what kind of object to process
TAY
LDA ObjAddressTable, y ; Get object's code/AI's location
STA obj_addr_lo
LDA ObjAddressTable+1, y
STA obj_addr_hi
JMP [obj_addr_lo] ; Jump to object's code/AI
NextObj: ; Program jumps here after object is processed
INX
CPX #$10
BNE HandlerLoop
RTS
LDX #$00 ; Offset in object memory
HandlerLoop:
LDA obj_alive, x ; Make sure that object still exists
CMP #$01
BNE NextObj ; Skip object if its not alive
LDA obj_id, x ; Check what kind of object to process
TAY
LDA ObjAddressTable, y ; Get object's code/AI's location
STA obj_addr_lo
LDA ObjAddressTable+1, y
STA obj_addr_hi
JMP [obj_addr_lo] ; Jump to object's code/AI
NextObj: ; Program jumps here after object is processed
INX
CPX #$10
BNE HandlerLoop
RTS