JewelianPerez_27
Member
Hello NesMakers!
The key pickup in my game has been causing a multitude of problems:
Whenever I pick up a key item and then kill an enemy, my game crashes.
On top of that, other pickups also don't work if my key script is written first in my Pickup scripts.
Adding the key pickup script anywhere else in the code causes the key to not function.
I've been stumped on this for a while, and I'm not sure how to fix this.
Any help is appreciated!
here is my Pickup Script:
The key pickup in my game has been causing a multitude of problems:
Whenever I pick up a key item and then kill an enemy, my game crashes.
On top of that, other pickups also don't work if my key script is written first in my Pickup scripts.
Adding the key pickup script anywhere else in the code causes the key to not function.
I've been stumped on this for a while, and I'm not sure how to fix this.
Any help is appreciated!
here is my Pickup Script:
Code:
;;; Pickup scripts.
;;; Right now, we need to look at the type of object that is in X.
;;; Then, we have to do pickup behavior accordingly.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KEY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
LDA Object_type,x
CMP #$06
BNE +notThisPickup
INC myKeys
LDA myKeys
;CMP #$3E7 ;; one more than the max
;BNE +dontNormalizeValue
; LDA #$63 ;; normalize the value to 999 if it got bigger than 999
; STA myKeys
;+dontNormalizeValue
UpdateHudElement #$07
TriggerScreen screenType
AddValue #$02, myKeys, #$0, #$00
AddValue #$07, myScore, #$1, #$02
UpdateHudElement #$06
;JMP +benchmark
+notThisPickup:
JMP +endPickups
;; Here is an example of how to set variable myAmmo to 5 if the pickup type
;; is gameobject 3.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;MELON;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
LDA Object_type,x
CMP #$03 ;;What object is your pickup? 00 - 0f
BNE +notThisPickup
;;;;;;;;;;;;;;;;;;;;;;;;; What do you want to do to the value?
;;;;;;;;;;;;;;;;;;;;;;;;; Increase? Decrease? Set it to a number?
;;;;;;;;;;;;;;;;;;;;;;;;; Here, we are setting myAmmo to 5.
LDA #$05
STA myAmmo
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;; Do we need to update the HUD to reflect this?
;;;;;;;;;;;;;;;;;;;;;;;;; If so, which element is the above variable represented in?
;DrawSprite #168, #28, #113, #01
;DrawSprite #176, #28, #114, #01
UpdateHudElement #$03
AddValue #$07, myScore, #$1, #$02
UpdateHudElement #$06
JMP +benchmark
JMP +endPickups
+notThisPickup:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;FIG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CMP #$04
BNE +notThisPickup
INC myCash
LDA myCash
;CMP #$3E7 ;; one more than the max
BNE +dontNormalizeValue
LDA #$63 ;; normalize the value to 999 if it got bigger than 999
STA myCash
+dontNormalizeValue
UpdateHudElement #$02
AddValue #$02, myCash, #$0, #$00
AddValue #$07, myScore, #$1, #$02
UpdateHudElement #$06
JMP +benchmark
JMP +endPickups
+notThisPickup:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;HEART;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
LDA Object_type,x
CMP #$07
BNE +notThisPickup
LDA myHealth
INC myHealth
;+increaseHealth
CMP #$03 ;; one more than the max
BNE +dontNormalizeValue
LDA #$03 ;; normalize the value to 3 if it got bigger than 3
STA myHealth
+dontNormalizeValue
UpdateHudElement #$04
AddValue #$07, myScore, #$1, #$02
UpdateHudElement #$06
JMP +benchmark
JMP +endPickups
+notThisPickup:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;APPLE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
LDA Object_type,x
CMP #$09 ;;What object is your pickup? 00 - 0f
BNE +notThisPickup
LDA #$05
STA myAmmo2
UpdateHudElement #$05
AddValue #$07, myScore, #$1, #$02
UpdateHudElement #$06
JMP +benchmark
+notThisPickup
JMP +endPickups
;;;;;;;;;;;;BENCHMARK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+benchmark:
LDA myScore_10000 ;;;;Load the 10,000 place
CMP myBenchmark ;;;;Check if the 10,000 place = benchmark
BNE +giveExtraFigs ;;;;If so...
;;We Will Increase the Benchmark with INC
;;INC adds variables just by *tens*
INC myBenchmark ;;;;Increase the benchmark
INC myCash_10 ;;;;Add an extra Figs, by tens
;;;Update HUD Element -- only if you use a tile HUD
;;;If you have a Sprite HUD, you can skip this
UpdateHudElement myLives, #$01 ;<------ or whatever number your lives variable is in the HUD
+giveExtraFigs
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+endPickups