Better random picking for new maps
authorLukas Krickl <lukas@krickl.dev>
Wed, 22 Mar 2023 05:26:43 +0000 (06:26 +0100)
committerLukas Krickl <lukas@krickl.dev>
Wed, 22 Mar 2023 05:26:43 +0000 (06:26 +0100)
main.asm

index 31cc412fe10ce596799aeb0f571d7dcebb0ad0cc..c78abd0cd2a68f54334781638935432ff18bb7e1 100644 (file)
--- a/main.asm
+++ b/main.asm
@@ -74,6 +74,8 @@ MapPtr1:         ds 2    ; used for drawing map
 MapPtr2:         ds 2    ; used for drawing map
 ; map counter for each PF, currently all of those are the same
 CurrentMap: ds 3 ; map counter - must increment by 6 for new map to fully load
+RandMap: ds 1 ; map timer, increments by one each frame until MAPCOUNT is reached
+; then resets to 0. used to get a random map
 
 MapsCleared: ds 1 ; amount of clreaded maps this level
 
@@ -170,6 +172,15 @@ Reset
 StartOfFrame
        ; start of new frame
        inc Framecount
+       
+       ldx RandMap
+       inx
+       cpx #MAPCOUNT+1
+       bne MapCountRandNotReached
+       ldx #0
+MapCountRandNotReached
+       stx RandMap
+
        ; compare Framecount to 0
        ldx Framecount
        cpx #0
@@ -1013,10 +1024,11 @@ NextMap
        ;sta CurrentMap+2
 
        ; this is the old code to pick a static map
-       jsr Random
-       lda Rand8
-       and #MAPCOUNT-1 ; only allow MAPCOUNT for roll
-       tay
+       ; jsr Random
+       ; lda Rand8
+       ; and #MAPCOUNT-1 ; only allow MAPCOUNT for roll
+       ; tay
+       ldy RandMap
        cpy #0 ; 0 does not require an offset
        beq NextMapDone
        ;dey