I'm having a problem with drawing my game map in Raylib.
As far as I'm seeing the site's examples, everything is correct... However, when I run it, it doesn't show anything about the game, just the screen in the color I put (RAYWHITE).
I'm trying to initialize the map first, and then I'm going to move characters within it.
The game will have more maps and they are being read from .txt files W K D P J M are the important characters of the map, which are in the files. They will tell each character's starting position and map wall
Can anyone help me with this problem?
Here's the code:
#include "raylib.h"
#include <stdio.h>
#define LARGURA 1200
#define ALTURA 500
#define LINE 100
#define PAREDE 'W'
#define PAREDEDESTRUTIVEL 'D'
#define POCAO 'P'
#define POSINICIALMAGO 'J'
#define POSISINICIALMONSTRO 'M'
#define POSINICIALCRIATURA 'K'
#define TAMANHO 40
int main(void){
FILE *file;
char path[] = "Mapa/mapa1.txt";
int x,y, posInicialMago[2], posMago[2], posInicialCriatura[2], posCriatura[2], posInicialMonstro[2], posMonstro[2];
char caracter;
file = fopen(path,"r");
if(file == NULL)
printf("Erro na abertura do arquivo! \n");
else
{
InitWindow(LARGURA, ALTURA, "Jogo");
SetTargetFPS(60);
x = y = 0;
Texture2D mage = LoadTexture("./Texturas/mage (1).png");
Texture2D fairy = LoadTexture("./Texturas/fairy (1).png");
Texture2D potion = LoadTexture("./Texturas/potion (1).png");
Texture2D monster = LoadTexture("./Texturas/monster (1).png");
Texture2D wall = LoadTexture("./Texturas/wall (1).png");
Texture2D indestructibleWall = LoadTexture("./Texturas/wall (1).png");
while (!WindowShouldClose())
{
BeginDrawing();
ClearBackground(RAYWHITE);
do
{
caracter = fgetc(file);
switch(caracter)
{
case PAREDE:
DrawTexture(indestructibleWall, x,y, BROWN);
break;
case PAREDEDESTRUTIVEL:
DrawTexture(wall, x,y, BROWN);
break;
case POCAO:
DrawTexture(potion, x,y, BLUE);
break;
case POSINICIALMAGO:
DrawTexture(mage, x,y, RAYWHITE);
posInicialMago[0] = posMago[0] = x;
posInicialMago[1] = posMago[1] = y;
break;
case POSINICIALCRIATURA:
DrawTexture(fairy, x,y, PURPLE);
posInicialCriatura[0] = x;
posInicialCriatura[1] = y;
break;
case POSISINICIALMONSTRO:
DrawTexture(monster, x,y, BLACK);
posInicialMonstro[0] = x;
posInicialMonstro[1] = y;
break;
case '\n':
break;
default:
DrawRectangle(LARGURA, ALTURA, x, y, DARKGRAY);
break;
}
x += TAMANHO;
if(caracter == '\n')
{
y += TAMANHO;
x = 0;
}
}while(caracter != EOF);
EndDrawing();
if (IsKeyPressed(KEY_RIGHT)) posMago[0] += TAMANHO;
if (IsKeyPressed(KEY_LEFT)) posMago[0] -= TAMANHO;
if (IsKeyPressed(KEY_UP)) posMago[1] -= TAMANHO;
if (IsKeyPressed(KEY_DOWN)) posMago[1] += TAMANHO;
}
}
fclose(file);
CloseWindow();
return 0;
}