[4.5.9] Open portals by shooting with specific weapons like Metroid

zero

New member
I'm working on a MetroidVania and i made this Script to open Doors by shooting with some weapons like in Metroid
I hope you like it

1 - Create a new Tile Type, like DoorTile
View attachment 5970

2 - Assign an Script to a same position as the new Tile. In this case "doorTile" is on 12 position so find the 12 script on TileTipes and load a Script like DoorTile.asm
View attachment 5971

3 - Get the tile code like below "0C"
View attachment 5972

4 - Script
How it works:
This tile is set to Solid so is aways checking for a specific weapon type collision, and you can set a Weapon you want, if its true start to check all tiles untill find the DoorTile so the Tile is replaced by another Tile also its Type and also you can choose what tile and what type you want. The Script below replace the Tile to a BlankTile but its type is a Warp type.
;;solid tile

LDA ObjectUpdateByte
ORA #%00000001
STA ObjectUpdateByte ;; makes solid


;check if colides with a weapon
LDA Object_type,x
CMP #$02 ;check if object is a Projectile in $02. If true so start to check all tiles utill find DoorTile to be destroyed
BEQ +destroyTile
JMP +weaponCantDestroy

+destroyTile
WEAPON_TILE = #$0C ; the number of your DoorTile.
LDX #$00
checkForDoorTiles
LDA currentNametable
AND #%00000001
BEQ +isEvenCt
LDA #$24
STA temp1 ;; high byte of thing
;;; is odd col table.
LDA collisionTable2,x
CMP #WEAPON_TILE
BEQ +IsDoorTile
JMP +notDoorTile
+IsDoorTile
;; is door tile.
LDA #$00
STA collisionTable2,x

JSR getTileToChange_afterColision

JMP +doneWithTileUpdate
+isEvenCt
LDA #$20
STA temp1 ;; high byte of thing.
;;; is odd col table.
LDA collisionTable,x
CMP #WEAPON_TILE
BEQ +IsDoorTile
JMP +notDoorTile
+IsDoorTile
;; is door tile.
LDA #$00
STA collisionTable,x
JSR getTileToChange_afterColision

JMP +doneWithTileUpdate

getTileToChange_afterColision:
TXA
STA temp
LSR
LSR
LSR
LSR
LSR
LSR
clc
ADC temp1
STA temp2
TXA
AND #%11110000
ASL
ASL
STA tempz
TXA
AND #%00001111
ASL
ORA tempz
STA temp3


;;; SET THE TILE NUMBER TO CHANGE TO.
LDA #$00 ;; 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 ;=> This is the tile type to set. In ths case i set Warp type
STA updateScreenData
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
TriggerScreen screenType
RTS
+doneWithTileUpdate


JSR doWaitFrame
+notDoorTile
INX
CPX #240
BEQ +weaponCantDestroy ;; done
JMP checkForDoorTiles ;; last door tile.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+weaponCantDestroy
rts
 

tbizzle

Well-known member
I'm working on a MetroidVania and i made this Script to open Doors by shooting with some weapons like in Metroid
I hope you like it

1 - Create a new Tile Type, like DoorTile
View attachment 5970

2 - Assign an Script to a same position as the new Tile. In this case "doorTile" is on 12 position so find the 12 script on TileTipes and load a Script like DoorTile.asm
View attachment 5971

3 - Get the tile code like below "0C"
View attachment 5972

4 - Script
How it works:
This tile is set to Solid so is aways checking for a specific weapon type collision, and you can set a Weapon you want, if its true start to check all tiles untill find the DoorTile so the Tile is replaced by another Tile also its Type and also you can choose what tile and what type you want. The Script below replace the Tile to a BlankTile but its type is a Warp type.
I wish there was a way to be able to destroy each individual tile instead of all tiles at once. @dale_coop???
 
Last edited:

dale_coop

Moderator
Staff member
@tbizzle In the tile script, instead of the code that destroys all the tiles, try calling the "ChangeTileAtCollision" macro...
Something like that:
Code:
;;solid tile

LDA ObjectUpdateByte
ORA #%00000001
STA ObjectUpdateByte ;; makes solid

;check if colides with a weapon
LDA Object_type,x
CMP #$02 ;check if object is a Projectile in $02. If true so start to check all tiles utill find DoorTile to be destroyed
BEQ +destroyTile
    JMP +weaponCantDestroy

+destroyTile:
    ChangeTileAtCollision #$00, #$00 ;; change to tile zero (make disappear), collision type 0
+weaponCantDestroy:
rts
 
Top Bottom