[SOLVED] bonus level warp

n8bit

Member
Would like to add bonus levels if conditions are met, for instance if the variable myMoney is greater or equal to 20.

So once the player reached the end of the level and touches the level clear tile they will either warp to the next level or warp to the bonus level if they collected enough items.

would something like this before my warp to screen code do the trick?

Code:
CPX myMoney
BEQ #$14
LDA warpMap
sta currentMap
clc
ADC #$01
STA temp
GoToScreen warpToScreen, ;;;place bonus screen coordinates here
RTS
 

dale_coop

Moderator
Staff member
To check a variable:
Code:
LDA myVariable
CMP #$01
BEQ goToLabelIfEqual
;; here the code if not equal

For a hud variable, to check if more than 20 you have to test the tenth number

Code:
LDA myVariable+1  ;; Check thé tenth digit
CMP #$02  ;; compare it with 2
BEQ goToLabelIfEqual
;; here the code if not equal

So for your warp script:

Code:
; cpx player1_object
; BNE dontDoWarp_tile
; LDA warpMap
; sta currentMap
; clc
; ADC #$01
; STA temp
; GoToScreen warpToScreen, temp

; dontDoWarp_tile

LDA #$00
STA newGameState

 LDA warpMap
 sta currentMap
 clc
 ADC #$01
 STA temp
 
 LDA myMoney+1
 CMP #$02
 BCC continueNormalWarp  ;; is less than 20
 ;; is equal or greater then 20
 LDA #ID_OF_THE_BONUS_SCREEN  ;; <—- HERE YOUR BONUS SCREEN ID (counting from 0 to 255, from top left to bottom right)
 STA warpToScreen
 
 continueNormalWarp:
 GoToScreen warpToScreen, temp, #$02
 LDA #$00
 STA playerToSpawn
 LDX player1_object
 DeactivateCurrentObject
 LDA #$01
 STA loadObjectFlag
 
LDA mapPosX
STA newX
LDA mapPosY
STA newY

Can’t test it, not home now.
 

n8bit

Member
hmmm... getting an error...

Routines\BASIC_021019\ModuleScripts\TileScripts\ScrollingPlatformer\WarpToScreen.asm(1): Illegal instruction

The only change I made was I added a screen id (#$09).

Will keep playing with it and see if I can get it working. Thanks for your help!
 

n8bit

Member
yup, was an error on my part...

Conditional warping not working though. Still warps to next level regardless of count.

Thanks for your help! You gave me some really good insight and a good foundation. Going to see if I can figure this out!

Thanks again Dale!
 
There's also this script:
Code:
LDA myMoney				
CLC

CMP #$05
BNE redherring_skip_warp

cpx player1_object
BNE redherring_skip_warp
LDA warpMap
adc #$01
STA temp
GoToScreen warpToScreen, temp

redherring_skip_warp:


This works in 4.0.11, it will of course need to be edited for 4.1.
But it's here if anyone else other than me is still using 4.0.11. :lol:
Just change "#$05" to whatever number you require.


Note: this is designed to be paired with my "easter egg" script.
 

Kasumi

New member
The CLC after LDA myMoney in that script is unneeded. cmp works as if the carry were clear even when it is set, and then changes the carry based on the result of the compare so that clc never does anything that has an effect on this script's behavior.

What happens after that is kind of interesting. CPX also changes the carry based on the result of the compare. If the two values are equal (for instance, ldx #4, cpx #4) the carry ends up set. So after the CPX is a branch if the values are NOT equal. If that branch isn't taken, though, the carry is set.

Which makes adc #$01 add 2 instead of 1. If two is indeed the value that works, I would change the code like this instead:
Code:
LDA warpMap
clc
adc #$02
STA temp
GoToScreen warpToScreen, temp
Because it makes the intent to add 2 much more clear.
 

n8bit

Member
dale_coop said:
To check a variable:
Code:
LDA myVariable
CMP #$01
BEQ goToLabelIfEqual
;; here the code if not equal

For a hud variable, to check if more than 20 you have to test the tenth number

Code:
LDA myVariable+1  ;; Check thé tenth digit
CMP #$02  ;; compare it with 2
BEQ goToLabelIfEqual
;; here the code if not equal

So for your warp script:

Code:
; cpx player1_object
; BNE dontDoWarp_tile
; LDA warpMap
; sta currentMap
; clc
; ADC #$01
; STA temp
; GoToScreen warpToScreen, temp

; dontDoWarp_tile

LDA #$00
STA newGameState

 LDA warpMap
 sta currentMap
 clc
 ADC #$01
 STA temp
 
 LDA myMoney+1
 CMP #$02
 BCC continueNormalWarp  ;; is less than 20
 ;; is equal or greater then 20
 LDA #ID_OF_THE_BONUS_SCREEN  ;; <—- HERE YOUR BONUS SCREEN ID (counting from 0 to 255, from top left to bottom right)
 STA warpToScreen
 
 continueNormalWarp:
 GoToScreen warpToScreen, temp, #$02
 LDA #$00
 STA playerToSpawn
 LDX player1_object
 DeactivateCurrentObject
 LDA #$01
 STA loadObjectFlag
 
LDA mapPosX
STA newX
LDA mapPosY
STA newY

Can’t test it, not home now.

Still trying to get this to work. Although it doesn't toss any errors or affect the gameplay, the warp does not work. Player just continues to next level even if they have more than 20 of the items. Doesn't warp to bonus screen at all.
 

n8bit

Member
dale_coop said:
Woohooo! Good job, man! (^_^)

Spoke too soon. looked like it was working but I had some other warp issues going on and it gave the appearance that the bonus warp was working (glitch was warping to same screen I was testing bonus warp with).

So bonus warp is still not working.

Here is my WarpToScreen script:

Code:
; cpx player1_object
; BNE dontDoWarp_tile
; LDA warpMap
; sta currentMap
; clc
; ADC #$01
; STA temp
; GoToScreen warpToScreen, temp

; dontDoWarp_tile

LDA #$00
STA newGameState

 LDA warpMap
 sta currentMap
 clc
 ADC #$01
 STA temp
 
 LDA myMoney+1
 CMP #$02
 BCC continueNormalWarp  ;; is less than 20
 ;; is equal or greater then 20
 LDA #$0A  ;; <—- HERE YOUR BONUS SCREEN ID (counting from 0 to 255, from top left to bottom right)
 STA warpToScreen
 
 continueNormalWarp:
 GoToScreen warpToScreen, temp, #$02
 LDA #$00
 STA playerToSpawn
 LDX player1_object
 DeactivateCurrentObject
 LDA #$01
 STA loadObjectFlag
 
LDA mapPosX
STA newX
LDA mapPosY
STA newY
 

dale_coop

Moderator
Staff member
Can you explain again the whole thing...? you want your player to warp to a bonus stage when he has a certain score.
But when this warp is supposed to be triggered ? As soon as the player gets the scrore? When he beats the level (at the end of the victory animation)? When the players touches a Warp tile?
 

n8bit

Member
dale_coop said:
Can you explain again the whole thing...? you want your player to warp to a bonus stage when he has a certain score.
But when this warp is supposed to be triggered ? As soon as the player gets the scrore? When he beats the level (at the end of the victory animation)? When the players touches a Warp tile?

The player collects objects (myMoney). If they collect at least 20 I would like them to warp to a bonus level when they beat the level (victory animation) rather than proceeding on to next level. If they do not collect at least 20 they simply warp to next level. I also need to figure out how to reset the myMoney counter after each level.

Hope that makes sense.
 

n8bit

Member
I got it working! For real this time! The issue was my end of level warp item...

I have the player touch an item to signal the end of level and warp to next level. I had the item set as "level clear". When I changed the collision on the item to "warp to screen" the bonus warp worked when I had 20 or more of "myMoney"!

EDIT: Now I have a new dilemma :lol: ...

I am going to have to create a bonus stage for each level. The bonus stage does not know which screen you were previously on so I think I am going to have to add a bunch of code to the warp script to check the current screen and, based on current screen, warp to a specific bonus screen that will then warp the player to the next level. Is that even possible?
 
Top Bottom