Spotlight - SGDK line scroll & Shadow mode sample demo

SGDK only sub forum

Moderator: Stef

Post Reply
realbrucest
Interested
Posts: 27
Joined: Wed Sep 21, 2011 9:00 pm
Location: Sevilla, Spain
Contact:

Spotlight - SGDK line scroll & Shadow mode sample demo

Post by realbrucest » Tue Jun 18, 2013 11:04 am

As talked to Stef at "parallax tearing thread" here's my little demo about "spotlights effects" written for SGDK and (attempted to be) translated to English:

Code: Select all

/******************************************************************************
  DEMO TEST SPOTLIGHT EFFECT (LINE SCROLL + SHADOW MODE)

******************************************************************************/
#include <genesis.h>

// CONSTANTS ==================================================================

// Some data to deal with graphical data
#define NUM_COLUMNS     40
#define NUM_ROWS        28
#define NUM_LINES       NUM_ROWS * 8

#define NUM_TILES_TILESET   3

// Places where we place tiles at Genesis VRAM
#define VRAM_POS_TILE1              1
#define VRAM_POS_BRICK_A            1
#define VRAM_POS_BRICK_B            2
#define VRAM_POS_TILE_VOID          3

// How many pixels bottom line is going to swing
#define SPOTLIGHT_SWING_RANGE       50

// Some other data
#define SPOTLIGHT_WIDTH             8
#define NUM_SPOTLIGHTS              NUM_COLUMNS / SPOTLIGHT_WIDTH

// TILESET ====================================================================
const u32 background_tileset[NUM_TILES_TILESET*8] =
{
    // TILE 1: brick left half
	0x11211111, 0x12222222, 0x12422222, 0x12242222, 0x12422222, 0x12222222, 0x12222222, 0x33333333,
	// TILE 2: brick right half
    0x11111113, 0x22222223, 0x22222223, 0x22222223, 0x22222223, 0x22222223, 0x22222223, 0x32333333,
	// TILE 3: empty/transparent tile
    0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
};


// PALETTE ====================================================================
const u16 background_palette[16] = {
	0x0000,0x06CE,0x044E,0x0008,0x008C,0x0000,0x0000,0x0000,
	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
};


// MACROS =====================================================================
#define DrawWall(); \
    for(row = 0; row < NUM_ROWS; row += 2) \
    for(column = 0; column < NUM_COLUMNS; column += 2) \
    { \
    	VDP_setTileMap( BPLAN, VRAM_POS_BRICK_A, column,   row); \
    	VDP_setTileMap( BPLAN, VRAM_POS_BRICK_B, column+1, row); \
    	VDP_setTileMap( BPLAN, VRAM_POS_BRICK_B, column,   row+1); \
    	VDP_setTileMap( BPLAN, VRAM_POS_BRICK_A, column+1, row+1); \
    }

#define DrawSpotlights(); \
    for(row = 0; row < NUM_ROWS; row++) \
    for(column = 0; column < NUM_SPOTLIGHTS; column++) \
    for(tile_spotlight = 0; tile_spotlight < SPOTLIGHT_WIDTH; tile_spotlight++) \
    { \
    	VDP_setTileMap( APLAN, TILE_ATTR_FULL(PAL0, column%2, 0, 0, VRAM_POS_TILE_VOID), \
    		(column * SPOTLIGHT_WIDTH) + tile_spotlight, row); \
    }

#define InitializeScrollTable(); \
    for(line = 0; line < NUM_LINES; line++) line_scroll_data[line] = FIX16(0);

#define InitializeSpeedTable(); \
    line_speed_data[0] = FIX16(0.05); \
    for(line = 1; line < NUM_LINES; line++) \
    	line_speed_data[line] = fix16Add(line_speed_data[line-1], FIX16(0.04));

//=============================================================================
// MAIN =======================================================================
//=============================================================================
int main()
{
    // Local data _____________________________________________________________

    // Indexes
    u8 row, column;     // Horizontal and vertical tile placement index/coords
    u8 line;            // Pixel line/row index
    u8 tile_spotlight;  // Horizontal tile counter for drawing spotlights
    u8 i;               // Auxiliar loop index

    // Line scroll buffers
    fix16 line_scroll_data[NUM_LINES];  // Current line scroll values
    fix16 line_speed_data[NUM_LINES];   // Line scroll speeds
    s16 aux[NUM_LINES];                 // Needed for VDP_setHorizontalScrollLine


    // Initialization lot _____________________________________________________

    // Scroll
    InitializeScrollTable();
    InitializeSpeedTable();


    // Process ________________________________________________________________

    // Screen setting
    VDP_setScrollingMode(HSCROLL_LINE, VSCROLL_PLANE);
    VDP_setHilightShadow(1);    // Hilight/shadow activation

    // Loading tile stuff and color data into VRAM/CRAM
    VDP_setPalette(PAL0, (u16 *) background_palette);
    VDP_loadTileData( (const u32 *) background_tileset, VRAM_POS_TILE1, NUM_TILES_TILESET, 1);

    // Drawing
    DrawWall();
    DrawSpotlights();


    // MAIN LOOP ______________________________________________________________
    while(1)
    {
    	for(line = 0; line < NUM_LINES;  line++)
        {
            // Sum the speed value
            line_scroll_data[line] = fix16Add(line_scroll_data[line], line_speed_data[line]);

            // Rebound when movement of bottom line reaches its left or right boundary
            if(line_scroll_data[NUM_LINES-1] >= FIX16(SPOTLIGHT_SWING_RANGE)
            || line_scroll_data[NUM_LINES-1] <= FIX16(-SPOTLIGHT_SWING_RANGE))
            	line_speed_data[line] *= -1;

            // An auxiliar "regular integer" buffer is needed for VDP_setHorizontalScrollLine
            aux[line] = fix16ToInt(line_scroll_data[line]);

	    }// end for(NUM_LINES)

        // Set Horizontal Scroll
        VDP_setHorizontalScrollLine(APLAN, 0, aux, NUM_LINES, 1);

		// Drawing/movement speed down
        for(i=0; i<4; i++) VDP_waitVSync();

    } // end main loop

    return 0;   // Ok ... we'll return something

} // end main()
Hope it can be useful for somebody

djcouchycouch
Very interested
Posts: 710
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch » Tue Jun 18, 2013 1:56 pm

Thanks!

Any sexy screenshots or bin downloads to go with the example code?

realbrucest
Interested
Posts: 27
Joined: Wed Sep 21, 2011 9:00 pm
Location: Sevilla, Spain
Contact:

Post by realbrucest » Tue Jun 18, 2013 5:21 pm

djcouchycouch wrote:Thanks!

Any sexy screenshots or bin downloads to go with the example code?
Here you have:

https://www.dropbox.com/s/ipnjcbn8633dz ... htdemo.zip

djcouchycouch
Very interested
Posts: 710
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch » Tue Jun 18, 2013 5:29 pm

Nice!

sega16
Very interested
Posts: 251
Joined: Sat Jan 29, 2011 3:16 pm
Location: U.S.A.

Post by sega16 » Tue Jun 18, 2013 5:54 pm

Wow very clever I never though of using of having 1 layer dedicated to shadow highlight and scrolling it.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Tue Jun 18, 2013 8:18 pm

Castlevania does it nicely for a level :
https://www.youtube.com/watch?v=6uf5lN4 ... ge#t=1862s

realbrucest> Thanks ! I will use it as example sample in the next SGDK version :) You did not write your name in the source as the author, can i use "realbrucest" ?

realbrucest
Interested
Posts: 27
Joined: Wed Sep 21, 2011 9:00 pm
Location: Sevilla, Spain
Contact:

Post by realbrucest » Tue Jun 18, 2013 9:18 pm

You're welcome.

I didn't bother about credit myself, but well... realbrucest in that case ;)

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Wed Jun 19, 2013 7:31 am

Ok perfect i will use it :)
I will propably modify it a bit to also show a bit of the sprite HS feature at the same time.

danibus
Very interested
Posts: 135
Joined: Sat Feb 03, 2018 12:41 pm

Re: Spotlight - SGDK line scroll & Shadow mode sample demo

Post by danibus » Sat May 11, 2019 11:06 am

Hi there

@realbrucest Could you pls put again dropbox link?
....
Forget, saw in sgdk examples :D

Post Reply