AAA
This commit is contained in:
parent
ce5426cef5
commit
51c33581e2
20 changed files with 16888 additions and 41985 deletions
4
.vscode/tasks.json
vendored
4
.vscode/tasks.json
vendored
|
@ -49,8 +49,8 @@
|
||||||
{ "value": "-Iraylib/src", "quoting": "strong" },
|
{ "value": "-Iraylib/src", "quoting": "strong" },
|
||||||
{ "value": "-Iraylib/src/extras", "quoting": "strong" },
|
{ "value": "-Iraylib/src/extras", "quoting": "strong" },
|
||||||
{ "value": "-Llib", "quoting": "strong" },
|
{ "value": "-Llib", "quoting": "strong" },
|
||||||
{ "value": "-std=c++2a", "quoting": "strong" },
|
{ "value": "-std=c17", "quoting": "strong" },
|
||||||
{ "value": "-Werro17 "quoting": "strong" },
|
{ "value": "-Werror" "quoting": "strong" },
|
||||||
{ "value": "-Wall", "quoting": "strong" },
|
{ "value": "-Wall", "quoting": "strong" },
|
||||||
{ "value": "-Wextra", "quoting": "strong" },
|
{ "value": "-Wextra", "quoting": "strong" },
|
||||||
{ "value": "-Wno-missing-field-initializers", "quoting": "strong" },
|
{ "value": "-Wno-missing-field-initializers", "quoting": "strong" },
|
||||||
|
|
|
@ -2,12 +2,23 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
void fileToBytes(const char *inputFileName, const char *outputFileName, const char *arrayName)
|
static char const DECLARATION_BEGIN[] = "static const unsigned char ";
|
||||||
|
static char const DECLARATION_END[] = "[] = {\n";
|
||||||
|
static char const FILE_END[] = "};";
|
||||||
|
static char const LINE[] = " 0x00\n";
|
||||||
|
|
||||||
|
static int const DECLARATION_BEGIN_SIZE = sizeof(DECLARATION_BEGIN) - 1;
|
||||||
|
static int const DECLARATION_END_SIZE = sizeof(DECLARATION_END) - 1;
|
||||||
|
static int const FILE_END_SIZE = sizeof(FILE_END) - 1;
|
||||||
|
static int const LINE_SIZE = sizeof(LINE) - 1;
|
||||||
|
|
||||||
|
static int const ADDITIONAL_SIZE = DECLARATION_BEGIN_SIZE + DECLARATION_END_SIZE + FILE_END_SIZE;
|
||||||
|
|
||||||
|
void fileToBytes(char const *const inputFileName, char const *const outputFileName, char const *const arrayName)
|
||||||
{
|
{
|
||||||
unsigned int fileSize = 0;
|
unsigned int fileSize = 0;
|
||||||
|
|
||||||
unsigned char *const fileData = LoadFileData(inputFileName, &fileSize);
|
unsigned char *const fileData = LoadFileData(inputFileName, &fileSize);
|
||||||
|
|
||||||
char *const content = (char *const)MemAlloc(sizeof(char) * fileSize * 10);
|
char *const content = (char *const)MemAlloc(sizeof(char) * fileSize * 10);
|
||||||
|
|
||||||
int cursor = 0;
|
int cursor = 0;
|
||||||
|
@ -18,13 +29,40 @@ void fileToBytes(const char *inputFileName, const char *outputFileName, const ch
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor = 0;
|
cursor = 0;
|
||||||
char *const final = (char *const)MemAlloc((sizeof("static const unsigned char ") + strlen(arrayName) + sizeof("[] = {\n") + (fileSize * sizeof(" 0x00,\n")) + sizeof("};")) * sizeof(char));
|
char *const final = (char *const)MemAlloc((ADDITIONAL_SIZE + strlen(arrayName) + (LINE_SIZE * fileSize)) * sizeof(char));
|
||||||
|
|
||||||
TextAppend(final, "static const unsigned char ", &cursor);
|
TextAppend(final, DECLARATION_BEGIN, &cursor);
|
||||||
TextAppend(final, arrayName, &cursor);
|
TextAppend(final, arrayName, &cursor);
|
||||||
TextAppend(final, TextFormat("[%d] = {\n", fileSize), &cursor);
|
TextAppend(final, DECLARATION_END, &cursor);
|
||||||
TextAppend(final, content, &cursor);
|
TextAppend(final, content, &cursor);
|
||||||
TextAppend(final, " };", &cursor);
|
TextAppend(final, FILE_END, &cursor);
|
||||||
|
|
||||||
|
MemFree(content);
|
||||||
|
|
||||||
|
SaveFileText(outputFileName, final);
|
||||||
|
|
||||||
|
MemFree(final);
|
||||||
|
}
|
||||||
|
|
||||||
|
void bytesToFile(unsigned char const *const input, unsigned int const inputSize, char const *const outputFileName, char const *const arrayName)
|
||||||
|
{
|
||||||
|
char *const content = (char *const)MemAlloc(sizeof(char) * inputSize * sizeof(" 0x00,\n"));
|
||||||
|
|
||||||
|
int cursor = 0;
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < inputSize; i++)
|
||||||
|
{
|
||||||
|
TextAppend(content, TextFormat(" 0x%02x,\n", input[i]), &cursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor = 0;
|
||||||
|
char *const final = (char *const)MemAlloc((ADDITIONAL_SIZE + strlen(arrayName) + (LINE_SIZE * inputSize)) * sizeof(char));
|
||||||
|
|
||||||
|
TextAppend(final, DECLARATION_BEGIN, &cursor);
|
||||||
|
TextAppend(final, arrayName, &cursor);
|
||||||
|
TextAppend(final, DECLARATION_END, &cursor);
|
||||||
|
TextAppend(final, content, &cursor);
|
||||||
|
TextAppend(final, FILE_END, &cursor);
|
||||||
|
|
||||||
MemFree(content);
|
MemFree(content);
|
||||||
|
|
||||||
|
|
2
include/fontLoader.h
Normal file
2
include/fontLoader.h
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
#include "raylib.h"
|
||||||
|
Font LoadTinyFont();
|
41510
include/monogram.ttf.h
41510
include/monogram.ttf.h
File diff suppressed because it is too large
Load diff
|
@ -1,54 +0,0 @@
|
||||||
#include "raylib.h"
|
|
||||||
|
|
||||||
static Color const ERROR_COLOR = {255, 0, 255, 255};
|
|
||||||
static Color const FLOOR_COLOR = {255, 255, 255, 255};
|
|
||||||
static Color const WALL_COLOR = {0, 0, 0, 255};
|
|
||||||
static Color const PLAYER_COLOR = {64, 64, 64 + 128, 255};
|
|
||||||
|
|
||||||
typedef struct Vector2i
|
|
||||||
{
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
} Vector2i;
|
|
||||||
|
|
||||||
typedef struct Entity
|
|
||||||
{
|
|
||||||
Vector2i position;
|
|
||||||
Color color;
|
|
||||||
} Entity;
|
|
||||||
|
|
||||||
typedef struct Room
|
|
||||||
{
|
|
||||||
int height;
|
|
||||||
int width;
|
|
||||||
Vector2i position;
|
|
||||||
Vector2i center;
|
|
||||||
} Room;
|
|
||||||
|
|
||||||
typedef struct Tile
|
|
||||||
{
|
|
||||||
bool walkable;
|
|
||||||
Color color;
|
|
||||||
} Tile;
|
|
||||||
|
|
||||||
bool tryMovePlayer(Vector2i const new_position);
|
|
||||||
|
|
||||||
Entity *createPlayer(Vector2i const start_position);
|
|
||||||
Tile **createMapTiles(void);
|
|
||||||
Vector2i setupMap(void);
|
|
||||||
void freeMapTiles(Tile **map_tiles);
|
|
||||||
|
|
||||||
Room createRoom(int x, int y, int height, int width);
|
|
||||||
void addRoomToMap(Room room);
|
|
||||||
void connectRoomCenters(Vector2i centerOne, Vector2i centerTwo);
|
|
||||||
|
|
||||||
void renderEverything(void);
|
|
||||||
|
|
||||||
void initGame(void);
|
|
||||||
void mainLoop(void);
|
|
||||||
void endGame(void);
|
|
||||||
|
|
||||||
extern unsigned int const MAP_HEIGHT;
|
|
||||||
extern unsigned int const MAP_WIDTH;
|
|
||||||
extern Entity *player;
|
|
||||||
extern Tile **map;
|
|
16686
include/tinyData.h
Normal file
16686
include/tinyData.h
Normal file
File diff suppressed because it is too large
Load diff
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 14 KiB |
Binary file not shown.
|
@ -1,100 +0,0 @@
|
||||||
info face="Tiny" size=-6 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=0 aa=1 padding=1,1,0,1 spacing=0,0 outline=0
|
|
||||||
common lineHeight=6 base=5 scaleW=128 scaleH=128 pages=1 packed=0 alphaChnl=0 redChnl=3 greenChnl=3 blueChnl=3
|
|
||||||
page id=0 file="tiny_0.png"
|
|
||||||
chars count=96
|
|
||||||
char id=32 x=0 y=28 width=5 height=7 xoffset=-1 yoffset=-1 xadvance=3 page=0 chnl=15
|
|
||||||
char id=33 x=37 y=28 width=4 height=7 xoffset=-1 yoffset=-1 xadvance=2 page=0 chnl=15
|
|
||||||
char id=34 x=7 y=7 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=35 x=16 y=0 width=8 height=7 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
|
||||||
char id=36 x=13 y=7 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=37 x=70 y=0 width=7 height=7 xoffset=-1 yoffset=-1 xadvance=5 page=0 chnl=15
|
|
||||||
char id=38 x=77 y=0 width=7 height=7 xoffset=-1 yoffset=-1 xadvance=5 page=0 chnl=15
|
|
||||||
char id=39 x=25 y=28 width=4 height=7 xoffset=-1 yoffset=-1 xadvance=2 page=0 chnl=15
|
|
||||||
char id=40 x=118 y=21 width=5 height=7 xoffset=-1 yoffset=-1 xadvance=3 page=0 chnl=15
|
|
||||||
char id=41 x=113 y=21 width=5 height=7 xoffset=-1 yoffset=-1 xadvance=3 page=0 chnl=15
|
|
||||||
char id=42 x=19 y=7 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=43 x=25 y=7 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=44 x=41 y=28 width=4 height=7 xoffset=-1 yoffset=-1 xadvance=2 page=0 chnl=15
|
|
||||||
char id=45 x=37 y=7 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=46 x=57 y=28 width=4 height=7 xoffset=-1 yoffset=-1 xadvance=2 page=0 chnl=15
|
|
||||||
char id=47 x=119 y=0 width=7 height=7 xoffset=-1 yoffset=-1 xadvance=5 page=0 chnl=15
|
|
||||||
char id=48 x=43 y=7 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=49 x=49 y=7 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=50 x=55 y=7 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=51 x=61 y=7 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=52 x=67 y=7 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=53 x=73 y=7 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=54 x=79 y=7 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=55 x=85 y=7 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=56 x=102 y=21 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=57 x=91 y=7 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=58 x=33 y=28 width=4 height=7 xoffset=-1 yoffset=-1 xadvance=2 page=0 chnl=15
|
|
||||||
char id=59 x=29 y=28 width=4 height=7 xoffset=-1 yoffset=-1 xadvance=2 page=0 chnl=15
|
|
||||||
char id=60 x=97 y=7 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=61 x=103 y=7 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=62 x=109 y=7 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=63 x=115 y=7 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=64 x=121 y=7 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=65 x=0 y=14 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=66 x=6 y=14 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=67 x=12 y=14 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=68 x=31 y=7 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=69 x=18 y=14 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=70 x=24 y=14 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=71 x=30 y=14 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=72 x=36 y=14 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=73 x=42 y=14 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=74 x=48 y=14 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=75 x=98 y=0 width=7 height=7 xoffset=-1 yoffset=-1 xadvance=5 page=0 chnl=15
|
|
||||||
char id=76 x=54 y=14 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=77 x=0 y=0 width=8 height=7 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
|
||||||
char id=78 x=91 y=0 width=7 height=7 xoffset=-1 yoffset=-1 xadvance=5 page=0 chnl=15
|
|
||||||
char id=79 x=105 y=0 width=7 height=7 xoffset=-1 yoffset=-1 xadvance=5 page=0 chnl=15
|
|
||||||
char id=80 x=90 y=14 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=81 x=63 y=0 width=7 height=7 xoffset=-1 yoffset=-1 xadvance=5 page=0 chnl=15
|
|
||||||
char id=82 x=66 y=14 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=83 x=72 y=14 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=84 x=78 y=14 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=85 x=56 y=0 width=7 height=7 xoffset=-1 yoffset=-1 xadvance=5 page=0 chnl=15
|
|
||||||
char id=86 x=48 y=0 width=8 height=7 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
|
||||||
char id=87 x=40 y=0 width=8 height=7 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
|
||||||
char id=88 x=84 y=14 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=89 x=32 y=0 width=8 height=7 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
|
||||||
char id=90 x=84 y=0 width=7 height=7 xoffset=-1 yoffset=-1 xadvance=5 page=0 chnl=15
|
|
||||||
char id=91 x=5 y=28 width=5 height=7 xoffset=-1 yoffset=-1 xadvance=3 page=0 chnl=15
|
|
||||||
char id=92 x=112 y=0 width=7 height=7 xoffset=-1 yoffset=-1 xadvance=5 page=0 chnl=15
|
|
||||||
char id=93 x=15 y=28 width=5 height=7 xoffset=-1 yoffset=-1 xadvance=3 page=0 chnl=15
|
|
||||||
char id=94 x=96 y=14 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=95 x=102 y=14 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=96 x=108 y=21 width=5 height=7 xoffset=-1 yoffset=-1 xadvance=3 page=0 chnl=15
|
|
||||||
char id=97 x=108 y=14 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=98 x=114 y=14 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=99 x=120 y=14 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=100 x=0 y=21 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=101 x=6 y=21 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=102 x=10 y=28 width=5 height=7 xoffset=-1 yoffset=-1 xadvance=3 page=0 chnl=15
|
|
||||||
char id=103 x=20 y=28 width=5 height=7 xoffset=-1 yoffset=-1 xadvance=3 page=0 chnl=15
|
|
||||||
char id=104 x=18 y=21 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=105 x=45 y=28 width=4 height=7 xoffset=-1 yoffset=-1 xadvance=2 page=0 chnl=15
|
|
||||||
char id=106 x=49 y=28 width=4 height=7 xoffset=-1 yoffset=-1 xadvance=2 page=0 chnl=15
|
|
||||||
char id=107 x=24 y=21 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=108 x=61 y=28 width=4 height=7 xoffset=-1 yoffset=-1 xadvance=2 page=0 chnl=15
|
|
||||||
char id=109 x=24 y=0 width=8 height=7 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
|
||||||
char id=110 x=30 y=21 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=111 x=36 y=21 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=112 x=42 y=21 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=113 x=48 y=21 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=114 x=123 y=21 width=5 height=7 xoffset=-1 yoffset=-1 xadvance=3 page=0 chnl=15
|
|
||||||
char id=115 x=12 y=21 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=116 x=54 y=21 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=117 x=60 y=21 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=118 x=66 y=21 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=119 x=8 y=0 width=8 height=7 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
|
||||||
char id=120 x=72 y=21 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=121 x=78 y=21 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=122 x=84 y=21 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=123 x=90 y=21 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=124 x=53 y=28 width=4 height=7 xoffset=-1 yoffset=-1 xadvance=2 page=0 chnl=15
|
|
||||||
char id=125 x=96 y=21 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
||||||
char id=126 x=0 y=7 width=7 height=7 xoffset=-1 yoffset=-1 xadvance=5 page=0 chnl=15
|
|
||||||
char id=127 x=60 y=14 width=6 height=7 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
|
|
BIN
resources/tiny.png
Normal file
BIN
resources/tiny.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 553 B |
Binary file not shown.
Before Width: | Height: | Size: 580 B |
24
src/draw.c
24
src/draw.c
|
@ -1,24 +0,0 @@
|
||||||
#include "raylib.h"
|
|
||||||
#include "rogue.h"
|
|
||||||
|
|
||||||
void drawMap(Tile **map)
|
|
||||||
{
|
|
||||||
for (unsigned int x = 0; x < MAP_WIDTH; x++)
|
|
||||||
{
|
|
||||||
for (unsigned int y = 0; y < MAP_HEIGHT; y++)
|
|
||||||
{
|
|
||||||
DrawPixel(x, y, map[x][y].color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void drawEntity(Entity *entity)
|
|
||||||
{
|
|
||||||
DrawPixel(entity->position.x, entity->position.y, entity->color);
|
|
||||||
}
|
|
||||||
|
|
||||||
void renderEverything()
|
|
||||||
{
|
|
||||||
drawMap(map);
|
|
||||||
drawEntity(player);
|
|
||||||
}
|
|
108
src/engine.c
108
src/engine.c
|
@ -1,108 +0,0 @@
|
||||||
#include "raylib.h"
|
|
||||||
#include "rogue.h"
|
|
||||||
#include <time.h> // Required for: time_t, tm, time(), localtime(), strftime()
|
|
||||||
|
|
||||||
static int const PIXEL_SCALE = 10;
|
|
||||||
static int const VIRTUAL_SCREEN_WIDTH = 80;
|
|
||||||
static int const VIRTUAL_SCREEN_HEIGHT = 45;
|
|
||||||
|
|
||||||
const unsigned int MAP_HEIGHT = VIRTUAL_SCREEN_HEIGHT;
|
|
||||||
const unsigned int MAP_WIDTH = VIRTUAL_SCREEN_WIDTH;
|
|
||||||
|
|
||||||
static int const REAL_SCREEN_WIDTH = VIRTUAL_SCREEN_WIDTH * PIXEL_SCALE;
|
|
||||||
static int const REAL_SCREEN_HEIGHT = VIRTUAL_SCREEN_HEIGHT * PIXEL_SCALE;
|
|
||||||
|
|
||||||
static Rectangle const virtualScreenRect = {0.0f, 0.0f, (float)VIRTUAL_SCREEN_WIDTH, -(float)VIRTUAL_SCREEN_HEIGHT};
|
|
||||||
static Rectangle const realScreenRect = {0.0f, 0.0f, (float)REAL_SCREEN_WIDTH, (float)REAL_SCREEN_HEIGHT};
|
|
||||||
|
|
||||||
RenderTexture2D virtualScreen;
|
|
||||||
|
|
||||||
void initGame()
|
|
||||||
{
|
|
||||||
// Initialization
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
#if defined(__DEBUG)
|
|
||||||
SetTraceLogLevel(LOG_ALL);
|
|
||||||
SetRandomSeed(0);
|
|
||||||
#else
|
|
||||||
SetTraceLogLevel(LOG_NONE);
|
|
||||||
SetRandomSeed(time(NULL));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
SetConfigFlags(0);
|
|
||||||
InitWindow(REAL_SCREEN_WIDTH, REAL_SCREEN_HEIGHT, "TODO: Add a title");
|
|
||||||
|
|
||||||
virtualScreen = LoadRenderTexture(VIRTUAL_SCREEN_WIDTH, VIRTUAL_SCREEN_HEIGHT);
|
|
||||||
|
|
||||||
map = createMapTiles();
|
|
||||||
player = createPlayer(setupMap());
|
|
||||||
|
|
||||||
// SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
|
||||||
}
|
|
||||||
|
|
||||||
void update()
|
|
||||||
{
|
|
||||||
// Update
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
Vector2i new_position = {player->position.x, player->position.y};
|
|
||||||
if (IsKeyPressed(KEY_RIGHT))
|
|
||||||
{
|
|
||||||
new_position.x++;
|
|
||||||
}
|
|
||||||
if (IsKeyPressed(KEY_LEFT))
|
|
||||||
{
|
|
||||||
new_position.x--;
|
|
||||||
}
|
|
||||||
if (IsKeyPressed(KEY_UP))
|
|
||||||
{
|
|
||||||
new_position.y--;
|
|
||||||
}
|
|
||||||
if (IsKeyPressed(KEY_DOWN))
|
|
||||||
{
|
|
||||||
new_position.y++;
|
|
||||||
}
|
|
||||||
tryMovePlayer(new_position);
|
|
||||||
}
|
|
||||||
|
|
||||||
void draw()
|
|
||||||
{
|
|
||||||
// Draw
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
BeginTextureMode(virtualScreen);
|
|
||||||
{
|
|
||||||
ClearBackground(ERROR_COLOR);
|
|
||||||
|
|
||||||
renderEverything();
|
|
||||||
}
|
|
||||||
EndTextureMode();
|
|
||||||
|
|
||||||
BeginDrawing();
|
|
||||||
{
|
|
||||||
// Draw rendered game texture
|
|
||||||
DrawTexturePro(virtualScreen.texture, virtualScreenRect, realScreenRect, (Vector2){0.0f, 0.0f}, 0.0f, WHITE);
|
|
||||||
|
|
||||||
// Draw GUI here
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
#if __DEBUG
|
|
||||||
DrawFPS(0, 0);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
EndDrawing();
|
|
||||||
}
|
|
||||||
|
|
||||||
void mainLoop()
|
|
||||||
{
|
|
||||||
update();
|
|
||||||
draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
void endGame()
|
|
||||||
{
|
|
||||||
// De-Initialization
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
MemFree(player);
|
|
||||||
freeMapTiles(map);
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
}
|
|
123
src/fontLoader.c
Normal file
123
src/fontLoader.c
Normal file
|
@ -0,0 +1,123 @@
|
||||||
|
#include "raylib.h"
|
||||||
|
#include "string.h"
|
||||||
|
#include "tinyData.h"
|
||||||
|
|
||||||
|
#define TINY_IMAGE_WIDTH 97
|
||||||
|
#define TINY_IMAGE_HEIGHT 43
|
||||||
|
|
||||||
|
Font LoadTinyFont()
|
||||||
|
{
|
||||||
|
Image image = (Image){
|
||||||
|
.data = tinyImageDataBytes,
|
||||||
|
.width = 97,
|
||||||
|
.height = 43,
|
||||||
|
.mipmaps = 1,
|
||||||
|
.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8,
|
||||||
|
};
|
||||||
|
|
||||||
|
static int const GLYPH_COUNT = 6 * 16;
|
||||||
|
static int const FIRST_CHAR = ' ';
|
||||||
|
|
||||||
|
#define COLOR_EQUAL_MAGENTA(col) ((col.r == 255) && (col.g == 0) && (col.b == 255) && (col.a == 255))
|
||||||
|
|
||||||
|
Font font;
|
||||||
|
|
||||||
|
// We allocate a temporal arrays for chars data measures,
|
||||||
|
// once we get the actual number of chars, we copy data to a sized arrays
|
||||||
|
int tempCharValues[GLYPH_COUNT];
|
||||||
|
Rectangle tempCharRecs[GLYPH_COUNT];
|
||||||
|
|
||||||
|
static int const HORIZONTAL_SPACING = 1;
|
||||||
|
static int const VERTICAL_SPACING = 1;
|
||||||
|
static int const CHAR_WIDTH = 5;
|
||||||
|
static int const CHAR_HEIGHT = 6;
|
||||||
|
|
||||||
|
for (unsigned char i = 0; i < GLYPH_COUNT; i++)
|
||||||
|
{
|
||||||
|
tempCharValues[i] = FIRST_CHAR + i;
|
||||||
|
int const x = HORIZONTAL_SPACING + i * (CHAR_WIDTH + HORIZONTAL_SPACING);
|
||||||
|
int const y = (x / TINY_IMAGE_WIDTH) * (CHAR_HEIGHT + VERTICAL_SPACING) + VERTICAL_SPACING;
|
||||||
|
tempCharRecs[i] = (Rectangle){x % TINY_IMAGE_WIDTH, y, CHAR_WIDTH, CHAR_HEIGHT};
|
||||||
|
}
|
||||||
|
|
||||||
|
Color pixels[sizeof(tinyImageDataBytes) / sizeof(Color)];
|
||||||
|
memcpy(pixels, image.data, sizeof(pixels));
|
||||||
|
|
||||||
|
// Check array values to get characters: value, x, y, w, h
|
||||||
|
int index = 0;
|
||||||
|
int lineToRead = 0;
|
||||||
|
int xPosToRead = HORIZONTAL_SPACING;
|
||||||
|
|
||||||
|
// Parse image data to get rectangle sizes
|
||||||
|
while ((VERTICAL_SPACING + lineToRead * (CHAR_HEIGHT + VERTICAL_SPACING)) < image.height)
|
||||||
|
{
|
||||||
|
while ((xPosToRead < image.width) &&
|
||||||
|
!COLOR_EQUAL_MAGENTA((pixels[(VERTICAL_SPACING + (CHAR_HEIGHT + VERTICAL_SPACING) * lineToRead) * image.width + xPosToRead])))
|
||||||
|
{
|
||||||
|
tempCharValues[index] = FIRST_CHAR + index;
|
||||||
|
|
||||||
|
tempCharRecs[index].x = (float)xPosToRead;
|
||||||
|
tempCharRecs[index].y = (float)(VERTICAL_SPACING + lineToRead * (CHAR_HEIGHT + VERTICAL_SPACING));
|
||||||
|
tempCharRecs[index].height = (float)CHAR_HEIGHT;
|
||||||
|
|
||||||
|
int charWidth = 0;
|
||||||
|
|
||||||
|
while (!COLOR_EQUAL_MAGENTA(pixels[(VERTICAL_SPACING + (CHAR_HEIGHT + VERTICAL_SPACING) * lineToRead) * image.width + xPosToRead + charWidth]))
|
||||||
|
charWidth++;
|
||||||
|
|
||||||
|
tempCharRecs[index].width = (float)charWidth;
|
||||||
|
|
||||||
|
index++;
|
||||||
|
|
||||||
|
xPosToRead += (charWidth + HORIZONTAL_SPACING);
|
||||||
|
}
|
||||||
|
|
||||||
|
lineToRead++;
|
||||||
|
xPosToRead = HORIZONTAL_SPACING;
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: We need to remove key color borders from image to avoid weird
|
||||||
|
// artifacts on texture scaling when using TEXTURE_FILTER_BILINEAR or TEXTURE_FILTER_TRILINEAR
|
||||||
|
for (int i = 0; i < image.height * image.width; i++)
|
||||||
|
if (COLOR_EQUAL_MAGENTA(pixels[i]))
|
||||||
|
pixels[i] = BLANK;
|
||||||
|
|
||||||
|
// Create a new image with the processed color data (key color replaced by BLANK)
|
||||||
|
Image fontClear = {
|
||||||
|
.data = pixels,
|
||||||
|
.width = image.width,
|
||||||
|
.height = image.height,
|
||||||
|
.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8,
|
||||||
|
.mipmaps = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Set font with all data parsed from image
|
||||||
|
font.texture = LoadTextureFromImage(fontClear); // Convert processed image to OpenGL texture
|
||||||
|
font.glyphCount = index;
|
||||||
|
font.glyphPadding = 0;
|
||||||
|
|
||||||
|
// We got tempCharValues and tempCharsRecs populated with chars data
|
||||||
|
// Now we move temp data to sized charValues and charRecs arrays
|
||||||
|
font.glyphs = (GlyphInfo *)MemAlloc(font.glyphCount * sizeof(GlyphInfo));
|
||||||
|
font.recs = (Rectangle *)MemAlloc(font.glyphCount * sizeof(Rectangle));
|
||||||
|
|
||||||
|
for (int i = 0; i < font.glyphCount; i++)
|
||||||
|
{
|
||||||
|
font.glyphs[i].value = tempCharValues[i];
|
||||||
|
|
||||||
|
// Get character rectangle in the font atlas texture
|
||||||
|
font.recs[i] = tempCharRecs[i];
|
||||||
|
|
||||||
|
// NOTE: On image based fonts (XNA style), character offsets and xAdvance are not required (set to 0)
|
||||||
|
font.glyphs[i].offsetX = 0;
|
||||||
|
font.glyphs[i].offsetY = 0;
|
||||||
|
font.glyphs[i].advanceX = 0;
|
||||||
|
|
||||||
|
// Fill character image data from fontClear data
|
||||||
|
font.glyphs[i].image = ImageFromImage(fontClear, tempCharRecs[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
font.baseSize = (int)CHAR_HEIGHT;
|
||||||
|
|
||||||
|
return font;
|
||||||
|
}
|
62
src/main.c
62
src/main.c
|
@ -1,9 +1,7 @@
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
#include "rogue.h"
|
#include "fileToCharArray.h"
|
||||||
|
#include "fontLoader.h"
|
||||||
Entity *player;
|
|
||||||
Tile **map;
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
@ -105,48 +103,50 @@ int main(void)
|
||||||
'~',
|
'~',
|
||||||
127,
|
127,
|
||||||
};
|
};
|
||||||
InitWindow(800, 600, "Font test");
|
static unsigned int const window_width = 800;
|
||||||
|
static unsigned int const window_height = 360;
|
||||||
|
|
||||||
Font tiny = LoadFont("resources/tiny.png");
|
static unsigned int const screen_scale_factor = 10;
|
||||||
RenderTexture2D target = LoadRenderTexture(80, 60);
|
static unsigned int const screen_width = window_width / screen_scale_factor;
|
||||||
|
static unsigned int const screen_height = window_height / screen_scale_factor;
|
||||||
|
|
||||||
static const int font_size = 6;
|
InitWindow(window_width, window_height, "Font test");
|
||||||
float const charWidth = MeasureTextEx(tiny, " ", font_size, 0).x;
|
|
||||||
|
// Image tinyImage = LoadImageFromMemory(".png", tinyFontBytes, sizeof(tinyFontBytes));
|
||||||
|
|
||||||
|
Font manualTinyFont = LoadTinyFont();
|
||||||
|
// Font tinyFont = LoadFontFromImage(manualTiny, MAGENTA, ' ');
|
||||||
|
RenderTexture2D target = LoadRenderTexture(screen_width, screen_height);
|
||||||
|
|
||||||
|
// bytesToFile(tinyImage.data, tinyImage.width * tinyImage.height * sizeof(Color), "include/tinyData.h", "tinyImageDataBytes");
|
||||||
|
|
||||||
|
static float const font_spacing = 0;
|
||||||
|
|
||||||
|
float const char_width = manualTinyFont.recs->width;
|
||||||
|
float const font_size = manualTinyFont.recs->height;
|
||||||
|
|
||||||
BeginTextureMode(target);
|
BeginTextureMode(target);
|
||||||
ClearBackground(BLACK);
|
ClearBackground(BLACK);
|
||||||
for (unsigned char i = 0; i < 96; i++)
|
for (unsigned char i = 0; i < 96; i++)
|
||||||
{
|
{
|
||||||
float const x = i * charWidth;
|
float const x = fmodf(i * char_width, screen_width);
|
||||||
float const y = ((int)x / target.texture.width) * font_size;
|
float const y = ((int)(i * char_width) / screen_width) * font_size;
|
||||||
char const *const text = TextFormat("%c", chars[i]);
|
char const *const text = TextFormat("%c", chars[i]);
|
||||||
if (y != 0)
|
DrawTextEx(manualTinyFont, text, (Vector2){x, y}, font_size, font_spacing, WHITE);
|
||||||
{
|
|
||||||
TraceLog(LOG_INFO, TextFormat("i: %i, x: %f, y: %f", i, x, y));
|
|
||||||
}
|
|
||||||
DrawTextEx(tiny, text, (Vector2){x, y}, font_size, 2, WHITE);
|
|
||||||
}
|
}
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
|
|
||||||
while (!WindowShouldClose())
|
while (!WindowShouldClose())
|
||||||
{
|
{
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
DrawTexturePro(target.texture, (Rectangle){0, 0, 80, -60}, (Rectangle){0, 0, 800, 600}, (Vector2){0, 0}, 0, WHITE);
|
DrawTexturePro(target.texture,
|
||||||
|
(Rectangle){0, 0, screen_width, -(float)screen_height},
|
||||||
|
(Rectangle){0, 0, window_width, window_height},
|
||||||
|
(Vector2){0, 0},
|
||||||
|
0,
|
||||||
|
WHITE);
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseWindow();
|
|
||||||
return 0;
|
return 0;
|
||||||
/*
|
|
||||||
initGame();
|
|
||||||
|
|
||||||
// Main game loop
|
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
|
||||||
{
|
|
||||||
mainLoop();
|
|
||||||
}
|
|
||||||
|
|
||||||
endGame();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
*/
|
|
||||||
}
|
}
|
65
src/map.c
65
src/map.c
|
@ -1,65 +0,0 @@
|
||||||
#include "rogue.h"
|
|
||||||
|
|
||||||
Tile **createMapTiles(void)
|
|
||||||
{
|
|
||||||
Tile **tiles = MemAlloc(sizeof(Tile *) * MAP_WIDTH);
|
|
||||||
|
|
||||||
for (unsigned int x = 0; x < MAP_WIDTH; x++)
|
|
||||||
{
|
|
||||||
tiles[x] = MemAlloc(sizeof(Tile) * MAP_HEIGHT);
|
|
||||||
for (unsigned int y = 0; y < MAP_HEIGHT; y++)
|
|
||||||
{
|
|
||||||
tiles[x][y].color = WALL_COLOR;
|
|
||||||
tiles[x][y].walkable = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return tiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const unsigned int MIN_ROOM_WIDTH = 5;
|
|
||||||
static const unsigned int MIN_ROOM_HEIGHT = 3;
|
|
||||||
|
|
||||||
static const unsigned int MAX_ROOM_WIDTH = 20;
|
|
||||||
static const unsigned int MAX_ROOM_HEIGHT = 10;
|
|
||||||
|
|
||||||
Vector2i setupMap(void)
|
|
||||||
{
|
|
||||||
int y, x, height, width, n_rooms;
|
|
||||||
n_rooms = GetRandomValue(5, 15);
|
|
||||||
Vector2i start_pos;
|
|
||||||
|
|
||||||
Room *const rooms = MemAlloc(n_rooms * sizeof(Room));
|
|
||||||
|
|
||||||
for (int i = 0; i < n_rooms; i++)
|
|
||||||
{
|
|
||||||
x = GetRandomValue(1, MAP_WIDTH - MAX_ROOM_WIDTH - 1U);
|
|
||||||
y = GetRandomValue(1, MAP_HEIGHT - MAX_ROOM_HEIGHT - 1U);
|
|
||||||
|
|
||||||
width = GetRandomValue(MIN_ROOM_WIDTH, MAX_ROOM_WIDTH);
|
|
||||||
height = GetRandomValue(MIN_ROOM_HEIGHT, MAX_ROOM_HEIGHT);
|
|
||||||
|
|
||||||
rooms[i] = createRoom(x, y, width, height);
|
|
||||||
|
|
||||||
addRoomToMap(rooms[i]);
|
|
||||||
|
|
||||||
if (i > 0)
|
|
||||||
{
|
|
||||||
connectRoomCenters(rooms[i - 1].center, rooms[i].center);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
start_pos = (Vector2i){rooms[0].center.x, rooms[0].center.y};
|
|
||||||
|
|
||||||
MemFree(rooms);
|
|
||||||
|
|
||||||
return start_pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
void freeMapTiles(Tile **map_tiles)
|
|
||||||
{
|
|
||||||
for (unsigned int x = 0; x < MAP_WIDTH; x++)
|
|
||||||
{
|
|
||||||
MemFree(map_tiles[x]);
|
|
||||||
}
|
|
||||||
MemFree(map_tiles);
|
|
||||||
}
|
|
22
src/player.c
22
src/player.c
|
@ -1,22 +0,0 @@
|
||||||
#include "rogue.h"
|
|
||||||
#include "raylib.h"
|
|
||||||
|
|
||||||
Entity *createPlayer(Vector2i const start_position)
|
|
||||||
{
|
|
||||||
Entity *const newPlayer = MemAlloc(sizeof(Entity));
|
|
||||||
|
|
||||||
newPlayer->position = start_position;
|
|
||||||
newPlayer->color = PLAYER_COLOR;
|
|
||||||
|
|
||||||
return newPlayer;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool tryMovePlayer(Vector2i const new_position)
|
|
||||||
{
|
|
||||||
if (map[new_position.x][new_position.y].walkable)
|
|
||||||
{
|
|
||||||
player->position = new_position;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
63
src/room.c
63
src/room.c
|
@ -1,63 +0,0 @@
|
||||||
#include "rogue.h"
|
|
||||||
#include "raymath.h"
|
|
||||||
|
|
||||||
Room createRoom(int x, int y, int width, int height)
|
|
||||||
{
|
|
||||||
Room newRoom = {
|
|
||||||
.position = {x, y},
|
|
||||||
.height = height,
|
|
||||||
.width = width,
|
|
||||||
.center = {
|
|
||||||
x + (int)(width / 2),
|
|
||||||
y + (int)(height / 2),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
return newRoom;
|
|
||||||
}
|
|
||||||
|
|
||||||
void addRoomToMap(Room room)
|
|
||||||
{
|
|
||||||
for (int x = room.position.x; x < room.position.x + room.width; x++)
|
|
||||||
{
|
|
||||||
for (int y = room.position.y; y < room.position.y + room.height; y++)
|
|
||||||
{
|
|
||||||
map[x][y].color = FLOOR_COLOR;
|
|
||||||
map[x][y].walkable = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void connectRoomCenters(Vector2i center1, Vector2i center2)
|
|
||||||
{
|
|
||||||
Vector2i current = {
|
|
||||||
center1.x,
|
|
||||||
center1.y,
|
|
||||||
};
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
if (abs((current.x - 1) - center2.x) < abs(current.x - center2.x))
|
|
||||||
{
|
|
||||||
current.x--;
|
|
||||||
}
|
|
||||||
else if (abs((current.x + 1) - center2.x) < abs(current.x - center2.x))
|
|
||||||
{
|
|
||||||
current.x++;
|
|
||||||
}
|
|
||||||
else if (abs((current.y - 1) - center2.y) < abs(current.y - center2.y))
|
|
||||||
{
|
|
||||||
current.y--;
|
|
||||||
}
|
|
||||||
else if (abs((current.y + 1) - center2.y) < abs(current.y - center2.y))
|
|
||||||
{
|
|
||||||
current.y++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
map[current.x][current.y].color = FLOOR_COLOR;
|
|
||||||
map[current.x][current.y].walkable = true;
|
|
||||||
}
|
|
||||||
}
|
|
Reference in a new issue