Skip to content

Commit

Permalink
Add SPRn_AUTOOFF counters (#300)
Browse files Browse the repository at this point in the history
* Change struct sprite::flags to an unsigned int
* add SPRn_AUTOOFF
* Rename to SPRn_OFFONEXIT, add test, other tweaks.

---------

Co-authored-by: AliceLR <[email protected]>
  • Loading branch information
flarn2006 and AliceLR authored Dec 22, 2023
1 parent 9673d1a commit 4cfa962
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 5 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ USERS
+ Added new counters VIEWPORT_X, VIEWPORT_Y, VIEWPORT_WIDTH,
and VIEWPORT_HEIGHT to read the current board's viewport
settings. (Sparkette)
+ Added a new counter SPRn_OFFONEXIT. When enabled for a sprite,
that sprite will be automatically turned off when exiting the
board (same as setting SPRn_OFF). This occurs even if the new
board and the previous board are the same. (Sparkette)
+ Added an "About MegaZeux" dialog, accessible from the main
menu. This menu contains extended version information, and
displays license information for MegaZeux and the 3rd party
Expand Down
7 changes: 6 additions & 1 deletion docs/counter_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,23 @@ name r/w g/n/f/b i
"SPRn_CX" r w b *
"SPRn_CY" r w b *
"SPRn_HEIGHT" r w b *
"SPRn_OFF" w f *
"SPRn_OFF" r w f *
"SPRn_OFFONEXIT" r w f *
"SPRn_OFFSET" r w b *
"SPRn_OVERLAID" w f *
"SPRn_OVERLAY" w f *
"SPRn_REFX" r w b *
"SPRn_REFY" r w b *
"SPRn_SETVIEW" w f *
"SPRn_STATIC" w b *
"SPRn_SWAP" w f *
"SPRn_TCOL" r w b *
"SPRn_UNBOUND" r w f *
"SPRn_VLAYER" w f *
"SPRn_WIDTH" r w b *
"SPRn_X" r w b *
"SPRn_Y" r w b *
"SPRn_Z" r w b *
"SQRTn" r f *
"TAN" r f *
"THISX" r b *
Expand Down
3 changes: 2 additions & 1 deletion docs/fileform.html
Original file line number Diff line number Diff line change
Expand Up @@ -2687,7 +2687,7 @@ <h3>Sprite Properties (.SAV only)</h3>
| `0x0004` | Sprite reference X | int(ds) | Each sprite
| `0x0005` | Sprite reference Y | int(ds) | Each sprite
| `0x0006` | Sprite color | int(b) | Each sprite
| `0x0007` | Sprite flags | int(b) | Each sprite<a href="#sprites290note2">(2)</a>
| `0x0007` | Sprite flags | int(d) | Each sprite<a href="#sprites290note2">(2)</a>
| `0x0008` | Sprite width | int(d) | Each sprite
| `0x0009` | Sprite height | int(d) | Each sprite
| `0x000A` | Sprite collision X | int(ds) | Each sprite
Expand Down Expand Up @@ -2724,6 +2724,7 @@ <h3>Sprite Properties (.SAV only)</h3>
| `0x20` | Sprite ccheck 2 is enabled
| `0x40` | Sprite references the vlayer
| `0x80` | Sprite is unbound
| `0x100`| Sprite off-on-exit is enabled
</div>
For unbound sprites, if both the ccheck 1 and ccheck 2 flags are set,
sprite ccheck 3 is enabled instead.
Expand Down
21 changes: 21 additions & 0 deletions src/counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,16 @@ static int spr_off_read(struct world *mzx_world,
return 0;
}

static int spr_offonexit_read(struct world *mzx_world,
const struct function_counter *counter, const char *name, int id)
{
int spr_num = strtol(name + 3, NULL, 10) & (MAX_SPRITES - 1);
if((mzx_world->sprite_list[spr_num])->flags & SPRITE_OFF_ON_EXIT)
return 1;

return 0;
}

static int spr_cwidth_read(struct world *mzx_world,
const struct function_counter *counter, const char *name, int id)
{
Expand Down Expand Up @@ -1064,6 +1074,16 @@ static void spr_off_write(struct world *mzx_world,
}
}

static void spr_offonexit_write(struct world *mzx_world,
const struct function_counter *counter, const char *name, int value, int id)
{
int spr_num = strtol(name + 3, NULL, 10) & (MAX_SPRITES - 1);
if(value)
(mzx_world->sprite_list[spr_num])->flags |= SPRITE_OFF_ON_EXIT;
else
(mzx_world->sprite_list[spr_num])->flags &= ~SPRITE_OFF_ON_EXIT;
}

static void spr_swap_write(struct world *mzx_world,
const struct function_counter *counter, const char *name, int value, int id)
{
Expand Down Expand Up @@ -2738,6 +2758,7 @@ static const struct function_counter builtin_counters[] =
{ "spr!_cy", V265, spr_cy_read, spr_cy_write },
{ "spr!_height", V265, spr_height_read, spr_height_write },
{ "spr!_off", V265, spr_off_read, spr_off_write },
{ "spr!_offonexit", V293, spr_offonexit_read, spr_offonexit_write },
{ "spr!_offset", V290, spr_offset_read, spr_offset_write },
{ "spr!_overlaid", V265, NULL, spr_overlaid_write },
{ "spr!_overlay", V269c, NULL, spr_overlaid_write },
Expand Down
1 change: 1 addition & 0 deletions src/editor/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ static const char *sprite_var_list[] =
"cheight",
"ccheck", // no read
"off",
"offonexit",
"offset",
"overlay", // no read
"static", // no read
Expand Down
16 changes: 14 additions & 2 deletions src/game_update.c
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,7 @@ boolean update_resolve_target(struct world *mzx_world,
char *level_id = src_board->level_id;
char *level_color = src_board->level_color;
char *level_under_id = src_board->level_under_id;
int i;

if(mzx_world->target_where != TARGET_NONE)
{
Expand All @@ -961,8 +962,8 @@ boolean update_resolve_target(struct world *mzx_world,
boolean load_assets = false;

// TELEPORT or ENTRANCE.
// Destroy message, bullets, spitfire?

// Destroy message, bullets, spitfire?
if(mzx_world->clear_on_exit)
{
int offset;
Expand All @@ -977,6 +978,18 @@ boolean update_resolve_target(struct world *mzx_world,
}
}

// Sprites can also optionally be disabled on exit.
for(i = 0; i < MAX_SPRITES; i++)
{
struct sprite *spr = mzx_world->sprite_list[i];

if((spr->flags & SPRITE_INITIALIZED) && (spr->flags & SPRITE_OFF_ON_EXIT))
{
spr->flags &= ~SPRITE_INITIALIZED;
mzx_world->active_sprites--;
}
}

// Load board
mzx_world->under_player_id = (char)SPACE;
mzx_world->under_player_param = 0;
Expand All @@ -1003,7 +1016,6 @@ boolean update_resolve_target(struct world *mzx_world,
// Find target x/y
if(mzx_world->target_where == TARGET_ENTRANCE)
{
int i;
int tmp_x[5];
int tmp_y[5];
int x, y, offset;
Expand Down
1 change: 1 addition & 0 deletions src/sprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ enum
SPRITE_CHAR_CHECK2 = (1 << 5), // CHAR_CHECK flag 2 (see below)
SPRITE_VLAYER = (1 << 6), // References the vlayer
SPRITE_UNBOUND = (1 << 7), // Uses pixel positioning and collision
SPRITE_OFF_ON_EXIT = (1 << 8), // Turn off sprite when switching boards

// Internal flag combination for pixel collision.
SPRITE_PIXCHECK = SPRITE_UNBOUND | SPRITE_CHAR_CHECK | SPRITE_CHAR_CHECK2,
Expand Down
2 changes: 1 addition & 1 deletion src/sprite_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct sprite
int ref_x;
int ref_y;
char color;
char flags;
unsigned int flags;
unsigned int width;
unsigned int height;
signed int col_x;
Expand Down
Binary file added testworlds/2.93/011 SPRn_OFFONEXIT.mzx
Binary file not shown.

0 comments on commit 4cfa962

Please sign in to comment.