mirror of
https://gitlab.com/octospacc/MultiSpaccSDK
synced 2025-06-05 22:09:21 +02:00
new WIP Pong example, change window setup API names, multi-layer in SDL
This commit is contained in:
BIN
LibMultiSpacc/Examples/CHARS.png
Normal file
BIN
LibMultiSpacc/Examples/CHARS.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 882 B |
@ -1,5 +1,5 @@
|
||||
AppName = $(notdir $(CURDIR))
|
||||
AppAssets = CHARS.png
|
||||
AppAssets = ../CHARS.png
|
||||
AppSources = $(wildcard *.c)
|
||||
AppHeaders = $(wildcard *.h)
|
||||
SpaccSources = $(wildcard ../../LibMultiSpacc/*.c)
|
||||
@ -125,7 +125,7 @@ __NES__:
|
||||
for i in $(VirtualBuildDir)/*.c $(VirtualBuildDir)/*.h; do sed -i 's|#include[ \t]"./|#include "LibMultiSpacc_|g' $$i; done
|
||||
cp ../../neslib/*.cfg ../../neslib/crt0.o ../../neslib/*.lib ../../neslib/*.h $(VirtualBuildDir)/
|
||||
printf ".segment \"CHARS\"\n\t.incbin \"CHARS.chr\"" > $(VirtualBuildDir)/CHARS.s
|
||||
echo "AppName='$(AppName)'; Defines='$(Defines)'; ProjectRoot=../..;" > $(VirtualBuildDir)/Make.sh
|
||||
echo "ProjectRoot=../..; AppName='$(AppName)'; AppAssets='$(AppAssets)'; Defines='$(Defines)';" > $(VirtualBuildDir)/Make.sh
|
||||
cat ../NES.mk.sh >> $(VirtualBuildDir)/Make.sh
|
||||
cd $(VirtualBuildDir); sh ./Make.sh
|
||||
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 773 B |
@ -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 );
|
||||
}
|
||||
|
@ -2,7 +2,10 @@
|
||||
set -e
|
||||
SdkRoot="${ProjectRoot}/../../.."
|
||||
|
||||
sh "${SdkRoot}/Tools/python3.sh" "${SdkRoot}/Tools/pilbmp2nes.py" -i "${ProjectRoot}/CHARS.png" -o ./CHARS.chr
|
||||
# TODO: multiple files
|
||||
for File in ${AppAssets}
|
||||
do sh "${SdkRoot}/Tools/python3.sh" "${SdkRoot}/Tools/pilbmp2nes.py" -i "${ProjectRoot}/${File}" -o ./CHARS.chr
|
||||
done
|
||||
|
||||
for File in *.c
|
||||
do cc65 -Oirs --target nes ${File} ${Defines}
|
||||
|
1
LibMultiSpacc/Examples/Pong/Makefile
Normal file
1
LibMultiSpacc/Examples/Pong/Makefile
Normal file
@ -0,0 +1 @@
|
||||
include ../Common.mk
|
128
LibMultiSpacc/Examples/Pong/Pong.c
Normal file
128
LibMultiSpacc/Examples/Pong/Pong.c
Normal file
@ -0,0 +1,128 @@
|
||||
#include "../../LibMultiSpacc/MultiSpacc.h"
|
||||
|
||||
#define AppName "Pong"
|
||||
|
||||
bool paused = false;
|
||||
Uint32 nextTick;
|
||||
|
||||
int ballX;
|
||||
int ballY;
|
||||
int accelX = 2;
|
||||
int accelY = 2;
|
||||
|
||||
// the Y position of the paddles, measured from the top
|
||||
int paddleSx;
|
||||
int paddleDx;
|
||||
|
||||
MultiSpacc_SurfaceConfig windowConfig = {0};
|
||||
MultiSpacc_Window *window;
|
||||
MultiSpacc_Surface *screen;
|
||||
MultiSpacc_Surface *background;
|
||||
MultiSpacc_Surface *tilesImg;
|
||||
|
||||
#define BallSize 8
|
||||
|
||||
#define TileBall 128
|
||||
#define TilePaddle 129
|
||||
|
||||
#define SpriteBall 0
|
||||
#define SpritePaddleSx 1
|
||||
#define SpritePaddleDx 1+4
|
||||
|
||||
/*{pal:"nes",layout:"nes"}*/
|
||||
const char palette[32] = {
|
||||
0x0F, // screen
|
||||
0x11,0x30,0x27,0x00, // background 0
|
||||
0x1c,0x20,0x2c,0x00, // background 1
|
||||
0x00,0x10,0x20,0x00, // background 2
|
||||
0x06,0x16,0x26,0x00, // background 3
|
||||
0x16,0x35,0x24,0x00, // sprite 0
|
||||
0x00,0x37,0x25,0x00, // sprite 1
|
||||
0x0d,0x2d,0x3a,0x00, // sprite 2
|
||||
0x0d,0x27,0x2a, // sprite 3
|
||||
};
|
||||
|
||||
bool MainLoop( void *args )
|
||||
{
|
||||
if (!paused)
|
||||
{
|
||||
MultiSpacc_BlitLayer( background, screen );
|
||||
|
||||
MultiSpacc_Sprite( SpriteBall, ballX, ballY, TileBall, tilesImg, screen );
|
||||
|
||||
// TODO: metasprites
|
||||
|
||||
MultiSpacc_Sprite( SpritePaddleSx , BallSize, paddleSx , TilePaddle, tilesImg, screen );
|
||||
MultiSpacc_Sprite( SpritePaddleSx+1, BallSize, paddleSx + BallSize, TilePaddle, tilesImg, screen );
|
||||
MultiSpacc_Sprite( SpritePaddleSx+2, BallSize, paddleSx + 2*BallSize, TilePaddle, tilesImg, screen );
|
||||
MultiSpacc_Sprite( SpritePaddleSx+3, BallSize, paddleSx + 3*BallSize, TilePaddle, tilesImg, screen );
|
||||
|
||||
MultiSpacc_Sprite( SpritePaddleDx , windowConfig.width - 2*BallSize, paddleDx , TilePaddle, tilesImg, screen );
|
||||
MultiSpacc_Sprite( SpritePaddleDx+1, windowConfig.width - 2*BallSize, paddleDx + BallSize, TilePaddle, tilesImg, screen );
|
||||
MultiSpacc_Sprite( SpritePaddleDx+2, windowConfig.width - 2*BallSize, paddleDx + 2*BallSize, TilePaddle, tilesImg, screen );
|
||||
MultiSpacc_Sprite( SpritePaddleDx+3, windowConfig.width - 2*BallSize, paddleDx + 3*BallSize, TilePaddle, tilesImg, screen );
|
||||
|
||||
ballX += accelX;
|
||||
ballY += accelY;
|
||||
|
||||
if( ballX == 0 || ballX == ( windowConfig.width - 8 ) )
|
||||
{
|
||||
accelX *= -1;
|
||||
}
|
||||
|
||||
if( ballY == 0 || ballY == ( windowConfig.height - 8 ) )
|
||||
{
|
||||
accelY *= -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: listen for OS terminate signal */
|
||||
if( MultiSpacc_CheckKey( MultiSpacc_Key_Pause, 0 ) )
|
||||
{
|
||||
if (!paused) paused = true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
if( !MultiSpacc_WaitUpdateDisplay( window, &nextTick ) )
|
||||
{
|
||||
MultiSpacc_PrintDebug("[E] Error Updating Screen.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
windowConfig.width = 320;
|
||||
windowConfig.height = 240;
|
||||
windowConfig.bits = 16;
|
||||
memcpy( windowConfig.palette, palette, 32 );
|
||||
|
||||
window = MultiSpacc_SetWindow( &windowConfig );
|
||||
screen = MultiSpacc_GetWindowSurface( window );
|
||||
background = MultiSpacc_CreateSurface( &windowConfig );
|
||||
if( window == NULL || screen == NULL || background == NULL )
|
||||
{
|
||||
MultiSpacc_PrintDebug("[E] Error Initializing Video System.\n");
|
||||
return -1;
|
||||
};
|
||||
|
||||
MultiSpacc_SetAppTitle( window, AppName );
|
||||
MultiSpacc_PrintDebug("[I] Ready!\n");
|
||||
|
||||
// Bitmap font forked from: <https://github.com/nesdoug/01_Hello/blob/master/Alpha.chr>
|
||||
// Original copyright (c) 2018 Doug Fraker www.nesdoug.com (MIT)
|
||||
tilesImg = MultiSpacc_LoadImage( "../CHARS.png", screen, NULL );
|
||||
if( tilesImg == NULL )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
ballX = windowConfig.width/2;
|
||||
ballY = windowConfig.height/2;
|
||||
paddleSx = windowConfig.height/2 - 24;
|
||||
paddleDx = windowConfig.height/2 - 24;
|
||||
|
||||
return MultiSpacc_SetMainLoop( MainLoop, NULL );
|
||||
}
|
Reference in New Issue
Block a user