Countdown Timer for Brawler module

Shining

New member
Hello !

Is there someone who can make a Countdown Timer tutorial for the Brawler module , at the end of the timer the player should lost a life and need to come back at the beginning of the level he is, Dale told me to use the DrawSprite method but i don't know what the hell to do with that :eek:

Thank you very much for your help ! :coffee:;)
 

CluckFox

Active member
I learned how to do countdown timers from the official arcade platformer advanced tutorial. It uses one to spawn enemies but it can be adapted to kill your player easily enough.
 

Shining

New member
ok but this is an invisible timer , what i need is a timer of 3 digits displayed in my HUD in brawler module , it seems very different than the joe's tutorial :cry:
 

Jonny

Well-known member
I don't know if this is the best way to go about it but this is my suggestion...
Use the doHandleGameTimer.asm script (linked above) but instead of having the HUD update, draw sprites (numbers) with DrawSprite macro.

Eg... "DrawSprite #11, #220, myTimerSeconds, #%00000000"

Essentially, the 'myTimer' variable would become the sprite (number) you want to draw as the timer goes down so you would need a seconds, tens and minutes as seperate variables which would be the sprites to be drawn.

I've seen it done with sprite HUD but not sure exactly how. I'm only speculating at the moment. I've not tried it.
 

CluckFox

Active member
I second the request for a tutorial on numbers/counters on a Sprite HUD. It's something that's trivial (for us) with the Text HUD but not obvious (to us) with sprites.

Representing a 7-segment LED display with a sprite might be a good tutorial objective.
 

Jonny

Well-known member
Accurate hours, minutes and seconds might be a bit difficult if not impossible. It would have to be Famiseconds, Nintendimins and Dendyhours šŸ˜
 

Shining

New member
I don't know if this is the best way to go about it but this is my suggestion...
Use the doHandleGameTimer.asm script (linked above) but instead of having the HUD update, draw sprites (numbers) with DrawSprite macro.

Eg... "DrawSprite #11, #220, myTimerSeconds, #%00000000"

Essentially, the 'myTimer' variable would become the sprite (number) you want to draw as the timer goes down so you would need a seconds, tens and minutes as seperate variables which would be the sprites to be drawn.

I've seen it done with sprite HUD but not sure exactly how. I'm only speculating at the moment. I've not tried it.
I've try that but really i don't know how to proceed , here is what i've try for testing with 9 seconds :

HandleGameTimer.asm
;;; handle game timer
LDA gameTimerTicks
CLC
ADC #$04 ;how fast to run
STA gameTimerTicks
BCC +normalwhatever
;;Joe's create monster script we're canceling out
;;#$80, #$80, #$10 #$00
;;x, y, what object, what state
SubtractValue #$02, myTimerSeconds, #$1, #$00
;;arg0 = how places value has
;;arg1 - home variable
;;arg2 = amount to subtract
;;arg3 = what place value is receiving subtaction
UpdateHudElement #$05
+normalwhatever

LDA gameTimerLo
ADC #$00
STA gameTimerLo
LDA gameTimerHi
ADC #$00
STA gameTimerHi

;; checking the value of the timer:
LDA myTimerSeconds_b
BNE +notEnded
LDA myTimerSeconds
BNE +notEnded
;; now 00
;; what we do:
;; execute a WARP !!!
WarpToScreen warpToMap, warpToScreen, #$01
+notEnded:
PostScreenLoad.asm
;; initialize the Game Timer to 9

LDA #$0
STA myTimerSeconds
LDA #$9
STA myTimerSeconds_b
doDrawSpriteHud_Brawler.asm
;;; Here is an example of how to do a sprite hud.
;;; Arg5, the one that has the value of myVar, must correspond to a user variable you have in your game.
;;; Don't forget, you can only draw 8 sprites per scanline, so a sprite hud can only be 8 sprites wide max.


;DrawSpriteHud #$08, #$08, #$11, #$10, #$10, myVar, #$00
; arg0 = starting position in pixels, x
; arg1 = starting position in pixels, y
; arg2 = sprite to draw, CONTAINER
; arg3 = MAX
; arg4 = sprite to draw, FILLED
; arg5 = variable.
; arg6 = attribute

DrawSpriteHud #16, #16, #$1C, #$12, #$1D, myHealth, #%00000010 ;;;; this draws health
DrawSprite #126, #220, myTimerSeconds, #%00000000 ;;;; this draws Seconds
and as you can see on this video nothing happen :p :

 

Jonny

Well-known member
Nailed it! So the only part that doesn't work is the warp?
Did you try a "JMP RESET" instead of your WarpToScreen just to double check that your countdown loop is definately getting to that part of the code?
Aside from that, maybe you have to load the player object into X for the warp to work? I'm not sure sorry. Needs some more expert eyes on it.
 

Jonny

Well-known member
I wrote a simpler script just to test if the Warp macro worked. I can get the game to reset after increasing the sprite value until at 8 but that's as far as I've got so far. For the Warp I get a 'value out of range' error when compiling. Did you ge that error or did it compile ok?

;;; GAME TIMER ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

LDA gameTimerTicks
CLC ;; CLEAR THE CARRY ;;
ADC #$09 ;; FRAME STEPS ;;
STA gameTimerTicks ;; STORE COUNTER ;;
BCC +normal ;; PAST 255 FRAMES?? ;;

;;; INCREASE SPRITE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

LDA spriteNum ;; LOAD NUM SPRITE ;;
CLC
ADC #01
STA spriteNum ;; STORE NEW SPRITE ;;

;;; CHECK SPRITE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

LDA spriteNum
CMP #08
BNE +normal ;; NOT 8 YET ;;

JMP RESET
; WarpToScreen warpToMap, warpToScreen, #$01 ;
; GET VALUE OUT OF RANGE ERROR ;

+normal

I'm just trying to get the warp to work with this. Not intended for your code as it doesn't do the things you want. This is as far as I got before running out of time. Daddy duties sorry.
 

dale_coop

Moderator
Staff member
In your DrawSprite line for the Seconds... you forgot a few parameters (the tiles to use for drawing the value)
But first, you need to add 0 1 2 3 4 5 6 7 8 9 in your GameObjectTiles.BMP
then you will be able to draw that number corresponding to your myTimerSeconds variable.
 

Jonny

Well-known member
If found it easier to increase rather than decrease the variable for which sprite is drawn...

timer.jpg

You can start with a different sprite when you're drawing in doDrawSpriteHUD.asm by setting up a User Constant e.g. FIRST_SPRITE

Code:
LDA spriteNum
ADC #FIRST_SPRITE
STA temp
DrawSprite #120, #210, temp, #%00000000

I believe you could even start with a monster sprite if you didn't want to use up your objects graphics.
(in this example I didn't offset as mentioned above as I started at 00 to draw the '9')

The only variable I have set up to do this is spriteNum in Zero Page RAM.

HandleGameTimer.asm code....

Code:
    LDA gameTimerTicks
    CLC                          
    ADC #$04              
    STA gameTimerTicks       
    BCC +normal               

    LDA spriteNum           
    CLC
    ADC #01                
    STA spriteNum            

    LDA spriteNum
    CMP #10
    BNE +normal           

    WarpToScreen warpToMap, warpToScreen, #$01

+normal

    LDA gameTimerLo
    ADC #$00
    STA gameTimerLo

    LDA gameTimerHi
    ADC #$00
    STA gameTimerHi

This is what happens....
(Warps after countdown has finished)

countdown2.gif

Is this what you need ?

Unless I'm missing something or misunderstood what is needed, I don't think you really need PostScreenLoad.asm or to do anything with the HudElements.

To stop the countdown on every screen you would need to add some sort of check in your HandleGameTimer.asm to make it happen only when you want it to.
 

Attachments

  • countdown.gif
    countdown.gif
    45.3 KB · Views: 7
Last edited:

Shining

New member
Hello @Jonny and thanks for the help !
I've tried to implement your code to my desire with the Minutes / Tens / Seconds , i've set the warp only on the minutes but in my opinion the minutes are too fast even if i set the gameTimerTicks on 1 :(
Also the sprites aren't looping after the 0 and after a death the Timer isn't initialized too

HandleGameTimer.asm
;;;;;;;;;;;;;;;;;;;;;;;;;;MINUTES;;;;;;;;;;;;;;;;;;;;;;;;;
LDA gameTimerTicks
CLC
ADC #$01
STA gameTimerTicks
BCC +normal

LDA spriteNumMinutes
CLC
ADC #01
STA spriteNumMinutes

LDA spriteNumMinutes
CMP #10
BNE +normal

WarpToScreen warpToMap, warpToScreen, #$01

+normal

LDA gameTimerLo
ADC #$00
STA gameTimerLo

LDA gameTimerHi
ADC #$00
STA gameTimerHi

;;;;;;;;;;;;;;;;;;;;;;;;;;Tens;;;;;;;;;;;;;;;;;;;;;;;;;
LDA gameTimerTicks
CLC
ADC #$04
STA gameTimerTicks
BCC +normal

LDA spriteNumTens
CLC
ADC #01
STA spriteNumTens

LDA spriteNumTens
CMP #10
BNE +normal

;;;WarpToScreen warpToMap, warpToScreen, #$01

+normal

LDA gameTimerLo
ADC #$00
STA gameTimerLo

LDA gameTimerHi
ADC #$00
STA gameTimerHi

;;;;;;;;;;;;;;;;;;;;;;;;;;Seconds;;;;;;;;;;;;;;;;;;;;;;;;;
LDA gameTimerTicks
CLC
ADC #$08
STA gameTimerTicks
BCC +normal

LDA spriteNumSeconds
CLC
ADC #01
STA spriteNumSeconds

LDA spriteNumSeconds
CMP #10
BNE +normal


;;;WarpToScreen warpToMap, warpToScreen, #$01

+normal

LDA gameTimerLo
ADC #$00
STA gameTimerLo

LDA gameTimerHi
ADC #$00
STA gameTimerHi

doDrawSpriteHud_Brawler.asm
;;; Here is an example of how to do a sprite hud.
;;; Arg5, the one that has the value of myVar, must correspond to a user variable you have in your game.
;;; Don't forget, you can only draw 8 sprites per scanline, so a sprite hud can only be 8 sprites wide max.


;DrawSpriteHud #$08, #$08, #$11, #$10, #$10, myVar, #$00
; arg0 = starting position in pixels, x
; arg1 = starting position in pixels, y
; arg2 = sprite to draw, CONTAINER
; arg3 = MAX
; arg4 = sprite to draw, FILLED
; arg5 = variable.
; arg6 = attribute

DrawSpriteHud #16, #16, #$1C, #$12, #$1D, myHealth, #%00000010 ;;;; this draws health


LDA spriteNumMinutes
ADC #00
STA temp
DrawSprite #100, #210, temp, #%00000000

LDA spriteNumTens
ADC #00
STA temp
DrawSprite #110, #210, temp, #%00000000

LDA spriteNumSeconds
ADC #00
STA temp
DrawSprite #120, #210, temp, #%00000000

 

Jonny

Well-known member
Where the warp is on the tens and seconds (which is currently commented out) you could try re-setting the sprite variables e.g spriteNumSeconds back to the first one then it should effectively loop.
I'll have a go tomorrow, unless you fix it beforehand.
 
Top Bottom