mirror of
https://gitlab.com/octospacc/BloccSpacc
synced 2025-06-05 21:39:15 +02:00
Start adding inventory support
This commit is contained in:
@ -31,6 +31,7 @@ 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;
|
static Uint32 NextTickTime;
|
||||||
|
static Uint32 InputTickTime;
|
||||||
Uint32 CalcTimeLeft() {
|
Uint32 CalcTimeLeft() {
|
||||||
Uint32 Now;
|
Uint32 Now;
|
||||||
Now = SDL_GetTicks();
|
Now = SDL_GetTicks();
|
||||||
@ -169,8 +170,11 @@ void DrawInventory() {
|
|||||||
s = 0;
|
s = 0;
|
||||||
}
|
}
|
||||||
DrawSurf( x, y, BlocksImg, &Blocks[i+1].Img, Screen );
|
DrawSurf( x, y, BlocksImg, &Blocks[i+1].Img, Screen );
|
||||||
|
if ( SelectedBlock == i+1 ) {
|
||||||
|
int Margin = BlockSize/8;
|
||||||
|
DrawOutlineRect( x-Margin, y-Margin, BlockSize+2*Margin, BlockSize+2*Margin, 4, 0x00, 0x00, 0x00, Screen );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
DrawOutlineRect ( SDL_Surface * Dst );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawMap() { // TODO: Reoptimize this to draw only visible blocks
|
void DrawMap() { // TODO: Reoptimize this to draw only visible blocks
|
||||||
@ -291,6 +295,13 @@ void GameInit() {
|
|||||||
InGame = true;
|
InGame = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KeyListen() {
|
||||||
|
Uint8 * Keys = SDL_GetKeyState( NULL );
|
||||||
|
if ( Keys [KeyUp] ) {
|
||||||
|
UsedKeys.Up = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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 ) );
|
||||||
@ -338,7 +349,7 @@ int main( int argc, char* args[] ) {
|
|||||||
SetRandomNoiseMap();
|
SetRandomNoiseMap();
|
||||||
}
|
}
|
||||||
else if ( Event.key.keysym.sym == KeyUp ) {
|
else if ( Event.key.keysym.sym == KeyUp ) {
|
||||||
UsedKeys.Up = true;
|
//UsedKeys.Up = true;
|
||||||
}
|
}
|
||||||
else if ( Event.key.keysym.sym == KeyRight ) {
|
else if ( Event.key.keysym.sym == KeyRight ) {
|
||||||
UsedKeys.Right = true;
|
UsedKeys.Right = true;
|
||||||
@ -363,8 +374,12 @@ int main( int argc, char* args[] ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( Recalc ) {
|
|
||||||
|
if ( InputTickTime % ( GameTick*3 ) == 0 ) {
|
||||||
EventHandle();
|
EventHandle();
|
||||||
|
}
|
||||||
|
if ( Recalc ) {
|
||||||
|
KeyListen();
|
||||||
FillSurfRGB ( 0xFF, 0xFF, 0xFF, Screen );
|
FillSurfRGB ( 0xFF, 0xFF, 0xFF, Screen );
|
||||||
if ( InGame && !InInventory ) {
|
if ( InGame && !InInventory ) {
|
||||||
SetCamera();
|
SetCamera();
|
||||||
@ -382,8 +397,10 @@ int main( int argc, char* args[] ) {
|
|||||||
}
|
}
|
||||||
Recalc = false;
|
Recalc = false;
|
||||||
}
|
}
|
||||||
|
printf("%d\n", InputTickTime);
|
||||||
SDL_Delay( CalcTimeLeft() );
|
SDL_Delay( CalcTimeLeft() );
|
||||||
NextTickTime += GameTick;
|
NextTickTime += GameTick;
|
||||||
|
InputTickTime += GameTick;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("[I] Exiting!\n");
|
printf("[I] Exiting!\n");
|
||||||
|
@ -32,8 +32,26 @@ void FillSurfRGB ( int R, int G, int B, SDL_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 ( SDL_Surface * Dst ) {
|
void DrawOutlineRect ( int x, int y, int w, int h, int Size, int R, int G, int B, SDL_Surface * Dst ) {
|
||||||
SDL_FillRect( Dst, 8, 8, 4, 16, SDL_MapRGB( Dst->format, 0x00, 0x00, 0x00 ) );
|
SDL_Rect Rect;
|
||||||
|
Rect.x = x;
|
||||||
|
Rect.y = y;
|
||||||
|
Rect.w = w;
|
||||||
|
Rect.h = Size;
|
||||||
|
SDL_FillRect( Dst, &Rect, SDL_MapRGB( Dst->format, R, G, B ) );
|
||||||
|
Rect.w = Size;
|
||||||
|
Rect.h = h;
|
||||||
|
SDL_FillRect( Dst, &Rect, SDL_MapRGB( Dst->format, R, G, B ) );
|
||||||
|
Rect.x = x;
|
||||||
|
Rect.y = y+h-Size;
|
||||||
|
Rect.w = w;
|
||||||
|
Rect.h = Size;
|
||||||
|
SDL_FillRect( Dst, &Rect, SDL_MapRGB( Dst->format, R, G, B ) );
|
||||||
|
Rect.x = x+w-Size;
|
||||||
|
Rect.y = y;
|
||||||
|
Rect.w = Size;
|
||||||
|
Rect.h = h;
|
||||||
|
SDL_FillRect( Dst, &Rect, SDL_MapRGB( Dst->format, R, G, B ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Surface * ScreenSet ( int Width, int Height, int Bits, SDL_Surface * Screen ) {
|
SDL_Surface * ScreenSet ( int Width, int Height, int Bits, SDL_Surface * Screen ) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
SDL_Surface * LoadImage ( char * FilePath );
|
SDL_Surface * LoadImage ( char * FilePath );
|
||||||
void DrawSurf ( int x, int y, SDL_Surface * Src, SDL_Rect * Clip, SDL_Surface * Dst );
|
void DrawSurf ( int x, int y, SDL_Surface * Src, SDL_Rect * Clip, SDL_Surface * Dst );
|
||||||
void FillSurfRGB ( int R, int G, int B, SDL_Surface * Dst );
|
void FillSurfRGB ( int R, int G, int B, SDL_Surface * Dst );
|
||||||
void DrawOutlineRect ( SDL_Surface * Dst );
|
void DrawOutlineRect ( int x, int y, int w, int h, int Size, int R, int G, int B, SDL_Surface * Dst );
|
||||||
SDL_Surface * ScreenSet ( int Width, int Height, int Bits, SDL_Surface * Screen );
|
SDL_Surface * ScreenSet ( int Width, int Height, int Bits, SDL_Surface * Screen );
|
||||||
bool FlipScreen( SDL_Surface * Screen );
|
bool FlipScreen( SDL_Surface * Screen );
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user