Block definitions

This commit is contained in:
octospacc 2022-08-03 12:31:18 +02:00
parent 3a5529c026
commit 34aba8b35a
5 changed files with 42 additions and 19 deletions

BIN
Assets/Blocks.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.3 KiB

View File

@ -8,6 +8,7 @@ BloccSpacc is a portable isometric voxel sandbox game, mainly focused on buildin
- [ ] View mode / Edit mode - [ ] View mode / Edit mode
- [ ] Moving cursor in all 3 axis - [ ] Moving cursor in all 3 axis
- [ ] Rotating view - [ ] Rotating view
- [ ] Inventory
- [ ] "Layer view" (showing and moving only on 2 axis at a time, hiding other layers) for complex buildings - [ ] "Layer view" (showing and moving only on 2 axis at a time, hiding other layers) for complex buildings
- [ ] Saving+Loading maps - [ ] Saving+Loading maps
- [ ] Zooming in/out on the map - [ ] Zooming in/out on the map

22
Source/Blocks.h Normal file
View File

@ -0,0 +1,22 @@
#pragma once
#include "SDL/SDL.h"
#define BlocksetNum 5
#define BlockSize 32
struct Block {
int Id;
char Name[63];
SDL_Rect Img;
int Light;
bool Falling;
bool Fluid;
};
struct Block Blocks[BlocksetNum] = {
{ 0, "Air", {}, 0, false, false },
{ 1, "White", {}, 0, false, false },
{ 2, "Black", {}, 0, false, false },
{ 3, "Gray", {}, 0, false, false },
{ 4, "Green", {}, 0, false, false },
};

View File

@ -4,6 +4,7 @@
#include "SDL/SDL.h" #include "SDL/SDL.h"
#include "SDL/SDL_image.h" #include "SDL/SDL_image.h"
#include "SDL/SDL_ttf.h" #include "SDL/SDL_ttf.h"
#include "Blocks.h"
#include "Util.h" #include "Util.h"
#define AppName "BloccSpacc" #define AppName "BloccSpacc"
@ -19,15 +20,12 @@ SDL_Surface * Cursorset = NULL;
#define CursorsNum 2 #define CursorsNum 2
SDL_Rect Cursors[CursorsNum]; SDL_Rect Cursors[CursorsNum];
SDL_Surface * Blockset = NULL; SDL_Surface * BlocksImg = NULL;
#define BlocksetNum 4
SDL_Rect Blocks[BlocksetNum];
SDL_Surface * DebugMsg = NULL; SDL_Surface * DebugMsg = NULL;
TTF_Font * DebugFont = NULL; TTF_Font * DebugFont = NULL;
SDL_Color DebugTextColor = { 80, 80, 80 }; SDL_Color DebugTextColor = { 80, 80, 80 };
#define BlockSize 32
#define ChunkSize 8 #define ChunkSize 8
bool Quit, DebugMode; bool Quit, DebugMode;
@ -74,8 +72,8 @@ bool LoadAssets() {
if ( Cursorset == NULL ) { if ( Cursorset == NULL ) {
Error = true; Error = true;
} }
Blockset = LoadImage ( "Assets/Blockset.png" ); BlocksImg = LoadImage ( "Assets/Blocks.png" );
if ( Blockset == NULL ) { if ( BlocksImg == NULL ) {
Error = true; Error = true;
} }
DebugFont = TTF_OpenFont ( "Assets/LiberationMono-Regular.ttf", 12 ); DebugFont = TTF_OpenFont ( "Assets/LiberationMono-Regular.ttf", 12 );
@ -147,9 +145,6 @@ void EventHandle() {
} }
void DrawMap( struct xyz ChunksNum ) { void DrawMap( struct xyz ChunksNum ) {
//struct xyz BlocksOnScreen = GetBlocksOnScreenNum();
//for ( int Row = CursorPos.y/BlockSize - BlocksOnScreen.y*4; Row < CursorPos.y/BlockSize + BlocksOnScreen.y*4; Row++ ) {
//for ( int Col = 0; Col < BlocksOnScreen.x*2; Col++ ) {
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++ ) {
@ -157,7 +152,7 @@ void DrawMap( struct xyz ChunksNum ) {
DrawSurf( DrawSurf(
MapCoords.x - Camera.x - BlockSize/2, MapCoords.x - Camera.x - BlockSize/2,
MapCoords.z - Camera.z - y*BlockSize/2, //- Camera.y, MapCoords.z - Camera.z - y*BlockSize/2, //- Camera.y,
Blockset, & Blocks[Map[y][z][x]], Screen BlocksImg, & Blocks[Map[y][z][x]].Img, Screen
); );
} }
} }
@ -170,7 +165,6 @@ void SetCamera() {
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.y = y - ScreenHeight/2 + BlockSize;//xyz.y - ScreenHeight/2;
Camera.z = xyz.z - ScreenHeight/2; Camera.z = xyz.z - ScreenHeight/2;
} }
@ -178,8 +172,9 @@ 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( DrawSurf(
CursorCoords.x - Camera.x - BlockSize/2, CursorCoords.x - Camera.x - BlockSize/2,
CursorCoords.z - Camera.z - BlockSize/2 - CursorPos.y/2, //- CursorCoords.y - Camera.y - BlockSize/2, CursorCoords.z - Camera.z - BlockSize/2 - CursorPos.y/2,
Cursorset, & Cursors [1], Screen ); Cursorset, & Cursors [1], Screen
);
} }
void DrawDebug() { // There's a memory leak somewhere here void DrawDebug() { // There's a memory leak somewhere here
@ -200,10 +195,15 @@ void DrawDebug() { // There's a memory leak somewhere here
} }
void SetSuperflatMap() { void SetSuperflatMap() {
for ( int y = 0; y < ChunksNum.y; y++ ) { for ( int z = 0; z < ChunksNum.z; z++ ) {
for ( int x = 0; x < ChunksNum.x; x++ ) {
Map[0][z][x] = 4;
}
}
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] = 2; Map[y][z][x] = 0;
} }
} }
} }
@ -242,10 +242,10 @@ int main( int argc, char* args[] ) {
Cursors [i].h = BlockSize; Cursors [i].h = BlockSize;
} }
for ( int i = 0; i < BlocksetNum; i++ ) { for ( int i = 0; i < BlocksetNum; i++ ) {
Blocks [i].x = BlockSize * i; Blocks[i].Img.x = BlockSize * i;
Blocks [i].y = 0; Blocks[i].Img.y = 0;
Blocks [i].w = BlockSize; Blocks[i].Img.w = BlockSize;
Blocks [i].h = BlockSize; Blocks[i].Img.h = BlockSize;
} }
ChunksNum.x = ChunkSize; ChunksNum.x = ChunkSize;