From: Holger Schemel Date: Fri, 29 Nov 2002 18:53:38 +0000 (+0100) Subject: rnd-20021129-2-src X-Git-Tag: 3.0.0^2~209 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=f22f670b327fa0e074a4ef0889585a33afb7f8a3;p=rocksndiamonds.git rnd-20021129-2-src --- diff --git a/src/cartoons.c b/src/cartoons.c index 5b38eb77..5db44a29 100644 --- a/src/cartoons.c +++ b/src/cartoons.c @@ -25,21 +25,21 @@ #define DWARF_Y 72 #define DWARF2_Y 186 #define DWARF_FRAMES 8 -#define DWARF_FPS 10 +#define DWARF_DELAY 5 #define DWARF_STEPSIZE 4 #define JUMPER_XSIZE 48 #define JUMPER_YSIZE 56 #define JUMPER_X 2 #define JUMPER_Y 125 #define JUMPER_FRAMES 8 -#define JUMPER_FPS 10 +#define JUMPER_DELAY 5 #define JUMPER_STEPSIZE 4 #define CLOWN_XSIZE 80 #define CLOWN_YSIZE 110 #define CLOWN_X 327 #define CLOWN_Y 10 #define CLOWN_FRAMES 1 -#define CLOWN_FPS 10 +#define CLOWN_DELAY 5 #define CLOWN_STEPSIZE 4 #define BIRD_XSIZE 32 #define BIRD_YSIZE 30 @@ -48,225 +48,206 @@ #define BIRD2_X 2 #define BIRD2_Y 37 #define BIRD_FRAMES 8 -#define BIRD_FPS 20 +#define BIRD_DELAY 2 #define BIRD_STEPSIZE 4 -#define GAMETOON_XSIZE TILEX -#define GAMETOON_YSIZE TILEY -#define GAMETOON_FRAMES_4 4 -#define GAMETOON_FRAMES_8 8 -#define GAMETOON_FPS 20 -#define GAMETOON_STEPSIZE 4 - struct ToonInfo toons[NUM_TOONS] = { { - PIX_TOONS, + IMG_MENU_TOONS, DWARF_XSIZE, DWARF_YSIZE, DWARF_X, DWARF_Y, DWARF_FRAMES, - DWARF_FPS, + DWARF_DELAY, DWARF_STEPSIZE, ANIM_LOOP, ANIMDIR_RIGHT, ANIMPOS_DOWN }, { - PIX_TOONS, + IMG_MENU_TOONS, DWARF_XSIZE, DWARF_YSIZE, DWARF_X, DWARF2_Y, DWARF_FRAMES, - DWARF_FPS, + DWARF_DELAY, DWARF_STEPSIZE, ANIM_LOOP, ANIMDIR_LEFT, ANIMPOS_DOWN }, { - PIX_TOONS, + IMG_MENU_TOONS, JUMPER_XSIZE, JUMPER_YSIZE, JUMPER_X, JUMPER_Y, JUMPER_FRAMES, - JUMPER_FPS, + JUMPER_DELAY, JUMPER_STEPSIZE, ANIM_LOOP, ANIMDIR_RIGHT, ANIMPOS_DOWN }, { - PIX_TOONS, + IMG_MENU_TOONS, CLOWN_XSIZE, CLOWN_YSIZE, CLOWN_X, CLOWN_Y, CLOWN_FRAMES, - CLOWN_FPS, + CLOWN_DELAY, CLOWN_STEPSIZE, ANIM_LOOP, ANIMDIR_UP, ANIMPOS_ANY }, { - PIX_TOONS, + IMG_MENU_TOONS, BIRD_XSIZE, BIRD_YSIZE, BIRD1_X, BIRD1_Y, BIRD_FRAMES, - BIRD_FPS, + BIRD_DELAY, BIRD_STEPSIZE, ANIM_PINGPONG, ANIMDIR_RIGHT, ANIMPOS_UPPER }, { - PIX_TOONS, + IMG_MENU_TOONS, BIRD_XSIZE, BIRD_YSIZE, BIRD2_X, BIRD2_Y, BIRD_FRAMES, - BIRD_FPS, + BIRD_DELAY, BIRD_STEPSIZE, ANIM_PINGPONG, ANIMDIR_LEFT, ANIMPOS_UPPER }, { - PIX_HEROES, - GAMETOON_XSIZE, GAMETOON_YSIZE, - ((GFX_SPIELER1_LEFT - GFX_START_ROCKSHEROES) % HEROES_PER_LINE)*TILEX, - ((GFX_SPIELER1_LEFT - GFX_START_ROCKSHEROES) / HEROES_PER_LINE)*TILEY, - GAMETOON_FRAMES_4, - GAMETOON_FPS, - GAMETOON_STEPSIZE, - ANIM_LOOP, + IMG_PLAYER1_LEFT_MOVING, + -1, -1, + -1, -1, + -1, + -1, + -1, + -1, ANIMDIR_LEFT, ANIMPOS_DOWN }, { - PIX_HEROES, - GAMETOON_XSIZE, GAMETOON_YSIZE, - ((GFX_SPIELER1_RIGHT - GFX_START_ROCKSHEROES) % HEROES_PER_LINE)*TILEX, - ((GFX_SPIELER1_RIGHT - GFX_START_ROCKSHEROES) / HEROES_PER_LINE)*TILEY, - GAMETOON_FRAMES_4, - GAMETOON_FPS, - GAMETOON_STEPSIZE, - ANIM_LOOP, + IMG_PLAYER1_RIGHT_MOVING, + -1, -1, + -1, -1, + -1, + -1, + -1, + -1, ANIMDIR_RIGHT, ANIMPOS_DOWN }, { - PIX_HEROES, - GAMETOON_XSIZE, GAMETOON_YSIZE, - ((GFX_PINGUIN_LEFT - GFX_START_ROCKSHEROES) % HEROES_PER_LINE)*TILEX, - ((GFX_PINGUIN_LEFT - GFX_START_ROCKSHEROES) / HEROES_PER_LINE)*TILEY, - GAMETOON_FRAMES_4, - GAMETOON_FPS, - GAMETOON_STEPSIZE, - ANIM_LOOP, + IMG_PENGUIN_LEFT_MOVING, + -1, -1, + -1, -1, + -1, + -1, + -1, + -1, ANIMDIR_LEFT, ANIMPOS_DOWN }, { - PIX_HEROES, - GAMETOON_XSIZE, GAMETOON_YSIZE, - ((GFX_PINGUIN_RIGHT - GFX_START_ROCKSHEROES) % HEROES_PER_LINE)*TILEX, - ((GFX_PINGUIN_RIGHT - GFX_START_ROCKSHEROES) / HEROES_PER_LINE)*TILEY, - GAMETOON_FRAMES_4, - GAMETOON_FPS, - GAMETOON_STEPSIZE, - ANIM_LOOP, + IMG_PENGUIN_RIGHT_MOVING, + -1, -1, + -1, -1, + -1, + -1, + -1, + -1, ANIMDIR_RIGHT, ANIMPOS_DOWN }, { - PIX_HEROES, - GAMETOON_XSIZE, GAMETOON_YSIZE, - ((GFX_MOLE_LEFT - GFX_START_ROCKSHEROES) % HEROES_PER_LINE)*TILEX, - ((GFX_MOLE_LEFT - GFX_START_ROCKSHEROES) / HEROES_PER_LINE)*TILEY, - GAMETOON_FRAMES_4, - GAMETOON_FPS, - GAMETOON_STEPSIZE, - ANIM_LOOP, + IMG_MOLE_LEFT_MOVING, + -1, -1, + -1, -1, + -1, + -1, + -1, + -1, ANIMDIR_LEFT, ANIMPOS_DOWN }, { - PIX_HEROES, - GAMETOON_XSIZE, GAMETOON_YSIZE, - ((GFX_MOLE_RIGHT - GFX_START_ROCKSHEROES) % HEROES_PER_LINE)*TILEX, - ((GFX_MOLE_RIGHT - GFX_START_ROCKSHEROES) / HEROES_PER_LINE)*TILEY, - GAMETOON_FRAMES_4, - GAMETOON_FPS, - GAMETOON_STEPSIZE, - ANIM_LOOP, + IMG_MOLE_RIGHT_MOVING, + -1, -1, + -1, -1, + -1, + -1, + -1, + -1, ANIMDIR_RIGHT, ANIMPOS_DOWN }, { - PIX_HEROES, - GAMETOON_XSIZE, GAMETOON_YSIZE, - ((GFX_SCHWEIN_LEFT - GFX_START_ROCKSHEROES) % HEROES_PER_LINE)*TILEX, - ((GFX_SCHWEIN_LEFT - GFX_START_ROCKSHEROES) / HEROES_PER_LINE)*TILEY, - GAMETOON_FRAMES_4, - GAMETOON_FPS, - GAMETOON_STEPSIZE, - ANIM_LOOP, + IMG_PIG_LEFT_MOVING, + -1, -1, + -1, -1, + -1, + -1, + -1, + -1, ANIMDIR_LEFT, ANIMPOS_DOWN }, { - PIX_HEROES, - GAMETOON_XSIZE, GAMETOON_YSIZE, - ((GFX_SCHWEIN_RIGHT - GFX_START_ROCKSHEROES) % HEROES_PER_LINE)*TILEX, - ((GFX_SCHWEIN_RIGHT - GFX_START_ROCKSHEROES) / HEROES_PER_LINE)*TILEY, - GAMETOON_FRAMES_4, - GAMETOON_FPS, - GAMETOON_STEPSIZE, - ANIM_LOOP, + IMG_PIG_RIGHT_MOVING, + -1, -1, + -1, -1, + -1, + -1, + -1, + -1, ANIMDIR_RIGHT, ANIMPOS_DOWN }, { - PIX_HEROES, - GAMETOON_XSIZE, GAMETOON_YSIZE, - ((GFX_DRACHE_LEFT - GFX_START_ROCKSHEROES) % HEROES_PER_LINE)*TILEX, - ((GFX_DRACHE_LEFT - GFX_START_ROCKSHEROES) / HEROES_PER_LINE)*TILEY, - GAMETOON_FRAMES_4, - GAMETOON_FPS, - GAMETOON_STEPSIZE, - ANIM_LOOP, + IMG_DRAGON_LEFT_MOVING, + -1, -1, + -1, -1, + -1, + -1, + -1, + -1, ANIMDIR_LEFT, ANIMPOS_DOWN }, { - PIX_HEROES, - GAMETOON_XSIZE, GAMETOON_YSIZE, - ((GFX_DRACHE_RIGHT - GFX_START_ROCKSHEROES) % HEROES_PER_LINE)*TILEX, - ((GFX_DRACHE_RIGHT - GFX_START_ROCKSHEROES) / HEROES_PER_LINE)*TILEY, - GAMETOON_FRAMES_4, - GAMETOON_FPS, - GAMETOON_STEPSIZE, - ANIM_LOOP, + IMG_DRAGON_RIGHT_MOVING, + -1, -1, + -1, -1, + -1, + -1, + -1, + -1, ANIMDIR_RIGHT, ANIMPOS_DOWN }, { - PIX_HEROES, - GAMETOON_XSIZE, GAMETOON_YSIZE, - ((GFX_SONDE - GFX_START_ROCKSHEROES) % HEROES_PER_LINE)*TILEX, - ((GFX_SONDE - GFX_START_ROCKSHEROES) / HEROES_PER_LINE)*TILEY, - GAMETOON_FRAMES_8, - GAMETOON_FPS, - GAMETOON_STEPSIZE, - ANIM_LOOP, + IMG_SATELLITE_MOVING, + -1, -1, + -1, -1, + -1, + -1, + -1, + -1, ANIMDIR_LEFT, ANIMPOS_ANY }, { - PIX_HEROES, - GAMETOON_XSIZE, GAMETOON_YSIZE, - ((GFX_SONDE - GFX_START_ROCKSHEROES) % HEROES_PER_LINE)*TILEX, - ((GFX_SONDE - GFX_START_ROCKSHEROES) / HEROES_PER_LINE)*TILEY, - GAMETOON_FRAMES_8, - GAMETOON_FPS, - GAMETOON_STEPSIZE, - ANIM_LOOP, + IMG_SATELLITE_MOVING, + -1, -1, + -1, -1, + -1, + -1, + -1, + -1, ANIMDIR_RIGHT, ANIMPOS_ANY }, @@ -310,7 +291,45 @@ boolean ToonNeedsRedraw() void InitToons() { - InitToonScreen(pix, bitmap_db_door, + int i; + + for (i=0; i num_frames - 1) + frame = num_frames - 1; + } + else if (mode & ANIM_PINGPONG) /* use border frames once */ + { + int max_anim_frames = 2 * num_frames - 2; + + frame = (sync_frame % (delay * max_anim_frames)) / delay; + frame = (frame < num_frames ? frame : max_anim_frames - frame); + } + else if (mode & ANIM_PINGPONG2) /* use border frames twice */ + { + int max_anim_frames = 2 * num_frames; + + frame = (sync_frame % (delay * max_anim_frames)) / delay; + frame = (frame < num_frames ? frame : max_anim_frames - frame - 1); + } + + if (mode & ANIM_REVERSE) /* use reverse animation direction */ + frame = num_frames - frame - 1; + + return frame; +} + + +/* ========================================================================= */ +/* toon animation functions */ +/* ========================================================================= */ + +void InitToonScreen(Bitmap *save_buffer, void (*update_function)(void), void (*prepare_backbuffer_function)(void), boolean (*redraw_needed_function)(void), @@ -32,7 +80,6 @@ void InitToonScreen(Bitmap **toon_bitmap_array, int startx, int starty, int width, int height) { - screen_info.toon_bitmap_array = toon_bitmap_array; screen_info.save_buffer = save_buffer; screen_info.update_function = update_function; screen_info.prepare_backbuffer_function = prepare_backbuffer_function; @@ -81,9 +128,10 @@ void DrawAnim(Bitmap *toon_bitmap, GC toon_clip_gc, boolean AnimateToon(int toon_nr, boolean restart) { + static unsigned long animation_frame_counter = 0; static int pos_x = 0, pos_y = 0; static int delta_x = 0, delta_y = 0; - static int frame = 0, frame_step = 1; + static int frame = 0; static boolean horiz_move, vert_move; static unsigned long anim_delay = 0; static unsigned long anim_delay_value = 0; @@ -92,18 +140,19 @@ boolean AnimateToon(int toon_nr, boolean restart) static int cut_x,cut_y; static int src_x, src_y; static int dest_x, dest_y; - struct ToonInfo *anim = &screen_info.toons[toon_nr]; - int bitmap_nr = screen_info.toons[toon_nr].bitmap_nr; - Bitmap *anim_bitmap = screen_info.toon_bitmap_array[bitmap_nr]; + Bitmap *anim_bitmap = screen_info.toons[toon_nr].bitmap; GC anim_clip_gc = anim_bitmap->stored_clip_gc; if (restart) { horiz_move = (anim->direction & (ANIMDIR_LEFT | ANIMDIR_RIGHT)); vert_move = (anim->direction & (ANIMDIR_UP | ANIMDIR_DOWN)); - anim_delay_value = 1000/anim->frames_per_second; - frame = 0; + anim_delay_value = anim->move_delay; + + frame = getAnimationFrame(anim->anim_frames, anim->anim_delay, + anim->anim_mode, anim->start_frame, + animation_frame_counter++); if (horiz_move) { @@ -189,7 +238,7 @@ boolean AnimateToon(int toon_nr, boolean restart) width = anim->width; height = anim->height; - if (pos_x<0) + if (pos_x < 0) { dest_x = 0; width += pos_x; @@ -198,7 +247,7 @@ boolean AnimateToon(int toon_nr, boolean restart) else if (pos_x > screen_info.width - anim->width) width -= (pos_x - (screen_info.width - anim->width)); - if (pos_y<0) + if (pos_y < 0) { dest_y = 0; height += pos_y; @@ -216,18 +265,10 @@ boolean AnimateToon(int toon_nr, boolean restart) pos_x += delta_x; pos_y += delta_y; - frame += frame_step; - if (frame<0 || frame>=anim->frames) - { - if (anim->mode == ANIM_PINGPONG) - { - frame_step *= -1; - frame = (frame<0 ? 1 : anim->frames-2); - } - else - frame = (frame<0 ? anim->frames-1 : 0); - } + frame = getAnimationFrame(anim->anim_frames, anim->anim_delay, + anim->anim_mode, anim->start_frame, + animation_frame_counter++); return FALSE; } diff --git a/src/libgame/toons.h b/src/libgame/toons.h index cf267345..75f76864 100644 --- a/src/libgame/toons.h +++ b/src/libgame/toons.h @@ -41,7 +41,6 @@ struct ToonScreenInfo { - Bitmap **toon_bitmap_array; Bitmap *save_buffer; void (*update_function)(void); void (*prepare_backbuffer_function)(void); @@ -56,18 +55,24 @@ struct ToonScreenInfo struct ToonInfo { - int bitmap_nr; + int graphic; int width, height; int src_x, src_y; - int frames; - int frames_per_second; + int anim_frames; + int move_delay; int stepsize; - int mode; + int anim_mode; int direction; int position; + + int anim_delay; + int start_frame; + Bitmap *bitmap; /* dynamically initialized */ }; +int getAnimationFrame(int, int, int, int, int); + void InitToonScreen(); void InitAnimation(void); void StopAnimation(void); diff --git a/src/tools.c b/src/tools.c index efb413e1..8ed62a52 100644 --- a/src/tools.c +++ b/src/tools.c @@ -32,7 +32,6 @@ #define NUM_TOOL_BUTTONS 7 /* forward declaration for internal use */ -static int getGraphicAnimationPhase(int, int, int); static void UnmapToolButtons(); static void HandleToolButtons(struct GadgetInfo *); @@ -384,6 +383,39 @@ void ClearWindow() redraw_mask |= REDRAW_FIELD; } +static int getGraphicAnimationPhase(int frames, int delay, int mode) +{ + int phase; + + if (mode & ANIM_PINGPONG) + { + int max_anim_frames = 2 * frames - 2; + + phase = (FrameCounter % (delay * max_anim_frames)) / delay; + phase = (phase < frames ? phase : max_anim_frames - phase); + } + else + phase = (FrameCounter % (delay * frames)) / delay; + + if (mode & ANIM_REVERSE) + phase = -phase; + + return phase; +} + +inline int getGraphicAnimationFrame(int graphic, int sync_frame) +{ + /* animation synchronized with global frame counter, not move position */ + if (new_graphic_info[graphic].anim_global_sync || sync_frame < 0) + sync_frame = FrameCounter; + + return getAnimationFrame(new_graphic_info[graphic].anim_frames, + new_graphic_info[graphic].anim_delay, + new_graphic_info[graphic].anim_mode, + new_graphic_info[graphic].anim_start_frame, + sync_frame); +} + void MarkTileDirty(int x, int y) { int xx = redraw_x1 + x; @@ -736,71 +768,6 @@ void DrawPlayer(struct PlayerInfo *player) MarkTileDirty(sx,sy); } -static int getGraphicAnimationPhase(int frames, int delay, int mode) -{ - int phase; - - if (mode & ANIM_PINGPONG) - { - int max_anim_frames = 2 * frames - 2; - - phase = (FrameCounter % (delay * max_anim_frames)) / delay; - phase = (phase < frames ? phase : max_anim_frames - phase); - } - else - phase = (FrameCounter % (delay * frames)) / delay; - - if (mode & ANIM_REVERSE) - phase = -phase; - - return phase; -} - -int getGraphicAnimationFrame(int graphic, int sync_frame) -{ - int num_frames = new_graphic_info[graphic].anim_frames; - int delay = new_graphic_info[graphic].anim_delay; - int mode = new_graphic_info[graphic].anim_mode; - int frame = 0; - - /* animation synchronized with global frame counter, not move position */ - if (new_graphic_info[graphic].anim_global_sync || sync_frame < 0) - sync_frame = FrameCounter; - - sync_frame += new_graphic_info[graphic].anim_start_frame * delay; - - if (mode & ANIM_LOOP) /* normal, looping animation */ - { - frame = (sync_frame % (delay * num_frames)) / delay; - } - else if (mode & ANIM_LINEAR) /* normal, non-looping animation */ - { - frame = sync_frame / delay; - - if (frame > num_frames - 1) - frame = num_frames - 1; - } - else if (mode & ANIM_PINGPONG) /* use border frames once */ - { - int max_anim_frames = 2 * num_frames - 2; - - frame = (sync_frame % (delay * max_anim_frames)) / delay; - frame = (frame < num_frames ? frame : max_anim_frames - frame); - } - else if (mode & ANIM_PINGPONG2) /* use border frames twice */ - { - int max_anim_frames = 2 * num_frames; - - frame = (sync_frame % (delay * max_anim_frames)) / delay; - frame = (frame < num_frames ? frame : max_anim_frames - frame - 1); - } - - if (mode & ANIM_REVERSE) /* use reverse animation direction */ - frame = num_frames - frame - 1; - - return frame; -} - void DrawGraphicAnimationExt(int x, int y, int graphic, int mask_mode) { if (IN_SCR_FIELD(x, y))