Dynamic Credits Screen

Discussion in 'Tutorials' started by Pacca, Apr 17, 2018.

  1. Pacca

    Pacca Having an online identity crisis since 2019 Member

    Joined:
    Jul 5, 2014
    Messages:
    1,175
    Location:
    Limbo
    I finally got around to centralizing all the main code for my credits screen, so that it's portable enough to release! It reads text from a raw .txt file, so editing it is easy; no more fiddling around with mappings or a spider web of macros required! The screen does all the work for you, so you can do what's important; credit the people who helped you along the way :3

    Here's a demo rom that doubles as the credits for this very tutorial :D The entire thing was built on top of Hitaxas' Splash Screen, which handles the screen clearing, background, and other stuff like that.

    Keep in mind that this guide is only for the Sonic 2 GitHub Disassembly! It uses a lot of its' labels, constants, and macros, so converting it into something more universal seemed like it would be a pain. So for now, no other games/disassemblies are supported.


    Implementing the main code

    For starters, download this. It includes the main assets required for it to work. copy the contents of the zip file into your disassembly.

    Next, copy the following into s2.asm. It could technically go anywhere, but I'd recommend putting it near the end of the rom, before the "end of 'ROM'" line.
    Code:
    CreditsCustom:
        INCLUDE "CreditsScreen/CreditsScreen.asm"; Credits Screen Code
    
    Now search for "s2.constants.asm". below that line, add this:
    Code:
        include "CreditsScreen/constants.asm"
    Next, search for "GameModesArray:". You should find this:
    Code:
    ; loc_3A2:
    GameModesArray: ;;
    GameMode_SegaScreen:    bra.w    SegaScreen        ; SEGA screen mode
    GameMode_TitleScreen:    bra.w    TitleScreen        ; Title screen mode
    GameMode_Demo:        bra.w    Level            ; Demo mode
    GameMode_Level:        bra.w    Level            ; Zone play mode
    GameMode_SpecialStage:    bra.w    SpecialStage        ; Special stage play mode
    GameMode_ContinueScreen:bra.w    ContinueScreen        ; Continue mode
    GameMode_2PResults:    bra.w    TwoPlayerResults    ; 2P results mode
    GameMode_2PLevelSelect:    bra.w    LevelSelectMenu2P    ; 2P level select mode
    GameMode_EndingSequence:bra.w    JmpTo_EndingSequence    ; End sequence mode
    GameMode_OptionsMenu:    bra.w    OptionsMenu        ; Options mode
    GameMode_LevelSelect:    bra.w    LevelSelectMenu        ; Level select mode
    
    Add the following line to the end of it:
    Code:
    GameMode_CustomCredits:    bra.w    CustomCredits
    
    Then scroll down to "LevelSelectMenu:". Copy this code after all the "=" characters, but before the ">" characters:
    Code:
    CustomCredits:
        jmp    CreditScreen_Init
    
    Now we need to add the new text object to the main object pointers list. Search for "ObjPtr_RingPrize:". You should find this:
    Code:
    ObjPtr_RingPrize:    dc.l ObjDC    ; Ring prize from Casino Night Zone
    
    After that, insert this line:
    Code:
    ObjPtr_TextChar:        dc.l ObjTextChar    ; Credits Text
    And with that, the Credits screen is now technically installed. Of course, there's no way to access it, though...


    ADDING CREDITS TO THE END OF THE GAME

    As it currently stands, the old, hardcoded credits screen still runs after you beat the game! Lets' fix that:

    Search for "EndgameCredits:". A ways below that should be this code:
    Code:
     ; Bug: The '+4' shouldn't be here; clearRAM accidentally clears an additional 4 bytes
     clearRAM Horiz_Scroll_Buf,Horiz_Scroll_Buf_End+4
    
    
    below that, paste this:
    Code:
     st (Level_Inactive_flag).w
       move.b    #GameModeID_CreditsCustom,(Game_Mode).w ; => CustomCredits
        rts
    
    And that's it! The credits now appear at the end of the game!


    ADDING CREDITS TO THE TITLE SCREEN

    Now, you can see the credits screen; but what's the point in crediting people if very few players will make it to the end? Heck, maybe your making a demo, or removing Death Egg Zone and the end cutscene entirely! How will people see the credits then? Fear no more, for this section will add the credits to the title screen!

    First, download this file and replace the old one in "mappings/sprite". Then, download this file and replace the old one in "art/nemesis". This new graphics will be used for the credits title screen menu.

    Now we need to edit the menu object itself. Search of "Obj0f:". Then find this line below it:
    Code:
        move.w    #make_art_tile(ArtTile_ArtKos_LevelArt,0,0),art_tile(a0)
    Replace that line with this:
    Code:
        move.w    #make_art_tile(ArtTile_ArtNem_Player1VS2,0,0),art_tile(a0)    ;changed to make mappings edits easier
    Now that the graphics are fixed, we need to change some values to add our new option. Go down a bit further, and find this line:
    Code:
        move.b    #2,d2
    
    Change the 2 to a 3. Then find this line:
    Code:
        cmpi.b    #3,d2
    And replace the 3 with a 4.

    Finally, search for "TitleScreen_ChoseOptions:". Add this code just under the label:
    Code:
     subq.b #1,d0
     bne.s TitleScreen_Option4
    
    And add this code before all the "=" signs:
    Code:
    ;Pacguys' custom credits screen
    TitleScreen_Option4:
        move.b    #GameModeID_CreditsCustom,(Game_Mode).w ; => Custom Credits screen
        move.b    #0,(Options_menu_box).w
        rts
    
    And that's it! Editing the credits is extremely easy; just open up Credits.txt and start typing! There are some tips at the end of the file, to help you figure out some of the quirks of the Credits screen (I highly recommend reading them).

    Of course, I can tell some of you aren't gonna be satisfied with just that, so here's some optional things you can do:
    Use your favorite mappings editor to load CreditsScreen/Alphabet.asm and art/nemesis/Credit text.bin . This will give you the ability to change the art used by the Character object. Each mapping frame corresponds to a character in the Microsoft ANSI character set; if you want to add more characters, number, lowercase letters, etc., just find the appropriate mapping frame (the hex numbers on the Wikipedia page correspond to the mapping frame), and add some new font art in.

    Maybe your unsatisfied with the control characters I used. Maybe your name has a dollar sign in it; or maybe you like to end every post with a ~. Whatever the case, this can be easily fixed. Open CreditsScreen.asm and search for "CustomCredits_readChars:". You should see the following:
    Code:
    ;this section finds control characters, and responds accordingly
    ;If you want to make your own control character, just add a check here!
        cmp.b    #$A,d2    ;is d2 a carriage return character (an actual ANSI control character for the end of a line)?
        beq.s    CustomCredits_readChars_endloop    ;if so, end loop
        cmp.b    #$24,d2    ;is d2 a '$' (control code defined by PACGUY)?
        beq.s    CustomCredits_readChars_setcolorflag    ;if so, set color flag and adjust header text
        cmp.b    #$7E,d2    ;is d2 a '~' (control code defined by PACGUY)?
        beq.s    CustomCredits_endoffile    ;if so, set as end of file (prevents further text reading)
    
        bsr.s    Hitaxas_splash_spawn_credits_object    ;otherwise, spawn a character/letter/symbol object
        bra.s    CustomCredits_readChars    ;continue looping inside character read loop
    
    These are where control characters are defined. The first one should never be touched; it's for an actual ANSI control character, which determines where the end of a line is. The others, however, can be freely changed; the hex values correspond to Microsoft ANSI characters, so you can replace them with what you like. You could even add your own custom control characters like so:
    Code:
        cmp.b    #$7,d2    ;is d2 a 'bel' character?
        beq.s    CustomCredits_readChars_playRingSound    ;if so, run a routine that makes a ring sound :3
    

    As you've probably seen by my videos, the credits screen in Sonic 2 CD Remix spawns the players, and lets them run amuck while the credits are going. It might not look quite as professional, but its' fun! The code for this was intentionally left in, but some things still need to be changed for it to work. Open up CreditsScreen.asm and find this line:
    Code:
        ;comment out this line if you want Sonic and/or Tails to spawn!
        bra.s    CustomCredits_skipplayers
    
    It should be self explanatory. Now, that'll spawn the players, and some walls and a floor. However, there will be some odd issues. To fix them, open up s2.asm and search for "RunObjects:". You should see this:
    Code:
        cmpi.b    #GameModeID_Demo,(Game_Mode).w    ; demo mode?
        beq.s    +    ; if in a level in a demo, branch
    
    Below that, insert this:
    Code:
        cmpi.b    #GameModeID_CreditsCustom,(Game_Mode).w    ; are we in Credits mode?
        beq.s    +    ; if in PACGUYs' custom credits mode, branch
    
    This will fix issues with Tails' Tails and the Skidding/Spindash dust.

    Yes! You can go all out and make your own mini game out of the credits! This will assume you've already setup Sonic and Tails to spawn (hint hint, it's the spoiler above this one)! To start, crack open CreditsScreen.asm and find "ObjTextChar_Init:" Below that, add this:
    Code:
        move.b    #$47,collision_flags(a0)
    That line allows Sonic and Tails to collide with the letters! On it's own, however, that'll make it so that touching a letter crashes the game :eek:

    But don't worry! It's an easy fix! Go to "ObjTextChar_Index:". You should see this:
    Code:
    ObjTextChar_Index:  
        dc.w    ObjTextChar_Init-ObjTextChar_Index        ;0
        dc.w    ObjTextChar_Main-ObjTextChar_Index        ;2
    
    Below that, add this:
    Code:
        dc.w    ObjTextChar_Collide-ObjTextChar_Index        ;4
    Now, make a new routine called "ObjTextChar_Collide". Here's an example:
    Code:
    ObjTextChar_Collide:
        jmp    DeleteObject
    This will make the letters disappear when you touch them! You can do anything in this routine; play sounds, change the colors, hurt Sonic and/or Tails, instakill them, move the letters, etc. The possibilities are endless!
     
    Last edited: Aug 3, 2018
    RouRouRou, EMK-20218, maple_t and 6 others like this.
  2. Greenknight9000

    Greenknight9000 Well-Known Member Member

    Joined:
    Apr 30, 2014
    Messages:
    53
    All the download links are dead, mind reuploading them?
     
  3. Pacca

    Pacca Having an online identity crisis since 2019 Member

    Joined:
    Jul 5, 2014
    Messages:
    1,175
    Location:
    Limbo
    Thanks for telling me, Dropbox has been messing with me lately. All the links have been updated to Mediafire links, and should work properly.
     
    Last edited: Aug 4, 2018