mirror of
https://gitlab.com/octospacc/BloccSpacc
synced 2025-06-05 21:39:15 +02:00
Update to latest LibMultiSpacc, support Web build, update Makefile, add 2 blocks
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,4 +1,8 @@
|
|||||||
*.exe
|
*.exe
|
||||||
|
*.js
|
||||||
|
*.wasm
|
||||||
|
*.data
|
||||||
|
*.run
|
||||||
*.o
|
*.o
|
||||||
Source/LibMultiSpacc
|
Source/LibMultiSpacc
|
||||||
Source/LibMultiSpacc/*
|
Source/LibMultiSpacc/*
|
||||||
|
22
.gitlab-ci.yml
Normal file
22
.gitlab-ci.yml
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
image: debian:latest
|
||||||
|
|
||||||
|
before_script: |
|
||||||
|
apt update
|
||||||
|
apt install -y git
|
||||||
|
git clone --depth 1 https://gitlab.com/octospacc/MultiSpaccSDK
|
||||||
|
bash ./MultiSpaccSDK/Tools/InstallBuildEnvironment.sh
|
||||||
|
mv ./MultiSpaccSDK/LibMultiSpacc/LibMultiSpacc ./Source/LibMultiSpacc
|
||||||
|
|
||||||
|
pages:
|
||||||
|
stage: deploy
|
||||||
|
script: |
|
||||||
|
make -j$(nproc --all) Target=Web
|
||||||
|
mkdir -p ./public
|
||||||
|
mv ./Emscripten.* ./public/
|
||||||
|
mv ./MultiSpaccSDK/LibMultiSpacc/Examples/Emscripten.html ./public/index.html
|
||||||
|
artifacts:
|
||||||
|
paths:
|
||||||
|
- public
|
||||||
|
publish: public
|
||||||
|
rules:
|
||||||
|
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
|
Binary file not shown.
Before Width: | Height: | Size: 8.5 KiB After Width: | Height: | Size: 1.7 KiB |
26
Makefile
26
Makefile
@@ -1,7 +1,7 @@
|
|||||||
AppName = BloccSpacc
|
AppName = BloccSpacc
|
||||||
ExeSuffix = .exe
|
ExeSuffix = .run
|
||||||
|
|
||||||
Sources = $(wildcard Source/*.c)
|
Sources = $(wildcard Source/*.c Source/LibMultiSpacc/*.c)
|
||||||
CFlags = -O2
|
CFlags = -O2
|
||||||
CC = gcc $(Defines)
|
CC = gcc $(Defines)
|
||||||
|
|
||||||
@@ -13,6 +13,12 @@ ifdef Target
|
|||||||
ifeq ($(Target), PC)
|
ifeq ($(Target), PC)
|
||||||
Defines = -DTarget_PC
|
Defines = -DTarget_PC
|
||||||
MultiSpacc_Target = SDL20
|
MultiSpacc_Target = SDL20
|
||||||
|
else ifeq ($(Target), Web)
|
||||||
|
Defines = -DTarget_PC -DTarget_Web
|
||||||
|
MultiSpacc_Target = Web
|
||||||
|
AppName = Emscripten
|
||||||
|
ExeSuffix = .js
|
||||||
|
CC = emcc $(Defines)
|
||||||
else ifeq ($(Target), PocketGo)
|
else ifeq ($(Target), PocketGo)
|
||||||
ExeSuffix = .PocketGo.exe
|
ExeSuffix = .PocketGo.exe
|
||||||
PathPrefix = /opt/miyoo/bin/arm-miyoo-linux-uclibcgnueabi
|
PathPrefix = /opt/miyoo/bin/arm-miyoo-linux-uclibcgnueabi
|
||||||
@@ -25,20 +31,26 @@ endif
|
|||||||
ifeq ($(MultiSpacc_Target), SDL12)
|
ifeq ($(MultiSpacc_Target), SDL12)
|
||||||
Defines += -DMultiSpacc_Target_SDL12
|
Defines += -DMultiSpacc_Target_SDL12
|
||||||
LdFlags += -lSDL -lSDL_image -lSDL_mixer -lSDL_ttf
|
LdFlags += -lSDL -lSDL_image -lSDL_mixer -lSDL_ttf
|
||||||
Sources += $(wildcard Source/LibMultiSpacc/*.c Source/LibMultiSpacc/SDL12/*.c)
|
Sources += $(wildcard Source/LibMultiSpacc/SDLCom/*.c Source/LibMultiSpacc/SDL12/*.c)
|
||||||
else ifeq ($(MultiSpacc_Target), SDL20)
|
else ifeq ($(MultiSpacc_Target), SDL20)
|
||||||
Defines += -DMultiSpacc_Target_SDL20
|
Defines += -DMultiSpacc_Target_SDL20
|
||||||
LdFlags += -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf
|
LdFlags += -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf
|
||||||
Sources += $(wildcard Source/LibMultiSpacc/*.c Source/LibMultiSpacc/SDL20/*.c)
|
Sources += $(wildcard Source/LibMultiSpacc/SDLCom/*.c Source/LibMultiSpacc/SDL20/*.c)
|
||||||
|
else ifeq ($(MultiSpacc_Target), Web)
|
||||||
|
Defines += -DMultiSpacc_Target_Web -DMultiSpacc_Target_SDL20 -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 --preload-file Assets/Blocks.png --preload-file Assets/Cursorset.png --preload-file Assets/Icon.png --preload-file Assets/LiberationMono-Regular.ttf
|
||||||
endif
|
endif
|
||||||
|
|
||||||
Objects = $(Sources:.c=.o)
|
Objects = $(Sources:.c=.o)
|
||||||
|
|
||||||
all: $(AppName)
|
all All: $(AppName)
|
||||||
|
|
||||||
$(AppName): $(Objects)
|
$(AppName): $(Objects)
|
||||||
$(CC) $^ $(CFlags) $(LdFlags) -o $(AppName)$(ExeSuffix)
|
$(CC) $^ $(CFlags) $(LdFlags) -o $(AppName)$(ExeSuffix)
|
||||||
|
|
||||||
clean:
|
run Run: All
|
||||||
|
./$(AppName)$(ExeSuffix)
|
||||||
|
|
||||||
|
clean Clean clear Clear:
|
||||||
find -L . -name "*.o" -type f -delete
|
find -L . -name "*.o" -type f -delete
|
||||||
rm -f $(AppName)$(ExeSuffix) $(AppName).*$(ExeSuffix)
|
rm -f $(AppName)$(ExeSuffix) $(AppName).*$(ExeSuffix) *.js *.wasm *.data
|
||||||
|
@@ -1,25 +1,26 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "LibMultiSpacc/MultiSpacc.h"
|
#include "LibMultiSpacc/MultiSpacc.h"
|
||||||
//#include "SDL/SDL.h"
|
|
||||||
|
|
||||||
#define BlocksetNum 6
|
#define BlocksetNum 8
|
||||||
#define BlockSize 32
|
#define BlockSize 32
|
||||||
#define ChunkSize 16
|
#define ChunkSize 16
|
||||||
|
|
||||||
struct Block {
|
struct Block {
|
||||||
int Id;
|
int Id;
|
||||||
char Name[63];
|
char Name[63];
|
||||||
SDL_Rect Img;
|
SDL_Rect Img;
|
||||||
int Light;
|
int Light;
|
||||||
bool Falling;
|
bool Falling;
|
||||||
bool Fluid;
|
bool Fluid;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Block Blocks[BlocksetNum] = {
|
struct Block Blocks[BlocksetNum] = {
|
||||||
{ 0, "Air", {}, 0, false, false },
|
{ 0, "Air", {}, 0, false, false },
|
||||||
{ 1, "White", {}, 0, false, false },
|
{ 1, "White", {}, 0, false, false },
|
||||||
{ 2, "Black", {}, 0, false, false },
|
{ 2, "Black", {}, 0, false, false },
|
||||||
{ 3, "Gray", {}, 0, false, false },
|
{ 3, "Gray", {}, 0, false, false },
|
||||||
{ 4, "Green", {}, 0, false, false },
|
{ 4, "Green", {}, 0, false, false },
|
||||||
{ 5, "Blue", {}, 0, false, false },
|
{ 5, "Blue", {}, 0, false, false },
|
||||||
|
{ 6, "Purple", {}, 0, false, false },
|
||||||
|
{ 7, "Red", {}, 0, false, false },
|
||||||
};
|
};
|
||||||
|
@@ -1,31 +1,31 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define KeyUp SDLK_UP
|
#define KeyUp SDLK_UP
|
||||||
#define KeyDown SDLK_DOWN
|
#define KeyDown SDLK_DOWN
|
||||||
#define KeyLeft SDLK_LEFT
|
#define KeyLeft SDLK_LEFT
|
||||||
#define KeyRight SDLK_RIGHT
|
#define KeyRight SDLK_RIGHT
|
||||||
#define KeyDebug SDLK_F3
|
#define KeyDebug SDLK_F3
|
||||||
|
|
||||||
#ifdef Target_PocketGo
|
#ifdef Target_PocketGo
|
||||||
|
|
||||||
#define KeyEsc SDLK_RCTRL // Reset
|
#define KeyEsc SDLK_RCTRL // Reset
|
||||||
#define KeyInventory SDLK_ESCAPE // Select
|
#define KeyInventory SDLK_ESCAPE // Select
|
||||||
#define KeyGenFlatMap SDLK_LSHIFT // X
|
#define KeyGenFlatMap SDLK_LSHIFT // X
|
||||||
#define KeyGenNoiseMap SDLK_SPACE // Y
|
#define KeyGenNoiseMap SDLK_SPACE // Y
|
||||||
#define KeyAbove SDLK_LALT // A
|
#define KeyAbove SDLK_LALT // A
|
||||||
#define KeyBelow SDLK_LCTRL // B
|
#define KeyBelow SDLK_LCTRL // B
|
||||||
#define KeyPlace SDLK_TAB // L
|
#define KeyPlace SDLK_TAB // L
|
||||||
#define KeyBreak SDLK_BACKSPACE // R
|
#define KeyBreak SDLK_BACKSPACE // R
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#define KeyEsc SDLK_ESCAPE
|
#define KeyEsc SDLK_ESCAPE
|
||||||
#define KeyInventory SDLK_i
|
#define KeyInventory SDLK_i
|
||||||
#define KeyGenFlatMap SDLK_F6
|
#define KeyGenFlatMap SDLK_F6
|
||||||
#define KeyGenNoiseMap SDLK_F7
|
#define KeyGenNoiseMap SDLK_F7
|
||||||
#define KeyAbove SDLK_LSHIFT
|
#define KeyAbove SDLK_LSHIFT
|
||||||
#define KeyBelow SDLK_LCTRL
|
#define KeyBelow SDLK_LCTRL
|
||||||
#define KeyPlace SDLK_z
|
#define KeyPlace SDLK_z
|
||||||
#define KeyBreak SDLK_x
|
#define KeyBreak SDLK_x
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
244
Source/Main.c
244
Source/Main.c
@@ -2,29 +2,28 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "LibMultiSpacc/MultiSpacc.h"
|
#include "LibMultiSpacc/MultiSpacc.h"
|
||||||
//#include "SDL/SDL.h"
|
|
||||||
//#include "SDL/SDL_image.h"
|
|
||||||
//#include "SDL/SDL_ttf.h"
|
|
||||||
#include "TargetsConfigs.h"
|
#include "TargetsConfigs.h"
|
||||||
#include "Blocks.h"
|
#include "Blocks.h"
|
||||||
#include "Keys.h"
|
#include "Keys.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
|
||||||
|
#define swcase break; case
|
||||||
|
|
||||||
#define AppName "BloccSpacc"
|
#define AppName "BloccSpacc"
|
||||||
|
|
||||||
MultiSpacc_Window *Window = NULL;
|
MultiSpacc_Window *Window = NULL;
|
||||||
MultiSpacc_Surface *Screen = NULL;
|
MultiSpacc_Surface *Screen = NULL;
|
||||||
SDL_Event Event;
|
MultiSpacc_Event Event;
|
||||||
#define GameTick 30
|
#define GameTick 30
|
||||||
|
|
||||||
SDL_Surface * Cursorset = NULL;
|
MultiSpacc_Surface *Cursorset = NULL;
|
||||||
#define CursorsNum 2
|
#define CursorsNum 2
|
||||||
SDL_Rect Cursors[CursorsNum];
|
SDL_Rect Cursors[CursorsNum];
|
||||||
|
|
||||||
SDL_Surface * BlocksImg = NULL;
|
MultiSpacc_Surface *BlocksImg = NULL;
|
||||||
|
|
||||||
SDL_Surface * DebugMsg = NULL;
|
MultiSpacc_Surface *DebugMsg = NULL;
|
||||||
TTF_Font * DebugFont = NULL;
|
TTF_Font *DebugFont = NULL;
|
||||||
SDL_Color DebugTextColor = { 80, 80, 80 };
|
SDL_Color DebugTextColor = { 80, 80, 80 };
|
||||||
|
|
||||||
int SelectedBlock;
|
int SelectedBlock;
|
||||||
@@ -32,16 +31,16 @@ bool InGame, InTitleMenu, InInventory;
|
|||||||
bool Quit, Recalc, DebugMode;
|
bool Quit, Recalc, DebugMode;
|
||||||
|
|
||||||
// <https://www.libsdl.org/release/SDL-1.2.15/docs/html/guidetimeexamples.html>
|
// <https://www.libsdl.org/release/SDL-1.2.15/docs/html/guidetimeexamples.html>
|
||||||
static Uint32 NextTickTime;
|
Uint32 NextTickTime;
|
||||||
Uint32 CalcTimeLeft() {
|
Uint32 CalcTimeLeft() {
|
||||||
Uint32 Now;
|
Uint32 Now;
|
||||||
Now = SDL_GetTicks();
|
Now = MultiSpacc_GetTicks();
|
||||||
if ( NextTickTime <= Now ) {
|
if ( NextTickTime <= Now ) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
return NextTickTime - Now;
|
return NextTickTime - Now;
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
struct UsedKeys {
|
struct UsedKeys {
|
||||||
bool Up, Down, Left, Right, Above, Below;
|
bool Up, Down, Left, Right, Above, Below;
|
||||||
@@ -63,20 +62,21 @@ struct xyz GetBlocksOnScreenNum() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool SysInit() {
|
bool SysInit() {
|
||||||
if ( SDL_Init ( SDL_INIT_EVERYTHING ) != 0 ) {
|
//if ( MultiSpacc_Init( SDL_INIT_EVERYTHING ) != 0 ) {
|
||||||
printf("[E] Error initializing SDL.\n");
|
// printf("[E] Error initializing Core.\n");
|
||||||
return false;
|
// return false;
|
||||||
}
|
//};
|
||||||
Window = MultiSpacc_SetWindow( ScreenWidth, ScreenHeight, ScreenBits, 0 );
|
MultiSpacc_SurfaceConfig windowConfig = {0};
|
||||||
|
Window = MultiSpacc_SetWindow( &windowConfig );
|
||||||
Screen = MultiSpacc_GetWindowSurface( Window );
|
Screen = MultiSpacc_GetWindowSurface( Window );
|
||||||
if ( Screen == NULL ) {
|
if ( Screen == NULL ) {
|
||||||
printf("[E] Error initializing screen.\n");
|
printf("[E] Error initializing Video System.\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
};
|
||||||
if( TTF_Init() != 0 ) {
|
if( TTF_Init() != 0 ) {
|
||||||
printf("[E] Error initializing SDL_TTF.\n");
|
printf("[E] Error initializing Font System.\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
};
|
||||||
MultiSpacc_SetAppTitle( Window, AppName );
|
MultiSpacc_SetAppTitle( Window, AppName );
|
||||||
MultiSpacc_SetAppIcon( Window, LoadImage( "Assets/Icon.png", Screen ) );
|
MultiSpacc_SetAppIcon( Window, LoadImage( "Assets/Icon.png", Screen ) );
|
||||||
return true;
|
return true;
|
||||||
@@ -87,19 +87,19 @@ bool LoadAssets() {
|
|||||||
Cursorset = LoadImage( "Assets/Cursorset.png", Screen );
|
Cursorset = LoadImage( "Assets/Cursorset.png", Screen );
|
||||||
if ( Cursorset == NULL ) {
|
if ( Cursorset == NULL ) {
|
||||||
Error = true;
|
Error = true;
|
||||||
}
|
};
|
||||||
BlocksImg = LoadImage( "Assets/Blocks.png", Screen );
|
BlocksImg = LoadImage( "Assets/Blocks.png", Screen );
|
||||||
if ( BlocksImg == NULL ) {
|
if ( BlocksImg == NULL ) {
|
||||||
Error = true;
|
Error = true;
|
||||||
}
|
};
|
||||||
DebugFont = TTF_OpenFont( "Assets/LiberationMono-Regular.ttf", 12 );
|
DebugFont = TTF_OpenFont( "Assets/LiberationMono-Regular.ttf", 12 );
|
||||||
if ( DebugFont == NULL ) {
|
if ( DebugFont == NULL ) {
|
||||||
Error = true;
|
Error = true;
|
||||||
}
|
};
|
||||||
if ( Error ) {
|
if ( Error ) {
|
||||||
printf("[E] Error loading assets.\n");
|
printf("[E] Error loading assets.\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
};
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,50 +247,54 @@ void DrawCursor() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawDebug() { // There's a memory leak somewhere here
|
void DrawString( char Str[], int x, int y, TTF_Font* Font, SDL_Color Color ) {
|
||||||
char Str[127];
|
MultiSpacc_Surface *MsgSurf = TTF_RenderText_Blended( Font, Str, Color );
|
||||||
|
DrawSurf( x, y, MsgSurf, NULL, Screen );
|
||||||
snprintf( Str, sizeof(Str), "CursorPos: x:%d y:%d z:%d", CursorPos.x, CursorPos.y, CursorPos.z );
|
SDL_FreeSurface( MsgSurf );
|
||||||
DebugMsg = TTF_RenderText_Blended( DebugFont, Str, DebugTextColor );
|
|
||||||
DrawSurf( 8, 8, DebugMsg, NULL, Screen );
|
|
||||||
|
|
||||||
snprintf( Str, sizeof(Str), "Camera: x:%d y:%d z:%d", Camera.x, Camera.y, Camera.z );
|
|
||||||
DebugMsg = TTF_RenderText_Blended( DebugFont, Str, DebugTextColor );
|
|
||||||
DrawSurf( 8, 20, DebugMsg, NULL, Screen );
|
|
||||||
|
|
||||||
struct xyz CursorCoords = OrthoToIso ( CursorPos.x, CursorPos.y, CursorPos.z, 1 );
|
|
||||||
snprintf( Str, sizeof(Str), "CursorCoords: x:%d y:%d z:%d", CursorCoords.x, CursorCoords.y, CursorCoords.z );
|
|
||||||
DebugMsg = TTF_RenderText_Blended( DebugFont, Str, DebugTextColor );
|
|
||||||
DrawSurf( 8, 32, DebugMsg, NULL, Screen );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetSuperflatMap() {
|
void DrawDebug() {
|
||||||
|
char Str[128];
|
||||||
|
|
||||||
|
snprintf( Str, sizeof(Str), "CursorPos: x:%d y:%d z:%d", CursorPos.x, CursorPos.y, CursorPos.z );
|
||||||
|
DrawString( Str, 8, 8, DebugFont, DebugTextColor );
|
||||||
|
|
||||||
|
snprintf( Str, sizeof(Str), "Camera: x:%d y:%d z:%d", Camera.x, Camera.y, Camera.z );
|
||||||
|
DrawString( Str, 8, 20, DebugFont, DebugTextColor );
|
||||||
|
|
||||||
|
struct xyz CursorCoords = OrthoToIso( CursorPos.x, CursorPos.y, CursorPos.z, 1 );
|
||||||
|
snprintf( Str, sizeof(Str), "CursorCoords: x:%d y:%d z:%d", CursorCoords.x, CursorCoords.y, CursorCoords.z );
|
||||||
|
DrawString( Str, 8, 32, DebugFont, DebugTextColor );
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetSuperflatMap(){
|
||||||
for ( int z = 0; z < ChunksNum.z; z++ ) {
|
for ( int z = 0; z < ChunksNum.z; z++ ) {
|
||||||
for ( int x = 0; x < ChunksNum.x; x++ ) {
|
for ( int x = 0; x < ChunksNum.x; x++ ) {
|
||||||
Map[0][z][x] = 4;
|
Map[0][z][x] = 4;
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
for ( int y = 1; y < ChunksNum.y; y++ ) {
|
for ( int y = 1; y < ChunksNum.y; y++ ) {
|
||||||
for ( int z = 0; z < ChunksNum.z; z++ ) {
|
for ( int z = 0; z < ChunksNum.z; z++ ) {
|
||||||
for ( int x = 0; x < ChunksNum.x; x++ ) {
|
for ( int x = 0; x < ChunksNum.x; x++ ) {
|
||||||
Map[y][z][x] = 0;
|
Map[y][z][x] = 0;
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
void SetRandomNoiseMap() {
|
|
||||||
|
void SetRandomNoiseMap(){
|
||||||
for ( int y = 0; y < ChunksNum.y; y++ ) {
|
for ( int y = 0; y < ChunksNum.y; y++ ) {
|
||||||
for ( int z = 0; z < ChunksNum.z; z++ ) {
|
for ( int z = 0; z < ChunksNum.z; z++ ) {
|
||||||
for ( int x = 0; x < ChunksNum.x; x++ ) {
|
for ( int x = 0; x < ChunksNum.x; x++ ) {
|
||||||
int r = rand() % BlocksetNum;
|
int r = rand() % BlocksetNum;
|
||||||
if ( r == 1 ) { // Avoid block 1 (all white, hard to see) for testing
|
if ( r == 1 ) { // Avoid block 1 (all white, hard to see) for testing
|
||||||
r = 2;
|
r = 2;
|
||||||
}
|
};
|
||||||
Map[y][z][x] = r;
|
Map[y][z][x] = r;
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
void GameInit() {
|
void GameInit() {
|
||||||
for ( int i = 0; i < CursorsNum; i++ ) {
|
for ( int i = 0; i < CursorsNum; i++ ) {
|
||||||
@@ -318,95 +322,73 @@ void GameInit() {
|
|||||||
SelectedBlock = 2;
|
SelectedBlock = 2;
|
||||||
Recalc = true;
|
Recalc = true;
|
||||||
InGame = true;
|
InGame = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool GameLoop ( void *args ) {
|
||||||
|
NextTickTime = MultiSpacc_GetTicks() + GameTick;
|
||||||
|
while ( MultiSpacc_PollEvent( &Event ) ) {
|
||||||
|
if ( Event.Type == SDL_QUIT ) {
|
||||||
|
Quit = true;
|
||||||
|
} else
|
||||||
|
if ( Event.Type == SDL_KEYUP ) {
|
||||||
|
Recalc = true;
|
||||||
|
switch( Event.Key ){
|
||||||
|
swcase KeyUp : UsedKeys.Up = true;
|
||||||
|
swcase KeyRight : UsedKeys.Right = true;
|
||||||
|
swcase KeyDown : UsedKeys.Down = true;
|
||||||
|
swcase KeyLeft : UsedKeys.Left = true;
|
||||||
|
swcase KeyAbove : UsedKeys.Above = true;
|
||||||
|
swcase KeyBelow : UsedKeys.Below = true;
|
||||||
|
swcase KeyPlace : UsedKeys.Place = true;
|
||||||
|
swcase KeyBreak : UsedKeys.Break = true;
|
||||||
|
swcase KeyEsc : UsedKeys.Esc = true;
|
||||||
|
swcase KeyInventory : UsedKeys.Inventory = true;
|
||||||
|
swcase KeyDebug : DebugMode = !DebugMode;
|
||||||
|
swcase KeyGenFlatMap : SetSuperflatMap();
|
||||||
|
swcase KeyGenNoiseMap : SetRandomNoiseMap();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
EventHandle();
|
||||||
|
if ( Recalc ) {
|
||||||
|
FillSurfRGB ( 0xFF, 0xFF, 0xFF, Screen );
|
||||||
|
if ( InGame && !InInventory ) {
|
||||||
|
SetCamera();
|
||||||
|
DrawMap();
|
||||||
|
DrawCursor();
|
||||||
|
if ( DebugMode ) {
|
||||||
|
DrawDebug();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
if ( InInventory ) {
|
||||||
|
DrawInventory();
|
||||||
|
};
|
||||||
|
if ( !FlipScreen( Window ) ) {
|
||||||
|
return 1;
|
||||||
|
};
|
||||||
|
Recalc = false;
|
||||||
|
};
|
||||||
|
//MultiSpacc_Sleep( CalcTimeLeft() );
|
||||||
|
NextTickTime += GameTick;
|
||||||
|
return !Quit;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main( int argc, char* args[] ) {
|
int main( int argc, char *args[] ) {
|
||||||
printf("[I] Starting!\n");
|
printf("[I] Starting!\n");
|
||||||
srand( time( NULL ) );
|
srand( time( NULL ) );
|
||||||
|
|
||||||
if ( !SysInit() ) {
|
if ( !SysInit() ) {
|
||||||
printf("[E] Error initializing SDL.\n");
|
printf("[E] Error initializing System.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
};
|
||||||
if ( !LoadAssets() ) {
|
if ( !LoadAssets() ) {
|
||||||
printf("[E] Error loading assets.\n");
|
printf("[E] Error loading assets.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
};
|
||||||
GameInit();
|
GameInit();
|
||||||
|
MultiSpacc_SetMainLoop( GameLoop, NULL, NULL );
|
||||||
while ( !Quit ) {
|
|
||||||
NextTickTime = SDL_GetTicks() + GameTick;
|
|
||||||
while ( SDL_PollEvent( & Event ) ) {
|
|
||||||
if ( Event.type == SDL_QUIT ) {
|
|
||||||
Quit = true;
|
|
||||||
}
|
|
||||||
else if ( Event.type == SDL_KEYUP ) {
|
|
||||||
Recalc = true;
|
|
||||||
if ( Event.key.keysym.sym == KeyEsc ) {
|
|
||||||
UsedKeys.Esc = true;
|
|
||||||
}
|
|
||||||
else if ( Event.key.keysym.sym == KeyDebug ) {
|
|
||||||
DebugMode = !DebugMode;
|
|
||||||
}
|
|
||||||
else if ( Event.key.keysym.sym == KeyInventory ) {
|
|
||||||
UsedKeys.Inventory = true;
|
|
||||||
}
|
|
||||||
else if ( Event.key.keysym.sym == KeyGenFlatMap ) {
|
|
||||||
SetSuperflatMap();
|
|
||||||
}
|
|
||||||
else if ( Event.key.keysym.sym == KeyGenNoiseMap ) {
|
|
||||||
SetRandomNoiseMap();
|
|
||||||
}
|
|
||||||
else if ( Event.key.keysym.sym == KeyUp ) {
|
|
||||||
UsedKeys.Up = true;
|
|
||||||
}
|
|
||||||
else if ( Event.key.keysym.sym == KeyRight ) {
|
|
||||||
UsedKeys.Right = true;
|
|
||||||
}
|
|
||||||
else if ( Event.key.keysym.sym == KeyDown ) {
|
|
||||||
UsedKeys.Down = true;
|
|
||||||
}
|
|
||||||
else if ( Event.key.keysym.sym == KeyLeft ) {
|
|
||||||
UsedKeys.Left = true;
|
|
||||||
}
|
|
||||||
else if ( Event.key.keysym.sym == KeyAbove ) {
|
|
||||||
UsedKeys.Above = true;
|
|
||||||
}
|
|
||||||
else if ( Event.key.keysym.sym == KeyBelow ) {
|
|
||||||
UsedKeys.Below = true;
|
|
||||||
}
|
|
||||||
else if ( Event.key.keysym.sym == KeyPlace ) {
|
|
||||||
UsedKeys.Place = true;
|
|
||||||
}
|
|
||||||
else if ( Event.key.keysym.sym == KeyBreak ) {
|
|
||||||
UsedKeys.Break = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
EventHandle();
|
|
||||||
if ( Recalc ) {
|
|
||||||
FillSurfRGB ( 0xFF, 0xFF, 0xFF, Screen );
|
|
||||||
if ( InGame && !InInventory ) {
|
|
||||||
SetCamera();
|
|
||||||
DrawMap();
|
|
||||||
DrawCursor();
|
|
||||||
if ( DebugMode ) {
|
|
||||||
DrawDebug();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( InInventory ) {
|
|
||||||
DrawInventory();
|
|
||||||
}
|
|
||||||
if ( !FlipScreen( Window ) ) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
Recalc = false;
|
|
||||||
}
|
|
||||||
SDL_Delay( CalcTimeLeft() );
|
|
||||||
NextTickTime += GameTick;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("[I] Exiting!\n");
|
printf("[I] Exiting!\n");
|
||||||
SDL_Quit();
|
//SDL_Quit();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
};
|
||||||
|
@@ -1,13 +1,13 @@
|
|||||||
#ifdef Target_PocketGo
|
#ifdef Target_PocketGo
|
||||||
|
|
||||||
#define ScreenBits 16
|
#define ScreenBits 16
|
||||||
int ScreenWidth = 320;
|
int ScreenWidth = 320;
|
||||||
int ScreenHeight = 240;
|
int ScreenHeight = 240;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#define ScreenBits 32
|
#define ScreenBits 32
|
||||||
int ScreenWidth = 512;
|
int ScreenWidth = 512;
|
||||||
int ScreenHeight = 512;
|
int ScreenHeight = 512;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -1,11 +1,9 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "LibMultiSpacc/MultiSpacc.h"
|
#include "LibMultiSpacc/MultiSpacc.h"
|
||||||
//#include "SDL/SDL.h"
|
|
||||||
//#include "SDL/SDL_image.h"
|
|
||||||
|
|
||||||
SDL_Surface * LoadImage ( char *FilePath, MultiSpacc_Surface *Screen ) {
|
MultiSpacc_Surface * LoadImage ( char *FilePath, MultiSpacc_Surface *Screen ) {
|
||||||
SDL_Surface *a = NULL;
|
MultiSpacc_Surface *a = NULL;
|
||||||
SDL_Surface *b = NULL;
|
MultiSpacc_Surface *b = NULL;
|
||||||
a = IMG_Load ( FilePath );///*
|
a = IMG_Load ( FilePath );///*
|
||||||
if ( a == NULL ) {
|
if ( a == NULL ) {
|
||||||
printf("[E] Error reading image %s.\n", FilePath);
|
printf("[E] Error reading image %s.\n", FilePath);
|
||||||
@@ -22,18 +20,18 @@ SDL_Surface * LoadImage ( char *FilePath, MultiSpacc_Surface *Screen ) {
|
|||||||
return b;//*/return a;
|
return b;//*/return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawSurf ( int x, int y, SDL_Surface * Src, SDL_Rect * Clip, SDL_Surface * Dst ) {
|
void DrawSurf ( int x, int y, MultiSpacc_Surface * Src, SDL_Rect * Clip, MultiSpacc_Surface * Dst ) {
|
||||||
SDL_Rect Offset;
|
SDL_Rect Offset;
|
||||||
Offset.x = x;
|
Offset.x = x;
|
||||||
Offset.y = y;
|
Offset.y = y;
|
||||||
SDL_BlitSurface( Src, Clip, Dst, &Offset );
|
SDL_BlitSurface( Src, Clip, Dst, &Offset );
|
||||||
}
|
}
|
||||||
|
|
||||||
void FillSurfRGB ( int R, int G, int B, SDL_Surface * Dst ) {
|
void FillSurfRGB ( int R, int G, int B, MultiSpacc_Surface * Dst ) {
|
||||||
SDL_FillRect( Dst, &Dst->clip_rect, SDL_MapRGB( Dst->format, R, G, B ) );
|
SDL_FillRect( Dst, &Dst->clip_rect, SDL_MapRGB( Dst->format, R, G, B ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawOutlineRect ( int x, int y, int w, int h, int Size, int R, int G, int B, SDL_Surface * Dst ) {
|
void DrawOutlineRect ( int x, int y, int w, int h, int Size, int R, int G, int B, MultiSpacc_Surface * Dst ) {
|
||||||
SDL_Rect Rect;
|
SDL_Rect Rect;
|
||||||
Rect.x = x;
|
Rect.x = x;
|
||||||
Rect.y = y;
|
Rect.y = y;
|
||||||
|
Reference in New Issue
Block a user