Start adding inventory support
This commit is contained in:
parent
c8b08f9cf7
commit
c426420870
Binary file not shown.
Before Width: | Height: | Size: 7.9 KiB After Width: | Height: | Size: 8.5 KiB |
Binary file not shown.
Before Width: | Height: | Size: 8.0 KiB After Width: | Height: | Size: 7.7 KiB |
15
README.md
15
README.md
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
BloccSpacc is a portable isometric voxel sandbox game, mainly focused on building.
|
BloccSpacc is a portable isometric voxel sandbox game, mainly focused on building.
|
||||||
|
|
||||||
|
### Development status and compatibility note
|
||||||
|
|
||||||
|
The game is still in heavy development. Edges are rough, stuff might break from one day to the other, saved maps might not work across new versions, and support for different platforms might break between updates. Play at your own risk.
|
||||||
|
|
||||||
### Development status / roadmap:
|
### Development status / roadmap:
|
||||||
|
|
||||||
- [x] Breaking/placing blocks
|
- [x] Breaking/placing blocks
|
||||||
|
@ -15,8 +19,8 @@ BloccSpacc is a portable isometric voxel sandbox game, mainly focused on buildin
|
||||||
- [ ] Zooming in/out on the map
|
- [ ] Zooming in/out on the map
|
||||||
- [ ] Water+Lava physics
|
- [ ] Water+Lava physics
|
||||||
- [ ] Random terrain generation
|
- [ ] Random terrain generation
|
||||||
|
- [ ] Lighting/shading (it's hard to see some blocks on different layers)
|
||||||
- [ ] Day/Night cycle
|
- [ ] Day/Night cycle
|
||||||
- [ ] Lighting
|
|
||||||
- [ ] Infinite maps (?)
|
- [ ] Infinite maps (?)
|
||||||
- [ ] Sounds
|
- [ ] Sounds
|
||||||
- [ ] Screenshots
|
- [ ] Screenshots
|
||||||
|
@ -28,3 +32,12 @@ BloccSpacc is a portable isometric voxel sandbox game, mainly focused on buildin
|
||||||
- [ ] Refined inputs
|
- [ ] Refined inputs
|
||||||
- [ ] Customize memory allocation
|
- [ ] Customize memory allocation
|
||||||
- [ ] Customize controls
|
- [ ] Customize controls
|
||||||
|
|
||||||
|
### Current and planned platforms
|
||||||
|
|
||||||
|
- [x] Desktop GNU+Linux (main development platform)
|
||||||
|
- [x] Miyoo CFW Linux (tested on PocketGo)
|
||||||
|
- [ ] Android
|
||||||
|
- [ ] Win32 (Windows 95 and up)
|
||||||
|
- [ ] Nintendo GBA
|
||||||
|
- [ ] Symbian
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "SDL/SDL.h"
|
#include "SDL/SDL.h"
|
||||||
|
|
||||||
#define BlocksetNum 5
|
#define BlocksetNum 6
|
||||||
#define BlockSize 32
|
#define BlockSize 32
|
||||||
#define ChunkSize 16
|
#define ChunkSize 16
|
||||||
|
|
||||||
|
@ -20,4 +20,5 @@ struct Block Blocks[BlocksetNum] = {
|
||||||
{ 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 },
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,11 +4,12 @@
|
||||||
#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 KeyEsc SDLK_ESCAPE
|
|
||||||
#define KeyDebug SDLK_F3
|
#define KeyDebug SDLK_F3
|
||||||
|
|
||||||
#ifdef Target_PocketGo
|
#ifdef Target_PocketGo
|
||||||
|
|
||||||
|
#define KeyEsc SDLK_RCTRL // Reset
|
||||||
|
#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
|
||||||
|
@ -18,6 +19,8 @@
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
#define KeyEsc SDLK_ESCAPE
|
||||||
|
#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
|
||||||
|
|
154
Source/Main.c
154
Source/Main.c
|
@ -11,10 +11,9 @@
|
||||||
|
|
||||||
#define AppName "BloccSpacc"
|
#define AppName "BloccSpacc"
|
||||||
|
|
||||||
#define GameTick 30
|
|
||||||
|
|
||||||
SDL_Surface * Screen = NULL;
|
SDL_Surface * Screen = NULL;
|
||||||
SDL_Event Event;
|
SDL_Event Event;
|
||||||
|
#define GameTick 30
|
||||||
|
|
||||||
SDL_Surface * Cursorset = NULL;
|
SDL_Surface * Cursorset = NULL;
|
||||||
#define CursorsNum 2
|
#define CursorsNum 2
|
||||||
|
@ -26,17 +25,19 @@ SDL_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;
|
||||||
|
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 NextTime;
|
static Uint32 NextTickTime;
|
||||||
Uint32 TimeLeft() {
|
Uint32 CalcTimeLeft() {
|
||||||
Uint32 Now;
|
Uint32 Now;
|
||||||
Now = SDL_GetTicks();
|
Now = SDL_GetTicks();
|
||||||
if ( NextTime <= Now ) {
|
if ( NextTickTime <= Now ) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
return NextTime - Now;
|
return NextTickTime - Now;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +59,7 @@ struct xyz GetBlocksOnScreenNum() {
|
||||||
return Num;
|
return Num;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Init() {
|
bool SysInit() {
|
||||||
if ( SDL_Init ( SDL_INIT_EVERYTHING ) != 0 ) {
|
if ( SDL_Init ( SDL_INIT_EVERYTHING ) != 0 ) {
|
||||||
printf("[E] Error initializing SDL.\n");
|
printf("[E] Error initializing SDL.\n");
|
||||||
return false;
|
return false;
|
||||||
|
@ -139,10 +140,10 @@ void EventHandle() {
|
||||||
MoveCursor( 9 );
|
MoveCursor( 9 );
|
||||||
}
|
}
|
||||||
if ( UsedKeys.Place ) {
|
if ( UsedKeys.Place ) {
|
||||||
Map[CursorPos.y/BlockSize][CursorPos.z/BlockSize][CursorPos.x/BlockSize] = 0;
|
Map[CursorPos.y/BlockSize][CursorPos.z/BlockSize][CursorPos.x/BlockSize] = SelectedBlock;
|
||||||
}
|
}
|
||||||
if ( UsedKeys.Break ) {
|
if ( UsedKeys.Break ) {
|
||||||
Map[CursorPos.y/BlockSize][CursorPos.z/BlockSize][CursorPos.x/BlockSize] = 3;
|
Map[CursorPos.y/BlockSize][CursorPos.z/BlockSize][CursorPos.x/BlockSize] = 0;
|
||||||
}
|
}
|
||||||
UsedKeys.Up = false;
|
UsedKeys.Up = false;
|
||||||
UsedKeys.Down = false;
|
UsedKeys.Down = false;
|
||||||
|
@ -154,7 +155,11 @@ void EventHandle() {
|
||||||
UsedKeys.Break = false;
|
UsedKeys.Break = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawMap( struct xyz ChunksNum ) { // TODO: Reoptimize this to draw only visible blocks
|
void DrawInventory() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawMap() { // TODO: Reoptimize this to draw only visible blocks
|
||||||
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++ ) {
|
||||||
|
@ -174,17 +179,29 @@ void SetCamera() {
|
||||||
int y = ( CursorPos.y + BlockSize/2 );
|
int y = ( CursorPos.y + BlockSize/2 );
|
||||||
int z = ( CursorPos.z + BlockSize/2 );
|
int z = ( CursorPos.z + BlockSize/2 );
|
||||||
struct xyz xyz = OrthoToIso ( x, y, z, 1 );
|
struct xyz xyz = OrthoToIso ( x, y, z, 1 );
|
||||||
Camera.x = xyz.x - ScreenWidth/2;
|
Camera.x = xyz.x - ScreenWidth/2;
|
||||||
Camera.z = xyz.z - ScreenHeight*0.80;
|
Camera.z = xyz.z - ScreenHeight*0.80;
|
||||||
|
}
|
||||||
|
|
||||||
|
int GetCursorState() {
|
||||||
|
/*
|
||||||
|
if ( CursorPos.y < BlockSize * (ChunksNum.y - 1) ) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawCursor() {
|
void DrawCursor() {
|
||||||
struct xyz CursorCoords = OrthoToIso ( CursorPos.x, CursorPos.y, CursorPos.z, 1 );
|
struct xyz CursorCoords = OrthoToIso ( CursorPos.x, CursorPos.y, CursorPos.z, 1 );
|
||||||
DrawSurf(
|
int CursorState = GetCursorState();
|
||||||
CursorCoords.x - Camera.x - BlockSize/2,
|
if ( CursorState != -1 ) {
|
||||||
CursorCoords.z - Camera.z - BlockSize/2 - CursorPos.y/2,
|
DrawSurf(
|
||||||
Cursorset, & Cursors [1], Screen
|
CursorCoords.x - Camera.x - BlockSize/2,
|
||||||
);
|
CursorCoords.z - Camera.z - BlockSize/2 - CursorPos.y/2,
|
||||||
|
Cursorset, & Cursors [CursorState], Screen
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawDebug() { // There's a memory leak somewhere here
|
void DrawDebug() { // There's a memory leak somewhere here
|
||||||
|
@ -232,22 +249,10 @@ void SetRandomNoiseMap() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main( int argc, char* args[] ) {
|
void GameInit() {
|
||||||
printf("[I] Starting!\n");
|
|
||||||
srand( time( NULL ) );
|
|
||||||
|
|
||||||
if ( !Init() ) {
|
|
||||||
printf("[E] Error initializing SDL.\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if ( !LoadAssets() ) {
|
|
||||||
printf("[E] Error loading assets.\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( int i = 0; i < CursorsNum; i++ ) {
|
for ( int i = 0; i < CursorsNum; i++ ) {
|
||||||
Cursors [i].x = 0;
|
Cursors [i].x = BlockSize * i;
|
||||||
Cursors [i].y = BlockSize * i;
|
Cursors [i].y = 0;
|
||||||
Cursors [i].w = BlockSize;
|
Cursors [i].w = BlockSize;
|
||||||
Cursors [i].h = BlockSize;
|
Cursors [i].h = BlockSize;
|
||||||
}
|
}
|
||||||
|
@ -264,57 +269,82 @@ int main( int argc, char* args[] ) {
|
||||||
|
|
||||||
SetRandomNoiseMap();
|
SetRandomNoiseMap();
|
||||||
CursorPos.x = BlockSize * (ChunksNum.x - 1);
|
CursorPos.x = BlockSize * (ChunksNum.x - 1);
|
||||||
CursorPos.y = 0;
|
CursorPos.y = BlockSize * (ChunksNum.y - 1);
|
||||||
CursorPos.z = BlockSize * (ChunksNum.z - 1);
|
CursorPos.z = BlockSize * (ChunksNum.z - 1);
|
||||||
|
|
||||||
|
SelectedBlock = 2;
|
||||||
Recalc = true;
|
Recalc = true;
|
||||||
|
InGame = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main( int argc, char* args[] ) {
|
||||||
|
printf("[I] Starting!\n");
|
||||||
|
srand( time( NULL ) );
|
||||||
|
|
||||||
|
if ( !SysInit() ) {
|
||||||
|
printf("[E] Error initializing SDL.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if ( !LoadAssets() ) {
|
||||||
|
printf("[E] Error loading assets.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
GameInit();
|
||||||
|
|
||||||
while ( !Quit ) {
|
while ( !Quit ) {
|
||||||
NextTime = SDL_GetTicks() + GameTick;
|
NextTickTime = SDL_GetTicks() + GameTick;
|
||||||
while ( SDL_PollEvent( & Event ) ) {
|
while ( SDL_PollEvent( & Event ) ) {
|
||||||
Recalc = true;
|
Recalc = true;
|
||||||
if ( Event.type == SDL_QUIT ) {
|
if ( Event.type == SDL_QUIT ) {
|
||||||
Quit = true;
|
Quit = true;
|
||||||
}
|
}
|
||||||
else if ( Event.type == SDL_KEYDOWN ) {
|
|
||||||
if ( Event.key.keysym.sym == KeyEsc ) {
|
|
||||||
Quit = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ( Event.type == SDL_KEYUP ) {
|
else if ( Event.type == SDL_KEYUP ) {
|
||||||
if ( Event.key.keysym.sym == KeyDebug ) {
|
if ( Event.key.keysym.sym == KeyEsc ) {
|
||||||
|
if ( InGame && !InInventory ) {
|
||||||
|
Quit = true;
|
||||||
|
}
|
||||||
|
if ( InInventory ) {
|
||||||
|
InInventory = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ( Event.key.keysym.sym == KeyDebug ) {
|
||||||
DebugMode = !DebugMode;
|
DebugMode = !DebugMode;
|
||||||
}
|
}
|
||||||
if ( Event.key.keysym.sym == KeyGenFlatMap ) {
|
else if ( Event.key.keysym.sym == KeyInventory ) {
|
||||||
|
if ( InInventory ) {
|
||||||
|
InInventory = false;
|
||||||
|
} else {
|
||||||
|
InInventory = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ( Event.key.keysym.sym == KeyGenFlatMap ) {
|
||||||
SetSuperflatMap();
|
SetSuperflatMap();
|
||||||
}
|
}
|
||||||
if ( Event.key.keysym.sym == KeyGenNoiseMap ) {
|
else if ( Event.key.keysym.sym == KeyGenNoiseMap ) {
|
||||||
SetRandomNoiseMap();
|
SetRandomNoiseMap();
|
||||||
}
|
}
|
||||||
|
else if ( Event.key.keysym.sym == KeyUp ) {
|
||||||
if ( Event.key.keysym.sym == KeyUp ) {
|
|
||||||
UsedKeys.Up = true;
|
UsedKeys.Up = true;
|
||||||
}
|
}
|
||||||
if ( Event.key.keysym.sym == KeyRight ) {
|
else if ( Event.key.keysym.sym == KeyRight ) {
|
||||||
UsedKeys.Right = true;
|
UsedKeys.Right = true;
|
||||||
}
|
}
|
||||||
if ( Event.key.keysym.sym == KeyDown ) {
|
else if ( Event.key.keysym.sym == KeyDown ) {
|
||||||
UsedKeys.Down = true;
|
UsedKeys.Down = true;
|
||||||
}
|
}
|
||||||
if ( Event.key.keysym.sym == KeyLeft ) {
|
else if ( Event.key.keysym.sym == KeyLeft ) {
|
||||||
UsedKeys.Left = true;
|
UsedKeys.Left = true;
|
||||||
}
|
}
|
||||||
if ( Event.key.keysym.sym == KeyAbove ) {
|
else if ( Event.key.keysym.sym == KeyAbove ) {
|
||||||
UsedKeys.Above = true;
|
UsedKeys.Above = true;
|
||||||
}
|
}
|
||||||
if ( Event.key.keysym.sym == KeyBelow ) {
|
else if ( Event.key.keysym.sym == KeyBelow ) {
|
||||||
UsedKeys.Below = true;
|
UsedKeys.Below = true;
|
||||||
}
|
}
|
||||||
|
else if ( Event.key.keysym.sym == KeyPlace ) {
|
||||||
if ( Event.key.keysym.sym == KeyPlace ) {
|
|
||||||
UsedKeys.Place = true;
|
UsedKeys.Place = true;
|
||||||
}
|
}
|
||||||
if ( Event.key.keysym.sym == KeyBreak ) {
|
else if ( Event.key.keysym.sym == KeyBreak ) {
|
||||||
UsedKeys.Break = true;
|
UsedKeys.Break = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -322,23 +352,27 @@ int main( int argc, char* args[] ) {
|
||||||
if ( Recalc ) {
|
if ( Recalc ) {
|
||||||
EventHandle();
|
EventHandle();
|
||||||
SDL_FillRect( Screen, &Screen->clip_rect, SDL_MapRGB( Screen->format, 0xFF, 0xFF, 0xFF ) );
|
SDL_FillRect( Screen, &Screen->clip_rect, SDL_MapRGB( Screen->format, 0xFF, 0xFF, 0xFF ) );
|
||||||
SetCamera();
|
if ( InGame && !InInventory ) {
|
||||||
DrawMap( ChunksNum );
|
SetCamera();
|
||||||
DrawCursor();
|
DrawMap();
|
||||||
if ( DebugMode ) {
|
DrawCursor();
|
||||||
DrawDebug();
|
if ( DebugMode ) {
|
||||||
|
DrawDebug();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( InInventory ) {
|
||||||
|
DrawInventory();
|
||||||
}
|
}
|
||||||
if ( !FlipScreen( Screen ) ) {
|
if ( !FlipScreen( Screen ) ) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
Recalc = false;
|
Recalc = false;
|
||||||
}
|
}
|
||||||
SDL_Delay( TimeLeft() );
|
SDL_Delay( CalcTimeLeft() );
|
||||||
NextTime += GameTick;
|
NextTickTime += GameTick;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("[I] Exiting!\n");
|
printf("[I] Exiting!\n");
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue