Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Blurry pixels?
#6
Hi,
Here attached is a little example on how to do this effect in C. It just loads a background tilemap, creates a blue tinted palette from the original one, and sets up the raster effect for reflection. There are comments inside. It scrolls right automatically, but you can control the height of the reflection surface with up/down arrow keys. Let me know if it fits your needs!

Code:
#include "Tilengine.h"

static TLN_Palette palette;
static TLN_Palette water;
static int limit = 180;
static int x = 0;

/* raster callback for the reflection effect */
static void reflection_raster(int line)
{
    /* top of frame: restore palette and vertical position */
    if (line == 0)
    {
        TLN_SetLayerPalette(0, palette);
        TLN_SetLayerPosition(0, x, 0);
    }
    
    /* surface line: set waterish palette */
    else if (line == limit)
        TLN_SetLayerPalette(0, water);
    
    /* below-surface line: calculate distance and set */
    else if (line > limit)
        TLN_SetLayerPosition(0, x, -(line - limit)*2);
}

/* create a blueish palette of the source */
static TLN_Palette create_water_palette(TLN_Palette source)
{
    typedef struct
    {
        uint8_t b,g,r,x;
    }
    Color;

    int c;
    TLN_Palette water = TLN_ClonePalette(source);

    for(c = 0; c<256; c++)
    {
        Color* color = (Color*)TLN_GetPaletteData(water, c);
        int mix = (color->r + color->g + color->b) / 3;
        color->r = 0;
        color->g = mix/2;
        color->b = mix;
    }
    return water;
}

void main(void)
{
    int frame = 0;
    TLN_Tilemap background;

    TLN_Init (400,240,1,0,20);
    TLN_SetLoadPath ("assets");
    background = TLN_LoadTilemap ("rolo.tmx", NULL);
    TLN_SetLayer (0, NULL, background);
    TLN_SetRasterCallback(reflection_raster);
    TLN_SetBGColorFromTilemap(background);
    
    palette = TLN_GetLayerPalette(0);
    water = create_water_palette(palette);

    TLN_CreateWindow (NULL, 0);
    while (TLN_ProcessWindow())
    {
        /* use arrow keys to displace surface line */
        if (TLN_GetInput(INPUT_UP) && limit > 120)
            limit -= 1;
        else if (TLN_GetInput(INPUT_DOWN))
            limit += 1;
        
        TLN_DrawFrame (frame);
        frame += 1;
        x += 2;
    }
    TLN_Deinit ();
}


Attached Files Thumbnail(s)
   

.zip   reflection.zip (Size: 8.73 KB / Downloads: 4)
Reply


Messages In This Thread
Blurry pixels? - by RootBeerKing - 11-14-2019, 11:02 PM
RE: Blurry pixels? - by megamarc - 11-15-2019, 02:46 AM
RE: Blurry pixels? - by RootBeerKing - 11-15-2019, 07:07 AM
RE: Blurry pixels? - by megamarc - 11-15-2019, 07:42 AM
RE: Blurry pixels? - by RootBeerKing - 11-15-2019, 09:19 AM
RE: Blurry pixels? - by megamarc - 11-15-2019, 07:49 PM
RE: Blurry pixels? - by RootBeerKing - 11-15-2019, 10:14 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)