[4.5.9] Adventure Slopes\Diagonal Walls

Craigery

Active member
I saw the other thread about Slopes Knietfeld made for the Platformer module, but I am trying to get Slope/Angled Walls to work in the Adventure Module. However this is not currently working, but I feel like I am on to something and maybe it will click with someone else.

THEORY

This will utilize multiple Tile Types; the top half of a slope and the bottom half for each Left \ and Right / slope (in theory 8 tiles). My player moves 1 Y pixel for every 2 X pixels moved. The player's Bottom Center point is compared against the following tables to determine slope collision.
  • Player X is AND to 16 and is used to determine which X pixel of the current tile we are on.
  • Player Y is compared against DiagValueY1_lo. Top half of slope Tile, pixels 0-7.
  • Player Y is compared against DiagValueY1_hi. Bottom half of slope Tile, pixels 8-15.
If the player tries to go into a Sloped area it will stop the player.
I have 1 User Variables to save the X center, but I am not sure I actually need this when trying to STY.
playerCenterX

Hopefully this image helps explain it a bit.
New Project.png

CODE

I have just been trying to get 1 set working before moving on to the Diagonal directions.
Type 01
Left Slope \ Top Half

Code:
    TXA
    STA temp    ;; assumes the object we want to move is in x.
      
        LDA Object_x_hi,x    ;;Load player X
        AND #%11110000        ;;Center X position
        AND #%00010000        ;;cull positions to 16
        STY playerCenterX    ;;Save players center X position into Y

        CLC
        LDA Object_y_hi,x    ;;Load player Y
        ADC #$10        ;;Add 16 pixels. Player is 16x16 so that would give us the bottom.
        AND #%00010000        ;;cull position to 16
        CMP DiagValueY1_lo,y    ;;Compare to Upper half of Tile Y table (0-7)
        BCS +playerStop            ;;If Player Y is larger than the table then Stop Movement.
        JMP +skip

    +playerStop:
        PlaySound #$01
        StopMoving player1_object, #$FF



+skip

Type 02
Left Slope \ Bottom Half

Code:
    TXA
    STA temp    ;; assumes the object we want to move is in x.
      
        LDA Object_x_hi,x    ;;Load player X
        AND #%11110000        ;;Center X position
        AND #%00010000        ;;cull positions to 16
        STY playerCenterX    ;;Save players center X position into Y

        CLC
        LDA Object_y_hi,x    ;;Load player Y
        ADC #$10        ;;Add 16 pixels. Player is 16x16 so that would give us the bottom.
        AND #%00010000        ;;cull position to 16
        CMP DiagValueY1_lo,y    ;;Compare to Lower half of Tile Y table (8-15)
        BCS +playerStop            ;;If Player Y is larger than the table then Stop Movement.
        JMP +skip

    +playerStop:
        PlaySound #$01
        StopMoving player1_object, #$FF



+skip


My tables in ExtraTables.asm

Code:
DiagValueY1_lo:
    .db #$00 , #$00 , #$01 , #$01 , #$02 , #$02 , #$03 , #$03 , #$04 , #$04 , #$05 , #$05 , #$06 , #$06 , #$07 , #$07

DiagValueY1_hi:
    .db #$08 , #$08 , #$09 , #$09 , #$0A , #$0A , #$0B , #$0B , #$0C , #$0C , #$0D , #$0D , #$0E , #$0E , #$0F , #$0F

So like I said I am not sure exactly I am going wrong, but maybe someone would see something obvious I am doing wrong or not considering.
 
Last edited:

kevin81

Well-known member
I think the theory is spot on, but the logic in the code doesn't fully reflect on the theory. For instance, looking at the Type 01 script, line 6 (AND #%00010000) sets the accumulator's value to either 0 or 16, whereas you probably want a value from 0-15 (the x-position of the player relative to the tile the player is on). Also, line 7 (STY playerCenterX) stores the value of the Y-register in a variable called playerCenterX, which is not what the comment (Save players center X position into Y) implies.

I've rewritten and commented the Type 01 script as follows:

Code:
    TXA                    ;; Assumes the object we want to move is in
    STA temp               ;; the X-register.

    LDA Object_x_hi,x      ;; Load the player's x-position on screen

    CLC                    ;; Add 8 to get the x-center of the player,
    ADC #8                 ;; since the player is 16 pixels wide.

    AND #%00001111         ;; Essentially MOD-16 this value to get a
                           ;; value of 0-15, which is the player's
                           ;; x-position relative to the 16x16 tile the
                           ;; player is on.

    TAY                    ;; Transfer this value to the Y-register.

    LDA Object_y_hi,x      ;; Load the player's y-position on screen

    CLC                    ;; Add 15 pixels. Player is 16x16 so that
    ADC #15                ;; would give us the bottom.

    AND #%00001111         ;; Essentially MOD-16 this value to get a
                           ;; value of 0-15, which is the player's
                           ;; y-position relative to the 16x16 tile the
                           ;; player is on.

    CMP DiagValueY1_hi,y   ;; Compare the player's y-bottom to the
                           ;; upper y-table (8-15), based on the
                           ;; player's x-center

    BCS +playerStop        ;; If the player's y-bottom is larger than
                           ;; the table value, then stop moving.

        JMP +skip          ;; If not... don't stop moving :)

+playerStop:
        PlaySound #$01
        StopMoving player1_object, #$FF

+skip:

Unfortunately I can't really test if this is working as intended right now, but perhaps it might be of help!
 

Craigery

Active member
Thank you cleaning that up! However it will Stop Moving the player when it makes contact with any part of the tile. Not sure how to proceed.
ASM is not my area of expertise, but I haves learned so much the last 2 or so years.
 
Last edited:
Top Bottom