Already did some fixes, trying to improve animations.

This commit is contained in:
mibi88 2023-07-18 19:47:47 +02:00
parent f71121a79e
commit acb859eaa8
4 changed files with 81 additions and 38 deletions

View File

@ -2,6 +2,7 @@
#include <gint/keyboard.h>
#include <gint/cpu.h>
#include <gint/image.h>
#include <string.h>
@ -13,7 +14,7 @@
extern font_t fontRPG;
#define FONT_USED fontRPG
#if GRAYMODEOK==1
#if GRAYMODEOK
#include <gint/gray.h>
uint32_t *lightVRAMnext, *darkVRAMnext;
uint32_t *lightVRAMcurrent, *darkVRAMcurrent;
@ -24,7 +25,7 @@ void blit()
{
dupdate();
#if GRAYMODEOK==1
#if GRAYMODEOK
dgray_getvram( &lightVRAMnext, &darkVRAMnext );
dgray_getscreen( &lightVRAMcurrent, &darkVRAMcurrent );
@ -43,11 +44,10 @@ int showtext_opt(Game *game, bopti_image_t *face, char *text,
unsigned int max_lines_amount = (BOX_HEIGHT-2)*PXSIZE/
(FONT_USED.line_height+PXSIZE);
const char *c;
draw(game);
if(start_anim){
/* Run a little fancy animation. */
for(i=0;i<BOX_HEIGHT;i++){
draw(game);
drect(0, 0, DWIDTH, i*PXSIZE, C_WHITE);
drect(0, i*PXSIZE, DWIDTH, (i+1)*PXSIZE, C_BLACK);
dsubimage(4*PXSIZE, 2*PXSIZE, face, 0, 0, F_WIDTH, (i-8)*PXSIZE,
@ -58,11 +58,16 @@ int showtext_opt(Game *game, bopti_image_t *face, char *text,
while(game->frame_duration < 20) sleep();
game->frame_duration = 0;
}
}else{
drect(0, 0, DWIDTH, (BOX_HEIGHT-1)*PXSIZE, C_WHITE);
drect(0, (BOX_HEIGHT-1)*PXSIZE, DWIDTH, BOX_HEIGHT*PXSIZE, C_BLACK);
dsubimage(4*PXSIZE, 2*PXSIZE, face, 0, 0, F_WIDTH,
(BOX_HEIGHT-7)*PXSIZE, DIMAGE_NONE);
dupdate();
}
/* We should start to drawint the text on the x axis at BOX_HEIGHT to avoid
/* We should start to drawing the text on the x axis at BOX_HEIGHT to avoid
* drawing on the face. */
/* Show a little message that showing text in dialogs is not implemented
* yet. */
for(i=0;i<strlen(text);i++){
/* Get how many chars we can draw on screen with a padding on the left
* of BOX_HEIGHT px and on the right of 1 px. */
@ -71,18 +76,26 @@ int showtext_opt(Game *game, bopti_image_t *face, char *text,
line_max_chars = c-(text+i);
/* TODO: Handle lines that are longer than what I can draw. */
/* Loop from the end to the start for word wrap. */
for(n=line_max_chars; n>0; n--) {
/* If we found a space, we can draw this line and do the same for
* the next line. */
if(text[i+n] == ' '){
dtext_opt(BOX_HEIGHT*PXSIZE, y, C_BLACK, C_NONE, DTEXT_LEFT,
DTEXT_TOP, text+i, n); /* Draw everything. */
/* Increment y by the line height. */
y += FONT_USED.line_height+PXSIZE;
i += n; /* We drew everything to i+n */
l++; /* We drew one more line. */
break;
if(*(c+1) != '\0'){
for(n=line_max_chars; n>0; n--) {
/* If we found a space, we can draw this line and do the same for
* the next line. */
if(text[i+n] == ' '){
dtext_opt(BOX_HEIGHT*PXSIZE, y, C_BLACK, C_NONE, DTEXT_LEFT,
DTEXT_TOP, text+i, n); /* Draw everything. */
/* Increment y by the line height. */
y += FONT_USED.line_height+PXSIZE;
i += n; /* We drew everything to i+n */
l++; /* We drew one more line. */
break;
}
}
}else{
dtext_opt(BOX_HEIGHT*PXSIZE, y, C_BLACK, C_NONE, DTEXT_LEFT,
DTEXT_TOP, text+i, line_max_chars);
y += FONT_USED.line_height+PXSIZE;
i += line_max_chars;
l++;
}
if(l>=max_lines_amount-1){
/* We drew one entire screen, reset everything to draw the next one.
@ -162,9 +175,35 @@ void showtext_dialog_end(Game *game, bopti_image_t *face, char *text) {
char *_choices;
int _choices_amount, _default_choice;
/* store_vram_part(int x1, int y1, int x2, int y2) and restore_vram_part(int x,
* int y) are needed in the animations of the interaction dialog. */
#ifdef FXCG50
image_t vram_part;
#else
// Really need to code this!
#endif
void store_vram_part(int x1, int y1, int x2, int y2) {
#ifdef FXCG50
image_sub(image_create_vram(), x1, y1, x2-x1, y2-y1, &vram_part);
#else
// Really need to code this!
#endif
}
void restore_vram_part(int x, int y) {
#ifdef FXCG50
dimage(x, y, &vram_part);
#else
// Really need to code this!
#endif
}
int _choice_call_before_end(Game *game) {
int i, key;
/* Make a little animation because we looove little animations ;) */
store_vram_part(0, (BOX_HEIGHT+1)*PXSIZE,
DWIDTH, (BOX_HEIGHT+CHOICE_BOX_HEIGHT+1)*PXSIZE);
for(i=0;i<DWIDTH/8+1;i++){
drect(0, BOX_HEIGHT*PXSIZE, i*(DWIDTH/8),
(BOX_HEIGHT+CHOICE_BOX_HEIGHT)*PXSIZE, C_WHITE);
@ -181,16 +220,17 @@ int _choice_call_before_end(Game *game) {
dsize(">", &FONT_USED, &arrow_width, NULL);
do{
/* Clear the box. */
drect(0, (BOX_HEIGHT+CHOICE_BOX_HEIGHT)*PXSIZE, (DWIDTH/8)*(DWIDTH/8),
(BOX_HEIGHT+CHOICE_BOX_HEIGHT)*PXSIZE, C_WHITE);
drect(0, (BOX_HEIGHT+CHOICE_BOX_HEIGHT)*PXSIZE, DWIDTH,
(BOX_HEIGHT+CHOICE_BOX_HEIGHT)*PXSIZE-1, C_WHITE);
/* Display the diffrent choices. */
for(i=0;i<_choices_amount;i++){
if(i == selected) dtext(i*choice_size+PXSIZE,
(BOX_HEIGHT+CHOICE_BOX_PADDING_TOP)*PXSIZE,
C_BLACK, ">");
pos += strlen(_choices);
dtext(i*choice_size+arrow_width+PXSIZE,
(BOX_HEIGHT+CHOICE_BOX_PADDING_TOP)*PXSIZE, C_BLACK,
&(_choices+pos)[i]);
_choices+pos+i);
pos += strlen(_choices+pos);
}
blit();
key = getkey().key;
@ -199,9 +239,10 @@ int _choice_call_before_end(Game *game) {
}while(key != KEY_EXE);
/* Make a little animation because we looove little animations ;) */
for(i=DWIDTH/8+1;i>0;i--){
drect(0, (BOX_HEIGHT+CHOICE_BOX_HEIGHT)*PXSIZE, i*(DWIDTH/8),
restore_vram_part(0, BOX_HEIGHT*PXSIZE);
drect(0, BOX_HEIGHT*PXSIZE, i*(DWIDTH/8),
(BOX_HEIGHT+CHOICE_BOX_HEIGHT)*PXSIZE, C_WHITE);
drect(i*(DWIDTH/8), 0, i*(DWIDTH/8)+PXSIZE,
drect(i*(DWIDTH/8), BOX_HEIGHT*PXSIZE, i*(DWIDTH/8)+PXSIZE,
(BOX_HEIGHT+CHOICE_BOX_HEIGHT)*PXSIZE, C_BLACK);
drect(0, (BOX_HEIGHT+CHOICE_BOX_HEIGHT)*PXSIZE, i*(DWIDTH/8),
(BOX_HEIGHT+CHOICE_BOX_HEIGHT+1)*PXSIZE, C_BLACK);
@ -209,6 +250,11 @@ int _choice_call_before_end(Game *game) {
while(game->frame_duration < 20) sleep();
game->frame_duration = 0;
}
#ifdef FXCG50
//
#else
// Really need to code this!
#endif
return selected;
}

View File

@ -40,7 +40,7 @@ void get_inputs(Game *game) {
/* if USB is enabled - keybinding for screencapture */
#if USB_FEATURE==1
#if USB_FEATURE
if(keydown(KEY_7)) game->screenshot = true;
if(keydown(KEY_8)) game->record = !game->record;

View File

@ -12,7 +12,7 @@
#endif //USB_FEATURE
#if GRAYMODEOK==1
#if GRAYMODEOK
#include <gint/gray.h>
#endif //GRAYMODEOK
@ -35,14 +35,14 @@ Game game = {
/* screen capture management code */
#if USB_FEATURE==1
#if USB_FEATURE
void USB_feature( void )
{
if (game.screenshot && usb_is_open()) {
#if GRAYMODEOK==1 // This is a trick, if GRAYMODEOK is defined then
// we make the code accessible
#if GRAYMODEOK // This is a trick, if GRAYMODEOK is defined then
// we make the code accessible
if (dgray_enabled())
usb_fxlink_screenshot_gray(false);
@ -58,7 +58,7 @@ Game game = {
if (game.record && usb_is_open()) {
#if GRAYMODEOK==1
#if GRAYMODEOK
if (dgray_enabled())
usb_fxlink_videocapture_gray(false);
@ -87,7 +87,7 @@ int main(void) {
}
timer_start(timer);
#if USB_FEATURE==1
#if USB_FEATURE
usb_interface_t const *interfaces[] = {&usb_ff_bulk, NULL};
usb_open(interfaces, GINT_CALL_NULL);
#endif
@ -95,7 +95,7 @@ int main(void) {
/* start grayscale engine */
#if GRAYMODEOK==1
#if GRAYMODEOK
dgray(DGRAY_ON);
#endif
@ -117,7 +117,7 @@ int main(void) {
dupdate();
/* Screen capture feature if enabled */
#if USB_FEATURE==1
#if USB_FEATURE
USB_feature();
#endif
@ -132,13 +132,13 @@ int main(void) {
/* shutdown grayengine*/
#if GRAYMODEOK==1
#if GRAYMODEOK
dgray(DGRAY_OFF);
#endif
/* close USB */
#if USB_FEATURE==1
#if USB_FEATURE
usb_close();
#endif

View File

@ -180,9 +180,6 @@ void render_map_by_layer(Player *player, Map *map_level, int layer) {
}
}
short int get_tile(Map *map_level, int x, int y, int l) {
/* Get the tile at (x, y) on layer l. Returns the tile ID or MAP_OUTSIDE if
* she's not found. */