... ...Yeay! Thanks tokumaru!tokumaru wrote:Bregalad's formula is correct, for when there are 7 items per row.
And cause it would be easy for my sister to edit the screens. The blue part below is almost how she did it! I never thought of not dividing the level into separate screens... that would be kind of insane I think. But it does sound like it would be easy scrolling beyond 2 screens; though I don't know how to... ...yet.tokumaru wrote: The formula for reading data from a 2D array which is stored in memory linearly is always Y * ElementsPerRow + X, that doesn't change. But you also have to take into consideration that the base unit is the type of element you are accessing, in this case, metatiles. If you have pixel coordinates, you have to first convert them to metatile coordinates, hence the need to divide both X and Y by the dimensions of your metatiles before applying that formula.
Another thing that will affect how you apply the formula is how your levels are stored in RAM/ROM. If you store it screen by screen, then ElementsPerRow will always be the same, because the number of metatiles per screen doesn't change. If you don't divide your level in screens, then ElementsPerRow will be the length of the entire level, and it will vary from level to level. IMO, things are easier if you divide the levels into screens, because the metatile offsets will always fit in 8 bits, and the multiplications/divisions can be easily done with shifts.
Swell... incredible! That takes less cycles. But it takes a bit moretokumaru wrote:Here comes another (untested) example of data arrangement (and how to access it):
codeLevelMap:
;first screen:
.db $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
.db $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
;(another 12 rows here)
.db $10, $10, $10, $10, $10, $10, $10, $10, $10, $10, $10, $10, $10, $10, $10, $10
;second screen:
.db $00, $00, $00, $00, $00, $10, $10, $00, $00, $00, $00, $00, $00, $00, $00, $00
.db $00, $00, $00, $00, $00, $10, $10, $00, $00, $00, $00, $00, $00, $00, $00, $00
;(another 12 rows here)
.db $10, $10, $20, $20, $20, $20, $20, $20, $20, $21, $22, $23, $00, $00, $00, $00
;third screen:
.db $22, $00, $22, $00, $22, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
.db $22, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
;(another 12 rows here)
.db $20, $20, $20, $20, $10, $10, $10, $10, $10, $10, $10, $10, $10, $10, $10, $10
;(keep going for as many screens as you want)
;Reads the index of the metatile at position (PointX, PointY) in the level map
ReadMetatile:
;get the index of the screen
ldy PointX+1
;multiply it by 240 (using a look-up table) and add it to the base
;address of the level to create a pointer to the screen we need
clc
lda ScreenOffsetLo, y
adc LevelMap+0
sta ScreenPointer+0
lda ScreenOffsetHi, y
adc LevelMap+1
sta ScreenPointer+1
;calculate the index of the metatile: (Y / 16) * 16 + (X / 16)
lda PointX+0
lsr
lsr
lsr
lsr
sta Temp
lda PointY+0
and #%11110000
ora Temp
tay
;read the metatile
lda (ScreenPointer), y
;return
rts/code
Now you can do whatever you want with that information. Want to know if that metatile is solid? Do something like this:
Code: Select all
tax lda MetatileCollision, x and #BITTHATINDICATESWHETHERAMETATILEISSOLID beq +NotSolid
Aw yes faster code!tokumaru wrote: Want to know what is the top left tile of that metatile?
Code: Select all
tax lda MetatileTopLeft, x
Ok I slowly changed my code to be just like your code all today.
But, I haven't implemented any of this bit of your yellow code up there... I just tried to use my variables. I got the first part of my code to look like the first part of your code. Now the lady sprite falls just halfway down the screen and then pauses. She is susposed to fall to the bottom of the screen. My code at the end is still the same:
Code: Select all
0C3DB
0C3DB ;GRAVITY
0C3DB C6 31 dec tC
0C3DD 10 02 bpl +skip
0C3DF
0C3DF B1 0C lda (rhombusCollision_low), y
0C3E1
0C3E1 ;if the metatile is not solid
0C3E1 0A asl a ;<pushes bit #7 into carry.
0C3E2 90 09 bcc +skip
0C3E4
0C3E4 ;then fall to the metatile below...
0C3E4
0C3E4 B1 1A ;lda (UCollision_low), y
0C3E6 A5 05 lda oY
0C3E8 18 clc
0C3E9 69 08 adc #8
0C3EB 85 05 sta oY
0C3ED +skip
0C3ED
0C3ED E6 31 ;inc tC
0C3EF
0C3EF 60 rts ;end of unpack and end of daprg-collisionU
edit: Ok... I want to say that I know that the yellow text will help me to make my game... almost... to make our game more like a machiene. A machiene with parts that work flawlessly together... I remember that tokumaru.