new WIP Pong example, change window setup API names, multi-layer in SDL

This commit is contained in:
2023-11-08 23:46:18 +01:00
parent 014f3eabab
commit 92e6e2cdb9
14 changed files with 255 additions and 117 deletions

View File

@ -7,17 +7,17 @@ typedef struct MainArgs {
int spriteY;
int accelX;
int accelY;
MultiSpacc_SurfaceConfig *WindowConfig;
MultiSpacc_Window *Window;
MultiSpacc_Surface *Screen;
MultiSpacc_Surface *Background;
MultiSpacc_Surface *Foreground;
MultiSpacc_Surface *TilesImg;
MultiSpacc_SurfaceConfig *windowConfig;
MultiSpacc_Window *window;
MultiSpacc_Surface *screen;
MultiSpacc_Surface *background;
//MultiSpacc_Surface *Foreground;
MultiSpacc_Surface *tilesImg;
} MainArgs;
/*{pal:"nes",layout:"nes"}*/
const char palette[32] = {
0x03, // screen
0x0F, // screen
0x11,0x30,0x27,0x00, // background 0
0x1c,0x20,0x2c,0x00, // background 1
0x00,0x10,0x20,0x00, // background 2
@ -34,18 +34,20 @@ bool MainLoop( void *args )
{
MainArgs *margs = (MainArgs*)args;
MultiSpacc_Sprite( 0, margs->spriteX, margs->spriteY, 1, margs->TilesImg, margs->Screen );
// ... this must go on Foreground
//SDL_FillRect(margs->Background, &rect, 0x000000);
MultiSpacc_BlitLayer( margs->background, margs->screen );
//SDL_BlitSurface( margs->Foreground, &rect, margs->Screen, &rect );
MultiSpacc_Sprite( 0, margs->spriteX, margs->spriteY, 1, margs->tilesImg, margs->screen );
//scroll(spriteX,0);
margs->spriteX += margs->accelX;
margs->spriteY += margs->accelY;
if( margs->spriteX >= margs->WindowConfig->Width )
if( margs->spriteX >= margs->windowConfig->width )
{
margs->spriteX = 0;
}
if( margs->spriteY == 0 || margs->spriteY == ( margs->WindowConfig->Height - 8 ) )
if( margs->spriteY == 0 || margs->spriteY == ( margs->windowConfig->height - 8 ) )
{
margs->accelY *= -1;
}
@ -56,54 +58,51 @@ bool MainLoop( void *args )
return false;
}
if( !MultiSpacc_WaitUpdateDisplay( margs->Window, &nextTick ) )
if( !MultiSpacc_WaitUpdateDisplay( margs->window, &nextTick ) )
{
MultiSpacc_PrintDebug("[E] Error Updating Screen.\n");
return false;
}
// apply Background and then Foreground on Screen
// ...
return true;
}
int main( int argc, char *argv[] )
{
MainArgs margs = {0};
MultiSpacc_SurfaceConfig WindowConfig = {0};
MultiSpacc_SurfaceConfig windowConfig = {0};
margs.WindowConfig = &WindowConfig;
margs.accelX = +1;
margs.windowConfig = &windowConfig;
margs.accelX = +2;
margs.accelY = +2;
WindowConfig.Width = 320;
WindowConfig.Height = 240;
WindowConfig.Bits = 16;
memcpy( WindowConfig.Palette, palette, 32 );
//WindowConfig.Frequency = 50;
windowConfig.width = 320;
windowConfig.height = 240;
windowConfig.bits = 16;
memcpy( windowConfig.palette, palette, 32 );
margs.Window = MultiSpacc_SetWindow( &WindowConfig );
margs.Screen = MultiSpacc_GetWindowSurface( margs.Window );
if( margs.Screen == NULL )
margs.window = MultiSpacc_SetWindow( &windowConfig );
margs.screen = MultiSpacc_GetWindowSurface( margs.window );
margs.background = MultiSpacc_CreateSurface( &windowConfig );
//margs.Foreground = MultiSpacc_CreateSurface( &windowConfig );
if( margs.screen == NULL || margs.background == NULL /*|| margs.Foreground == NULL*/ )
{
MultiSpacc_PrintDebug("[E] Error Initializing Video System.\n");
return -1;
};
MultiSpacc_SetAppTitle( margs.Window, AppName );
MultiSpacc_SetAppTitle( margs.window, AppName );
MultiSpacc_PrintDebug("[I] Ready!\n");
// Bitmap font borrowed from: <https://github.com/nesdoug/01_Hello/blob/master/Alpha.chr>
// Copyright (c) 2018 Doug Fraker www.nesdoug.com (MIT)
margs.TilesImg = MultiSpacc_LoadImage( "CHARS.png", margs.Screen, NULL );
if( margs.TilesImg == NULL )
// Bitmap font forked from: <https://github.com/nesdoug/01_Hello/blob/master/Alpha.chr>
// Original copyright (c) 2018 Doug Fraker www.nesdoug.com (MIT)
margs.tilesImg = MultiSpacc_LoadImage( "../CHARS.png", margs.screen, NULL );
if( margs.tilesImg == NULL )
{
return -1;
}
MultiSpacc_PrintText( "Hello, World!", margs.Screen, &WindowConfig, 2, 2, margs.TilesImg );
// ... this must print on Background
MultiSpacc_PrintText( "Hello, World!", margs.background, &windowConfig, 2, 2, margs.tilesImg );
return MultiSpacc_SetMainLoop( MainLoop, &margs );
}