[4.5.9] How to put a tile at position x,y and check what tile is at given location

m8si

Active member
How to put a tile at a specific location on the screen?

Let's say I would like to put tile on screen location 3,1 (in tiles) how can I do that in code?

I found out I can somehow put a tile on screen at "position 2" with a code taken from ChangeTileAtCollision. At first line (LDY #$02, original code has LDY temp1)

However this code will crash the game. Maybe because the tile I'm colliding with is never set to walkable after I run this code and I get an infinite loop. I tried to make it walkable and added another line after these: ChangeTileAtCollision #$00,#$00 but after that the code below stopped working...

Also another question. How can I tell what tile is at a given location?
E.g. IF Tile at location 4,3 is TileNumber02 ---> Do something


Code:
LDY #$02 ;; X Position goes here this was originally LDY temp1
    LDA temp2
    BEQ +isEvenCt
        ;; is an odd ct, so looking in collisionTable2
        LDA #$00 ; = collision to change into.
        STA collisionTable2,y
        JMP +doneWithTileUpdate
    +isEvenCt
        LDA #$00  ; = collision to change into.
        STA collisionTable,y
       
       
   
       
    +doneWithTileUpdate
   
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  
;;;; This part will actually update the tile with tile 0 in the tile set.
;;; ys is carried over from above.

;;; GET THE HIGH BYTE OF THE TILE TO CHANGE
    LDA temp2
    BEQ +isEvenNt
        ;; is odd nt
        LDA #$24
        JMP +gotNt
    +isEvenNt
        ;; is even nt
        LDA #$20
    +gotNt
        STA temp1
;;; GET THE LOW BYTE OF THE TILE TO CHANGE
        TYA
        STA temp
        LSR
        LSR
        LSR
        LSR
        LSR
        LSR
        clc
        ADC temp1
        STA temp2 ;;;temp16+1
        TYA
        AND #%11110000
        ASL
        ASL
        STA tempz
        TYA
        AND #%00001111
        ASL
        ORA tempz
        STA temp3 ;temp16
       
;;; SET THE TILE NUMBER TO CHANGE TO.  
    LDA #$20 ;; the tile to change.
            ;;; this is in tiles, so if you wanted the second "metatile",
            ;;; use 2, not 1.  If you wanted the tile in the next row,
            ;;; use #$20, not #$10.  Etc.
    STA tempA
    CLC
    ADC #$01
    STA tempB
    CLC
    ADC #$0F
    STA tempC
    CLC
    ADC #$01
    STA tempD
   
   
    LDY #$00
        LDA temp2
        STA scrollUpdateRam,y
        INY
        LDA temp3
        STA scrollUpdateRam,y
        INY
        LDA tempA
        STA scrollUpdateRam,y
        INY
       
        LDA temp2
        STA scrollUpdateRam,y
        INY
        LDA temp3
        CLC
        ADC #$01
        STA scrollUpdateRam,y
        INY
        LDA tempB
        STA scrollUpdateRam,y
        INY
       
            LDA temp3
            CLC
            ADC #$20
            STA temp3
            LDA temp2
            ADC #$00
            STA temp2
       
        LDA temp2
        STA scrollUpdateRam,y
        INY
        LDA temp3
        STA scrollUpdateRam,y
        INY
        LDA tempC
        STA scrollUpdateRam,y
        INY
       
        LDA temp2
        STA scrollUpdateRam,y
        INY
        LDA temp3
        CLC
        ADC #$01
        STA scrollUpdateRam,y
        INY
        LDA tempD
        STA scrollUpdateRam,y
        INY
   
    TYA
    STA maxScrollOffsetCounter
   
   
           
   
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Turn on update screen on next frame.
        LDA updateScreenData
        ORA #%0000100
        STA updateScreenData
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
Last edited:

m8si

Active member
Here is a video what this code does:


So the actual problem is:

I want to get the tileID of that "I" tile and put the same tile on top of the screen. Ideally that would work the same with a "V" tile.
After that I want to hide the tile that is under the player.

And Yea! It's going to be an accordion game. What's cooler than that?!? =D
 

m8si

Active member
I ended up using a hud for this after I got no response. It still bothers me... Is it possible to manipulate tiles in game?
 

PasseGaming

Active member
Sorry, I haven't the faintest idea. Occasionally you'll find the forums just as stumped as you are. We're all learning here.
 

m8si

Active member
Oh. I thought it would be quite basic operation to get a tile and change it. If someone somehow finds out how to do it I would be grateful. :)
 

CluckFox

Active member
And Yea! It's going to be an accordion game. What's cooler than that?!? =D
This is awesome. Allow me to just leave a picture of my rig right here... Feel free to @ me in an Offtopic thread if you want to talk shop. :)
107917213_423690.jpg
 

m8si

Active member
This is awesome. Allow me to just leave a picture of my rig right here... Feel free to @ me in an Offtopic thread if you want to talk shop. :)
View attachment 4426
Cool! Do you play yourself? I play only chromatic 5-row accordion, but always wanted to try out a bandoneon. I guess this is a bandoneon accordion, right?
 

CluckFox

Active member
Cool! Do you play yourself? I play only chromatic 5-row accordion, but always wanted to try out a bandoneon. I guess this is a bandoneon accordion, right?
I've been playing for about two years now. It's really fun to play, just like 8bit games :p
Mine is an Anglo concertina, very similar to a bandoneon.
 

Moehr

New member
Oh. I thought it would be quite basic operation to get a tile and change it. If someone somehow finds out how to do it I would be grateful. :)
Hey, do you got this figured out yet? If not I'm working on it now as well :D

I'll keep you posted if I get it working.

I'm setting up two tiletypes. One is a triggered tile that is solid except while a timer is active, the other responds to being shot by starting the timer.

Everything works at this point except the graphics change hits some tile other than the triggered tile.

If I get it sorted I'll post the code as well


edit:
Got it sorted! Here's a zip that has some scripts that'll let you use a trigger tile that can swap up to 4 tiles onscreen when triggered to illustrate [in particular the simple change to ChangeTileAtCollision, which the others combine to leverage]:
 

Attachments

  • shot-triggers-multi-tile-change.zip
    3.5 KB · Views: 21
Last edited:
Top Bottom