SOLVED (4.5.9.) Countdown Timer in Maze Module

Arctic Blizzard

New member
NESmaker 4.5.9 version - Game Timer
Here it is. This is the best I could do. And thanks again 5kids2feed & Dale_Coop!!! A game timer that counts down kind of Mario style where when it gets to zero it takes 1 life away and restarts the level. I'm still learning how to cut up code and use the macros for help. Its a fun learning process. Hope this script helps.
NESmaker 4.5.9 version



;;; Do Handle Game Timer My Lives (DALE COOP, 5kids2feed, ARCTIC BLIZZARD collab)

;;; What this script does is the Game Timer counts down. When timer reaches zero you will lose one life and the game will reset to the last continue point.



;;;Game Timer Ticks
LDA gameTimerTicks
CLC
ADC #$04 ;how fast the Game Timer will tick
STA gameTimerTicks
BCC +normalwhatever

;No Game Timer on Screen Flags.
LDA ScreenFlags00
AND #%01000000 ;; if "hide hud" is set.
BNE +normalwhatever ;; skip all the code related to myTimer

;;;Hud Game Timer Value
SubtractValue #$02, myTimer, #$1, #$00
;;arg0 = how places value has
;;arg1 - home variable
;;arg2 = amount to subtract
;;arg3 = what place value is receiving subtaction
UpdateHudElement #$02

+normalwhatever

;;;Game Timer 1's, & 10's place
LDA gameTimerLo
ADC #$09 ;this represents the 1's place in the timer.
STA gameTimerLo
LDA gameTimerHi
ADC #$09 ;this represents the 10's place in the timer.
STA gameTimerHi

;;; checking the value of the Game Timer:
LDA myTimer_10
BNE +notEnded
LDA myTimer
BNE +notEnded
;; when Game Timer reaches 00.

;; this is what will happen. Level will start over and you will lose one life.


ChangeActionStep player1_object, #$07
;arg0 = what object?
;arg1 = what step?

JSR doChangeActionStep
;;Level will start over and you will lose one life.



+notEnded:


;;;;Special Thanks to NESmaker Community; Dale Coop & 5Kids2feed for helping to create this script.
 
Last edited:

Arctic Blizzard

New member
NESmaker 4.5.9 version - Game Timer - Post Screen Load
Also if anyone wants to use the Game Timer make sure to put this script in your PostScreenLoad script so your timer resets to the time you set.
NESmaker 4.5.9 version




;; initialize the Game Timer to 99

UpdateHudElement #$02
LDA #$9
STA myTimer
LDA #$9
STA myTimer_10
 

XavierOrionGames

New member
Thanks guys for this...i'm extremely new to NES Maker (like started tinkering with it 2 days ago). After going thru 12 Days of NESmas i got inspired to start porting over my Xbox One game Loony Lawns ,and i couldn't find a way to do create a timer (in my case fuel countdown) until i came across your thread. Curious question my original game also had a mode where as you cut the grass instead of the fuel counting down the fuel would be consumed by 1 for each uncut grass tile you touched if you touched an already cut grass tile you would be penalized by losing 2 units of fuel.

I currently have the uncut tiles marked out as prize but when i try to set it up to have it count down a unit of fuel once you touch it along with adding points to your score i cant seem to get it effect both variables on one tile type. It maybe something very elementary that I'm not aware of especially considering im just barely even attempting to start to understand the coding for this.

Anyway thank you so much for having this script available
 

Attachments

  • Screenshot (141).png
    Screenshot (141).png
    22.4 KB · Views: 25
  • Screenshot (142).png
    Screenshot (142).png
    22.4 KB · Views: 25

dale_coop

Moderator
Staff member
You can't have 2 HUD variables updated at the same time... you'll have to find a creative way to do that (maybe your timer script could update your score variable or your fuel variable at a regular interval)
 

XavierOrionGames

New member
You can't have 2 HUD variables updated at the same time... you'll have to find a creative way to do that (maybe your timer script could update your score variable or your fuel variable at a regular interval)
I'll just have to base the game off the arcade mode only of the original version of the game. In the original there was a Puzzle Mode which you had a set amount of fuel ,and set amount of fuel tanks available in a level so you had to find the best route to cut all the grass in the level without backtracking over previously cut patches as you would get a fuel penalty. So each uncut grass tile ate up 1 unit of fuel where as back tracking took 2.

In arcade mode the fuel just acted as a timer ,and fuel tanks would randomly spawn in and you would collect them. In that there was no penalties for going over cut patches. So i'm likely just going to base this version off the arcade mode only. (Which how the current prototype is setup)

Now i just need to figure out how to get the fuel to spawn in random places ,and how to get the game to know how many uncut tiles there are when to know when all the tiles are in cut status so it can advance to the next level.
 

BITVADER

Member
I'm trying the code provided in this thread, but it doesn't seem to implement it well.
My game hides the HUD so I can't see if the countdown is working and I'm not sure where it's failing.
I would like to know if you know the booby trap that is easy to fall into when implementing the countdown timer for the first time.
 

BITVADER

Member
Even if I change the number of the user variable (myTimer & myTimer_10), it remains 99 in the HUD and is not counted down.
I would like to know if there is a cause.
 

TolerantX

Active member
Maybe this code doesn't work if the HUD is hidden?
yeah, you'll see here how it jumps in code past the SubtractValue portion of the code... I added a picture to illustrate this.
 

Attachments

  • Screenshot 2022-02-06 135029.png
    Screenshot 2022-02-06 135029.png
    38.3 KB · Views: 13

BITVADER

Member
Thank you Tolerant X.
I will do my best to learn the knowledge that I have been taught.
The game I'm making now has a timer that uses monster objects, so I'm sure it's useful as a knowledge of the next game.
 

CamdenTown

New member
Hi ,I am new to NES Maker so apologies in advance if this code is clunky.
When I used the script in my platform game 4.5.9 in this post for some reason the lives variable wouldn't go down - I also wanted the game to go back to the title screen when lives reached 0 so I created my first modified version of a script using a combination of the hurt player script and the one from earlier in this thread.

Code below runs timer and then reduces life and takes player back to last check point
If lives are 0 then the game goes back to start screen.


;;; Do Handle Game Timer My Lives (DALE COOP, 5kids2feed, ARCTIC BLIZZARD collab)

;;; What this script does is the Game Timer counts down. When timer reaches zero you will lose one life and the game will reset to the last continue point.


;;;Game Timer Ticks
LDA gameTimerTicks
CLC
ADC #$14 ;how fast the Game Timer will tick 4 is a good value
STA gameTimerTicks
BCC +normalwhatever

;No Game Timer on Screen Flags.
LDA ScreenFlags00
AND #%01000000 ;; if "hide hud" is set.
BNE +normalwhatever ;; skip all the code related to myTimer

;;;Hud Game Timer Value
SubtractValue #$02, myTimer, #$1, #$00
;;arg0 = how places value has
;;arg1 - home variable
;;arg2 = amount to subtract
;;arg3 = what place value is receiving subtaction
UpdateHudElement #$05

+normalwhatever

;;;Game Timer 1's, & 10's place
LDA gameTimerLo
ADC #$09 ;this represents the 1's place in the timer.
STA gameTimerLo
LDA gameTimerHi
ADC #$09 ;this represents the 10's place in the timer.
STA gameTimerHi

;;; checking the value of the Game Timer:
LDA myTimer_10
BNE +notEnded
LDA myTimer
BNE +notEnded
;; when Game Timer reaches 00.

;; this is what will happen. Level will start over and you will lose one life.
;;Level will start over and you will lose one life.

;HAVE TAKEN OUT DEATH ROUTINE
;ChangeActionStep player1_object, #$07
;arg0 = what object?
;arg1 = what step?

+doHurtPlayer
Dec myLives
LDA myLives
;THIS IS THE BIT I NEED HELP WITH - HOW TO WARP TO TITLE SCREEN AND RESET WHEN LIVES ZERO
BNE +myLivesNotZero
JMP RESET
WarpToScreen warpToMap, warpToScreen, #$01

+myLivesNotZero:
LDA continueMap
STA warpMap

LDA continueScreen
STA currentNametable
AND #%00001111
STA camX_hi

LDX player1_object
STA Object_screen,x

LDA #$02 ;; this is continue type warp.
STA screenTransitionType ;; is of warp type

LDA #$00
STA camX
LDA gameHandler
ORA #%10000000
STA gameHandler

+notEnded:
 
Last edited:

TolerantX

Active member
Hi ,I am new to NES Maker so apologies in advance if this code is clunky.
When I used the script in my platform game 4.5.9 in this post for some reason the lives variable wouldn't go down - I also wanted the game to go back to the title screen when lives reached 0 so I created my first modified version of a script using a combination of the hurt player script and the one from earlier in this thread.

Code below runs timer and then reduces life and takes player back to last check point
If lives are 0 then the game goes back to start screen.


;;; Do Handle Game Timer My Lives (DALE COOP, 5kids2feed, ARCTIC BLIZZARD collab)

;;; What this script does is the Game Timer counts down. When timer reaches zero you will lose one life and the game will reset to the last continue point.


;;;Game Timer Ticks
LDA gameTimerTicks
CLC
ADC #$14 ;how fast the Game Timer will tick 4 is a good value
STA gameTimerTicks
BCC +normalwhatever

;No Game Timer on Screen Flags.
LDA ScreenFlags00
AND #%01000000 ;; if "hide hud" is set.
BNE +normalwhatever ;; skip all the code related to myTimer

;;;Hud Game Timer Value
SubtractValue #$02, myTimer, #$1, #$00
;;arg0 = how places value has
;;arg1 - home variable
;;arg2 = amount to subtract
;;arg3 = what place value is receiving subtaction
UpdateHudElement #$05

+normalwhatever

;;;Game Timer 1's, & 10's place
LDA gameTimerLo
ADC #$09 ;this represents the 1's place in the timer.
STA gameTimerLo
LDA gameTimerHi
ADC #$09 ;this represents the 10's place in the timer.
STA gameTimerHi

;;; checking the value of the Game Timer:
LDA myTimer_10
BNE +notEnded
LDA myTimer
BNE +notEnded
;; when Game Timer reaches 00.

;; this is what will happen. Level will start over and you will lose one life.
;;Level will start over and you will lose one life.

;HAVE TAKEN OUT DEATH ROUTINE
;ChangeActionStep player1_object, #$07
;arg0 = what object?
;arg1 = what step?

+doHurtPlayer
Dec myLives
LDA myLives
;THIS IS THE BIT I NEED HELP WITH - HOW TO WARP TO TITLE SCREEN AND RESET WHEN LIVES ZERO
BNE +myLivesNotZero
JMP RESET
WarpToScreen warpToMap, warpToScreen, #$01

+myLivesNotZero:
LDA continueMap
STA warpMap

LDA continueScreen
STA currentNametable
AND #%00001111
STA camX_hi

LDX player1_object
STA Object_screen,x

LDA #$02 ;; this is continue type warp.
STA screenTransitionType ;; is of warp type

LDA #$00
STA camX
LDA gameHandler
ORA #%10000000
STA gameHandler

+notEnded:
Don't use JMP RESET
Step 1: comment it out
What you do afterwards depends on your game...
You could have in your myPlayerHurt script a check for lives being zero... And edit this script accordingly.
OR
You could put a warp to screen there, which I think you have... On the warped to screen have an invisible monster after animation reset game.

A third option is in my videos where I made an entire continue or game over system including yeah continues if you want. :)
 
Top Bottom