mirror of
https://gitlab.com/octospacc/MultiSpaccSDK
synced 2025-06-05 22:09:21 +02:00
Update Pong example with border tiles drawing and AI
This commit is contained in:
Binary file not shown.
Before Width: | Height: | Size: 882 B After Width: | Height: | Size: 901 B |
@ -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
|
@ -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
|
@ -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 );
|
||||
}
|
||||
|
Reference in New Issue
Block a user