How To Make The Screen Shake (Version 4.1.5)

Now I just need to add player object hurt to the screen shake if the player is touching a solid object, if not player doesnt not lose health
 

Bucket Mouse

Active member
Updating it for 4.5.9 is actually really simple as you just have to replace some of the command names with the updated ones NESMaker uses now. However...

It won't work for what you want to use it for, because it stops all other actions to shake the screen! The script is only good for cutscenes and other times when you don't have control of your character. I'm working on a freeze-less version right now.

I'll post the 4.5.9 version anyway....
Code:
        ;;;;; THIS MATERIAL ADDED TO SHAKE THE SCREEN ON COMMAND
    
    LDA shakeOn
    CMP #$01
    BNE shakeskipper
    
    shake:
    INC camY ;xScroll
    INC XScrollNo ; variable counting the current number of pixels away from the norm
    JSR doWaitFrame
    LDA #$04 ; this means it will shake four pixels...change the number to what you desire
    CMP XScrollNo
    BEQ shakeBack
    JMP shake

    shakeBack:
    DEC camY ;xScroll
    DEC XScrollNo
    JSR doWaitFrame
    LDA #$00
    CMP XScrollNo
    BEQ shakeOver
    JMP shakeBack

    shakeOver:
    INC shakeCycle ; variable for number of vibrations in sequence
    LDA shakeCycle
    CMP #$04 ; stops shaking after four vibrations...change the number to what you desire
    BNE shake
    LDA #$00
    STA shakeCycle ; resets the shake cycle so you can use it again elsewhere
    STA shakeOn

shakeskipper:
 

9Panzer

Well-known member
@Bucket Mouse It would totally work. If I time it for the moment of impact everything can freeze and still give the effect. Think Hardman from Megaman 2 :)


I'll see if I can free up enough space to add the code tonight! :D
 

9Panzer

Well-known member
@Bucket Mouse I got it working with your updates! Worked like a charm. Now I just need to figure out the action step recent when the boss lands on a solid. I tried getting the timing so he would shake right before he hit but it was hit or miss.

Thank you so much for putting this together. I think when I get it all working the way I want its going to make this boss pop so much better!


only thing I needed to tweek the Variable lookup, I needed to have it look for 00 rather then 01:
LDA shakeOn
CMP #$00
BNE shakeskipper
 

9Panzer

Well-known member
BOOM got it!


All I had to do was edit the doHandlephysics_Platform.asm and add a check for the screenflag and monster to disregard the action step change :)
isSolidSoLand:

;; move to position
;;; load the top of the tile that is being run into.
;;check if in a jumping state.
TXA
STA temp
GetActionStep temp
CMP #$02 ;; presums jump is in state 2
BNE +dontChangeToIdle
LDA gamepad
AND #%11110000
BNE +isRunningWhenLanding
;; is idle when landing
LDA #$00
STA temp1
JMP +gotLandingState
+isRunningWhenLanding
LDA #$01
STA temp1
+gotLandingState
LDA ScreenFlags01 ;Uses Screen Flags 2
AND #%01000000 ; Grokk Boss Fight
BEQ +
LDA Object_flags,x
AND #%00001000 ;; is it a monster?
jmp doneWithGravity
+
ChangeActionStep temp, temp1 ;; changes to either idle or running depending on if a direction key is pressed.
+dontChangeToIdle
 
Interested in a Freezeless version. I've trying to adapt this to use for a Tile based boss fight. Does xScroll just naturally freeze the player?
 
I'm running into issue with this on 4.1.5, wondering if anyone else encountered/solved. Sometimes, the screen shake will push my main player into the floor, causing them to ignore collissions, and just loop around the screen vertically forever.
 
Fantastic. Where do I add the shaketrigger.asm trigger
Thanks to Mr. Granato for pointing me in the right direction to find the solution to this....
UPDATED 5-24-2020 to fix a bug that prevented the sprites from showing during the shaking process

Make three variables, shakeOn, XScrollNo and shakeCycle, before using.
Then open HandleScreenLoads.asm and add this right below the opening line. The notes in the code describe how it works.

Code:
    ;;;;; THIS MATERIAL ADDED TO SHAKE THE SCREEN ON COMMAND
   
    LDA shakeOn
    CMP #$01
    BNE shakeskipper
   
    shake:
    INC xScroll
    INC XScrollNo ; variable counting the current number of pixels away from the norm
    JSR WaitFrame
    LDA #$04 ; this means it will shake four pixels...change the number to what you desire
    CMP XScrollNo
    BEQ shakeBack
    JMP shake

    shakeBack:
    DEC xScroll
    DEC XScrollNo
    JSR WaitFrame
    LDA #$00
    CMP XScrollNo
    BEQ shakeOver
    JMP shakeBack

    shakeOver:
    INC shakeCycle ; variable for number of vibrations in sequence
    LDA shakeCycle
    CMP #$04 ; stops shaking after four vibrations...change the number to what you desire
    BNE shake
    LDA #$00
    STA shakeCycle ; resets the shake cycle so you can use it again elsewhere
    STA shakeOn

shakeskipper:

;;; END OF ADDED MATERIAL

Now you'll need a trigger to make the screen shake when you want it to. So create a file called shaketrigger.asm that contains just these two lines:

Code:
    LDA #$01
    STA shakeOn

This code shakes the screen horizontally. To shake it vertically, change "xScroll" to "yScroll"

You cannot move your character while the screen shakes. Any sprites on screen will also be stationary. This is just how screen shake works on 8-bit (I distinctly remember Link's Awakening screen shakes working like this).

Au naturel, it works as a button press and as a monster AI option (which makes it perfect for cutscenes). But if you want to add the effect to a tile, the screen will shake endlessly because your sprite is perpetually on it. You will have to add a fourth variable, shakeOff. You would put this before everything else in the script:

Code:
    LDA shakeOff
    CMP #$01
    BEQ shakeReallyOver
    INC shakeOff

Then add
shakeReallyOver:
at the end.

This will prevent the screen shake from looping again. Though you will have to reset shakeOff back to zero if you want to use the same tile somewhere else.
Fantastic. Where do I add the shaketrigger.asm trigger
 
Top Bottom