Update Pong example with border tiles drawing and AI

This commit is contained in:
OctoSpacc 2023-11-14 18:51:12 +01:00
parent 33ebd6ca69
commit dcb6aebc27
11 changed files with 278 additions and 155 deletions

View File

@ -1,41 +1,11 @@
image: debian:latest
before_script: |
apt update
apt install -y \
make gcc mingw-w64 wine cc65 emscripten curl wget p7zip-full python3 python3-pil \
libsdl1.2-dev libsdl-image1.2-dev libsdl-ttf2.0-dev libsdl-mixer1.2-dev \
libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev libsdl2-mixer-dev \
;
curl -o ./mingw32.7z https://hlb0.octt.eu.org/Drive/Misc/mingw32-9.2.0.7z.sfx.exe
7z x ./mingw32.7z
cp ./mingw32/bin/*.dll ./mingw32/libexec/gcc/mingw32/9.2.0/
mkdir -p /opt/Sdk
mv ./mingw32 /opt/Sdk/mingw32
curl https://apt.devkitpro.org/install-devkitpro-pacman | bash
dkp-pacman -Sy nds-dev
sh ./Tools/InstallBuildEnvironment.sh
Tests:
stage: build
script: |
cd ./LibMultiSpacc/Examples
for Example in */
do
cd ${Example}
for Build in \
"Target=LinuxPC MultiSpacc_Target=SDL12"
"Target=LinuxPC MultiSpacc_Target=SDL20"
"Target=WindowsPC MultiSpacc_Target=SDL12"
"Target=WindowsPC MultiSpacc_Target=SDL20"
"Target=Windows9x"
"Target=Web"
"Target=NDS"
"Target=NES"
; do
make clean
make -j$(nproc --all) ${Build}
done
cd ..
done
make -j($nproc --all)
rules:
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH

Binary file not shown.

Before

Width:  |  Height:  |  Size: 882 B

After

Width:  |  Height:  |  Size: 901 B

View File

@ -26,6 +26,7 @@ ifeq ($(Target), LinuxPC)
ExeSuffix = .run
Defines += -DTarget_LinuxPC -DMultiSpacc_Target_PC -DMultiSpacc_Target_Linux
MultiSpacc_Target = SDL20
else ifeq ($(Target), WindowsPC)
ExeSuffix = .exe
Defines += -DTarget_WindowsPC -DMultiSpacc_Target_PC -DMultiSpacc_Target_Windows
@ -33,6 +34,7 @@ else ifeq ($(Target), WindowsPC)
ifneq ($(Host), Windows)
ToolsSuffix = -mingw-w64
endif
else ifeq ($(Target), Windows9x)
ExeSuffix = .exe
Defines += -DTarget_Windows9x -DMultiSpacc_Target_PC -DMultiSpacc_Target_Windows
@ -47,15 +49,19 @@ else ifeq ($(Target), Windows9x)
LdFlags += -LZ:/opt/Sdk/mingw32/lib
endif
ToolsPrefix = $(ToolsSyspath)/
else ifeq ($(Target), Web)
Defines += -DTarget_Web
MultiSpacc_Target = Web
else ifeq ($(Target), NDS)
Defines += -DTarget_NDS
MultiSpacc_Target = NDS
else ifeq ($(Target), NES)
Defines += -DTarget_NES
MultiSpacc_Target = NES
endif
ifeq ($(MultiSpacc_Target), SDL12)
@ -63,21 +69,30 @@ ifeq ($(MultiSpacc_Target), SDL12)
CFlags += $(shell sdl-config --cflags)
LdFlags += $(shell sdl-config --libs) -lSDLmain -lSDL -lSDL_image -lSDL_mixer -lSDL_ttf
BuildProcess = __Normal__
else ifeq ($(MultiSpacc_Target), SDL20)
Defines += -DMultiSpacc_Target_SDL20 -DMultiSpacc_Target_SDLCom -DMultiSpacc_Target_SDLCommon -DMultiSpacc_Target_SDLStandard
CFlags += $(shell sdl2-config --cflags)
LdFlags += $(shell sdl2-config --libs) -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf
BuildProcess = __Normal__
else ifeq ($(MultiSpacc_Target), Web)
Defines += -DMultiSpacc_Target_Web -DMultiSpacc_Target_SDL20 -DMultiSpacc_Target_SDLCom -DMultiSpacc_Target_SDLCommon -DMultiSpacc_Target_SDLWeb
LdFlags += -sWASM=1 -sUSE_SDL=2 -sUSE_SDL_IMAGE=2 -sSDL2_IMAGE_FORMATS='["png"]' -sUSE_SDL_TTF=2 -sUSE_SDL_MIXER=2
BuildProcess = __Web__
else ifeq ($(MultiSpacc_Target), NDS)
ExeSuffix = .nds
Defines += -DMultiSpacc_Target_NDS
BuildProcess = __NDS__
OutLauncher = melonDS
else ifeq ($(MultiSpacc_Target), NES)
ExeSuffix = .nes
Defines += -DMultiSpacc_Target_NES
BuildProcess = __NES__
OutLauncher = fceux
endif
BuildSources = $(AppSources) $(SpaccSources)
@ -87,53 +102,64 @@ ifeq ($(BuildProcess), __Normal__)
CC = $(ToolsWrapper) $(ToolsPrefix)gcc$(ToolsSuffix) $(CFlags) $(Defines)
endif
define BuildDirSourcesReformat
for i in $(BuildDirSources)/*.c $(BuildDirSources)/*.h; do sed -i 's|#include[ \t]"../../LibMultiSpacc/|#include "LibMultiSpacc_|g' $$i; done
for i in $(BuildDirSources)/*.c $(BuildDirSources)/*.h; do sed -i 's|#include[ \t]"../MultiSpacc|#include "LibMultiSpacc_MultiSpacc|g' $$i; done
for i in $(BuildDirSources)/*.c $(BuildDirSources)/*.h; do sed -i 's|#include[ \t]"./|#include "LibMultiSpacc_|g' $$i; done
endef
All all: $(BuildProcess)
# TODO: use virtual build dirs even for normals to allow linking against different libraries without recleaning
__Normal__: $(BuildObjects)
$(eval BuildDir = .)
$(CC) $^ $(LdFlags) -o $(AppName)$(ExeSuffix)
# TODO: copy required DLLs on PC for Dist
__Web__:
mkdir -p ./Build/Web
emcc $(BuildSources) $(CFlags) $(Defines) $(LdFlags) --preload-file $(AppAssets)@CHARS.png -o ./Build/Web/Emscripten.js
cp ../Emscripten.html ./Build/Web/$(AppName).html
# TODO: bundle JS, WASM, and assets package in HTML file
$(eval BuildDir = ./Build/Web)
mkdir -p $(BuildDir)
emcc $(BuildSources) $(CFlags) $(Defines) $(LdFlags) --preload-file $(AppAssets)@CHARS.png -o $(BuildDir)/Emscripten.js
cp ../Emscripten.html $(BuildDir)/$(AppName).html
# TODO: bundle JS, WASM, and assets package in HTML file for Dist
# TODO: Fix include substitutions properly in non-standard build processes, and make all custom build processes lest wasteful
__NDS__:
$(eval VirtualBuildDir = ./Build/NDS)
mkdir -p $(VirtualBuildDir)/source/.tmp
cp ../NDS.mk $(VirtualBuildDir)/Makefile
cp $(SpaccSources) $(SpaccHeaders) $(VirtualBuildDir)/source/.tmp/
cd $(VirtualBuildDir)/source/.tmp; for i in *; do mv ./$$i ../LibMultiSpacc_$$i; done
cp $(AppSources) $(AppHeaders) $(VirtualBuildDir)/source/
for i in $(VirtualBuildDir)/source/*.c $(VirtualBuildDir)/source/*.h; do sed -i 's|#include[ \t]"../../LibMultiSpacc/|#include "LibMultiSpacc_|g' $$i; done
for i in $(VirtualBuildDir)/source/*.c $(VirtualBuildDir)/source/*.h; do sed -i 's|#include[ \t]"../MultiSpacc|#include "LibMultiSpacc_MultiSpacc|g' $$i; done
for i in $(VirtualBuildDir)/source/*.c $(VirtualBuildDir)/source/*.h; do sed -i 's|#include[ \t]"./|#include "LibMultiSpacc_|g' $$i; done
cd $(VirtualBuildDir); make
$(eval BuildDir = ./Build/NDS)
$(eval BuildDirSources = $(BuildDir)/source)
mkdir -p $(BuildDir)/source/.tmp
cp ../NDS.mk $(BuildDir)/Makefile
cp $(SpaccSources) $(SpaccHeaders) $(BuildDir)/source/.tmp/
cd $(BuildDir)/source/.tmp; for i in *; do mv ./$$i ../LibMultiSpacc_$$i; done
cp $(AppSources) $(AppHeaders) $(BuildDir)/source/
$(BuildDirSourcesReformat)
cd $(BuildDir); make
__NES__:
__NES__: __neslib__
$(eval BuildDir = ./Build/NES)
$(eval BuildDirSources = $(BuildDir))
mkdir -p $(BuildDir)/.tmp
cp $(SpaccSources) $(SpaccHeaders) $(BuildDir)/.tmp/
cd $(BuildDir)/.tmp; for i in *; do mv ./$$i ../LibMultiSpacc_$$i; done
cp $(AppSources) $(AppHeaders) $(BuildDir)/
$(BuildDirSourcesReformat)
cp ../../neslib/*.cfg ../../neslib/crt0.o ../../neslib/*.lib ../../neslib/*.h $(BuildDir)/
printf ".segment \"CHARS\"\n\t.incbin \"CHARS.chr\"" > $(BuildDir)/CHARS.s
echo "ProjectRoot=../..; AppName='$(AppName)'; AppAssets='$(AppAssets)'; Defines='$(Defines)';" > $(BuildDir)/Make.sh
cat ../NES.mk.sh >> $(BuildDir)/Make.sh
cd $(BuildDir); sh ./Make.sh
__neslib__:
cd ../../neslib; make
$(eval VirtualBuildDir = ./Build/NES)
mkdir -p $(VirtualBuildDir)/.tmp
cp $(SpaccSources) $(SpaccHeaders) $(VirtualBuildDir)/.tmp/
cd $(VirtualBuildDir)/.tmp; for i in *; do mv ./$$i ../LibMultiSpacc_$$i; done
cp $(AppSources) $(AppHeaders) $(VirtualBuildDir)/
for i in $(VirtualBuildDir)/*.c $(VirtualBuildDir)/*.h; do sed -i 's|#include[ \t]"../../LibMultiSpacc/|#include "LibMultiSpacc_|g' $$i; done
for i in $(VirtualBuildDir)/*.c $(VirtualBuildDir)/*.h; do sed -i 's|#include[ \t]"../MultiSpacc|#include "LibMultiSpacc_MultiSpacc|g' $$i; done
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 "ProjectRoot=../..; AppName='$(AppName)'; AppAssets='$(AppAssets)'; Defines='$(Defines)';" > $(VirtualBuildDir)/Make.sh
cat ../NES.mk.sh >> $(VirtualBuildDir)/Make.sh
cd $(VirtualBuildDir); sh ./Make.sh
Run run: All
./$(AppName)$(ExeSuffix)
$(OutLauncher) $(BuildDir)/$(AppName)$(ExeSuffix)
Clean clean Clear clear:
find -L . -name "*.o" -type f -delete
find -L ../../LibMultiSpacc -name "*.o" -type f -delete
rm -f ./$(AppName)$(ExeSuffix)
rm -rf ./Build
.PHONY: All all Run run Clean clean Clear clear

View File

@ -0,0 +1,21 @@
All all:
for Example in */; \
do \
cd $${Example}; \
for Build in \
"Target=LinuxPC MultiSpacc_Target=SDL12" \
"Target=LinuxPC MultiSpacc_Target=SDL20" \
"Target=WindowsPC MultiSpacc_Target=SDL12" \
"Target=WindowsPC MultiSpacc_Target=SDL20" \
"Target=Windows9x" \
"Target=Web" \
"Target=NDS" \
"Target=NES" \
; do \
make clean; \
make -j$$(nproc --all) $${Build}; \
done; \
cd ..; \
done
.PHONY: All all

View File

@ -8,7 +8,9 @@ int scoreDx = 0;
int ballX;
int ballY;
int accelX = 3;
// NOTE: changing these breaks some logic (mainly AI) on different platforms, should be fixed
int accelX = 2;
int accelY = 3;
int paddleSxY;
@ -16,7 +18,7 @@ int paddleDxY;
signed char paddleSxMove = 0;
signed char paddleDxMove = 0;
char scoreChar[6];
//char scoreChar[6];
MultiSpacc_SurfaceConfig windowConfig = {0};
MultiSpacc_Window *window;
@ -26,22 +28,28 @@ MultiSpacc_Surface *tilesImg;
#define BallSize 8
#define PaddleWidth 8
#define PaddleHeightTiles 4
#define PaddleHeightPx 8*PaddleHeightTiles
#define PaddleHeightTl 4
#define PaddleHeightPx 8*PaddleHeightTl
#define BallTile 128
#define PaddleTile 129
#define DivisorTile 130
#define BorderTile 131
#define BallSprite 0
#define PaddleSxSprite 1
#define PaddleDxSprite 1 + PaddleHeightTiles
#define PaddleDxSprite 1 + PaddleHeightTl
#define PaddleSxX PaddleWidth
#define PaddleDxX windowConfig.width - 2*PaddleWidth
#define PaddleAccel 4
#define PaddleMarginXPx 8
#define PaddleMarginYPx 8
#define ScreenMarginYPx 8
// TODO: more defines for frequently-used expressions
/*{pal:"nes",layout:"nes"}*/
const char palette[32] = {
0x0F, // screen
0x11,0x30,0x27,0x00, // background 0
@ -54,14 +62,6 @@ const char palette[32] = {
0x0d,0x27,0x2a, // sprite 3
};
const unsigned char paddleMetaSprite[] = {
0, 0, PaddleTile, 0,
0, 8, PaddleTile, 0,
0, 16, PaddleTile, 0,
0, 24, PaddleTile, 0,
128
};
MultiSpacc_SpritesMap msdata;
void ResetBall(void)
@ -70,10 +70,15 @@ void ResetBall(void)
ballY = windowConfig.height/2;
}
void UpdateBall(void)
void AccelerateBall(void)
{
ballX += accelX;
ballY += accelY;
}
void UpdateBall(void)
{
AccelerateBall();
if( ballX <= 0-BallSize )
{
@ -88,66 +93,86 @@ void UpdateBall(void)
#define IsTouchingPaddleSx ( ballX >= PaddleSxX-BallSize && ballX <= PaddleSxX+BallSize && ballY >= paddleSxY-BallSize && ballY <= paddleSxY+PaddleHeightPx )
#define IsTouchingPaddleDx ( ballX >= PaddleDxX-BallSize && ballX <= PaddleDxX+BallSize && ballY >= paddleDxY-BallSize && ballY <= paddleDxY+PaddleHeightPx )
if( IsTouchingPaddleSx || IsTouchingPaddleDx )
{
// idk what I did there but it's working to add some variety to the bounce angles
if( accelX > 0 || abs( ballY - paddleSxY+PaddleHeightPx ) > PaddleHeightPx/4 )
{
++accelX;
}
else if( accelX < 0 || abs( ballY - paddleDxY+PaddleHeightPx ) > PaddleHeightPx/4 )
{
++accelY;
}
accelX *= -1;
ballX += accelX;
ballY += accelY;
AccelerateBall();
}
// TODO: fix collision with upper borders of paddle, currently too aggressive and also broken? disabling everything makes the ball stick to paddles tho --- edit: with current setup it's kinda better but can still get stuck near the bottom/top of the screen and between paddle and side border, should fix (simply: don't allow paddle or ball near the very bottom of screen, put a mini-wall)
if( ballY <= 0 || ballY >= (windowConfig.height - BallSize) || (IsTouchingPaddleSx && ballX >= PaddleSxX && ballX <= PaddleSxX+BallSize) || (IsTouchingPaddleDx && ballX >= PaddleDxX && ballX <= PaddleDxX+BallSize) )
#define IsTouchingFieldTop ( ballY <= 0+ScreenMarginYPx+PaddleMarginYPx )
#define IsTouchingFieldBottom ( ballY >= windowConfig.height-ScreenMarginYPx-PaddleMarginYPx-BallSize )
#define IsTouchingPaddleAngle ( (IsTouchingPaddleSx && ballX >= PaddleSxX && ballX <= PaddleSxX+BallSize) || (IsTouchingPaddleDx && ballX >= PaddleDxX && ballX <= PaddleDxX+BallSize) )
if( IsTouchingFieldTop || IsTouchingFieldBottom )
{
accelY *= -1;
ballX += accelX;
ballY += accelY;
AccelerateBall();
if( IsTouchingPaddleAngle )
{
AccelerateBall();
}
}
}
void UpdatePlayer(void)
{
// if (paddleSxMove == -1)
// {
// paddleSxY -= PaddleAccel;
// paddleSxMove = 0;
// }
// else if (paddleSxMove == +1)
// {
// paddleSxY += PaddleAccel;
// paddleSxMove = 0;
// }
paddleSxY += PaddleAccel*paddleSxMove;
paddleSxMove = 0;
}
// TODO: fix this, it breaks when all conditions mentioned in other places change, and it gets always worse (moves relatively too slow) the larger the screen is
void UpdateCpuPlayer(void)
{
#define PaddleDxYCenter paddleDxY+PaddleHeightPx/2
if( accelX <= 0 )
// ball is going left, recenter CPU paddle
{
if( paddleDxY < windowConfig.height/2 )
{
paddleDxY += PaddleAccel;
}
else if( paddleDxY > windowConfig.height/2 )
if( paddleDxY > windowConfig.height/2 )
{
paddleDxY -= PaddleAccel;
}
else if( paddleDxY < windowConfig.height/2 )
{
paddleDxY += PaddleAccel;
}
}
else if( rand() % PaddleAccel != 1 )
else if( rand() % 3*PaddleAccel < 2*PaddleAccel )
// if CPU is lucky, it can get close to the ball coming right (note: works good only with these values...)
{
if ( PaddleDxYCenter < ballY )
{
paddleDxY += PaddleAccel;
}
else if ( PaddleDxYCenter > ballY )
if ( PaddleDxYCenter > ballY && paddleDxY > 0+ScreenMarginYPx+PaddleMarginYPx+BallSize )
{
paddleDxY -= PaddleAccel;
}
else if ( PaddleDxYCenter < ballY && paddleDxY < windowConfig.height-ScreenMarginYPx-PaddleMarginYPx-PaddleHeightPx-BallSize )
{
paddleDxY += PaddleAccel;
}
}
}
bool PollPlayerPaddle(void)
{
if( paddleSxY > 0+ScreenMarginYPx+PaddleMarginYPx+BallSize && MultiSpacc_CheckKey( MultiSpacc_Key_Up, 0 ) )
{
paddleSxMove = -1;
}
else if( paddleSxY < windowConfig.height-ScreenMarginYPx-PaddleMarginYPx-PaddleHeightPx-BallSize && MultiSpacc_CheckKey( MultiSpacc_Key_Down, 0 ) )
{
paddleSxMove = +1;
}
}
// TODO: the ball bouncing should be more varied, the AI should work better with different parameters
bool FixedUpdate( void *args )
{
if(!paused)
@ -159,6 +184,25 @@ bool FixedUpdate( void *args )
return true;
}
// TODO: flip needed sprites, must implement flags in MultiSpacc API first
// TODO: set metatile without cycle here
bool DisplayBorders(void)
{
int i;
for( i=1; i<(windowConfig.height/8 - 1); i++ )
{
MultiSpacc_SetTile( windowConfig.width/8/2 , i, DivisorTile, tilesImg, background );
MultiSpacc_SetTile( windowConfig.width/8/2 - 1, i, DivisorTile, tilesImg, background );
}
for( i=0; i<windowConfig.width/8; i++ )
{
MultiSpacc_SetTile( i, 1, BorderTile, tilesImg, background );
MultiSpacc_SetTile( i, windowConfig.height/8 - 2, BorderTile, tilesImg, background );
}
}
bool RealUpdate( void *args, double deltaTime )
{
if(!paused)
@ -168,29 +212,24 @@ bool RealUpdate( void *args, double deltaTime )
MultiSpacc_SetSprite( BallSprite, ballX+accelX*deltaTime, ballY+accelY*deltaTime, BallTile, tilesImg, screen );
#define PaddleSxYDisplay (paddleSxY + PaddleAccel*paddleSxMove*deltaTime)
#define PaddleDxYDisplay (paddleDxY + PaddleAccel*paddleDxMove*deltaTime)
MultiSpacc_SetMetaSprite( PaddleSxSprite, PaddleSxX, PaddleSxYDisplay, &msdata, PaddleHeightTiles, tilesImg, screen );
MultiSpacc_SetMetaSprite( PaddleDxSprite, PaddleDxX, PaddleDxYDisplay, &msdata, PaddleHeightTiles, tilesImg, screen );
#define PaddleAccelDelta PaddleAccel*deltaTime
#define PaddleSxYDisplay (paddleSxY + paddleSxMove*PaddleAccelDelta)
#define PaddleDxYDisplay (paddleDxY + paddleDxMove*PaddleAccelDelta)
MultiSpacc_SetMetaSprite( PaddleSxSprite, PaddleSxX, PaddleSxYDisplay, &msdata, PaddleHeightTl, tilesImg, screen );
MultiSpacc_SetMetaSprite( PaddleDxSprite, PaddleDxX, PaddleDxYDisplay, &msdata, PaddleHeightTl, tilesImg, screen );
//RefreshScore():
//itoa(scoreSx, scoreChar, 10);
//MultiSpacc_PrintText( scoreChar, screen, &windowConfig, 1, 1, tilesImg );
//itoa(scoreDx, scoreChar, 10);
//MultiSpacc_PrintText( scoreChar, screen, &windowConfig, windowConfig.width/8-6, 1, tilesImg );
if( paddleSxY > 0 && MultiSpacc_CheckKey( MultiSpacc_Key_Up, 0 ) )
{
paddleSxMove = -1;
}
else if( paddleSxY < windowConfig.height-PaddleHeightPx && MultiSpacc_CheckKey( MultiSpacc_Key_Down, 0 ) )
{
paddleSxMove = +1;
}
PollPlayerPaddle();
}
// TODO: listen for OS terminate signal
// TODO: fix SDL not waiting for key release with inputs checked this way
// TODO: proper pause menu
// TODO: proper pause menu?
if( MultiSpacc_CheckKey( MultiSpacc_Key_Pause, 0 ) )
{
if(!paused)
@ -216,14 +255,14 @@ bool RealUpdate( void *args, double deltaTime )
int main( int argc, char *argv[] )
{
int chr[] = { 129, 129, 129, 129 };
int chr[] = { PaddleTile, PaddleTile, PaddleTile, PaddleTile };
int x[] = { 0, 0, 0, 0 };
int y[] = { 0, 8, 16, 24 };
msdata.chr = chr;
msdata.x = x;
msdata.y = y;
windowConfig.width = 256;
windowConfig.width = 320;
windowConfig.height = 240;
windowConfig.bits = 16;
memcpy( windowConfig.palette, palette, 32 );
@ -248,9 +287,10 @@ int main( int argc, char *argv[] )
return -1;
}
DisplayBorders();
ResetBall();
paddleSxY = windowConfig.height/2 - 24;
paddleDxY = windowConfig.height/2 - 24;
paddleSxY = windowConfig.height/2 - PaddleHeightPx;
paddleDxY = windowConfig.height/2 - PaddleHeightPx;
return MultiSpacc_SetMainLoop( FixedUpdate, RealUpdate, NULL );
}

View File

@ -99,40 +99,66 @@ int MultiSpacc_SetColorKey( MultiSpacc_Surface *Surface, bool Flag, Uint32 Key )
void MultiSpacc_SetSprite( int id, int x, int y, int sprite, MultiSpacc_Surface *tiles, MultiSpacc_Surface *screen )
{
#if defined(MultiSpacc_Target_SDLCom)
MultiSpacc_Rect Offset = { .x = x, .y = y, };
MultiSpacc_Rect Clip = {
#if defined(MultiSpacc_Target_SDLCommon)
MultiSpacc_Rect offset = { .x = x, .y = y, };
MultiSpacc_Rect clip = {
.x = (8 * (sprite % 16)),
.y = (8 * (sprite / 16)),
.w = 8,
.h = 8,
};
SDL_BlitSurface( tiles, &Clip, screen, &Offset );
SDL_BlitSurface( tiles, &clip, screen, &offset );
#elif defined(MultiSpacc_Target_NES)
oam_spr( x, y, sprite, 0, id*4 );
#endif
}
void MultiSpacc_SetMetaSprite( int id, int x, int y, MultiSpacc_SpritesMap *map, int mapSize, MultiSpacc_Surface *tiles, MultiSpacc_Surface *screen )
{
int i;
for(i=0; i<mapSize; i++)
{
MultiSpacc_SetSprite( (id + i), (x + map->x[i]), (y + map->y[i]), map->chr[i], tiles, screen );
}
}
void MultiSpacc_SetTile( int x, int y, int tile, MultiSpacc_Surface *tiles, MultiSpacc_Surface *screen )
{
#if defined(MultiSpacc_Target_SDLCommon)
MultiSpacc_Rect offset = {
.x = 8*x,
.y = 8*y,
};
MultiSpacc_Rect clip = {
.x = (8 * (tile % 16)),
.y = (8 * (tile / 16)),
.w = 8,
.h = 8,
};
SDL_BlitSurface( tiles, &clip, screen, &offset );
#elif defined(MultiSpacc_Target_NES)
// NOTE: is there no alternative to ppu off and on there? it makes the screen flicker and so makes programming more difficult
ppu_off();
vram_adr(NTADR_A( x, y ));
vram_put(tile);
ppu_on_all();
#endif
}
void MultiSpacc_BlitLayer( MultiSpacc_Surface *source, MultiSpacc_Surface *destination )
{
#if defined(MultiSpacc_Target_SDLCom)
#if defined(MultiSpacc_Target_SDLCommon)
SDL_BlitSurface( source, NULL, destination, NULL );
#endif
}
MultiSpacc_Surface *MultiSpacc_CreateSurface( MultiSpacc_SurfaceConfig *surfaceConfig )
{
#if defined(MultiSpacc_Target_SDLCom)
#if defined(MultiSpacc_Target_SDLCommon)
return SDL_CreateRGBSurface( 0, surfaceConfig->width, surfaceConfig->height, surfaceConfig->bits, 0, 0, 0, 0 );
#endif
}
@ -164,15 +190,15 @@ bool MultiSpacc_MainLoopHandler( MultiSpacc_MainLoopHandlerArgs *handlerArgs )
return false;
}
#elif defined(MultiSpacc_Target_NES)
ppu_wait_frame();
#elif defined(MultiSpacc_Target_NDS)
// TODO: limit FixedUpdate to 50 FPS, since NDS vblank is 60 Hz
swiWaitForVBlank();
if( AssertDirectCallUpdates ){
return false;
}
#elif defined(MultiSpacc_Target_NDS)
// TODO: limit FixedUpdate to 50 FPS, since NDS vblank is 60 Hz
swiWaitForVBlank();
#elif defined(MultiSpacc_Target_NES)
ppu_wait_frame();
if( AssertDirectCallUpdates ){
return false;
}

View File

@ -128,12 +128,15 @@ int MultiSpacc_SetColorKey( MultiSpacc_Surface *Surface, bool Flag, Uint32 Key )
int MultiSpacc_PollEvent( MultiSpacc_Event *Event );
void MultiSpacc_PrintText( char Text[], MultiSpacc_Surface *Surface, MultiSpacc_SurfaceConfig *surfaceConfig, int x, int y, MultiSpacc_Surface *Tiles /*, int FontSize, int Color */ ); // WIP
void MultiSpacc_PrintText( char text[], MultiSpacc_Surface *Surface, MultiSpacc_SurfaceConfig *surfaceConfig, int x, int y, MultiSpacc_Surface *Tiles /*, int FontSize, int Color */ ); // WIP
void MultiSpacc_PrintDebug( const char *format, ... );
void MultiSpacc_SetSprite( int id, int x, int y, int sprite, MultiSpacc_Surface *tiles, MultiSpacc_Surface *screen );
void MultiSpacc_SetMetaSprite( int id, int x, int y, MultiSpacc_SpritesMap *map, int mapSize, MultiSpacc_Surface *tiles, MultiSpacc_Surface *screen );
void MultiSpacc_SetTile( int x, int y, int tile, MultiSpacc_Surface *tiles, MultiSpacc_Surface *screen );
// void MultiSpacc_SetMetaTile( );
MultiSpacc_Surface *MultiSpacc_CreateSurface( MultiSpacc_SurfaceConfig *surfaceConfig );
void MultiSpacc_BlitLayer( MultiSpacc_Surface *source, MultiSpacc_Surface *destination );

View File

@ -1,34 +1,34 @@
#include "./MultiSpacc.h"
void MultiSpacc_PrintText( char Text[], MultiSpacc_Surface *Surface, MultiSpacc_SurfaceConfig *surfaceConfig, int x, int y, MultiSpacc_Surface *Tiles /*, int FontSize, int Color */ )
void MultiSpacc_PrintText( char text[], MultiSpacc_Surface *Surface, MultiSpacc_SurfaceConfig *surfaceConfig, int x, int y, MultiSpacc_Surface *Tiles /*, int FontSize, int Color */ )
{
#ifdef MultiSpacc_Target_SDLCom
#if defined(MultiSpacc_Target_SDLCommon)
/* TODO: not just 8x8 tiles, and account for surface dimensions */
for( int i = 0; i < strlen(Text); i++ )
for( int i = 0; i < strlen(text); i++ )
{
MultiSpacc_Rect Offset = {
.x = (x * 8) + (8 * i),
.y = (y * 8),
MultiSpacc_Rect offset = {
.x = 8*x + 8*i,
.y = 8*y,
};
MultiSpacc_Rect Clip = {
.x = 8 * (Text[i] % 16),
.y = 8 * (Text[i] / 16),
MultiSpacc_Rect clip = {
.x = 8 * (text[i] % 16),
.y = 8 * (text[i] / 16),
.w = 8,
.h = 8,
};
SDL_BlitSurface( Tiles, &Clip, Surface, &Offset );
SDL_BlitSurface( Tiles, &clip, Surface, &offset );
};
#endif
#ifdef MultiSpacc_Target_NDS
iprintf( "%s", Text );
#endif
#elif defined(MultiSpacc_Target_NDS)
iprintf( "\x1b[%d;%dH%s", y, x, text );
#ifdef MultiSpacc_Target_NES
#elif defined(MultiSpacc_Target_NES)
// NOTE: is there no alternative to ppu off and on there? it makes the screen flicker and so makes programming more difficult
ppu_off();
vram_adr(NTADR_A( x, y ));
vram_write( Text, strlen(Text) );
vram_write( text, strlen(text) );
ppu_on_all();
#endif
}

View File

@ -24,11 +24,19 @@ bool MultiSpacc_SetMainLoop( bool functionFixedUpdate( void *args ), bool functi
MultiSpacc_Window *MultiSpacc_SetWindow( MultiSpacc_SurfaceConfig *windowConfig )
{
#if defined(MultiSpacc_Target_SDL12)
return SDL_SetVideoMode( windowConfig->width, windowConfig->height, windowConfig->bits, windowConfig->flags );
#elif defined(MultiSpacc_Target_SDL20)
return SDL_CreateWindow( NULL, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, windowConfig->width, windowConfig->height, windowConfig->flags );
#if defined(MultiSpacc_Target_SDLCommon)
if( windowConfig->width <= 0 || windowConfig->height <= 0 ){
windowConfig->width = 512;
windowConfig->height = 480;
}
if( windowConfig->bits <= 0 ){
windowConfig->bits = 24;
}
#if defined(MultiSpacc_Target_SDL12)
return SDL_SetVideoMode( windowConfig->width, windowConfig->height, windowConfig->bits, windowConfig->flags );
#elif defined(MultiSpacc_Target_SDL20)
return SDL_CreateWindow( NULL, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, windowConfig->width, windowConfig->height, windowConfig->flags );
#endif
#elif defined(MultiSpacc_Target_NDS)
PrintConsole *bottomScreen = NULL;

4
Makefile Normal file
View File

@ -0,0 +1,4 @@
All all:
cd ./LibMultiSpacc/Examples; make -j$$(nproc --all)
.PHONY: All all

View File

@ -0,0 +1,25 @@
#!/bin/sh
[ "$(whoami)" != root ] && {
echo "This script must run as root".
exit -1
}
mkdir -p /tmp /opt/Sdk
apt update
apt install -y \
make wine curl wget p7zip-full python3 python3-pil \
gcc mingw-w64 cc65 emscripten \
libsdl1.2-dev libsdl-image1.2-dev libsdl-ttf2.0-dev libsdl-mixer1.2-dev \
libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev libsdl2-mixer-dev \
;
curl -o /tmp/mingw32.7z https://hlb0.octt.eu.org/Drive/Misc/mingw32-9.2.0.7z.sfx.exe
7z x /tmp/mingw32.7z
cp ./mingw32/bin/*.dll ./mingw32/libexec/gcc/mingw32/9.2.0/
mv ./mingw32 /opt/Sdk/mingw32
curl -o /tmp/dkp.sh https://apt.devkitpro.org/install-devkitpro-pacman
yes | bash /tmp/dkp.sh
dkp-pacman -Sy nds-dev