~ndiddy/libremo

68894960f00fd46d6661e0cefb8a3d351b68ed6f — Nathan Misner 2 years ago f781591
fade from white
10 files changed, 48 insertions(+), 40 deletions(-)

M compile_flags.txt
M cutscene.cpp
M fade.cpp
M fade.h
M game.cpp
M intro.cpp
M logo.cpp
M main.cpp
M menu.cpp
M tutorial.cpp
M compile_flags.txt => compile_flags.txt +1 -0
@@ 1,3 1,4 @@
-I/opt/homebrew/include/SDL2
-I/usr/include/SDL2
-Wall
-std=c++20

M cutscene.cpp => cutscene.cpp +3 -3
@@ 30,14 30,14 @@

void Cutscene_Init(const std::string &filename) {
    Global_SetHiRes();
    Fade_In();
    Fade_In(30);
    Anim_Init(filename, 0);
}

int Cutscene_Run() {
    Anim_Disp(0, 0, (float)WINDOW_WIDTH / (float)CUTSCENE_WIDTH, 1);
    if (padDataE && !Fade_Active()) {
        Fade_Out();
        Fade_Out(30);
    }

    if (Fade_OutDone()) {


@@ 45,4 45,4 @@ int Cutscene_Run() {
    }

    return 0;
}
\ No newline at end of file
}

M fade.cpp => fade.cpp +17 -6
@@ 36,6 36,8 @@ static float brightDiff;
static float duration;
static int enable;
static int mode;
// screen color we fade to
static uint8_t fadeR, fadeG, fadeB;


void Fade_Init() {


@@ 43,13 45,17 @@ void Fade_Init() {
	mode = MODE_FADE_NONE;
}

void Fade_Start(uint8_t start, uint8_t end, int frameCnt) {
void Fade_Start(uint8_t start, uint8_t end, int frameCnt, uint8_t r, uint8_t g, uint8_t b) {
	frames = 0;
	duration = (float)frameCnt;
	startBright = (int)start;
	brightDiff = (float)((int)end - (int)start) / duration;
	enable = 1;
	mode = MODE_FADE_NONE;

    fadeR = r;
    fadeG = g;
    fadeB = b;
}

void Fade_Stop() {


@@ 62,17 68,22 @@ int Fade_Active() {
	return frames < duration;
}

void Fade_In() {
	Fade_Start(0xFF, 0x00, 30);
void Fade_In(int frameCnt) {
	Fade_Start(0xFF, 0x00, frameCnt, 0, 0, 0);
	mode = MODE_FADE_IN;
}

void Fade_InWhite(int frameCnt) {
    Fade_Start(0xFF, 0x00, frameCnt, 0xff, 0xff, 0xff);
    mode = MODE_FADE_IN;
}

int Fade_InDone() {
	return (mode == MODE_FADE_IN) && (frames >= duration);
}

void Fade_Out() {
	Fade_Start(0x00, 0xFF, 30);
void Fade_Out(int frameCnt) {
	Fade_Start(0x00, 0xFF, frameCnt, 0, 0, 0);
	mode = MODE_FADE_OUT;
}



@@ 104,7 115,7 @@ void Fade_Draw() {
		}

		uint8_t brightness = interpolate((float)startBright, brightDiff, frames);
		SDL_SetRenderDrawColor(gRenderer, 0x00, 0x00, 0x00, brightness);
		SDL_SetRenderDrawColor(gRenderer, fadeR, fadeG, fadeB, brightness);
		SDL_Rect dimensions = {
			.x = 0,
			.y = 0,

M fade.h => fade.h +10 -6
@@ 25,7 25,8 @@
void Fade_Init();

// fades the screen from start to end in frameCnt frames
void Fade_Start(uint8_t start, uint8_t end, int frameCnt);
// r, g, b: color to fade to
void Fade_Start(uint8_t start, uint8_t end, int frameCnt, uint8_t r, uint8_t g, uint8_t b);

// disables the fade
void Fade_Stop();


@@ 33,14 34,17 @@ void Fade_Stop();
// returns 1 if there is a fade currently happening
int Fade_Active();

// simple half-second fade-in
void Fade_In();
// simple fade-in
void Fade_In(int frameCnt);

// same as Fade_In but fades to white rather to black
void Fade_InWhite(int frameCnt);

// returns 1 if the fade started by Fade_In is done
int Fade_InDone();

// simple half-second fade-out
void Fade_Out();
// simple fade-out
void Fade_Out(int frameCnt);

// returns 1 if the fade started by Fade_Out is done
int Fade_OutDone();


@@ 49,4 53,4 @@ int Fade_OutDone();
int Fade_Active();

// should be run every frame at the end of drawing
void Fade_Draw();
\ No newline at end of file
void Fade_Draw();

M game.cpp => game.cpp +2 -2
@@ 209,7 209,7 @@ void Game_StateReset() {
}

void Game_Init(int level, int numLevels, int isStageClear, int bonusPoints) {
    Fade_Start(0xFF, 0x00, 30);
    Fade_In(30);
    Global_SetLoRes();
    shipSprite = SpriteInfo("ship.png");
    shipSprite.source.h = SHIP_SPRITE_HEIGHT;


@@ 745,7 745,7 @@ int Game_Run() {
        Bonus_Display(bonus, stageClear);
        frames += Speed_Multiplier();
        if (frames >= 60) {
            Fade_Out();
            Fade_Out(30);
            state = STATE_GAME_FADEOUT;
        }
        break;

M intro.cpp => intro.cpp +1 -1
@@ 266,7 266,7 @@ int Intro_Run() {

    if ((fadeFrames < 0) && padData) {
        fadeFrames = 0;
        Fade_Start(0, 0xFF, 60);
        Fade_Out(60);
    }

    if (fadeFrames >= 0) {

M logo.cpp => logo.cpp +5 -9
@@ 98,23 98,20 @@ int Logo_Run(void) {

    if ((state < STATE_LOGO_FADEOUT) && padData) {
        state = STATE_LOGO_FADEOUT;
        frame = 0;
        Fade_Start(0x00, 0xFF, 60);
        Fade_Out(60);
        state = STATE_LOGO_FADEOUT;
    }

    switch(state) {
        case STATE_LOGO_INIT:
            Fade_Start(0xFF, 0x00, 60);

            Fade_In(60);
            Logo_Init();
            frame = 0;
            state = STATE_LOGO_FADEIN;
            break;
        
        case STATE_LOGO_FADEIN:
            frame += Speed_Multiplier();
            if (frame > 60) {
            if (Fade_InDone()) {
                if (!Sound_PlayVGM("music/28 Opening (with SFX).vgz")) {
                    printf("Error loading logo music!\n");
                }


@@ 145,7 142,7 @@ int Logo_Run(void) {
        case STATE_LOGO_DONE:
            frame += Speed_Multiplier();
            if (frame > 60) {
                Fade_Start(0x00, 0xFF, 60);
                Fade_Out(60);
                frame = 0;
                state = STATE_LOGO_FADEOUT;
            }


@@ 153,8 150,7 @@ int Logo_Run(void) {
            break;
            
        case STATE_LOGO_FADEOUT:
            frame += Speed_Multiplier();
            if (frame > 60) {
            if (Fade_OutDone()) {
                state = STATE_LOGO_END;
            }
            chipSprite.draw();

M main.cpp => main.cpp +1 -1
@@ 136,7 136,7 @@ int main(int argc, char **argv) {

	SDL_Event event;
	int quit = 0;
    int state = STATE_MENU;
    int state = STATE_LOGO;
    Stage_Init();
	
    try {

M menu.cpp => menu.cpp +5 -9
@@ 165,15 165,12 @@ int Menu_Run() {
    switch (state) {
        case STATE_MENU_INIT:
            Menu_Init();
            timer = 0;
            Fade_Start(0xFF, 0x00, 30);
            Fade_In(30);
            state = STATE_MENU_FADEIN;
            break;

        case STATE_MENU_FADEIN:
            timer += Speed_Multiplier();
            if (timer >= 30) {
                timer = 0;
            if (Fade_InDone()) {
                state = STATE_MENU_ANIMIN;
                Chip_AnimIn();
            }


@@ 190,6 187,7 @@ int Menu_Run() {
        
        case STATE_MENU_ANIMOUT:
            if (Chip_AnimOutDone()) {
                timer = 0;
                state = STATE_MENU_WAITFADE;
            }
            break;


@@ 198,15 196,13 @@ int Menu_Run() {
            timer += Speed_Multiplier();
            //wait a second before fading out
            if (timer >= 60) {
				timer = 0;
                Fade_Start(0x00, 0xFF, 30);
                Fade_Out(30);
				state = STATE_MENU_FADEOUT;
            }
			break;

        case STATE_MENU_FADEOUT:
			timer += Speed_Multiplier();
            if (timer >= 30) {
            if (Fade_OutDone()) {
                stars.removeAll();
                state = STATE_MENU_DONE;
            }

M tutorial.cpp => tutorial.cpp +3 -3
@@ 426,7 426,7 @@ void Tutorial_Init(int level, int numLevels, const std::string &text) {
	optionsFont->print("NEXT\nMENU", FONT_TIMING_IMMEDIATE);
	descriptionFont->print(text, 4);
	Chip_AnimIn();
	Fade_In();
	Fade_In(30);
}

int Tutorial_Run() {


@@ 438,7 438,7 @@ int Tutorial_Run() {
		descriptionFont->showRest();
	}
	if (Chip_AnimOutDone() && !Fade_Active()) {
		Fade_Out();
		Fade_Out(30);
	}

	if (!Chip_AnimInDone());


@@ 481,4 481,4 @@ int Tutorial_Run() {
	}

	return 0;
}
\ No newline at end of file
}