Added fade.
This commit is contained in:
68
src/conversation/fade.c
Normal file
68
src/conversation/fade.c
Normal file
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* Copyright (c) 2022 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "fade.h"
|
||||
|
||||
void conversationFadeToBlack() {
|
||||
TIME_FUTURE = TIME_CURRENT;
|
||||
TIME_FUTURE_TYPE = TIME_FUTURE_TYPE_FADE_TO_BLACK;
|
||||
}
|
||||
|
||||
void conversationFadeFromBlack() {
|
||||
TIME_FUTURE = TIME_CURRENT;
|
||||
TIME_FUTURE_TYPE = TIME_FUTURE_TYPE_FADE_FROM_BLACK;
|
||||
}
|
||||
void conversationFadeToWhite() {
|
||||
TIME_FUTURE = TIME_CURRENT;
|
||||
TIME_FUTURE_TYPE = TIME_FUTURE_TYPE_FADE_TO_WHITE;
|
||||
}
|
||||
|
||||
void conversationFadeFromWhite() {
|
||||
TIME_FUTURE = TIME_CURRENT;
|
||||
TIME_FUTURE_TYPE = TIME_FUTURE_TYPE_FADE_FROM_WHITE;
|
||||
}
|
||||
|
||||
void conversationFadeUpdate() {
|
||||
uint16_t diff;
|
||||
|
||||
if(
|
||||
TIME_FUTURE_TYPE < TIME_FUTURE_TYPE_FADE_TO_BLACK ||
|
||||
TIME_FUTURE_TYPE > TIME_FUTURE_TYPE_FADE_FROM_WHITE
|
||||
) return;
|
||||
|
||||
diff = TIME_CURRENT - TIME_FUTURE;
|
||||
|
||||
// Now we work out the steps. Time is measured in steps which are made of
|
||||
// parts of a second.
|
||||
if(diff == FADE_STEP) {
|
||||
// First step
|
||||
BGP_REG = (
|
||||
TIME_FUTURE_TYPE == TIME_FUTURE_TYPE_FADE_TO_BLACK ? COMMON_SHADE_DARK :
|
||||
TIME_FUTURE_TYPE == TIME_FUTURE_TYPE_FADE_TO_WHITE ? COMMON_SHADE_BRIGHT :
|
||||
TIME_FUTURE_TYPE == TIME_FUTURE_TYPE_FADE_FROM_BLACK ? COMMON_SHADE_DARKER :
|
||||
COMMON_SHADE_BRIGHTER
|
||||
);
|
||||
} else if(diff == FADE_STEP * 2) {
|
||||
// First step
|
||||
BGP_REG = (
|
||||
TIME_FUTURE_TYPE == TIME_FUTURE_TYPE_FADE_TO_BLACK ? COMMON_SHADE_DARKER :
|
||||
TIME_FUTURE_TYPE == TIME_FUTURE_TYPE_FADE_TO_WHITE ? COMMON_SHADE_BRIGHTER :
|
||||
TIME_FUTURE_TYPE == TIME_FUTURE_TYPE_FADE_FROM_BLACK ? COMMON_SHADE_DARK :
|
||||
COMMON_SHADE_BRIGHT
|
||||
);
|
||||
} else if(diff == FADE_STEP * 3) {
|
||||
// First step
|
||||
BGP_REG = (
|
||||
TIME_FUTURE_TYPE == TIME_FUTURE_TYPE_FADE_TO_BLACK ? COMMON_SHADE_BLACK :
|
||||
TIME_FUTURE_TYPE == TIME_FUTURE_TYPE_FADE_TO_WHITE ? COMMON_SHADE_WHITE :
|
||||
COMMON_SHADE_NORMAL
|
||||
);
|
||||
} else if(diff == FADE_STEP * 4) {
|
||||
TIME_FUTURE_TYPE = TIME_FUTURE_TYPE_NULL;
|
||||
conversationQueueNext();
|
||||
}
|
||||
}
|
21
src/conversation/fade.h
Normal file
21
src/conversation/fade.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright (c) 2022 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
#include "queue.h"
|
||||
#include "pause.h"
|
||||
#include "../display/common.h"
|
||||
|
||||
// There are 4 total shades, so this is all 4 shades in a second.
|
||||
#define FADE_STEP TIME_PER_SECOND / COMMON_TILE_COUNT
|
||||
|
||||
void conversationFadeToBlack();
|
||||
void conversationFadeFromBlack();
|
||||
void conversationFadeToWhite();
|
||||
void conversationFadeFromWhite();
|
||||
void conversationFadeUpdate();
|
@@ -7,18 +7,16 @@
|
||||
|
||||
#include "pause.h"
|
||||
|
||||
uint16_t PAUSE_END;
|
||||
|
||||
void conversationPauseInit() {
|
||||
PAUSE_END = 0;
|
||||
}
|
||||
|
||||
void conversationPause(uint16_t duration) {
|
||||
PAUSE_END = TIME_CURRENT + (duration * TIME_PER_SECOND);
|
||||
TIME_FUTURE = TIME_CURRENT + (duration * TIME_PER_SECOND);
|
||||
TIME_FUTURE_TYPE = TIME_FUTURE_TYPE_PAUSE;
|
||||
}
|
||||
|
||||
void conversationPauseUpdate() {
|
||||
if(PAUSE_END == 0 || TIME_CURRENT != PAUSE_END) return;
|
||||
if(TIME_FUTURE_TYPE != TIME_FUTURE_TYPE_PAUSE || TIME_CURRENT != TIME_FUTURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
TIME_FUTURE_TYPE = TIME_FUTURE_TYPE_NULL;
|
||||
conversationQueueNext();
|
||||
PAUSE_END = 0;
|
||||
}
|
@@ -10,8 +10,5 @@
|
||||
#include "../time.h"
|
||||
#include "queue.h"
|
||||
|
||||
extern uint16_t PAUSE_END;
|
||||
|
||||
void conversationPauseInit();
|
||||
void conversationPause(uint16_t duration);
|
||||
void conversationPauseUpdate();
|
@@ -8,6 +8,7 @@
|
||||
#include "queue.h"
|
||||
#include "pause.h"
|
||||
#include "textbox.h"
|
||||
#include "fade.h"
|
||||
|
||||
uint16_t QUEUE_ITEM;
|
||||
|
||||
@@ -19,18 +20,35 @@ void conversationQueueNext() {
|
||||
BGB_printf("Queue item: %d\n", QUEUE_ITEM);
|
||||
|
||||
switch(QUEUE_ITEM) {
|
||||
// case 0:
|
||||
// conversationTextboxSetText(STR_POKER_GAME_START_DATA, STR_POKER_GAME_START_LENGTH);
|
||||
// conversationPause(3);
|
||||
// QUEUE_ITEM++;
|
||||
// break;
|
||||
|
||||
case 0:
|
||||
conversationTextboxSetText(STR_POKER_GAME_START_DATA, STR_POKER_GAME_START_LENGTH);
|
||||
conversationFadeToBlack();
|
||||
QUEUE_ITEM++;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
conversationPause(3);
|
||||
conversationFadeFromBlack();
|
||||
QUEUE_ITEM++;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
conversationTextboxSetText(STR_POKER_GAME_START_DATA, STR_POKER_GAME_START_LENGTH);
|
||||
conversationFadeToWhite();
|
||||
QUEUE_ITEM++;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
conversationFadeFromWhite();
|
||||
QUEUE_ITEM++;
|
||||
break;
|
||||
|
||||
// case 2:
|
||||
// conversationTextboxSetText(STR_POKER_GAME_START_DATA, STR_POKER_GAME_START_LENGTH);
|
||||
// QUEUE_ITEM++;
|
||||
// break;
|
||||
}
|
||||
}
|
@@ -15,6 +15,23 @@
|
||||
#define COMMON_TILE_2 0x02
|
||||
#define COMMON_TILE_3 0x03
|
||||
|
||||
// Shades are mapped where each set of 4 colors is mapped to two bits that will
|
||||
// specify its darkness. Higher = Darker, Lower = Brighter
|
||||
// 11 11 11 11
|
||||
#define COMMON_SHADE_BLACK 0xFF
|
||||
// 11 11 11 10
|
||||
#define COMMON_SHADE_DARKER 0xFE
|
||||
// 11 11 10 01
|
||||
#define COMMON_SHADE_DARK 0xF9
|
||||
// 11 10 01 00
|
||||
#define COMMON_SHADE_NORMAL 0xE4
|
||||
// 10 01 00 00
|
||||
#define COMMON_SHADE_BRIGHT 0x90
|
||||
// 01 00 00 00
|
||||
#define COMMON_SHADE_BRIGHTER 0x40
|
||||
// 00 00 00 00
|
||||
#define COMMON_SHADE_WHITE 0x00
|
||||
|
||||
extern const uint8_t COMMON_TILES[];
|
||||
|
||||
void commonTilesInit();
|
13
src/main.c
13
src/main.c
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "main.h"
|
||||
#include "SM.h"
|
||||
|
||||
void main() {
|
||||
int16_t j;
|
||||
@@ -21,13 +22,12 @@ void main() {
|
||||
initarand(DIV_REG);
|
||||
|
||||
// Prepare time and input
|
||||
TIME_CURRENT = 0;
|
||||
INPUT_STATE = joypad();
|
||||
|
||||
// Init things
|
||||
timeInit();
|
||||
commonTilesInit();
|
||||
conversationTextboxInit();
|
||||
conversationPauseInit();
|
||||
conversationQueueInit();
|
||||
pokerInit();
|
||||
|
||||
@@ -37,6 +37,12 @@ void main() {
|
||||
SCX_REG = 0x00;
|
||||
SCY_REG = 0x00;
|
||||
|
||||
|
||||
set_bkg_data(SM_DATA_POSITION, SM_IMAGE_TILES, SM_IMAGE);
|
||||
uint8_t sm[SM_IMAGE_TILES];
|
||||
for(j = 0; j < SM_IMAGE_TILES; j++) sm[j] = j + SM_DATA_POSITION;
|
||||
set_bkg_tiles(0x00, 0x00, SM_IMAGE_COLUMNS, SM_IMAGE_ROWS, sm);
|
||||
|
||||
// Now turn the screen on
|
||||
DISPLAY_ON;
|
||||
enable_interrupts();
|
||||
@@ -55,8 +61,9 @@ void main() {
|
||||
|
||||
conversationTextboxUpdate();
|
||||
conversationPauseUpdate();
|
||||
conversationFadeUpdate();
|
||||
|
||||
// Tick time.
|
||||
TIME_CURRENT++;
|
||||
timeUpdate();
|
||||
}
|
||||
}
|
||||
|
@@ -13,6 +13,7 @@
|
||||
#include "display/common.h"
|
||||
#include "display/tilemap.h"
|
||||
#include "poker/poker.h"
|
||||
#include "conversation/fade.h"
|
||||
#include "conversation/pause.h"
|
||||
#include "conversation/queue.h"
|
||||
#include "conversation/textbox.h"
|
||||
|
14
src/time.c
14
src/time.c
@@ -7,4 +7,16 @@
|
||||
|
||||
#include "time.h"
|
||||
|
||||
uint16_t TIME_CURRENT;
|
||||
uint16_t TIME_CURRENT;
|
||||
uint16_t TIME_FUTURE;
|
||||
uint8_t TIME_FUTURE_TYPE;
|
||||
|
||||
void timeInit() {
|
||||
TIME_CURRENT = 0;
|
||||
TIME_FUTURE = 0;
|
||||
TIME_FUTURE_TYPE = TIME_FUTURE_TYPE_NULL;
|
||||
}
|
||||
|
||||
void timeUpdate() {
|
||||
TIME_CURRENT++;
|
||||
}
|
15
src/time.h
15
src/time.h
@@ -9,4 +9,17 @@
|
||||
#include "libs.h"
|
||||
|
||||
#define TIME_PER_SECOND 60
|
||||
extern uint16_t TIME_CURRENT;
|
||||
|
||||
#define TIME_FUTURE_TYPE_NULL 0x00
|
||||
#define TIME_FUTURE_TYPE_PAUSE 0x01
|
||||
#define TIME_FUTURE_TYPE_FADE_TO_BLACK 0x02
|
||||
#define TIME_FUTURE_TYPE_FADE_FROM_BLACK 0x03
|
||||
#define TIME_FUTURE_TYPE_FADE_TO_WHITE 0x04
|
||||
#define TIME_FUTURE_TYPE_FADE_FROM_WHITE 0x05
|
||||
|
||||
extern uint16_t TIME_CURRENT;
|
||||
extern uint16_t TIME_FUTURE;
|
||||
extern uint8_t TIME_FUTURE_TYPE;
|
||||
|
||||
void timeInit();
|
||||
void timeUpdate();
|
Reference in New Issue
Block a user